@@ -55,7 +55,7 @@ def make_sarif_run(tool_name: str) -> dict:
55
55
return sarif_run
56
56
57
57
58
- def flake8_linter (target : Path , * args ) -> None :
58
+ def flake8_linter (target : Path , * _args ) -> None :
59
59
"""Run the flake8 linter.
60
60
61
61
In contrast to the other linters, flake8 has plugin architecture.
@@ -155,7 +155,7 @@ def ruff_format_sarif(results: List[Dict[str, Any]], target: Path) -> dict:
155
155
return sarif_run
156
156
157
157
158
- def ruff_linter (target : Path , * args ) -> Optional [dict ]:
158
+ def ruff_linter (target : Path , * _args ) -> Optional [dict ]:
159
159
"""Run the ruff linter."""
160
160
try :
161
161
# pylint: disable=import-outside-toplevel
@@ -257,7 +257,7 @@ def pylint_format_sarif(results: List[Dict[str, Any]], target: Path) -> dict:
257
257
return sarif_run
258
258
259
259
260
- def pylint_linter (target : Path , * args ) -> Optional [dict ]:
260
+ def pylint_linter (target : Path , * _args ) -> Optional [dict ]:
261
261
"""Run the pylint linter."""
262
262
process = run (
263
263
["pylint" , "--output-format=json" , "--recursive=y" , target .absolute ().as_posix ()],
@@ -680,7 +680,7 @@ def fixit_format_sarif(results: str, target: Path) -> dict:
680
680
return sarif_run
681
681
682
682
683
- def fixit_linter (target : Path ) -> Optional [dict ]:
683
+ def fixit_linter (target : Path , * _args ) -> Optional [dict ]:
684
684
"""Run the fixit linter, from Meta."""
685
685
process = run (["fixit" , "lint" , target .absolute ().as_posix ()], capture_output = True , check = False )
686
686
@@ -712,6 +712,31 @@ def make_paths_relative_to_target(runs: List[dict], target: Path) -> None:
712
712
)
713
713
714
714
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
+
715
740
LINTERS = {
716
741
"pylint" : pylint_linter ,
717
742
"ruff" : ruff_linter ,
@@ -751,7 +776,7 @@ def main() -> None:
751
776
sarif_runs : List [dict ] = []
752
777
753
778
target = Path (args .target ).resolve ().absolute ()
754
- typeshed_path = Path (args .typeshed_path ).resolve ().absolute ()
779
+ typeshed_path = Path (args .typeshed_path ).resolve ().absolute () if args . typeshed_path is not None else None
755
780
756
781
for linter in args .linter :
757
782
LOG .debug ("Running %s" , linter )
0 commit comments