Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit code frames for fixes with empty ranges #12304

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 0 additions & 134 deletions crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,6 @@ fn redirect_direct() {
exit_code: 1
----- stdout -----
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
|
|

Found 1 error.

----- stderr -----
Expand Down Expand Up @@ -1294,9 +1291,6 @@ fn redirect_prefix() {
exit_code: 1
----- stdout -----
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
|
|

Found 1 error.

----- stderr -----
Expand All @@ -1314,9 +1308,6 @@ fn deprecated_direct() {
exit_code: 1
----- stdout -----
-:1:1: RUF920 Hey this is a deprecated test rule.
|
|

Found 1 error.

----- stderr -----
Expand All @@ -1334,13 +1325,7 @@ fn deprecated_multiple_direct() {
exit_code: 1
----- stdout -----
-:1:1: RUF920 Hey this is a deprecated test rule.
|
|

-:1:1: RUF921 Hey this is another deprecated test rule.
|
|

Found 2 errors.

----- stderr -----
Expand All @@ -1359,13 +1344,7 @@ fn deprecated_indirect() {
exit_code: 1
----- stdout -----
-:1:1: RUF920 Hey this is a deprecated test rule.
|
|

-:1:1: RUF921 Hey this is another deprecated test rule.
|
|

Found 2 errors.

----- stderr -----
Expand Down Expand Up @@ -1544,13 +1523,7 @@ fn check_hints_hidden_unsafe_fixes() {
exit_code: 1
----- stdout -----
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Expand All @@ -1568,11 +1541,6 @@ fn check_hints_hidden_unsafe_fixes_with_no_safe_fixes() {
exit_code: 1
----- stdout -----
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
1 | x = {'a': 1, 'a': 1}
| RUF902
|

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Expand All @@ -1591,13 +1559,7 @@ fn check_no_hint_for_hidden_unsafe_fixes_when_disabled() {
exit_code: 1
----- stdout -----
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
[*] 1 fixable with the --fix option.

Expand All @@ -1617,11 +1579,6 @@ fn check_no_hint_for_hidden_unsafe_fixes_with_no_safe_fixes_when_disabled() {
exit_code: 1
----- stdout -----
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
1 | x = {'a': 1, 'a': 1}
| RUF902
|

Found 1 error.

----- stderr -----
Expand All @@ -1639,13 +1596,7 @@ fn check_shows_unsafe_fixes_with_opt_in() {
exit_code: 1
----- stdout -----
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
[*] 2 fixable with the --fix option.

Expand All @@ -1667,11 +1618,6 @@ fn fix_applies_safe_fixes_by_default() {

----- stderr -----
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
1 | # fix from stable-test-rule-safe-fix
| RUF902
|

Found 2 errors (1 fixed, 1 remaining).
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
"###);
Expand Down Expand Up @@ -1709,11 +1655,6 @@ fn fix_does_not_apply_display_only_fixes() {
def add_to_list(item, some_list=[]): ...
----- stderr -----
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
|
1 | def add_to_list(item, some_list=[]): ...
| RUF903
|

Found 1 error.
"###);
}
Expand All @@ -1732,11 +1673,6 @@ fn fix_does_not_apply_display_only_fixes_with_unsafe_fixes_enabled() {
def add_to_list(item, some_list=[]): ...
----- stderr -----
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
|
1 | def add_to_list(item, some_list=[]): ...
| RUF903
|

Found 1 error.
"###);
}
Expand All @@ -1754,9 +1690,6 @@ fn fix_only_unsafe_fixes_available() {

----- stderr -----
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
|

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
"###);
Expand Down Expand Up @@ -1893,13 +1826,7 @@ extend-unsafe-fixes = ["RUF901"]
exit_code: 1
----- stdout -----
-:1:1: RUF901 Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
No fixes available (2 hidden fixes can be enabled with the `--unsafe-fixes` option).

Expand Down Expand Up @@ -1931,13 +1858,7 @@ extend-safe-fixes = ["RUF902"]
exit_code: 1
----- stdout -----
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -1971,13 +1892,7 @@ extend-safe-fixes = ["RUF902"]
exit_code: 1
----- stdout -----
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
|
|

-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
|
|

Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Expand Down Expand Up @@ -2013,61 +1928,12 @@ extend-safe-fixes = ["RUF9"]
exit_code: 1
----- stdout -----
-:1:1: RUF900 Hey this is a stable test rule.
|
1 | x = {'a': 1, 'a': 1}
| RUF900
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF901 Hey this is a stable test rule with a safe fix.
|
1 | x = {'a': 1, 'a': 1}
| RUF901
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
|
1 | x = {'a': 1, 'a': 1}
| RUF902
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
|
1 | x = {'a': 1, 'a': 1}
| RUF903
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF920 Hey this is a deprecated test rule.
|
1 | x = {'a': 1, 'a': 1}
| RUF920
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF921 Hey this is another deprecated test rule.
|
1 | x = {'a': 1, 'a': 1}
| RUF921
2 | print(('foo'))
3 | print(str('foo'))
|

-:1:1: RUF950 Hey this is a test rule that was redirected from another.
|
1 | x = {'a': 1, 'a': 1}
| RUF950
2 | print(('foo'))
3 | print(str('foo'))
|

Found 7 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Expand Down
19 changes: 11 additions & 8 deletions crates/ruff_linter/src/message/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ impl Emitter for TextEmitter {
)?;

if self.flags.intersects(EmitterFlags::SHOW_SOURCE) {
writeln!(
writer,
"{}",
MessageCodeFrame {
message,
notebook_index
}
)?;
// The `0..0` range is used to highlight file-level diagnostics.
if message.range() != TextRange::default() {
writeln!(
writer,
"{}",
MessageCodeFrame {
message,
notebook_index
}
)?;
}
}

if self.flags.intersects(EmitterFlags::SHOW_FIX_DIFF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক
| CPY001
|


Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Copyright (C) 2023 Some Author
| CPY001
2 |
3 | import os
|


Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Content Content Content Content Content Content Content Content Content Content
| CPY001
2 | # Content Content Content Content Content Content Content Content Content Content
3 | # Content Content Content Content Content Content Content Content Content Content
|


Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Copyright (C) 2022,2023 Ruff
| CPY001
2 |
3 | import os
|
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Copyright (C) 2022 , 2023 Ruff
| CPY001
2 |
3 | import os
|
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Copyright (C) 2022- 2023 Ruff
| CPY001
2 |
3 | import os
|
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
---
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
1 | # Copyright (C) 2022 - 2023 Ruff
| CPY001
2 |
3 | import os
|
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_executable/mod.rs
---
EXE002_1.py:1:1: EXE002 The file is executable but no shebang is present
|
1 | if __name__ == '__main__':
| EXE002
2 | print('I should be executable.')
|
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
source: crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs
---
example.py:1:1: INP001 File `./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py` is part of an implicit namespace package. Add an `__init__.py`.
|
|


Loading
Loading