From 6f31e9c00eee00e30781f3395ce9f286520f2254 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 24 Oct 2023 17:28:35 -0500 Subject: [PATCH] Match rule prefixes from `external` codes setting in `unused-noqa` (#8177) Supersedes https://github.com/astral-sh/ruff/pull/8176 Closes https://github.com/astral-sh/ruff/pull/8174 ## Test plan Old snapshot contains the new / unmatched `V` code New snapshot contains no `V` prefixed codes --- .../resources/test/fixtures/ruff/RUF100_0.py | 3 + crates/ruff_linter/src/checkers/noqa.rs | 5 +- crates/ruff_linter/src/rules/ruff/mod.rs | 21 +- ..._linter__rules__ruff__tests__ruf100_0.snap | 226 ++++++++------- ...__rules__ruff__tests__ruf100_0_prefix.snap | 267 ++++++++++++++++++ crates/ruff_linter/src/settings/mod.rs | 5 +- crates/ruff_workspace/src/configuration.rs | 2 +- crates/ruff_workspace/src/options.rs | 8 +- ruff.schema.json | 4 +- 9 files changed, 426 insertions(+), 115 deletions(-) create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF100_0.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF100_0.py index 5e51807ef90c9..25c8854b5434c 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF100_0.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF100_0.py @@ -21,6 +21,9 @@ def f() -> None: # Invalid (but external) d = 1 # noqa: F841, V101 + # Invalid (but external) + d = 1 # noqa: V500 + # fmt: off # Invalid - no space before # d = 1# noqa: E501 diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index fcd86d70fc8ae..7b4224c4e1e99 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -128,7 +128,10 @@ pub(crate) fn check_noqa( } if line.matches.iter().any(|match_| *match_ == code) - || settings.external.contains(code) + || settings + .external + .iter() + .any(|external| code.starts_with(external)) { valid_codes.push(code); } else { diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 59cf6fa350657..6e89cc19c82eb 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -106,7 +106,26 @@ mod tests { let diagnostics = test_path( Path::new("ruff/RUF100_0.py"), &settings::LinterSettings { - external: FxHashSet::from_iter(vec!["V101".to_string()]), + external: vec!["V101".to_string()], + ..settings::LinterSettings::for_rules(vec![ + Rule::UnusedNOQA, + Rule::LineTooLong, + Rule::UnusedImport, + Rule::UnusedVariable, + Rule::TabIndentation, + ]) + }, + )?; + assert_messages!(diagnostics); + Ok(()) + } + + #[test] + fn ruf100_0_prefix() -> Result<()> { + let diagnostics = test_path( + Path::new("ruff/RUF100_0.py"), + &settings::LinterSettings { + external: vec!["V".to_string()], ..settings::LinterSettings::for_rules(vec![ Rule::UnusedNOQA, Rule::LineTooLong, diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap index 956aa90abd781..911789f49f078 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap @@ -86,7 +86,7 @@ RUF100_0.py:22:12: RUF100 [*] Unused `noqa` directive (unused: `F841`) 22 | d = 1 # noqa: F841, V101 | ^^^^^^^^^^^^^^^^^^ RUF100 23 | -24 | # fmt: off +24 | # Invalid (but external) | = help: Remove unused `noqa` directive @@ -97,171 +97,191 @@ RUF100_0.py:22:12: RUF100 [*] Unused `noqa` directive (unused: `F841`) 22 |- d = 1 # noqa: F841, V101 22 |+ d = 1 # noqa: V101 23 23 | -24 24 | # fmt: off -25 25 | # Invalid - no space before # +24 24 | # Invalid (but external) +25 25 | d = 1 # noqa: V500 -RUF100_0.py:26:10: RUF100 [*] Unused `noqa` directive (unused: `E501`) +RUF100_0.py:25:12: RUF100 [*] Unused `noqa` directive (unknown: `V500`) | -24 | # fmt: off -25 | # Invalid - no space before # -26 | d = 1# noqa: E501 - | ^^^^^^^^^^^^ RUF100 -27 | -28 | # Invalid - many spaces before # +24 | # Invalid (but external) +25 | d = 1 # noqa: V500 + | ^^^^^^^^^^^^ RUF100 +26 | +27 | # fmt: off | = help: Remove unused `noqa` directive ℹ Fix +22 22 | d = 1 # noqa: F841, V101 23 23 | -24 24 | # fmt: off -25 25 | # Invalid - no space before # -26 |- d = 1# noqa: E501 - 26 |+ d = 1 -27 27 | -28 28 | # Invalid - many spaces before # -29 29 | d = 1 # noqa: E501 +24 24 | # Invalid (but external) +25 |- d = 1 # noqa: V500 + 25 |+ d = 1 +26 26 | +27 27 | # fmt: off +28 28 | # Invalid - no space before # + +RUF100_0.py:29:10: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +27 | # fmt: off +28 | # Invalid - no space before # +29 | d = 1# noqa: E501 + | ^^^^^^^^^^^^ RUF100 +30 | +31 | # Invalid - many spaces before # + | + = help: Remove unused `noqa` directive + +ℹ Fix +26 26 | +27 27 | # fmt: off +28 28 | # Invalid - no space before # +29 |- d = 1# noqa: E501 + 29 |+ d = 1 +30 30 | +31 31 | # Invalid - many spaces before # +32 32 | d = 1 # noqa: E501 -RUF100_0.py:29:5: F841 [*] Local variable `d` is assigned to but never used +RUF100_0.py:32:5: F841 [*] Local variable `d` is assigned to but never used | -28 | # Invalid - many spaces before # -29 | d = 1 # noqa: E501 +31 | # Invalid - many spaces before # +32 | d = 1 # noqa: E501 | ^ F841 -30 | # fmt: on +33 | # fmt: on | = help: Remove assignment to unused variable `d` ℹ Suggested fix -26 26 | d = 1# noqa: E501 -27 27 | -28 28 | # Invalid - many spaces before # -29 |- d = 1 # noqa: E501 -30 29 | # fmt: on -31 30 | -32 31 | +29 29 | d = 1# noqa: E501 +30 30 | +31 31 | # Invalid - many spaces before # +32 |- d = 1 # noqa: E501 +33 32 | # fmt: on +34 33 | +35 34 | -RUF100_0.py:29:33: RUF100 [*] Unused `noqa` directive (unused: `E501`) +RUF100_0.py:32:33: RUF100 [*] Unused `noqa` directive (unused: `E501`) | -28 | # Invalid - many spaces before # -29 | d = 1 # noqa: E501 +31 | # Invalid - many spaces before # +32 | d = 1 # noqa: E501 | ^^^^^^^^^^^^ RUF100 -30 | # fmt: on +33 | # fmt: on | = help: Remove unused `noqa` directive ℹ Fix -26 26 | d = 1# noqa: E501 -27 27 | -28 28 | # Invalid - many spaces before # -29 |- d = 1 # noqa: E501 - 29 |+ d = 1 -30 30 | # fmt: on -31 31 | -32 32 | +29 29 | d = 1# noqa: E501 +30 30 | +31 31 | # Invalid - many spaces before # +32 |- d = 1 # noqa: E501 + 32 |+ d = 1 +33 33 | # fmt: on +34 34 | +35 35 | -RUF100_0.py:55:6: RUF100 [*] Unused `noqa` directive (unused: `F841`) +RUF100_0.py:58:6: RUF100 [*] Unused `noqa` directive (unused: `F841`) | -54 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -55 | """ # noqa: E501, F841 +57 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +58 | """ # noqa: E501, F841 | ^^^^^^^^^^^^^^^^^^ RUF100 -56 | -57 | # Invalid +59 | +60 | # Invalid | = help: Remove unused `noqa` directive ℹ Fix -52 52 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 -53 53 | -54 54 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -55 |-""" # noqa: E501, F841 - 55 |+""" # noqa: E501 +55 55 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 56 56 | -57 57 | # Invalid -58 58 | _ = """Lorem ipsum dolor sit amet. +57 57 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +58 |-""" # noqa: E501, F841 + 58 |+""" # noqa: E501 +59 59 | +60 60 | # Invalid +61 61 | _ = """Lorem ipsum dolor sit amet. -RUF100_0.py:63:6: RUF100 [*] Unused `noqa` directive (unused: `E501`) +RUF100_0.py:66:6: RUF100 [*] Unused `noqa` directive (unused: `E501`) | -62 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. -63 | """ # noqa: E501 +65 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +66 | """ # noqa: E501 | ^^^^^^^^^^^^ RUF100 -64 | -65 | # Invalid +67 | +68 | # Invalid | = help: Remove unused `noqa` directive ℹ Fix -60 60 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 -61 61 | -62 62 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. -63 |-""" # noqa: E501 - 63 |+""" +63 63 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 64 64 | -65 65 | # Invalid -66 66 | _ = """Lorem ipsum dolor sit amet. +65 65 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +66 |-""" # noqa: E501 + 66 |+""" +67 67 | +68 68 | # Invalid +69 69 | _ = """Lorem ipsum dolor sit amet. -RUF100_0.py:71:6: RUF100 [*] Unused blanket `noqa` directive +RUF100_0.py:74:6: RUF100 [*] Unused blanket `noqa` directive | -70 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. -71 | """ # noqa +73 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +74 | """ # noqa | ^^^^^^ RUF100 -72 | -73 | # Valid +75 | +76 | # Valid | = help: Remove unused `noqa` directive ℹ Fix -68 68 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 -69 69 | -70 70 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. -71 |-""" # noqa - 71 |+""" +71 71 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 72 72 | -73 73 | # Valid -74 74 | # this is a veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy long comment # noqa: E501 +73 73 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +74 |-""" # noqa + 74 |+""" +75 75 | +76 76 | # Valid +77 77 | # this is a veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy long comment # noqa: E501 -RUF100_0.py:85:8: F401 [*] `shelve` imported but unused +RUF100_0.py:88:8: F401 [*] `shelve` imported but unused | -83 | import collections # noqa -84 | import os # noqa: F401, RUF100 -85 | import shelve # noqa: RUF100 +86 | import collections # noqa +87 | import os # noqa: F401, RUF100 +88 | import shelve # noqa: RUF100 | ^^^^^^ F401 -86 | import sys # noqa: F401, RUF100 +89 | import sys # noqa: F401, RUF100 | = help: Remove unused import: `shelve` ℹ Fix -82 82 | -83 83 | import collections # noqa -84 84 | import os # noqa: F401, RUF100 -85 |-import shelve # noqa: RUF100 -86 85 | import sys # noqa: F401, RUF100 -87 86 | -88 87 | print(sys.path) +85 85 | +86 86 | import collections # noqa +87 87 | import os # noqa: F401, RUF100 +88 |-import shelve # noqa: RUF100 +89 88 | import sys # noqa: F401, RUF100 +90 89 | +91 90 | print(sys.path) -RUF100_0.py:90:89: E501 Line too long (89 > 88) +RUF100_0.py:93:89: E501 Line too long (89 > 88) | -88 | print(sys.path) -89 | -90 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 +91 | print(sys.path) +92 | +93 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 | ^ E501 | -RUF100_0.py:90:92: RUF100 [*] Unused `noqa` directive (unused: `F401`) +RUF100_0.py:93:92: RUF100 [*] Unused `noqa` directive (unused: `F401`) | -88 | print(sys.path) -89 | -90 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 +91 | print(sys.path) +92 | +93 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 | ^^^^^^^^^^^^ RUF100 | = help: Remove unused `noqa` directive ℹ Fix -87 87 | -88 88 | print(sys.path) -89 89 | -90 |-"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 - 90 |+"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" -91 91 | +90 90 | +91 91 | print(sys.path) 92 92 | -93 93 | def f(): +93 |-"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + 93 |+"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" +94 94 | +95 95 | +96 96 | def f(): diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap new file mode 100644 index 0000000000000..926354aa430d6 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap @@ -0,0 +1,267 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +--- +RUF100_0.py:9:12: RUF100 [*] Unused blanket `noqa` directive + | + 8 | # Invalid + 9 | c = 1 # noqa + | ^^^^^^ RUF100 +10 | print(c) + | + = help: Remove unused `noqa` directive + +ℹ Fix +6 6 | b = 2 # noqa: F841 +7 7 | +8 8 | # Invalid +9 |- c = 1 # noqa + 9 |+ c = 1 +10 10 | print(c) +11 11 | +12 12 | # Invalid + +RUF100_0.py:13:12: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +12 | # Invalid +13 | d = 1 # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +14 | +15 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Fix +10 10 | print(c) +11 11 | +12 12 | # Invalid +13 |- d = 1 # noqa: E501 + 13 |+ d = 1 +14 14 | +15 15 | # Invalid +16 16 | d = 1 # noqa: F841, E501 + +RUF100_0.py:16:12: RUF100 [*] Unused `noqa` directive (unused: `F841`, `E501`) + | +15 | # Invalid +16 | d = 1 # noqa: F841, E501 + | ^^^^^^^^^^^^^^^^^^ RUF100 +17 | +18 | # Invalid (and unimplemented or not enabled) + | + = help: Remove unused `noqa` directive + +ℹ Fix +13 13 | d = 1 # noqa: E501 +14 14 | +15 15 | # Invalid +16 |- d = 1 # noqa: F841, E501 + 16 |+ d = 1 +17 17 | +18 18 | # Invalid (and unimplemented or not enabled) +19 19 | d = 1 # noqa: F841, W191, F821 + +RUF100_0.py:19:12: RUF100 [*] Unused `noqa` directive (unused: `F841`, `W191`; non-enabled: `F821`) + | +18 | # Invalid (and unimplemented or not enabled) +19 | d = 1 # noqa: F841, W191, F821 + | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF100 +20 | +21 | # Invalid (but external) + | + = help: Remove unused `noqa` directive + +ℹ Fix +16 16 | d = 1 # noqa: F841, E501 +17 17 | +18 18 | # Invalid (and unimplemented or not enabled) +19 |- d = 1 # noqa: F841, W191, F821 + 19 |+ d = 1 +20 20 | +21 21 | # Invalid (but external) +22 22 | d = 1 # noqa: F841, V101 + +RUF100_0.py:22:12: RUF100 [*] Unused `noqa` directive (unused: `F841`) + | +21 | # Invalid (but external) +22 | d = 1 # noqa: F841, V101 + | ^^^^^^^^^^^^^^^^^^ RUF100 +23 | +24 | # Invalid (but external) + | + = help: Remove unused `noqa` directive + +ℹ Fix +19 19 | d = 1 # noqa: F841, W191, F821 +20 20 | +21 21 | # Invalid (but external) +22 |- d = 1 # noqa: F841, V101 + 22 |+ d = 1 # noqa: V101 +23 23 | +24 24 | # Invalid (but external) +25 25 | d = 1 # noqa: V500 + +RUF100_0.py:29:10: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +27 | # fmt: off +28 | # Invalid - no space before # +29 | d = 1# noqa: E501 + | ^^^^^^^^^^^^ RUF100 +30 | +31 | # Invalid - many spaces before # + | + = help: Remove unused `noqa` directive + +ℹ Fix +26 26 | +27 27 | # fmt: off +28 28 | # Invalid - no space before # +29 |- d = 1# noqa: E501 + 29 |+ d = 1 +30 30 | +31 31 | # Invalid - many spaces before # +32 32 | d = 1 # noqa: E501 + +RUF100_0.py:32:5: F841 [*] Local variable `d` is assigned to but never used + | +31 | # Invalid - many spaces before # +32 | d = 1 # noqa: E501 + | ^ F841 +33 | # fmt: on + | + = help: Remove assignment to unused variable `d` + +ℹ Suggested fix +29 29 | d = 1# noqa: E501 +30 30 | +31 31 | # Invalid - many spaces before # +32 |- d = 1 # noqa: E501 +33 32 | # fmt: on +34 33 | +35 34 | + +RUF100_0.py:32:33: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +31 | # Invalid - many spaces before # +32 | d = 1 # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +33 | # fmt: on + | + = help: Remove unused `noqa` directive + +ℹ Fix +29 29 | d = 1# noqa: E501 +30 30 | +31 31 | # Invalid - many spaces before # +32 |- d = 1 # noqa: E501 + 32 |+ d = 1 +33 33 | # fmt: on +34 34 | +35 35 | + +RUF100_0.py:58:6: RUF100 [*] Unused `noqa` directive (unused: `F841`) + | +57 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +58 | """ # noqa: E501, F841 + | ^^^^^^^^^^^^^^^^^^ RUF100 +59 | +60 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Fix +55 55 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +56 56 | +57 57 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +58 |-""" # noqa: E501, F841 + 58 |+""" # noqa: E501 +59 59 | +60 60 | # Invalid +61 61 | _ = """Lorem ipsum dolor sit amet. + +RUF100_0.py:66:6: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +65 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +66 | """ # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +67 | +68 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Fix +63 63 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +64 64 | +65 65 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +66 |-""" # noqa: E501 + 66 |+""" +67 67 | +68 68 | # Invalid +69 69 | _ = """Lorem ipsum dolor sit amet. + +RUF100_0.py:74:6: RUF100 [*] Unused blanket `noqa` directive + | +73 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +74 | """ # noqa + | ^^^^^^ RUF100 +75 | +76 | # Valid + | + = help: Remove unused `noqa` directive + +ℹ Fix +71 71 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +72 72 | +73 73 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +74 |-""" # noqa + 74 |+""" +75 75 | +76 76 | # Valid +77 77 | # this is a veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy long comment # noqa: E501 + +RUF100_0.py:88:8: F401 [*] `shelve` imported but unused + | +86 | import collections # noqa +87 | import os # noqa: F401, RUF100 +88 | import shelve # noqa: RUF100 + | ^^^^^^ F401 +89 | import sys # noqa: F401, RUF100 + | + = help: Remove unused import: `shelve` + +ℹ Fix +85 85 | +86 86 | import collections # noqa +87 87 | import os # noqa: F401, RUF100 +88 |-import shelve # noqa: RUF100 +89 88 | import sys # noqa: F401, RUF100 +90 89 | +91 90 | print(sys.path) + +RUF100_0.py:93:89: E501 Line too long (89 > 88) + | +91 | print(sys.path) +92 | +93 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + | ^ E501 + | + +RUF100_0.py:93:92: RUF100 [*] Unused `noqa` directive (unused: `F401`) + | +91 | print(sys.path) +92 | +93 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + | ^^^^^^^^^^^^ RUF100 + | + = help: Remove unused `noqa` directive + +ℹ Fix +90 90 | +91 91 | print(sys.path) +92 92 | +93 |-"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + 93 |+"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" +94 94 | +95 95 | +96 96 | def f(): + + diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 32c9131883a7b..199b4a490d607 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -2,7 +2,6 @@ //! command-line options. Structure is optimized for internal usage, as opposed //! to external visibility or parsing. -use std::collections::HashSet; use std::path::{Path, PathBuf}; use anyhow::Result; @@ -54,7 +53,7 @@ pub struct LinterSettings { pub allowed_confusables: FxHashSet, pub builtins: Vec, pub dummy_variable_rgx: Regex, - pub external: FxHashSet, + pub external: Vec, pub ignore_init_module_imports: bool, pub logger_objects: Vec, pub namespace_packages: Vec, @@ -144,7 +143,7 @@ impl LinterSettings { builtins: vec![], dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone(), - external: HashSet::default(), + external: vec![], ignore_init_module_imports: false, logger_objects: vec![], namespace_packages: vec![], diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index efe7d4d52016f..842dea912b062 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -226,7 +226,7 @@ impl Configuration { dummy_variable_rgx: lint .dummy_variable_rgx .unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()), - external: FxHashSet::from_iter(lint.external.unwrap_or_default()), + external: lint.external.unwrap_or_default(), ignore_init_module_imports: lint.ignore_init_module_imports.unwrap_or_default(), tab_size: self.indent_width.unwrap_or_default(), namespace_packages: self.namespace_packages.unwrap_or_default(), diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 0189e93857cff..ace00a2463b27 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -548,7 +548,7 @@ pub struct LintCommonOptions { )] pub extend_unfixable: Option>, - /// A list of rule codes that are unsupported by Ruff, but should be + /// A list of rule codes or prefixes that are unsupported by Ruff, but should be /// preserved when (e.g.) validating `# noqa` directives. Useful for /// retaining `# noqa` directives that cover plugins not yet implemented /// by Ruff. @@ -556,9 +556,9 @@ pub struct LintCommonOptions { default = "[]", value_type = "list[str]", example = r#" - # Avoiding flagging (and removing) `V101` from any `# noqa` - # directives, despite Ruff's lack of support for `vulture`. - external = ["V101"] + # Avoiding flagging (and removing) any codes starting with `V` from any + # `# noqa` directives, despite Ruff's lack of support for `vulture`. + external = ["V"] "# )] pub external: Option>, diff --git a/ruff.schema.json b/ruff.schema.json index 2e422405377ee..fb57ef8d84801 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -159,7 +159,7 @@ } }, "external": { - "description": "A list of rule codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", + "description": "A list of rule codes or prefixes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", "type": [ "array", "null" @@ -1733,7 +1733,7 @@ } }, "external": { - "description": "A list of rule codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", + "description": "A list of rule codes or prefixes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", "type": [ "array", "null"