Skip to content

Commit

Permalink
cssort --key=checker: sort ShellCheck defects by the [SC1234] suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudka committed Mar 2, 2018
1 parent 8673651 commit c240f53
Show file tree
Hide file tree
Showing 5 changed files with 12,404 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cssort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/foreach.hpp>
#include <boost/program_options.hpp>
#include <boost/regex.hpp>

class SortFactory {
public:
Expand Down Expand Up @@ -134,9 +135,26 @@ bool operator<(const DefByChecker &a, const DefByChecker &b) {
// compare checker names
RETURN_IF_COMPARED(a, b, checker);

// compare name of the key events
// resolve key events
const DefEvent &ea = a.events[a.keyEventIdx];
const DefEvent &eb = b.events[b.keyEventIdx];

if ("SHELLCHECK_WARNING" == a.checker /* == b.checker */) {
// sort ShellCheck warnings by the [SC1234] suffixes
const boost::regex reCode("^.* \\[SC([0-9]+)\\]$");
std::string aCode, bCode;
boost::smatch sm;
if (boost::regex_match(ea.msg, sm, reCode))
aCode = sm[1];
if (boost::regex_match(eb.msg, sm, reCode))
bCode = sm[1];
if (aCode < bCode)
return true;
if (bCode < aCode)
return false;
}

// compare name of the key events
RETURN_IF_COMPARED(ea, eb, event);

return cmpFileNames(a, b);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ test_cssort(cssort-5.8 00)
test_cssort(cssort-5.8 01)
test_cssort(cssort-5.8 02)
test_cssort(cssort-5.8 03)
test_cssort(cssort-misc 00)

# csdiff tests
test_csdiff(diff5.9-kernel 00)
Expand Down
Loading

0 comments on commit c240f53

Please sign in to comment.