Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruff parsing for source files with syntax errors #914

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linters/ruff/ruff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion linters/ruff/ruff_to_sarif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
43 changes: 43 additions & 0 deletions linters/ruff/test_data/ruff_v0.2.1_syntax.check.shot
Original file line number Diff line number Diff line change
@@ -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": [],
}
`;
1 change: 1 addition & 0 deletions linters/ruff/test_data/syntax.in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def f(): {
Loading