Skip to content

Commit c2c374a

Browse files
committed
Fix up SARIF locations
1 parent ae5422d commit c2c374a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python_lint.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,31 @@ def make_paths_relative_to_target(runs: List[dict], target: Path) -> None:
712712
)
713713

714714

715+
def fix_sarif_locations(runs: List[dict]) -> None:
716+
"""Fix the SARIF locations.
717+
718+
Normalise values less than 1 to 1, e.g. -1 or 0.
719+
720+
Convert strings to ints.
721+
722+
For anything that can't be converted to an int, set it to 1.
723+
"""
724+
for sarif_run in runs:
725+
for result in sarif_run["results"]:
726+
for location in result["locations"]:
727+
region = location["physicalLocation"]["region"]
728+
for key in ("startLine", "endLine", "startColumn", "endColumn"):
729+
if key in region:
730+
try:
731+
region[key] = int(region[key])
732+
except ValueError:
733+
LOG.error("Unable to convert %s to int", region[key])
734+
region[key] = 1
735+
continue
736+
if region[key] < 1:
737+
region[key] = 1
738+
739+
715740
LINTERS = {
716741
"pylint": pylint_linter,
717742
"ruff": ruff_linter,

0 commit comments

Comments
 (0)