mirror of https://github.com/astral-sh/ruff
Allow globs in `external` codes setting
This commit is contained in:
parent
3bbdfee69f
commit
0e36b9e709
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(|pattern| pattern.matches(code))
|
||||
{
|
||||
valid_codes.push(code);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
use crate::pyproject_toml::lint_pyproject_toml;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::resolve_per_file_ignores;
|
||||
use crate::settings::types::{PerFileIgnore, PythonVersion};
|
||||
use crate::settings::types::{CodePattern, PerFileIgnore, PythonVersion};
|
||||
use crate::test::{test_path, test_resource_path};
|
||||
use crate::{assert_messages, settings};
|
||||
|
||||
|
|
@ -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![CodePattern::new("V101")?],
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedNOQA,
|
||||
Rule::LineTooLong,
|
||||
Rule::UnusedImport,
|
||||
Rule::UnusedVariable,
|
||||
Rule::TabIndentation,
|
||||
])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruf100_0_glob() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_0.py"),
|
||||
&settings::LinterSettings {
|
||||
external: vec![CodePattern::new("V*")?],
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedNOQA,
|
||||
Rule::LineTooLong,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
24 | # Invalid (but external)
|
||||
25 | d = 1 # noqa: V500
|
||||
| ^^^^^^^^^^^^ RUF100
|
||||
27 |
|
||||
28 | # Invalid - many spaces before #
|
||||
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:5: F841 [*] Local variable `d` is assigned to but never used
|
||||
RUF100_0.py:29:10: RUF100 [*] Unused `noqa` directive (unused: `E501`)
|
||||
|
|
||||
28 | # Invalid - many spaces before #
|
||||
29 | d = 1 # noqa: 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
|
||||
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():
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -29,7 +28,7 @@ use crate::{codes, RuleSelector};
|
|||
use super::line_width::IndentWidth;
|
||||
|
||||
use self::rule_table::RuleTable;
|
||||
use self::types::PreviewMode;
|
||||
use self::types::{CodePattern, PreviewMode};
|
||||
use crate::rule_selector::PreviewOptions;
|
||||
|
||||
pub mod flags;
|
||||
|
|
@ -54,7 +53,7 @@ pub struct LinterSettings {
|
|||
pub allowed_confusables: FxHashSet<char>,
|
||||
pub builtins: Vec<String>,
|
||||
pub dummy_variable_rgx: Regex,
|
||||
pub external: FxHashSet<String>,
|
||||
pub external: Vec<CodePattern>,
|
||||
pub ignore_init_module_imports: bool,
|
||||
pub logger_objects: Vec<String>,
|
||||
pub namespace_packages: Vec<PathBuf>,
|
||||
|
|
@ -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![],
|
||||
|
|
|
|||
|
|
@ -338,9 +338,18 @@ impl Deref for Version {
|
|||
///
|
||||
/// [`glob::Pattern`] matches a little differently than we ideally want to.
|
||||
/// Specifically it uses `**` to match an arbitrary number of subdirectories,
|
||||
/// luckily this not relevant since identifiers don't contains slashes.
|
||||
/// however this not relevant since identifiers don't contains slashes.
|
||||
///
|
||||
/// For reference pep8-naming uses
|
||||
/// [`fnmatch`](https://docs.python.org/3/library/fnmatch.html) for
|
||||
/// pattern matching.
|
||||
pub type IdentifierPattern = glob::Pattern;
|
||||
|
||||
/// Pattern to match a rule code.
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// [`glob::Pattern`] matches a little differently than we ideally want to.
|
||||
/// Specifically it uses `**` to match an arbitrary number of subdirectories,
|
||||
/// however this not relevant since identifiers don't contains slashes.
|
||||
pub type CodePattern = glob::Pattern;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ use ruff_linter::rule_selector::{PreviewOptions, Specificity};
|
|||
use ruff_linter::rules::pycodestyle;
|
||||
use ruff_linter::settings::rule_table::RuleTable;
|
||||
use ruff_linter::settings::types::{
|
||||
FilePattern, FilePatternSet, PerFileIgnore, PreviewMode, PythonVersion, SerializationFormat,
|
||||
UnsafeFixes, Version,
|
||||
CodePattern, FilePattern, FilePatternSet, PerFileIgnore, PreviewMode, PythonVersion,
|
||||
SerializationFormat, UnsafeFixes, Version,
|
||||
};
|
||||
use ruff_linter::settings::{
|
||||
resolve_per_file_ignores, LinterSettings, DEFAULT_SELECTORS, DUMMY_VARIABLE_RGX, TASK_TAGS,
|
||||
|
|
@ -226,7 +226,16 @@ 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
|
||||
.map(|code| {
|
||||
code.into_iter()
|
||||
.map(|name| CodePattern::new(&name))
|
||||
.collect()
|
||||
})
|
||||
.transpose()
|
||||
.map_err(|e| anyhow!("Invalid `external` value: {e}"))?
|
||||
.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(),
|
||||
|
|
|
|||
|
|
@ -552,6 +552,9 @@ pub struct LintCommonOptions {
|
|||
/// preserved when (e.g.) validating `# noqa` directives. Useful for
|
||||
/// retaining `# noqa` directives that cover plugins not yet implemented
|
||||
/// by Ruff.
|
||||
///
|
||||
/// Supports glob patterns. For more information on the glob syntax, refer
|
||||
/// to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "list[str]",
|
||||
|
|
|
|||
|
|
@ -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 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.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).",
|
||||
"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 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.\n\nSupports glob patterns. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
|
|
|
|||
Loading…
Reference in New Issue