From 421cc742d5ae5e8670b4d628aef959feafb49e34 Mon Sep 17 00:00:00 2001 From: Chris Clearwater Date: Tue, 12 Nov 2024 14:22:46 -0800 Subject: [PATCH 1/3] --- linters/ruff/ruff.test.ts | 2 +- linters/ruff/ruff_to_sarif.py | 3 +- .../test_data/ruff_v0.2.1_syntax.check.shot | 43 +++++++++++++++++++ linters/ruff/test_data/syntax.in.py | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot create mode 100644 linters/ruff/test_data/syntax.in.py diff --git a/linters/ruff/ruff.test.ts b/linters/ruff/ruff.test.ts index 288de6565..4427e030a 100644 --- a/linters/ruff/ruff.test.ts +++ b/linters/ruff/ruff.test.ts @@ -3,7 +3,7 @@ import { linterCheckTest, linterFmtTest } from "tests"; import { TrunkLintDriver } from "tests/driver"; import { skipOS } from "tests/utils"; -linterCheckTest({ linterName: "ruff", namedTestPrefixes: ["basic", "interface"] }); +linterCheckTest({ linterName: "ruff", namedTestPrefixes: ["basic", "interface", "syntax"] }); const skipJupyterTestIf = (version?: string) => { if (!version || !semver.valid(version)) { diff --git a/linters/ruff/ruff_to_sarif.py b/linters/ruff/ruff_to_sarif.py index 20a81ace9..0f9a63a6f 100755 --- a/linters/ruff/ruff_to_sarif.py +++ b/linters/ruff/ruff_to_sarif.py @@ -30,7 +30,8 @@ def get_region(entry, column_offset=0): continue filepath = result["filename"] - rule_id = result["code"] + # Ruff will set code to null for syntax errors + rule_id = result["code"] or "syntax" message = result["message"] sarif_result = { diff --git a/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot new file mode 100644 index 000000000..8a963657f --- /dev/null +++ b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot @@ -0,0 +1,43 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing linter ruff test syntax 1`] = ` +{ + "issues": [ + { + "code": "E999", + "column": "1", + "file": "test_data/syntax.in.py", + "issueClass": "ISSUE_CLASS_EXISTING", + "issueUrl": "https://docs.astral.sh/ruff/rules/#E999", + "level": "LEVEL_HIGH", + "line": "2", + "linter": "ruff", + "message": "SyntaxError: unexpected EOF while parsing", + "targetType": "python", + }, + ], + "lintActions": [ + { + "command": "lint", + "fileGroupName": "python", + "linter": "ruff", + "paths": [ + "test_data/syntax.in.py", + ], + "verb": "TRUNK_VERB_CHECK", + }, + { + "command": "lint", + "fileGroupName": "python", + "linter": "ruff", + "paths": [ + "test_data/syntax.in.py", + ], + "upstream": true, + "verb": "TRUNK_VERB_CHECK", + }, + ], + "taskFailures": [], + "unformattedFiles": [], +} +`; diff --git a/linters/ruff/test_data/syntax.in.py b/linters/ruff/test_data/syntax.in.py new file mode 100644 index 000000000..4314b3c57 --- /dev/null +++ b/linters/ruff/test_data/syntax.in.py @@ -0,0 +1 @@ +def f(): { From 276fc8fc041a51d2a407b415a6c3c84ee6465860 Mon Sep 17 00:00:00 2001 From: Chris Clearwater Date: Tue, 12 Nov 2024 14:36:42 -0800 Subject: [PATCH 2/3] --- linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot index 8a963657f..56230b0f0 100644 --- a/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot +++ b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot @@ -4,11 +4,11 @@ exports[`Testing linter ruff test syntax 1`] = ` { "issues": [ { - "code": "E999", + "code": "syntax", "column": "1", "file": "test_data/syntax.in.py", "issueClass": "ISSUE_CLASS_EXISTING", - "issueUrl": "https://docs.astral.sh/ruff/rules/#E999", + "issueUrl": "https://docs.astral.sh/ruff/rules/#syntax", "level": "LEVEL_HIGH", "line": "2", "linter": "ruff", From c393eb677e0b26a14b7670d91cf15ac1ef570d19 Mon Sep 17 00:00:00 2001 From: Chris Clearwater Date: Tue, 12 Nov 2024 14:49:31 -0800 Subject: [PATCH 3/3] --- linters/ruff/ruff_to_sarif.py | 2 +- linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/linters/ruff/ruff_to_sarif.py b/linters/ruff/ruff_to_sarif.py index 0f9a63a6f..73e2afefc 100755 --- a/linters/ruff/ruff_to_sarif.py +++ b/linters/ruff/ruff_to_sarif.py @@ -31,7 +31,7 @@ def get_region(entry, column_offset=0): filepath = result["filename"] # Ruff will set code to null for syntax errors - rule_id = result["code"] or "syntax" + rule_id = result["code"] or "E999" message = result["message"] sarif_result = { diff --git a/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot index 56230b0f0..8a963657f 100644 --- a/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot +++ b/linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot @@ -4,11 +4,11 @@ exports[`Testing linter ruff test syntax 1`] = ` { "issues": [ { - "code": "syntax", + "code": "E999", "column": "1", "file": "test_data/syntax.in.py", "issueClass": "ISSUE_CLASS_EXISTING", - "issueUrl": "https://docs.astral.sh/ruff/rules/#syntax", + "issueUrl": "https://docs.astral.sh/ruff/rules/#E999", "level": "LEVEL_HIGH", "line": "2", "linter": "ruff",