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 4, 2024
1 parent 874b5a5 commit c09b7a9
Show file tree
Hide file tree
Showing 8 changed files with 12,871 additions and 5,802 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 @@ -230,16 +230,14 @@ static void sarifEncodeLoc(object *pLoc, const Defect &def, unsigned idx)

// 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.

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"uri": "test.c"
},
"region": {
"startLine": 0
"startLine": 0,
"endLine": 0
}
}
}
Expand All @@ -53,7 +54,8 @@
"uri": "test.c"
},
"region": {
"startLine": 0
"startLine": 0,
"endLine": 0
}
},
"message": {
Expand Down
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 c09b7a9

Please sign in to comment.