diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs index 5d4c294903bb0..5ac6ef68a485a 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs @@ -82,6 +82,7 @@ pub(crate) fn duplicate_value(checker: &Checker, set: &ast::ExprSet) { }, value.range(), ); + diagnostic.secondary_annotation("Previous occurrence here", existing); diagnostic.try_set_fix(|| { edits::remove_member(&set.elts, index, checker.locator().contents()).map( |edit| { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__B033_B033.py.snap b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__B033_B033.py.snap index 339b89232ed2a..47ec9b1201eb1 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__B033_B033.py.snap +++ b/crates/ruff_linter/src/rules/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__B033_B033.py.snap @@ -2,12 +2,14 @@ source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs --- B033 [*] Sets should not contain duplicate item `"value1"` - --> B033.py:4:35 + --> B033.py:4:18 | 2 | # Errors. 3 | ### 4 | incorrect_set = {"value1", 23, 5, "value1"} - | ^^^^^^^^ + | -------- ^^^^^^^^ + | | + | Previous occurrence here 5 | incorrect_set = {1, 1, 2} 6 | incorrect_set_multiline = { | @@ -22,12 +24,14 @@ help: Remove duplicate item 7 | "value1", B033 [*] Sets should not contain duplicate item `1` - --> B033.py:5:21 + --> B033.py:5:18 | 3 | ### 4 | incorrect_set = {"value1", 23, 5, "value1"} 5 | incorrect_set = {1, 1, 2} - | ^ + | - ^ + | | + | Previous occurrence here 6 | incorrect_set_multiline = { 7 | "value1", | @@ -42,8 +46,12 @@ help: Remove duplicate item 8 | 23, B033 [*] Sets should not contain duplicate item `"value1"` - --> B033.py:10:5 + --> B033.py:7:5 | + 5 | incorrect_set = {1, 1, 2} + 6 | incorrect_set_multiline = { + 7 | "value1", + | -------- Previous occurrence here 8 | 23, 9 | 5, 10 | "value1", @@ -61,12 +69,14 @@ help: Remove duplicate item 12 | incorrect_set = {1, 1} B033 [*] Sets should not contain duplicate item `1` - --> B033.py:13:21 + --> B033.py:13:18 | 11 | # B033 12 | } 13 | incorrect_set = {1, 1} - | ^ + | - ^ + | | + | Previous occurrence here 14 | incorrect_set = {1, 1,} 15 | incorrect_set = {0, 1, 1,} | @@ -81,12 +91,14 @@ help: Remove duplicate item 16 | incorrect_set = {0, 1, 1} B033 [*] Sets should not contain duplicate item `1` - --> B033.py:14:21 + --> B033.py:14:18 | 12 | } 13 | incorrect_set = {1, 1} 14 | incorrect_set = {1, 1,} - | ^ + | - ^ + | | + | Previous occurrence here 15 | incorrect_set = {0, 1, 1,} 16 | incorrect_set = {0, 1, 1} | @@ -101,12 +113,14 @@ help: Remove duplicate item 17 | incorrect_set = { B033 [*] Sets should not contain duplicate item `1` - --> B033.py:15:24 + --> B033.py:15:21 | 13 | incorrect_set = {1, 1} 14 | incorrect_set = {1, 1,} 15 | incorrect_set = {0, 1, 1,} - | ^ + | - ^ + | | + | Previous occurrence here 16 | incorrect_set = {0, 1, 1} 17 | incorrect_set = { | @@ -121,12 +135,14 @@ help: Remove duplicate item 18 | 0, B033 [*] Sets should not contain duplicate item `1` - --> B033.py:16:24 + --> B033.py:16:21 | 14 | incorrect_set = {1, 1,} 15 | incorrect_set = {0, 1, 1,} 16 | incorrect_set = {0, 1, 1} - | ^ + | - ^ + | | + | Previous occurrence here 17 | incorrect_set = { 18 | 0, | @@ -141,10 +157,12 @@ help: Remove duplicate item 19 | 1, B033 [*] Sets should not contain duplicate item `1` - --> B033.py:20:5 + --> B033.py:19:5 | +17 | incorrect_set = { 18 | 0, 19 | 1, + | - Previous occurrence here 20 | 1, | ^ 21 | } @@ -160,12 +178,14 @@ help: Remove duplicate item 22 | incorrect_set_multiline_with_comment = { B033 [*] Sets should not contain duplicate items, but `False` and `0` has the same value - --> B033.py:22:28 + --> B033.py:22:18 | 20 | 1, 21 | } 22 | incorrect_set = {False, 1, 0} - | ^ + | ----- ^ + | | + | Previous occurrence here 23 | incorrect_set_multiline_with_comment = { 24 | "value1", | @@ -180,8 +200,12 @@ help: Remove duplicate item 25 | 23, B033 [*] Sets should not contain duplicate item `"value1"` - --> B033.py:27:5 + --> B033.py:24:5 | +22 | incorrect_set = {False, 1, 0} +23 | incorrect_set_multiline_with_comment = { +24 | "value1", + | -------- Previous occurrence here 25 | 23, 26 | # B033 27 | "value1",