Skip to content

Commit

Permalink
writer-json-sarif: write endLine/endColumn unconditionally
Browse files Browse the repository at this point in the history
... paired with each startLine/startColumn to be compatible
with `shellcheck-sarif` and `sarif-fmt`.

Resolves: csutils#136
Closes: csutils#167
  • Loading branch information
kdudka committed Apr 9, 2024
1 parent f0fcbe9 commit 6477631
Show file tree
Hide file tree
Showing 7 changed files with 12,647 additions and 5,690 deletions.
8 changes: 3 additions & 5 deletions src/lib/writer-json-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,14 @@ static void sarifEncodeLoc(object *pLoc, const Defect &def, unsigned idx)
if (evt.line) {
// line start/end
object reg = {
{ "startLine", evt.line }
{ "startLine", evt.line },
{ "endLine", evt.line + evt.vSize }
};
if (0 < evt.vSize)
reg["endLine"] = evt.line + evt.vSize;

// column start/end
if (evt.column) {
reg["startColumn"] = evt.column;
if (0 < evt.hSize)
reg["endColumn"] = evt.column + evt.hSize;
reg["endColumn"] = evt.column + evt.hSize;
}

locPhy["region"] = std::move(reg);
Expand Down
1,360 changes: 1,020 additions & 340 deletions tests/csgrep/0080-sarif-writer-stdout.txt

Large diffs are not rendered by default.

13,167 changes: 8,778 additions & 4,389 deletions tests/csgrep/0081-sarif-writer-stdout.txt

Large diffs are not rendered by default.

154 changes: 110 additions & 44 deletions tests/csgrep/0085-sarif-writer-stdout.txt

Large diffs are not rendered by default.

1,816 changes: 1,362 additions & 454 deletions tests/csgrep/0096-sarif-levels-stdout.txt

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions tests/csgrep/0097-sarif-set-tool-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
},
"region": {
"startLine": 6,
"startColumn": 1
"endLine": 6,
"startColumn": 1,
"endColumn": 1
}
}
}
Expand All @@ -82,7 +84,9 @@
},
"region": {
"startLine": 6,
"startColumn": 1
"endLine": 6,
"startColumn": 1,
"endColumn": 1
}
},
"message": {
Expand Down Expand Up @@ -112,7 +116,9 @@
},
"region": {
"startLine": 4,
"startColumn": 7
"endLine": 4,
"startColumn": 7,
"endColumn": 7
}
}
}
Expand All @@ -134,7 +140,9 @@
},
"region": {
"startLine": 4,
"startColumn": 7
"endLine": 4,
"startColumn": 7,
"endColumn": 7
}
},
"message": {
Expand Down
1,816 changes: 1,362 additions & 454 deletions tests/csgrep/0109-shellcheck-sarif-cwe-stdout.txt

Large diffs are not rendered by default.

0 comments on commit 6477631

Please sign in to comment.