From b73278ee727f8200f523b244ba8bf1e16a63b9bd Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Thu, 8 Sep 2022 12:46:28 +0200 Subject: [PATCH] json-parser: basic support for ShellCheck's JSON output ... which is produced by `shellcheck --format=json ...` Fixes: https://github.com/csutils/csdiff/issues/75 --- src/json-parser.cc | 59 + .../csgrep/97-json-parser-shellcheck-args.txt | 1 + .../97-json-parser-shellcheck-stdin.txt | 1330 +++++++++++++++++ .../97-json-parser-shellcheck-stdout.txt | 724 +++++++++ tests/csgrep/CMakeLists.txt | 1 + 5 files changed, 2115 insertions(+) create mode 100644 tests/csgrep/97-json-parser-shellcheck-args.txt create mode 100644 tests/csgrep/97-json-parser-shellcheck-stdin.txt create mode 100644 tests/csgrep/97-json-parser-shellcheck-stdout.txt diff --git a/src/json-parser.cc b/src/json-parser.cc index 23206a84..835eea98 100644 --- a/src/json-parser.cc +++ b/src/json-parser.cc @@ -109,6 +109,15 @@ class GccTreeDecoder: public AbstractTreeDecoder { const GccPostProcessor postProc; }; +/// tree decoder of the JSON format produced by ShellCheck +class ShellCheckTreeDecoder: public AbstractTreeDecoder { + public: + bool readNode(Defect *def, pt::ptree::const_iterator defIter) override; + + private: + const GccPostProcessor postProc; +}; + struct JsonParser::Private { InStream &input; AbstractTreeDecoder *decoder = nullptr; @@ -168,7 +177,11 @@ JsonParser::JsonParser(InStream &input): else if (findChildOf(&node, d->root, "runs")) // SARIF format d->decoder = new SarifTreeDecoder; + else if (findChildOf(&node, d->root, "comments")) + // ShellCheck JSON format + d->decoder = new ShellCheckTreeDecoder; else if (first.not_found() != first.find("kind")) + // GCC JSON format d->decoder = new GccTreeDecoder; else throw pt::ptree_error("unknown JSON format"); @@ -781,3 +794,49 @@ bool GccTreeDecoder::readNode(Defect *def, pt::ptree::const_iterator defIter) return true; } + +static bool scReadEvent(DefEvent *pEvt, const pt::ptree &evtNode) +{ + using std::string; + + // read level (error, warning, note) + string &evtName = pEvt->event; + evtName = valueOf(evtNode, "level", ""); + if (evtName.empty()) + return false; + + // read location + pEvt->fileName = valueOf(evtNode, "file", ""); + pEvt->line = valueOf (evtNode, "line", 0); + pEvt->column = valueOf (evtNode, "byte-column", 0); + + // read message + pEvt->msg = valueOf(evtNode, "message", ""); + + // append [SC...] if available + const string code = valueOf(evtNode, "code", ""); + if (!code.empty()) + pEvt->msg += " [SC" + code + "]"; + + return true; +} + +bool ShellCheckTreeDecoder::readNode( + Defect *def, + pt::ptree::const_iterator defIter) +{ + *def = Defect("SHELLCHECK_WARNING"); + const pt::ptree &defNode = defIter->second; + + // read key event + def->events.push_back(DefEvent()); + if (!scReadEvent(&def->events.back(), defNode)) + return false; + + // TODO: go through fix/replacements nodes + + // apply post-processing rules + this->postProc.apply(def); + + return true; +} diff --git a/tests/csgrep/97-json-parser-shellcheck-args.txt b/tests/csgrep/97-json-parser-shellcheck-args.txt new file mode 100644 index 00000000..7df3c951 --- /dev/null +++ b/tests/csgrep/97-json-parser-shellcheck-args.txt @@ -0,0 +1 @@ +--mode=json diff --git a/tests/csgrep/97-json-parser-shellcheck-stdin.txt b/tests/csgrep/97-json-parser-shellcheck-stdin.txt new file mode 100644 index 00000000..8969093a --- /dev/null +++ b/tests/csgrep/97-json-parser-shellcheck-stdin.txt @@ -0,0 +1,1330 @@ +{ + "comments": [ + { + "file": "tests/test-lib.sh", + "line": 1, + "endLine": 1, + "column": 1, + "endColumn": 1, + "level": "error", + "code": 2148, + "message": "Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.", + "fix": null + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 2, + "endLine": 2, + "column": 8, + "endColumn": 14, + "level": "warning", + "code": 2155, + "message": "Declare and assign separately to avoid masking return values.", + "fix": null + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 5, + "endLine": 5, + "column": 8, + "endColumn": 12, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 5, + "endLine": 5, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 8, + "replacement": "\"", + "endColumn": 8 + }, + { + "line": 5, + "endLine": 5, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 12, + "replacement": "\"", + "endColumn": 12 + } + ] + } + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 7, + "endLine": 7, + "column": 31, + "endColumn": 37, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 7, + "endLine": 7, + "precedence": 22, + "insertionPoint": "afterEnd", + "column": 31, + "replacement": "\"", + "endColumn": 31 + }, + { + "line": 7, + "endLine": 7, + "precedence": 22, + "insertionPoint": "beforeStart", + "column": 37, + "replacement": "\"", + "endColumn": 37 + } + ] + } + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 9, + "endLine": 9, + "column": 33, + "endColumn": 41, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 9, + "endLine": 9, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 33, + "replacement": "\"", + "endColumn": 33 + }, + { + "line": 9, + "endLine": 9, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 41, + "replacement": "\"", + "endColumn": 41 + } + ] + } + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 9, + "endLine": 9, + "column": 56, + "endColumn": 69, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 9, + "endLine": 9, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 9, + "endLine": 9, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 69, + "replacement": "\"", + "endColumn": 69 + } + ] + } + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 10, + "endLine": 10, + "column": 33, + "endColumn": 41, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 33, + "replacement": "\"", + "endColumn": 33 + }, + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 41, + "replacement": "\"", + "endColumn": 41 + } + ] + } + }, + { + "file": "tests/cssort/sync-diff.sh", + "line": 10, + "endLine": 10, + "column": 56, + "endColumn": 69, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 10, + "endLine": 10, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 10, + "endLine": 10, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 69, + "replacement": "\"", + "endColumn": 69 + } + ] + } + }, + { + "file": "tests/cslinker/0002-xml-parser/runtest.sh", + "line": 6, + "endLine": 6, + "column": 3, + "endColumn": 36, + "level": "info", + "code": 1091, + "message": "Not following: ./../../test-lib.sh was not specified as input (see shellcheck -x).", + "fix": null + }, + { + "file": "tests/cslinker/0002-xml-parser/runtest.sh", + "line": 6, + "endLine": 6, + "column": 3, + "endColumn": 18, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 6, + "endLine": 6, + "precedence": 7, + "insertionPoint": "afterEnd", + "column": 3, + "replacement": "\"", + "endColumn": 3 + }, + { + "line": 6, + "endLine": 6, + "precedence": 7, + "insertionPoint": "beforeStart", + "column": 18, + "replacement": "\"", + "endColumn": 18 + } + ] + } + }, + { + "file": "tests/cslinker/0001-smoke/runtest.sh", + "line": 6, + "endLine": 6, + "column": 3, + "endColumn": 36, + "level": "info", + "code": 1091, + "message": "Not following: ./../../test-lib.sh was not specified as input (see shellcheck -x).", + "fix": null + }, + { + "file": "tests/cslinker/0001-smoke/runtest.sh", + "line": 6, + "endLine": 6, + "column": 3, + "endColumn": 18, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 6, + "endLine": 6, + "precedence": 7, + "insertionPoint": "afterEnd", + "column": 3, + "replacement": "\"", + "endColumn": 3 + }, + { + "line": 6, + "endLine": 6, + "precedence": 7, + "insertionPoint": "beforeStart", + "column": 18, + "replacement": "\"", + "endColumn": 18 + } + ] + } + }, + { + "file": "tests/csgrep/sync.sh", + "line": 1, + "endLine": 1, + "column": 1, + "endColumn": 1, + "level": "error", + "code": 1071, + "message": "ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!", + "fix": null + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 2, + "endLine": 2, + "column": 8, + "endColumn": 14, + "level": "warning", + "code": 2155, + "message": "Declare and assign separately to avoid masking return values.", + "fix": null + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 2, + "endLine": 2, + "column": 16, + "endColumn": 59, + "level": "style", + "code": 2006, + "message": "Use $(...) notation instead of legacy backticked `...`.", + "fix": { + "replacements": [ + { + "line": 2, + "endLine": 2, + "precedence": 9, + "insertionPoint": "afterEnd", + "column": 16, + "replacement": "$(", + "endColumn": 17 + }, + { + "line": 2, + "endLine": 2, + "precedence": 9, + "insertionPoint": "beforeStart", + "column": 58, + "replacement": ")", + "endColumn": 59 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 5, + "endLine": 5, + "column": 8, + "endColumn": 10, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 5, + "endLine": 5, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 8, + "replacement": "\"", + "endColumn": 8 + }, + { + "line": 5, + "endLine": 5, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 10, + "replacement": "\"", + "endColumn": 10 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 10, + "endLine": 10, + "column": 24, + "endColumn": 30, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 24, + "replacement": "\"", + "endColumn": 24 + }, + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 30, + "replacement": "\"", + "endColumn": 30 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 10, + "endLine": 10, + "column": 39, + "endColumn": 45, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 39, + "replacement": "\"", + "endColumn": 39 + }, + { + "line": 10, + "endLine": 10, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 45, + "replacement": "\"", + "endColumn": 45 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 10, + "endLine": 10, + "column": 56, + "endColumn": 62, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 10, + "endLine": 10, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 10, + "endLine": 10, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 62, + "replacement": "\"", + "endColumn": 62 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 11, + "endLine": 11, + "column": 24, + "endColumn": 30, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 11, + "endLine": 11, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 24, + "replacement": "\"", + "endColumn": 24 + }, + { + "line": 11, + "endLine": 11, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 30, + "replacement": "\"", + "endColumn": 30 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 11, + "endLine": 11, + "column": 39, + "endColumn": 45, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 11, + "endLine": 11, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 39, + "replacement": "\"", + "endColumn": 39 + }, + { + "line": 11, + "endLine": 11, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 45, + "replacement": "\"", + "endColumn": 45 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 11, + "endLine": 11, + "column": 56, + "endColumn": 62, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 11, + "endLine": 11, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 11, + "endLine": 11, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 62, + "replacement": "\"", + "endColumn": 62 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 12, + "endLine": 12, + "column": 24, + "endColumn": 30, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 12, + "endLine": 12, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 24, + "replacement": "\"", + "endColumn": 24 + }, + { + "line": 12, + "endLine": 12, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 30, + "replacement": "\"", + "endColumn": 30 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 12, + "endLine": 12, + "column": 39, + "endColumn": 45, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 12, + "endLine": 12, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 39, + "replacement": "\"", + "endColumn": 39 + }, + { + "line": 12, + "endLine": 12, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 45, + "replacement": "\"", + "endColumn": 45 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 12, + "endLine": 12, + "column": 56, + "endColumn": 62, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 12, + "endLine": 12, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 12, + "endLine": 12, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 62, + "replacement": "\"", + "endColumn": 62 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 13, + "endLine": 13, + "column": 24, + "endColumn": 30, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 13, + "endLine": 13, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 24, + "replacement": "\"", + "endColumn": 24 + }, + { + "line": 13, + "endLine": 13, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 30, + "replacement": "\"", + "endColumn": 30 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 13, + "endLine": 13, + "column": 39, + "endColumn": 45, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 13, + "endLine": 13, + "precedence": 16, + "insertionPoint": "afterEnd", + "column": 39, + "replacement": "\"", + "endColumn": 39 + }, + { + "line": 13, + "endLine": 13, + "precedence": 16, + "insertionPoint": "beforeStart", + "column": 45, + "replacement": "\"", + "endColumn": 45 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 13, + "endLine": 13, + "column": 56, + "endColumn": 62, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 13, + "endLine": 13, + "precedence": 17, + "insertionPoint": "afterEnd", + "column": 56, + "replacement": "\"", + "endColumn": 56 + }, + { + "line": 13, + "endLine": 13, + "precedence": 17, + "insertionPoint": "beforeStart", + "column": 62, + "replacement": "\"", + "endColumn": 62 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 25, + "endLine": 25, + "column": 25, + "endColumn": 31, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 25, + "replacement": "\"", + "endColumn": 25 + }, + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 31, + "replacement": "\"", + "endColumn": 31 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 25, + "endLine": 25, + "column": 44, + "endColumn": 50, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 44, + "replacement": "\"", + "endColumn": 44 + }, + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 50, + "replacement": "\"", + "endColumn": 50 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 25, + "endLine": 25, + "column": 59, + "endColumn": 65, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 59, + "replacement": "\"", + "endColumn": 59 + }, + { + "line": 25, + "endLine": 25, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 65, + "replacement": "\"", + "endColumn": 65 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 25, + "endLine": 25, + "column": 76, + "endColumn": 82, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 25, + "endLine": 25, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 76, + "replacement": "\"", + "endColumn": 76 + }, + { + "line": 25, + "endLine": 25, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 82, + "replacement": "\"", + "endColumn": 82 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 26, + "endLine": 26, + "column": 25, + "endColumn": 31, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 25, + "replacement": "\"", + "endColumn": 25 + }, + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 31, + "replacement": "\"", + "endColumn": 31 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 26, + "endLine": 26, + "column": 44, + "endColumn": 50, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 44, + "replacement": "\"", + "endColumn": 44 + }, + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 50, + "replacement": "\"", + "endColumn": 50 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 26, + "endLine": 26, + "column": 59, + "endColumn": 65, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 59, + "replacement": "\"", + "endColumn": 59 + }, + { + "line": 26, + "endLine": 26, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 65, + "replacement": "\"", + "endColumn": 65 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 26, + "endLine": 26, + "column": 76, + "endColumn": 82, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 26, + "endLine": 26, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 76, + "replacement": "\"", + "endColumn": 76 + }, + { + "line": 26, + "endLine": 26, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 82, + "replacement": "\"", + "endColumn": 82 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 27, + "endLine": 27, + "column": 25, + "endColumn": 31, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 25, + "replacement": "\"", + "endColumn": 25 + }, + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 31, + "replacement": "\"", + "endColumn": 31 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 27, + "endLine": 27, + "column": 44, + "endColumn": 50, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 44, + "replacement": "\"", + "endColumn": 44 + }, + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 50, + "replacement": "\"", + "endColumn": 50 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 27, + "endLine": 27, + "column": 59, + "endColumn": 65, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 59, + "replacement": "\"", + "endColumn": 59 + }, + { + "line": 27, + "endLine": 27, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 65, + "replacement": "\"", + "endColumn": 65 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 27, + "endLine": 27, + "column": 76, + "endColumn": 82, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 27, + "endLine": 27, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 76, + "replacement": "\"", + "endColumn": 76 + }, + { + "line": 27, + "endLine": 27, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 82, + "replacement": "\"", + "endColumn": 82 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 28, + "endLine": 28, + "column": 25, + "endColumn": 31, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 25, + "replacement": "\"", + "endColumn": 25 + }, + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 31, + "replacement": "\"", + "endColumn": 31 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 28, + "endLine": 28, + "column": 44, + "endColumn": 50, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 44, + "replacement": "\"", + "endColumn": 44 + }, + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 50, + "replacement": "\"", + "endColumn": 50 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 28, + "endLine": 28, + "column": 59, + "endColumn": 65, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "afterEnd", + "column": 59, + "replacement": "\"", + "endColumn": 59 + }, + { + "line": 28, + "endLine": 28, + "precedence": 13, + "insertionPoint": "beforeStart", + "column": 65, + "replacement": "\"", + "endColumn": 65 + } + ] + } + }, + { + "file": "tests/csdiff/sync-diff.sh", + "line": 28, + "endLine": 28, + "column": 76, + "endColumn": 82, + "level": "info", + "code": 2086, + "message": "Double quote to prevent globbing and word splitting.", + "fix": { + "replacements": [ + { + "line": 28, + "endLine": 28, + "precedence": 14, + "insertionPoint": "afterEnd", + "column": 76, + "replacement": "\"", + "endColumn": 76 + }, + { + "line": 28, + "endLine": 28, + "precedence": 14, + "insertionPoint": "beforeStart", + "column": 82, + "replacement": "\"", + "endColumn": 82 + } + ] + } + }, + { + "file": "tests/csdiff/diff-misc/sync.sh", + "line": 1, + "endLine": 1, + "column": 1, + "endColumn": 1, + "level": "error", + "code": 1071, + "message": "ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!", + "fix": null + }, + { + "file": "make-srpm.sh", + "line": 41, + "endLine": 41, + "column": 8, + "endColumn": 37, + "level": "style", + "code": 2001, + "message": "See if you can use ${variable//search/replace} instead.", + "fix": null + }, + { + "file": "make-srpm.sh", + "line": 46, + "endLine": 46, + "column": 8, + "endColumn": 48, + "level": "style", + "code": 2001, + "message": "See if you can use ${variable//search/replace} instead.", + "fix": null + }, + { + "file": "make-srpm.sh", + "line": 58, + "endLine": 58, + "column": 19, + "endColumn": 23, + "level": "warning", + "code": 2064, + "message": "Use single quotes, otherwise this expands now rather than when signalled.", + "fix": null + } + ] +} diff --git a/tests/csgrep/97-json-parser-shellcheck-stdout.txt b/tests/csgrep/97-json-parser-shellcheck-stdout.txt new file mode 100644 index 00000000..c5b21e5e --- /dev/null +++ b/tests/csgrep/97-json-parser-shellcheck-stdout.txt @@ -0,0 +1,724 @@ +{ + "defects": [ + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/test-lib.sh", + "line": 1, + "event": "error[SC2148]", + "message": "Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 2, + "event": "warning[SC2155]", + "message": "Declare and assign separately to avoid masking return values.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 5, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 7, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 9, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 9, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 10, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cssort/sync-diff.sh", + "line": 10, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cslinker/0002-xml-parser/runtest.sh", + "line": 6, + "event": "info[SC1091]", + "message": "Not following: ./../../test-lib.sh was not specified as input (see shellcheck -x).", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cslinker/0002-xml-parser/runtest.sh", + "line": 6, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cslinker/0001-smoke/runtest.sh", + "line": 6, + "event": "info[SC1091]", + "message": "Not following: ./../../test-lib.sh was not specified as input (see shellcheck -x).", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/cslinker/0001-smoke/runtest.sh", + "line": 6, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csgrep/sync.sh", + "line": 1, + "event": "error[SC1071]", + "message": "ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 2, + "event": "warning[SC2155]", + "message": "Declare and assign separately to avoid masking return values.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 2, + "event": "style[SC2006]", + "message": "Use $(...) notation instead of legacy backticked `...`.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 5, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 10, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 10, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 10, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 11, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 11, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 11, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 12, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 12, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 12, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 13, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 13, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 13, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 25, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 25, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 25, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 25, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 26, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 26, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 26, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 26, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 27, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 27, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 27, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 27, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 28, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 28, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 28, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/sync-diff.sh", + "line": 28, + "event": "info[SC2086]", + "message": "Double quote to prevent globbing and word splitting.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "tests/csdiff/diff-misc/sync.sh", + "line": 1, + "event": "error[SC1071]", + "message": "ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "make-srpm.sh", + "line": 41, + "event": "style[SC2001]", + "message": "See if you can use ${variable//search/replace} instead.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "make-srpm.sh", + "line": 46, + "event": "style[SC2001]", + "message": "See if you can use ${variable//search/replace} instead.", + "verbosity_level": 0 + } + ] + }, + { + "checker": "SHELLCHECK_WARNING", + "language": "shell", + "tool": "shellcheck", + "key_event_idx": 0, + "events": [ + { + "file_name": "make-srpm.sh", + "line": 58, + "event": "warning[SC2064]", + "message": "Use single quotes, otherwise this expands now rather than when signalled.", + "verbosity_level": 0 + } + ] + } + ] +} diff --git a/tests/csgrep/CMakeLists.txt b/tests/csgrep/CMakeLists.txt index 404041ca..6eb5bbef 100644 --- a/tests/csgrep/CMakeLists.txt +++ b/tests/csgrep/CMakeLists.txt @@ -140,3 +140,4 @@ test_csgrep("93-csgrep-tool-predicate" ) test_csgrep("94-gcc-json" ) test_csgrep("95-gcc-sarif" ) test_csgrep("96-sarif-levels" ) +test_csgrep("97-json-parser-shellcheck" )