Skip to content

Commit

Permalink
Fix ruff-nbqa (#815)
Browse files Browse the repository at this point in the history
Ruff `0.5.0` deprecated running on files without the `check` subcommand.
Fix our `ruff-nbqa` definition to support this and forward args
correctly. Fixes failures in
[run](https://github.com/trunk-io/plugins/actions/runs/9709549433/job/26798463120)
  • Loading branch information
TylerJang27 authored Jun 29, 2024
1 parent e8b2864 commit 70f8284
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
4 changes: 2 additions & 2 deletions linters/ruff/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ lint:
files: [jupyter]
commands:
- name: lint
run: nbqa ruff --cache-dir=${cachedir} ${target}
run: nbqa 'ruff check --cache-dir=${cachedir} --quiet' ${target}
output: pass_fail
batch: true
success_codes: [0, 1]
runtime: python
package: ruff
extra_packages: [nbqa==1.6.3]
extra_packages: [nbqa==1.8.5]
direct_configs: [ruff.toml]
affects_cache:
- pyproject.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ exports[`Testing linter ruff-nbqa test basic_nb 1`] = `
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"linter": "ruff-nbqa",
"message": "/tmp/plugins_/test_data/basic_nb.in.ipynb:cell_1:1:8: F401 [*] \`os\` imported but unused
Found 1 error.
[*] 1 potentially fixable with the --fix option.",
"message": "/tmp/plugins_/test_data/basic_nb.in.ipynb:cell_1:1:8: F401 [*] \`os\` imported but unused",
"targetType": "jupyter",
},
],
Expand Down
4 changes: 1 addition & 3 deletions linters/ruff/test_data/ruff_nbqa_v0.1.0_basic_nb.check.shot
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ exports[`Testing linter ruff-nbqa test basic_nb 1`] = `
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"linter": "ruff-nbqa",
"message": "/tmp/plugins_/test_data/basic_nb.in.ipynb:cell_1:1:8: F401 [*] \`os\` imported but unused
Found 1 error.
[*] 1 fixable with the \`--fix\` option.",
"message": "/tmp/plugins_/test_data/basic_nb.in.ipynb:cell_1:1:8: F401 [*] \`os\` imported but unused",
"targetType": "jupyter",
},
],
Expand Down
48 changes: 48 additions & 0 deletions linters/ruff/test_data/ruff_nbqa_v0.5.0_basic_nb.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter ruff-nbqa test basic_nb 1`] = `
{
"issues": [
{
"code": "error",
"file": "test_data/basic_nb.in.ipynb",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"linter": "ruff-nbqa",
"message": "/tmp/plugins_/test_data/basic_nb.in.ipynb:cell_1:1:8: F401 [*] \`os\` imported but unused
|
1 | # %%NBQA-CELL-SEP
2 | import os
| ^^ F401
3 |
4 | print("Hello World!")
|
= help: Remove unused import: \`os\`",
"targetType": "jupyter",
},
],
"lintActions": [
{
"command": "lint",
"fileGroupName": "jupyter",
"linter": "ruff-nbqa",
"paths": [
"test_data/basic_nb.in.ipynb",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "jupyter",
"linter": "ruff-nbqa",
"paths": [
"test_data/basic_nb.in.ipynb",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;
1 change: 1 addition & 0 deletions tests/utils/landing_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const normalizeMessage = (message?: string) =>
.replaceAll("\\", "/")
.replace(/\/plugins_.{6}/gm, "/plugins_")
.replace(".dup.", ".")
.replace(/NBQA-CELL-SEP.{6}/gm, "NBQA-CELL-SEP")
.trim();

// trunk-ignore(eslint/@typescript-eslint/no-non-null-assertion)
Expand Down

0 comments on commit 70f8284

Please sign in to comment.