@@ -55,7 +55,7 @@ def make_sarif_run(tool_name: str) -> dict:
5555 return sarif_run
5656
5757
58- def flake8_linter (target : Path , * args ) -> None :
58+ def flake8_linter (target : Path , * _args ) -> None :
5959 """Run the flake8 linter.
6060
6161 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:
155155 return sarif_run
156156
157157
158- def ruff_linter (target : Path , * args ) -> Optional [dict ]:
158+ def ruff_linter (target : Path , * _args ) -> Optional [dict ]:
159159 """Run the ruff linter."""
160160 try :
161161 # pylint: disable=import-outside-toplevel
@@ -257,7 +257,7 @@ def pylint_format_sarif(results: List[Dict[str, Any]], target: Path) -> dict:
257257 return sarif_run
258258
259259
260- def pylint_linter (target : Path , * args ) -> Optional [dict ]:
260+ def pylint_linter (target : Path , * _args ) -> Optional [dict ]:
261261 """Run the pylint linter."""
262262 process = run (
263263 ["pylint" , "--output-format=json" , "--recursive=y" , target .absolute ().as_posix ()],
@@ -680,7 +680,7 @@ def fixit_format_sarif(results: str, target: Path) -> dict:
680680 return sarif_run
681681
682682
683- def fixit_linter (target : Path ) -> Optional [dict ]:
683+ def fixit_linter (target : Path , * _args ) -> Optional [dict ]:
684684 """Run the fixit linter, from Meta."""
685685 process = run (["fixit" , "lint" , target .absolute ().as_posix ()], capture_output = True , check = False )
686686
@@ -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+
715740LINTERS = {
716741 "pylint" : pylint_linter ,
717742 "ruff" : ruff_linter ,
@@ -751,7 +776,7 @@ def main() -> None:
751776 sarif_runs : List [dict ] = []
752777
753778 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
755780
756781 for linter in args .linter :
757782 LOG .debug ("Running %s" , linter )
0 commit comments