Skip to content

Commit c240f53

Browse files
committed
cssort --key=checker: sort ShellCheck defects by the [SC1234] suffixes
1 parent 8673651 commit c240f53

File tree

5 files changed

+12404
-1
lines changed

5 files changed

+12404
-1
lines changed

cssort.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <boost/foreach.hpp>
2424
#include <boost/program_options.hpp>
25+
#include <boost/regex.hpp>
2526

2627
class SortFactory {
2728
public:
@@ -134,9 +135,26 @@ bool operator<(const DefByChecker &a, const DefByChecker &b) {
134135
// compare checker names
135136
RETURN_IF_COMPARED(a, b, checker);
136137

137-
// compare name of the key events
138+
// resolve key events
138139
const DefEvent &ea = a.events[a.keyEventIdx];
139140
const DefEvent &eb = b.events[b.keyEventIdx];
141+
142+
if ("SHELLCHECK_WARNING" == a.checker /* == b.checker */) {
143+
// sort ShellCheck warnings by the [SC1234] suffixes
144+
const boost::regex reCode("^.* \\[SC([0-9]+)\\]$");
145+
std::string aCode, bCode;
146+
boost::smatch sm;
147+
if (boost::regex_match(ea.msg, sm, reCode))
148+
aCode = sm[1];
149+
if (boost::regex_match(eb.msg, sm, reCode))
150+
bCode = sm[1];
151+
if (aCode < bCode)
152+
return true;
153+
if (bCode < aCode)
154+
return false;
155+
}
156+
157+
// compare name of the key events
140158
RETURN_IF_COMPARED(ea, eb, event);
141159

142160
return cmpFileNames(a, b);

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ test_cssort(cssort-5.8 00)
156156
test_cssort(cssort-5.8 01)
157157
test_cssort(cssort-5.8 02)
158158
test_cssort(cssort-5.8 03)
159+
test_cssort(cssort-misc 00)
159160

160161
# csdiff tests
161162
test_csdiff(diff5.9-kernel 00)

0 commit comments

Comments
 (0)