Skip to content

Commit 940df67

Browse files
Omit code frames for fixes with empty ranges (#12304)
## Summary Closes #12291. ## Test Plan ```shell ❯ cargo run check ../uv/foo --select INP /Users/crmarsh/workspace/uv/foo/bar/baz.py:1:1: INP001 File `/Users/crmarsh/workspace/uv/foo/bar/baz.py` is part of an implicit namespace package. Add an `__init__.py`. Found 1 error. ```
1 parent e58713e commit 940df67

File tree

42 files changed

+11
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+11
-457
lines changed

crates/ruff/tests/integration_test.rs

-134
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,6 @@ fn redirect_direct() {
12591259
exit_code: 1
12601260
----- stdout -----
12611261
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
1262-
|
1263-
|
1264-
12651262
Found 1 error.
12661263
12671264
----- stderr -----
@@ -1294,9 +1291,6 @@ fn redirect_prefix() {
12941291
exit_code: 1
12951292
----- stdout -----
12961293
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
1297-
|
1298-
|
1299-
13001294
Found 1 error.
13011295
13021296
----- stderr -----
@@ -1314,9 +1308,6 @@ fn deprecated_direct() {
13141308
exit_code: 1
13151309
----- stdout -----
13161310
-:1:1: RUF920 Hey this is a deprecated test rule.
1317-
|
1318-
|
1319-
13201311
Found 1 error.
13211312
13221313
----- stderr -----
@@ -1334,13 +1325,7 @@ fn deprecated_multiple_direct() {
13341325
exit_code: 1
13351326
----- stdout -----
13361327
-:1:1: RUF920 Hey this is a deprecated test rule.
1337-
|
1338-
|
1339-
13401328
-:1:1: RUF921 Hey this is another deprecated test rule.
1341-
|
1342-
|
1343-
13441329
Found 2 errors.
13451330
13461331
----- stderr -----
@@ -1359,13 +1344,7 @@ fn deprecated_indirect() {
13591344
exit_code: 1
13601345
----- stdout -----
13611346
-:1:1: RUF920 Hey this is a deprecated test rule.
1362-
|
1363-
|
1364-
13651347
-:1:1: RUF921 Hey this is another deprecated test rule.
1366-
|
1367-
|
1368-
13691348
Found 2 errors.
13701349
13711350
----- stderr -----
@@ -1544,13 +1523,7 @@ fn check_hints_hidden_unsafe_fixes() {
15441523
exit_code: 1
15451524
----- stdout -----
15461525
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
1547-
|
1548-
|
1549-
15501526
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1551-
|
1552-
|
1553-
15541527
Found 2 errors.
15551528
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
15561529
@@ -1568,11 +1541,6 @@ fn check_hints_hidden_unsafe_fixes_with_no_safe_fixes() {
15681541
exit_code: 1
15691542
----- stdout -----
15701543
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1571-
|
1572-
1 | x = {'a': 1, 'a': 1}
1573-
| RUF902
1574-
|
1575-
15761544
Found 1 error.
15771545
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
15781546
@@ -1591,13 +1559,7 @@ fn check_no_hint_for_hidden_unsafe_fixes_when_disabled() {
15911559
exit_code: 1
15921560
----- stdout -----
15931561
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
1594-
|
1595-
|
1596-
15971562
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1598-
|
1599-
|
1600-
16011563
Found 2 errors.
16021564
[*] 1 fixable with the --fix option.
16031565
@@ -1617,11 +1579,6 @@ fn check_no_hint_for_hidden_unsafe_fixes_with_no_safe_fixes_when_disabled() {
16171579
exit_code: 1
16181580
----- stdout -----
16191581
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1620-
|
1621-
1 | x = {'a': 1, 'a': 1}
1622-
| RUF902
1623-
|
1624-
16251582
Found 1 error.
16261583
16271584
----- stderr -----
@@ -1639,13 +1596,7 @@ fn check_shows_unsafe_fixes_with_opt_in() {
16391596
exit_code: 1
16401597
----- stdout -----
16411598
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
1642-
|
1643-
|
1644-
16451599
-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
1646-
|
1647-
|
1648-
16491600
Found 2 errors.
16501601
[*] 2 fixable with the --fix option.
16511602
@@ -1667,11 +1618,6 @@ fn fix_applies_safe_fixes_by_default() {
16671618
16681619
----- stderr -----
16691620
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1670-
|
1671-
1 | # fix from stable-test-rule-safe-fix
1672-
| RUF902
1673-
|
1674-
16751621
Found 2 errors (1 fixed, 1 remaining).
16761622
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
16771623
"###);
@@ -1709,11 +1655,6 @@ fn fix_does_not_apply_display_only_fixes() {
17091655
def add_to_list(item, some_list=[]): ...
17101656
----- stderr -----
17111657
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
1712-
|
1713-
1 | def add_to_list(item, some_list=[]): ...
1714-
| RUF903
1715-
|
1716-
17171658
Found 1 error.
17181659
"###);
17191660
}
@@ -1732,11 +1673,6 @@ fn fix_does_not_apply_display_only_fixes_with_unsafe_fixes_enabled() {
17321673
def add_to_list(item, some_list=[]): ...
17331674
----- stderr -----
17341675
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
1735-
|
1736-
1 | def add_to_list(item, some_list=[]): ...
1737-
| RUF903
1738-
|
1739-
17401676
Found 1 error.
17411677
"###);
17421678
}
@@ -1754,9 +1690,6 @@ fn fix_only_unsafe_fixes_available() {
17541690
17551691
----- stderr -----
17561692
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1757-
|
1758-
|
1759-
17601693
Found 1 error.
17611694
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
17621695
"###);
@@ -1893,13 +1826,7 @@ extend-unsafe-fixes = ["RUF901"]
18931826
exit_code: 1
18941827
----- stdout -----
18951828
-:1:1: RUF901 Hey this is a stable test rule with a safe fix.
1896-
|
1897-
|
1898-
18991829
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1900-
|
1901-
|
1902-
19031830
Found 2 errors.
19041831
No fixes available (2 hidden fixes can be enabled with the `--unsafe-fixes` option).
19051832
@@ -1931,13 +1858,7 @@ extend-safe-fixes = ["RUF902"]
19311858
exit_code: 1
19321859
----- stdout -----
19331860
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
1934-
|
1935-
|
1936-
19371861
-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
1938-
|
1939-
|
1940-
19411862
Found 2 errors.
19421863
[*] 2 fixable with the `--fix` option.
19431864
@@ -1971,13 +1892,7 @@ extend-safe-fixes = ["RUF902"]
19711892
exit_code: 1
19721893
----- stdout -----
19731894
-:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
1974-
|
1975-
|
1976-
19771895
-:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
1978-
|
1979-
|
1980-
19811896
Found 2 errors.
19821897
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
19831898
@@ -2013,61 +1928,12 @@ extend-safe-fixes = ["RUF9"]
20131928
exit_code: 1
20141929
----- stdout -----
20151930
-:1:1: RUF900 Hey this is a stable test rule.
2016-
|
2017-
1 | x = {'a': 1, 'a': 1}
2018-
| RUF900
2019-
2 | print(('foo'))
2020-
3 | print(str('foo'))
2021-
|
2022-
20231931
-:1:1: RUF901 Hey this is a stable test rule with a safe fix.
2024-
|
2025-
1 | x = {'a': 1, 'a': 1}
2026-
| RUF901
2027-
2 | print(('foo'))
2028-
3 | print(str('foo'))
2029-
|
2030-
20311932
-:1:1: RUF902 [*] Hey this is a stable test rule with an unsafe fix.
2032-
|
2033-
1 | x = {'a': 1, 'a': 1}
2034-
| RUF902
2035-
2 | print(('foo'))
2036-
3 | print(str('foo'))
2037-
|
2038-
20391933
-:1:1: RUF903 Hey this is a stable test rule with a display only fix.
2040-
|
2041-
1 | x = {'a': 1, 'a': 1}
2042-
| RUF903
2043-
2 | print(('foo'))
2044-
3 | print(str('foo'))
2045-
|
2046-
20471934
-:1:1: RUF920 Hey this is a deprecated test rule.
2048-
|
2049-
1 | x = {'a': 1, 'a': 1}
2050-
| RUF920
2051-
2 | print(('foo'))
2052-
3 | print(str('foo'))
2053-
|
2054-
20551935
-:1:1: RUF921 Hey this is another deprecated test rule.
2056-
|
2057-
1 | x = {'a': 1, 'a': 1}
2058-
| RUF921
2059-
2 | print(('foo'))
2060-
3 | print(str('foo'))
2061-
|
2062-
20631936
-:1:1: RUF950 Hey this is a test rule that was redirected from another.
2064-
|
2065-
1 | x = {'a': 1, 'a': 1}
2066-
| RUF950
2067-
2 | print(('foo'))
2068-
3 | print(str('foo'))
2069-
|
2070-
20711937
Found 7 errors.
20721938
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
20731939

crates/ruff_linter/src/message/text.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,17 @@ impl Emitter for TextEmitter {
116116
)?;
117117

118118
if self.flags.intersects(EmitterFlags::SHOW_SOURCE) {
119-
writeln!(
120-
writer,
121-
"{}",
122-
MessageCodeFrame {
123-
message,
124-
notebook_index
125-
}
126-
)?;
119+
// The `0..0` range is used to highlight file-level diagnostics.
120+
if message.range() != TextRange::default() {
121+
writeln!(
122+
writer,
123+
"{}",
124+
MessageCodeFrame {
125+
message,
126+
notebook_index
127+
}
128+
)?;
129+
}
127130
}
128131

129132
if self.flags.intersects(EmitterFlags::SHOW_FIX_DIFF) {

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__char_boundary.snap

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক
7-
| CPY001
8-
|
9-
10-

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__invalid_author.snap

-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Copyright (C) 2023 Some Author
7-
| CPY001
8-
2 |
9-
3 | import os
10-
|
11-
12-

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__late_notice.snap

-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Content Content Content Content Content Content Content Content Content Content
7-
| CPY001
8-
2 | # Content Content Content Content Content Content Content Content Content Content
9-
3 | # Content Content Content Content Content Content Content Content Content Content
10-
|
11-
12-

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__valid_author_with_comma_invalid_no_space.snap

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Copyright (C) 2022,2023 Ruff
7-
| CPY001
8-
2 |
9-
3 | import os
10-
|

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__valid_author_with_comma_invalid_spaces.snap

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Copyright (C) 2022 , 2023 Ruff
7-
| CPY001
8-
2 |
9-
3 | import os
10-
|

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__valid_author_with_dash_invalid_space.snap

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Copyright (C) 2022- 2023 Ruff
7-
| CPY001
8-
2 |
9-
3 | import os
10-
|

crates/ruff_linter/src/rules/flake8_copyright/snapshots/ruff_linter__rules__flake8_copyright__tests__valid_author_with_dash_invalid_spaces.snap

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
33
---
44
<filename>:1:1: CPY001 Missing copyright notice at top of file
5-
|
6-
1 | # Copyright (C) 2022 - 2023 Ruff
7-
| CPY001
8-
2 |
9-
3 | import os
10-
|

crates/ruff_linter/src/rules/flake8_executable/snapshots/ruff_linter__rules__flake8_executable__tests__EXE002_1.py.snap

-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_executable/mod.rs
33
---
44
EXE002_1.py:1:1: EXE002 The file is executable but no shebang is present
5-
|
6-
1 | if __name__ == '__main__':
7-
| EXE002
8-
2 | print('I should be executable.')
9-
|

crates/ruff_linter/src/rules/flake8_no_pep420/snapshots/ruff_linter__rules__flake8_no_pep420__tests__test_fail_empty.snap

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22
source: crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs
33
---
44
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`.
5-
|
6-
|
7-
8-

0 commit comments

Comments
 (0)