Skip to content

Commit

Permalink
Add test cases for ERA100 noqa conflict with RUF100
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Aug 23, 2023
1 parent 0688883 commit 3ea77d2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/ruff/resources/test/fixtures/eradicate/ERA001.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ def foo(x, y, z):
class A():
pass
# b = c


dictionary = {
# "key1": 123, # noqa: ERA001
# "key2": 456,
}
8 changes: 8 additions & 0 deletions crates/ruff/resources/test/fixtures/ruff/RUF100_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import os # noqa: ERA001

dictionary = {
# "key1": 123, # noqa: ERA001
# "key2": 456,
}

#import os # noqa: E501
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,25 @@ ERA001.py:21:5: ERA001 [*] Found commented-out code
19 19 | class A():
20 20 | pass
21 |- # b = c
22 21 |
23 22 |
24 23 | dictionary = {

ERA001.py:26:5: ERA001 [*] Found commented-out code
|
24 | dictionary = {
25 | # "key1": 123, # noqa: ERA001
26 | # "key2": 456,
| ^^^^^^^^^^^^^^ ERA001
27 | }
|
= help: Remove commented-out code

Possible fix
23 23 |
24 24 | dictionary = {
25 25 | # "key1": 123, # noqa: ERA001
26 |- # "key2": 456,
27 26 | }


15 changes: 15 additions & 0 deletions crates/ruff/src/rules/ruff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ mod tests {
Ok(())
}

#[test]
fn ruf100_5() -> Result<()> {
let diagnostics = test_path(
Path::new("ruff/RUF100_5.py"),
&settings::Settings {
..settings::Settings::for_rules(vec![
Rule::UnusedNOQA,
Rule::LineTooLong,
Rule::CommentedOutCode,
])
},
)?;
assert_messages!(diagnostics);
Ok(())
}
#[test]
fn flake8_noqa() -> Result<()> {
let diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
source: crates/ruff/src/rules/ruff/mod.rs
---
RUF100_5.py:4:21: RUF100 [*] Unused `noqa` directive (unused: `ERA001`)
|
3 | dictionary = {
4 | # "key1": 123, # noqa: ERA001
| ^^^^^^^^^^^^^^ RUF100
5 | # "key2": 456,
6 | }
|
= help: Remove unused `noqa` directive

Suggested fix
1 1 | #import os # noqa: ERA001
2 2 |
3 3 | dictionary = {
4 |- # "key1": 123, # noqa: ERA001
4 |+ # "key1": 123,
5 5 | # "key2": 456,
6 6 | }
7 7 |

RUF100_5.py:5:5: ERA001 [*] Found commented-out code
|
3 | dictionary = {
4 | # "key1": 123, # noqa: ERA001
5 | # "key2": 456,
| ^^^^^^^^^^^^^^ ERA001
6 | }
|
= help: Remove commented-out code

Possible fix
2 2 |
3 3 | dictionary = {
4 4 | # "key1": 123, # noqa: ERA001
5 |- # "key2": 456,
6 5 | }
7 6 |
8 7 | #import os # noqa: E501

RUF100_5.py:8:1: ERA001 [*] Found commented-out code
|
6 | }
7 |
8 | #import os # noqa: E501
| ^^^^^^^^^^^^^^^^^^^^^^^^ ERA001
|
= help: Remove commented-out code

Possible fix
5 5 | # "key2": 456,
6 6 | }
7 7 |
8 |-#import os # noqa: E501

RUF100_5.py:8:13: RUF100 [*] Unused `noqa` directive (unused: `E501`)
|
6 | }
7 |
8 | #import os # noqa: E501
| ^^^^^^^^^^^^ RUF100
|
= help: Remove unused `noqa` directive

Suggested fix
5 5 | # "key2": 456,
6 6 | }
7 7 |
8 |-#import os # noqa: E501
8 |+#import os


0 comments on commit 3ea77d2

Please sign in to comment.