Skip to content

Commit 1586572

Browse files
committed
Add test covering expected diagnostics from range suppressions
1 parent 0564a86 commit 1586572

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def f():
2+
# These should both be ignored by the range suppression.
3+
# ruff: disable[E741, F841]
4+
I = 1
5+
# ruff: enable[E741, F841]
6+
7+
8+
def f():
9+
# These should both be ignored by the range suppression.
10+
# ruff:disable[E741,F841]
11+
I = 1
12+
# ruff:enable[E741,F841]
13+
14+
15+
def f():
16+
# These should both be ignored by the range suppression.
17+
# ruff: disable[E741]
18+
# ruff: disable[F841]
19+
I = 1
20+
# ruff: enable[E741]
21+
# ruff: enable[F841]
22+
23+
24+
def f():
25+
# One should both be ignored by the range suppression, and
26+
# the other logged to the user.
27+
# ruff: disable[E741]
28+
I = 1
29+
# ruff: enable[E741]
30+
31+
32+
def f():
33+
# Neither of these are ignored and warning is
34+
# logged to user
35+
# ruff: disable[E501]
36+
I = 1
37+
# ruff: enable[E501]
38+
39+
40+
def f():
41+
# These should both be ignored by the range suppression,
42+
# and an unusued noqa diagnostic should be logged.
43+
# ruff:disable[E741,F841]
44+
I = 1 # noqa: E741,F841
45+
# ruff:enable[E741,F841]

crates/ruff_linter/src/rules/ruff/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@ mod tests {
305305
Ok(())
306306
}
307307

308+
#[test]
309+
fn range_suppressions() -> Result<()> {
310+
let diagnostics = test_path(
311+
Path::new("ruff/suppressions.py"),
312+
&settings::LinterSettings::for_rules(vec![
313+
Rule::UnusedVariable,
314+
Rule::AmbiguousVariableName,
315+
Rule::UnusedNOQA,
316+
]),
317+
)?;
318+
assert_diagnostics!(diagnostics);
319+
Ok(())
320+
}
321+
308322
#[test]
309323
fn ruf100_0() -> Result<()> {
310324
let diagnostics = test_path(
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
source: crates/ruff_linter/src/rules/ruff/mod.rs
3+
---
4+
F841 [*] Local variable `I` is assigned to but never used
5+
--> suppressions.py:28:5
6+
|
7+
26 | # the other logged to the user.
8+
27 | # ruff: disable[E741]
9+
28 | I = 1
10+
| ^
11+
29 | # ruff: enable[E741]
12+
|
13+
help: Remove assignment to unused variable `I`
14+
25 | # One should both be ignored by the range suppression, and
15+
26 | # the other logged to the user.
16+
27 | # ruff: disable[E741]
17+
- I = 1
18+
28 + pass
19+
29 | # ruff: enable[E741]
20+
30 |
21+
31 |
22+
note: This is an unsafe fix and may change runtime behavior
23+
24+
E741 Ambiguous variable name: `I`
25+
--> suppressions.py:36:5
26+
|
27+
34 | # logged to user
28+
35 | # ruff: disable[E501]
29+
36 | I = 1
30+
| ^
31+
37 | # ruff: enable[E501]
32+
|
33+
34+
F841 [*] Local variable `I` is assigned to but never used
35+
--> suppressions.py:36:5
36+
|
37+
34 | # logged to user
38+
35 | # ruff: disable[E501]
39+
36 | I = 1
40+
| ^
41+
37 | # ruff: enable[E501]
42+
|
43+
help: Remove assignment to unused variable `I`
44+
33 | # Neither of these are ignored and warning is
45+
34 | # logged to user
46+
35 | # ruff: disable[E501]
47+
- I = 1
48+
36 + pass
49+
37 | # ruff: enable[E501]
50+
38 |
51+
39 |
52+
note: This is an unsafe fix and may change runtime behavior
53+
54+
RUF100 [*] Unused `noqa` directive (unused: `E741`, `F841`)
55+
--> suppressions.py:44:12
56+
|
57+
42 | # and an unusued noqa diagnostic should be logged.
58+
43 | # ruff:disable[E741,F841]
59+
44 | I = 1 # noqa: E741,F841
60+
| ^^^^^^^^^^^^^^^^^
61+
45 | # ruff:enable[E741,F841]
62+
|
63+
help: Remove unused `noqa` directive
64+
41 | # These should both be ignored by the range suppression,
65+
42 | # and an unusued noqa diagnostic should be logged.
66+
43 | # ruff:disable[E741,F841]
67+
- I = 1 # noqa: E741,F841
68+
44 + I = 1
69+
45 | # ruff:enable[E741,F841]

0 commit comments

Comments
 (0)