Skip to content

Fix ruff for jupyter notebooks #986

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion linters/ruff/ruff_to_sarif.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ def get_region(entry, column_offset=0):
"ruleId": rule_id,
}

if "fix" in result and result["fix"] is not None:
have_fix = "fix" in result and result["fix"] is not None
# Skip autofixes specific to a jupyter notebook cell and they are difficult to apply.
have_cell = "cell" in result and result["cell"] is not None

if have_fix and not have_cell:
# Locations for jupyter notebooks are not relative to the file,
# so we can not easily handle them.
fixes = result["fix"]

# TODO(Tyler): If output format changes any more substantially, consider version-specific parsers
Expand Down
11 changes: 0 additions & 11 deletions linters/ruff/test_data/ruff_v0.6.0_basic_nb.check.shot
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ exports[`Testing linter ruff test basic_nb 1`] = `
{
"issues": [
{
"autofixOptions": [
{
"message": "Remove unused import: \`os\`",
"replacements": [
{
"filePath": "test_data/basic_nb.in.ipynb",
"length": "2",
},
],
},
],
"code": "F401",
"column": "1",
"file": "test_data/basic_nb.in.ipynb",
Expand Down
Loading