Skip to content

Commit a167803

Browse files
committed
avoid duplicate noqa code in primary message
1 parent a4521ac commit a167803

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

crates/ruff_db/src/diagnostic/render.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ def fibonacci(n):
26102610

26112611
let diagnostics = vec![
26122612
env.builder("unused-import", Severity::Error, "`os` imported but unused")
2613-
.primary("fib.py", "1:7", "1:9", "F401")
2613+
.primary("fib.py", "1:7", "1:9", "")
26142614
.help("Remove unused import: `os`")
26152615
.secondary_code("F401")
26162616
.fix(Fix::unsafe_edit(Edit::range_deletion(TextRange::new(
@@ -2624,7 +2624,7 @@ def fibonacci(n):
26242624
Severity::Error,
26252625
"Local variable `x` is assigned to but never used",
26262626
)
2627-
.primary("fib.py", "6:4", "6:5", "F841")
2627+
.primary("fib.py", "6:4", "6:5", "")
26282628
.help("Remove assignment to unused variable `x`")
26292629
.secondary_code("F841")
26302630
.fix(Fix::unsafe_edit(Edit::deletion(
@@ -2634,7 +2634,7 @@ def fibonacci(n):
26342634
.noqa_offset(TextSize::from(94))
26352635
.build(),
26362636
env.builder("undefined-name", Severity::Error, "Undefined name `a`")
2637-
.primary("undef.py", "1:3", "1:4", "F821")
2637+
.primary("undef.py", "1:3", "1:4", "")
26382638
.secondary_code("F821")
26392639
.noqa_offset(TextSize::from(3))
26402640
.build(),
@@ -2727,7 +2727,7 @@ if call(foo
27272727

27282728
let diagnostics = vec![
27292729
env.builder("unused-import", Severity::Error, "`os` imported but unused")
2730-
.primary("notebook.ipynb", "2:7", "2:9", "F401")
2730+
.primary("notebook.ipynb", "2:7", "2:9", "")
27312731
.help("Remove unused import: `os`")
27322732
.secondary_code("F401")
27332733
.fix(Fix::safe_edit(Edit::range_deletion(TextRange::new(
@@ -2741,7 +2741,7 @@ if call(foo
27412741
Severity::Error,
27422742
"`math` imported but unused",
27432743
)
2744-
.primary("notebook.ipynb", "4:7", "4:11", "F401")
2744+
.primary("notebook.ipynb", "4:7", "4:11", "")
27452745
.help("Remove unused import: `math`")
27462746
.secondary_code("F401")
27472747
.fix(Fix::safe_edit(Edit::range_deletion(TextRange::new(
@@ -2755,7 +2755,7 @@ if call(foo
27552755
Severity::Error,
27562756
"Local variable `x` is assigned to but never used",
27572757
)
2758-
.primary("notebook.ipynb", "10:4", "10:5", "F841")
2758+
.primary("notebook.ipynb", "10:4", "10:5", "")
27592759
.help("Remove assignment to unused variable `x`")
27602760
.secondary_code("F841")
27612761
.fix(Fix::unsafe_edit(Edit::range_deletion(TextRange::new(

crates/ruff_db/src/diagnostic/render/full.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod tests {
1313
--> fib.py:1:8
1414
|
1515
1 | import os
16-
| ^^ F401
16+
| ^^
1717
|
1818
help: Remove unused import: `os`
1919
@@ -23,7 +23,7 @@ mod tests {
2323
4 | def fibonacci(n):
2424
5 | """Compute the nth number in the Fibonacci sequence."""
2525
6 | x = 1
26-
| ^ F841
26+
| ^
2727
7 | if n == 0:
2828
8 | return 0
2929
|
@@ -33,7 +33,7 @@ mod tests {
3333
--> undef.py:1:4
3434
|
3535
1 | if a == 1: pass
36-
| ^ F821
36+
| ^
3737
|
3838
"#);
3939
}

crates/ruff_linter/src/message/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ where
7474
body,
7575
);
7676

77-
let noqa_code = rule.noqa_code().to_string();
78-
7977
let span = Span::from(file).with_range(range);
80-
let annotation = Annotation::primary(span).message(&noqa_code);
78+
let annotation = Annotation::primary(span);
8179
diagnostic.annotate(annotation);
8280

8381
if let Some(suggestion) = suggestion {
@@ -96,7 +94,7 @@ where
9694
diagnostic.set_noqa_offset(noqa_offset);
9795
}
9896

99-
diagnostic.set_secondary_code(SecondaryCode::new(noqa_code));
97+
diagnostic.set_secondary_code(SecondaryCode::new(rule.noqa_code().to_string()));
10098

10199
diagnostic
102100
}

0 commit comments

Comments
 (0)