Skip to content

Commit 22c284a

Browse files
committed
add a primary annotation too
1 parent 683ae20 commit 22c284a

File tree

25 files changed

+38
-34
lines changed

25 files changed

+38
-34
lines changed

crates/ruff/tests/lint.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5588,15 +5588,15 @@ fn cookiecutter_globbing() -> Result<()> {
55885588
.args(STDIN_BASE_OPTIONS)
55895589
.arg("--select=F811")
55905590
.current_dir(tempdir.path()), @r"
5591-
success: false
5592-
exit_code: 1
5593-
----- stdout -----
5594-
{{cookiecutter.repo_name}}/tests/maintest.py:3:8: F811 [*] Redefinition of unused `foo` from line 1
5595-
Found 1 error.
5596-
[*] 1 fixable with the `--fix` option.
5591+
success: false
5592+
exit_code: 1
5593+
----- stdout -----
5594+
{{cookiecutter.repo_name}}/tests/maintest.py:3:8: F811 [*] Redefinition of unused `foo` from line 1: `foo` redefined here
5595+
Found 1 error.
5596+
[*] 1 fixable with the `--fix` option.
55975597
5598-
----- stderr -----
5599-
");
5598+
----- stderr -----
5599+
");
56005600
});
56015601

56025602
Ok(())

crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ pub(crate) fn redefined_while_unused(checker: &Checker, scope_id: ScopeId, scope
197197
shadowed,
198198
);
199199

200+
if let Some(ann) = diagnostic.primary_annotation_mut() {
201+
ann.set_message(format_args!("`{name}` redefined here"));
202+
}
203+
200204
if let Some(range) = binding.parent_range(checker.semantic()) {
201205
diagnostic.set_parent(range.start());
202206
}

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ F811 Redefinition of unused `bar` from line 6
55
--> F811_0.py:10:5
66
|
77
10 | def bar():
8-
| ^^^
8+
| ^^^ `bar` redefined here
99
11 | pass
1010
|
1111
::: F811_0.py:6:5

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ F811 Redefinition of unused `FU` from line 1
55
--> F811_1.py:1:14
66
|
77
1 | import fu as FU, bar as FU
8-
| -- ^^
8+
| -- ^^ `FU` redefined here
99
| |
1010
| previous definition of `FU` here
1111
|

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ F811 Redefinition of unused `mixer` from line 2
1111
4 | pass
1212
5 | else:
1313
6 | from bb import mixer
14-
| ^^^^^
14+
| ^^^^^ `mixer` redefined here
1515
7 | mixer(123)
1616
|
1717
help: Remove definition: `mixer`

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ F811 Redefinition of unused `fu` from line 1
55
--> F811_15.py:4:5
66
|
77
4 | def fu():
8-
| ^^
8+
| ^^ `fu` redefined here
99
5 | pass
1010
|
1111
::: F811_15.py:1:8

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ F811 Redefinition of unused `fu` from line 3
77
6 | def bar():
88
7 | def baz():
99
8 | def fu():
10-
| ^^
10+
| ^^ `fu` redefined here
1111
9 | pass
1212
|
1313
::: F811_16.py:3:8

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ F811 [*] Redefinition of unused `fu` from line 2
66
|
77
5 | def bar():
88
6 | import fu
9-
| ^^
9+
| ^^ `fu` redefined here
1010
7 |
1111
8 | def baz():
1212
|
@@ -36,7 +36,7 @@ F811 Redefinition of unused `fu` from line 6
3636
7 |
3737
8 | def baz():
3838
9 | def fu():
39-
| ^^
39+
| ^^ `fu` redefined here
4040
10 | pass
4141
|
4242
help: Remove definition: `fu`

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ F811 Redefinition of unused `FU` from line 1
55
--> F811_2.py:1:23
66
|
77
1 | from moo import fu as FU, bar as FU
8-
| -- ^^
8+
| -- ^^ `FU` redefined here
99
| |
1010
| previous definition of `FU` here
1111
|

crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ F811 [*] Redefinition of unused `Sequence` from line 26
77
30 | from typing import (
88
31 | List, # noqa: F811
99
32 | Sequence,
10-
| ^^^^^^^^
10+
| ^^^^^^^^ `Sequence` redefined here
1111
33 | )
1212
|
1313
::: F811_21.py:26:5

0 commit comments

Comments
 (0)