From 4c23f4435e00481b6c0079888278aa081fdf6ea6 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Mon, 23 Feb 2026 17:24:00 -0800 Subject: [PATCH 1/7] test case showing RUF100/RUF102 overlap on invalid codes --- crates/ruff_linter/src/rules/ruff/mod.rs | 13 + ..._rule_code_external_rules_with_unused.snap | 415 ++++++++++++++++++ 2 files changed, 428 insertions(+) create mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 939067fd24d41..1efdd71dfc619 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -517,6 +517,19 @@ mod tests { Ok(()) } + #[test] + fn invalid_rule_code_external_rules_with_unused() -> Result<()> { + let diagnostics = test_path( + Path::new("ruff/RUF102.py"), + &settings::LinterSettings { + external: vec!["V".to_string()], + ..settings::LinterSettings::for_rules(vec![Rule::InvalidRuleCode, Rule::UnusedNOQA]) + }, + )?; + assert_diagnostics!(diagnostics); + Ok(()) + } + #[test] fn ruff_per_file_ignores() -> Result<()> { let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap new file mode 100644 index 0000000000000..39e3d8492e995 --- /dev/null +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap @@ -0,0 +1,415 @@ +--- +source: crates/ruff_linter/src/rules/ruff/mod.rs +--- +RUF100 [*] Unused `noqa` directive (unknown: `INVALID123`) + --> RUF102.py:2:12 + | +1 | # Invalid code +2 | import os # noqa: INVALID123 + | ^^^^^^^^^^^^^^^^^^ +3 | # External code +4 | import re # noqa: V123 + | +help: Remove unused `noqa` directive +1 | # Invalid code + - import os # noqa: INVALID123 +2 + import os +3 | # External code +4 | import re # noqa: V123 +5 | # Valid noqa + +RUF102 [*] Invalid rule code in `# noqa`: INVALID123 + --> RUF102.py:2:12 + | +1 | # Invalid code +2 | import os # noqa: INVALID123 + | ^^^^^^^^^^^^^^^^^^ +3 | # External code +4 | import re # noqa: V123 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the `# noqa` comment +1 | # Invalid code + - import os # noqa: INVALID123 +2 + import os +3 | # External code +4 | import re # noqa: V123 +5 | # Valid noqa + +RUF100 [*] Unused `noqa` directive (non-enabled: `E402`) + --> RUF102.py:6:13 + | +4 | import re # noqa: V123 +5 | # Valid noqa +6 | import sys # noqa: E402 + | ^^^^^^^^^^^^ +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 +8 | from itertools import product # Preceeding comment # noqa: INVALID789 + | +help: Remove unused `noqa` directive +3 | # External code +4 | import re # noqa: V123 +5 | # Valid noqa + - import sys # noqa: E402 +6 + import sys +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment + +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID456`) + --> RUF102.py:7:51 + | +5 | # Valid noqa +6 | import sys # noqa: E402 +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + | ^^^^^^^^^^^^^^^^^^^^^^^^ +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment + | +help: Remove unused `noqa` directive +4 | import re # noqa: V123 +5 | # Valid noqa +6 | import sys # noqa: E402 + - from functools import cache # Preceeding comment # noqa: F401, INVALID456 +7 + from functools import cache # Preceeding comment +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + +RUF102 [*] Invalid rule code in `# noqa`: INVALID456 + --> RUF102.py:7:65 + | +5 | # Valid noqa +6 | import sys # noqa: E402 +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + | ^^^^^^^^^^ +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID456` +4 | import re # noqa: V123 +5 | # Valid noqa +6 | import sys # noqa: E402 + - from functools import cache # Preceeding comment # noqa: F401, INVALID456 +7 + from functools import cache # Preceeding comment # noqa: F401 +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + +RUF100 [*] Unused `noqa` directive (unknown: `INVALID789`) + --> RUF102.py:8:53 + | + 6 | import sys # noqa: E402 + 7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + 8 | from itertools import product # Preceeding comment # noqa: INVALID789 + | ^^^^^^^^^^^^^^^^^^ + 9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + | +help: Remove unused `noqa` directive +5 | # Valid noqa +6 | import sys # noqa: E402 +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + - from itertools import product # Preceeding comment # noqa: INVALID789 +8 + from itertools import product # Preceeding comment +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid + +RUF102 [*] Invalid rule code in `# noqa`: INVALID789 + --> RUF102.py:8:53 + | + 6 | import sys # noqa: E402 + 7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + 8 | from itertools import product # Preceeding comment # noqa: INVALID789 + | ^^^^^^^^^^^^^^^^^^ + 9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the `# noqa` comment +5 | # Valid noqa +6 | import sys # noqa: E402 +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 + - from itertools import product # Preceeding comment # noqa: INVALID789 +8 + from itertools import product # Preceeding comment +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid + +RUF100 [*] Unused `noqa` directive (unknown: `INVALID000`) + --> RUF102.py:10:13 + | + 8 | from itertools import product # Preceeding comment # noqa: INVALID789 + 9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + | ^^^^^^^^^^^^^^^^^^ +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 + | +help: Remove unused `noqa` directive +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment + - import math # noqa: INVALID000 # Succeeding comment +10 + import math # Succeeding comment +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid + +RUF102 [*] Invalid rule code in `# noqa`: INVALID000 + --> RUF102.py:10:13 + | + 8 | from itertools import product # Preceeding comment # noqa: INVALID789 + 9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment + | ^^^^^^^^^^^^^^^^^^ +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the `# noqa` comment +7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 +8 | from itertools import product # Preceeding comment # noqa: INVALID789 +9 | # Succeeding comment + - import math # noqa: INVALID000 # Succeeding comment +10 + import math # Succeeding comment +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid + +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID123`) + --> RUF102.py:12:26 + | +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 + | ^^^^^^^^^^^^^^^^^^^^^^^^ +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 + | +help: Remove unused `noqa` directive +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid + - from typing import List # noqa: F401, INVALID123 +12 + from typing import List +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing + +RUF102 [*] Invalid rule code in `# noqa`: INVALID123 + --> RUF102.py:12:40 + | +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 + | ^^^^^^^^^^ +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID123` +9 | # Succeeding comment +10 | import math # noqa: INVALID000 # Succeeding comment +11 | # Mixed valid and invalid + - from typing import List # noqa: F401, INVALID123 +12 + from typing import List # noqa: F401 +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing + +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID100`, `INVALID200`) + --> RUF102.py:14:38 + | +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 + | +help: Remove unused `noqa` directive +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid + - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +14 + from collections import defaultdict +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types + +RUF102 [*] Invalid rule code in `# noqa`: INVALID100 + --> RUF102.py:14:46 + | +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 + | ^^^^^^^^^^ +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID100` +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid + - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +14 + from collections import defaultdict # noqa: INVALID200, F401 +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types + +RUF102 [*] Invalid rule code in `# noqa`: INVALID200 + --> RUF102.py:14:58 + | +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 + | ^^^^^^^^^^ +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID200` +11 | # Mixed valid and invalid +12 | from typing import List # noqa: F401, INVALID123 +13 | # Test for multiple invalid + - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +14 + from collections import defaultdict # noqa: INVALID100, F401 +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types + +RUF100 [*] Unused `noqa` directive (non-enabled: `E402`, `F401`; unknown: `INVALID300`) + --> RUF102.py:16:30 + | +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 + | +help: Remove unused `noqa` directive +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing + - from itertools import chain # noqa: E402, INVALID300, F401 +16 + from itertools import chain +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects + +RUF102 [*] Invalid rule code in `# noqa`: INVALID300 + --> RUF102.py:16:44 + | +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 + | ^^^^^^^^^^ +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID300` +13 | # Test for multiple invalid +14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 +15 | # Test for preserving valid codes when fixing + - from itertools import chain # noqa: E402, INVALID300, F401 +16 + from itertools import chain # noqa: E402, F401 +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects + +RUF100 [*] Unused `noqa` directive (non-enabled: `E402`; unknown: `INVALID400`) + --> RUF102.py:18:14 + | +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 + | +help: Remove unused `noqa` directive +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types + - import json # noqa: E402, INVALID400, V100 +18 + import json # noqa: V100 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) + +RUF102 [*] Invalid rule code in `# noqa`: INVALID400 + --> RUF102.py:18:28 + | +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 + | ^^^^^^^^^^ +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the rule code `INVALID400` +15 | # Test for preserving valid codes when fixing +16 | from itertools import chain # noqa: E402, INVALID300, F401 +17 | # Test for mixed code types + - import json # noqa: E402, INVALID400, V100 +18 + import json # noqa: E402, V100 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) + +RUF100 [*] Unused `noqa` directive (non-enabled: `TCH002`) + --> RUF102.py:20:22 + | +18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 + | ^^^^^^^^^^^^^^ +21 | # Invalid code with trailing reason (single comment) +22 | import pathlib # noqa: INVALID123 some reason + | +help: Remove unused `noqa` directive +17 | # Test for mixed code types +18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects + - import pandas as pd # noqa: TCH002 +20 + import pandas as pd +21 | # Invalid code with trailing reason (single comment) +22 | import pathlib # noqa: INVALID123 some reason + +RUF100 [*] Unused `noqa` directive (unknown: `INVALID123`) + --> RUF102.py:22:17 + | +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) +22 | import pathlib # noqa: INVALID123 some reason + | ^^^^^^^^^^^^^^^^^^ + | +help: Remove unused `noqa` directive +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) + - import pathlib # noqa: INVALID123 some reason +22 + import pathlib + +RUF102 [*] Invalid rule code in `# noqa`: INVALID123 + --> RUF102.py:22:17 + | +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) +22 | import pathlib # noqa: INVALID123 some reason + | ^^^^^^^^^^^^^^^^^^ + | +help: Add non-Ruff rule codes to the `lint.external` configuration option +help: Remove the `# noqa` comment +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 +21 | # Invalid code with trailing reason (single comment) + - import pathlib # noqa: INVALID123 some reason +22 + import pathlib From 7a6b8379f652588378c10bb9fdc35c72286b6d82 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Mon, 23 Feb 2026 17:32:03 -0800 Subject: [PATCH 2/7] Only include code in RUF100 'unknown' list if RUF102 is disabled --- crates/ruff_linter/src/checkers/noqa.rs | 2 +- ..._rule_code_external_rules_with_unused.snap | 82 ++----------------- 2 files changed, 6 insertions(+), 78 deletions(-) diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index 83f026a462402..c4eb2418d1848 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -187,7 +187,7 @@ pub(crate) fn check_noqa( } else { disabled_codes.push(original_code); } - } else { + } else if !context.is_rule_enabled(Rule::InvalidRuleCode) { unknown_codes.push(original_code); } } else { diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap index 39e3d8492e995..d518397f509ea 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap @@ -1,23 +1,6 @@ --- source: crates/ruff_linter/src/rules/ruff/mod.rs --- -RUF100 [*] Unused `noqa` directive (unknown: `INVALID123`) - --> RUF102.py:2:12 - | -1 | # Invalid code -2 | import os # noqa: INVALID123 - | ^^^^^^^^^^^^^^^^^^ -3 | # External code -4 | import re # noqa: V123 - | -help: Remove unused `noqa` directive -1 | # Invalid code - - import os # noqa: INVALID123 -2 + import os -3 | # External code -4 | import re # noqa: V123 -5 | # Valid noqa - RUF102 [*] Invalid rule code in `# noqa`: INVALID123 --> RUF102.py:2:12 | @@ -56,7 +39,7 @@ help: Remove unused `noqa` directive 8 | from itertools import product # Preceeding comment # noqa: INVALID789 9 | # Succeeding comment -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID456`) +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) --> RUF102.py:7:51 | 5 | # Valid noqa @@ -97,26 +80,6 @@ help: Remove the rule code `INVALID456` 9 | # Succeeding comment 10 | import math # noqa: INVALID000 # Succeeding comment -RUF100 [*] Unused `noqa` directive (unknown: `INVALID789`) - --> RUF102.py:8:53 - | - 6 | import sys # noqa: E402 - 7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - 8 | from itertools import product # Preceeding comment # noqa: INVALID789 - | ^^^^^^^^^^^^^^^^^^ - 9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - | -help: Remove unused `noqa` directive -5 | # Valid noqa -6 | import sys # noqa: E402 -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - - from itertools import product # Preceeding comment # noqa: INVALID789 -8 + from itertools import product # Preceeding comment -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid - RUF102 [*] Invalid rule code in `# noqa`: INVALID789 --> RUF102.py:8:53 | @@ -138,26 +101,6 @@ help: Remove the `# noqa` comment 10 | import math # noqa: INVALID000 # Succeeding comment 11 | # Mixed valid and invalid -RUF100 [*] Unused `noqa` directive (unknown: `INVALID000`) - --> RUF102.py:10:13 - | - 8 | from itertools import product # Preceeding comment # noqa: INVALID789 - 9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - | ^^^^^^^^^^^^^^^^^^ -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 - | -help: Remove unused `noqa` directive -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment - - import math # noqa: INVALID000 # Succeeding comment -10 + import math # Succeeding comment -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid - RUF102 [*] Invalid rule code in `# noqa`: INVALID000 --> RUF102.py:10:13 | @@ -179,7 +122,7 @@ help: Remove the `# noqa` comment 12 | from typing import List # noqa: F401, INVALID123 13 | # Test for multiple invalid -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID123`) +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) --> RUF102.py:12:26 | 10 | import math # noqa: INVALID000 # Succeeding comment @@ -220,7 +163,7 @@ help: Remove the rule code `INVALID123` 14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 15 | # Test for preserving valid codes when fixing -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`; unknown: `INVALID100`, `INVALID200`) +RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) --> RUF102.py:14:38 | 12 | from typing import List # noqa: F401, INVALID123 @@ -282,7 +225,7 @@ help: Remove the rule code `INVALID200` 16 | from itertools import chain # noqa: E402, INVALID300, F401 17 | # Test for mixed code types -RUF100 [*] Unused `noqa` directive (non-enabled: `E402`, `F401`; unknown: `INVALID300`) +RUF100 [*] Unused `noqa` directive (non-enabled: `E402`, `F401`) --> RUF102.py:16:30 | 14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 @@ -323,7 +266,7 @@ help: Remove the rule code `INVALID300` 18 | import json # noqa: E402, INVALID400, V100 19 | # Test for rule redirects -RUF100 [*] Unused `noqa` directive (non-enabled: `E402`; unknown: `INVALID400`) +RUF100 [*] Unused `noqa` directive (non-enabled: `E402`) --> RUF102.py:18:14 | 16 | from itertools import chain # noqa: E402, INVALID300, F401 @@ -383,21 +326,6 @@ help: Remove unused `noqa` directive 21 | # Invalid code with trailing reason (single comment) 22 | import pathlib # noqa: INVALID123 some reason -RUF100 [*] Unused `noqa` directive (unknown: `INVALID123`) - --> RUF102.py:22:17 - | -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) -22 | import pathlib # noqa: INVALID123 some reason - | ^^^^^^^^^^^^^^^^^^ - | -help: Remove unused `noqa` directive -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) - - import pathlib # noqa: INVALID123 some reason -22 + import pathlib - RUF102 [*] Invalid rule code in `# noqa`: INVALID123 --> RUF102.py:22:17 | From 03f5fa2f94b1303e1906b523963f9c878d4d6a76 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Tue, 24 Feb 2026 11:32:48 -0800 Subject: [PATCH 3/7] Drop unused code handling entirely --- crates/ruff_linter/src/checkers/noqa.rs | 7 +-- .../src/rules/ruff/rules/unused_noqa.rs | 11 ---- ..._linter__rules__ruff__tests__ruf100_0.snap | 58 +------------------ ...__rules__ruff__tests__ruf100_0_prefix.snap | 39 +------------ 4 files changed, 3 insertions(+), 112 deletions(-) diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index c4eb2418d1848..bef2073f3c858 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -187,7 +187,7 @@ pub(crate) fn check_noqa( } else { disabled_codes.push(original_code); } - } else if !context.is_rule_enabled(Rule::InvalidRuleCode) { + } else { unknown_codes.push(original_code); } } else { @@ -201,7 +201,6 @@ pub(crate) fn check_noqa( if !(disabled_codes.is_empty() && duplicated_codes.is_empty() - && unknown_codes.is_empty() && unmatched_codes.is_empty()) { let edit = if valid_codes.is_empty() { @@ -233,10 +232,6 @@ pub(crate) fn check_noqa( .iter() .map(|code| (*code).to_string()) .collect(), - unknown: unknown_codes - .iter() - .map(|code| (*code).to_string()) - .collect(), unmatched: unmatched_codes .iter() .map(|code| (*code).to_string()) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index cf60acfcb6306..d5686a68ed724 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -8,7 +8,6 @@ use crate::AlwaysFixableViolation; pub(crate) struct UnusedCodes { pub disabled: Vec, pub duplicated: Vec, - pub unknown: Vec, pub unmatched: Vec, } @@ -124,16 +123,6 @@ impl AlwaysFixableViolation for UnusedNOQA { .join(", ") )); } - if !codes.unknown.is_empty() { - codes_by_reason.push(format!( - "unknown: {}", - codes - .unknown - .iter() - .map(|code| format!("`{code}`")) - .join(", ") - )); - } if codes_by_reason.is_empty() { format!("Unused {}", self.kind.as_str()) } else { diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap index 1da7089332bf7..f4cec08d34ffa 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap @@ -95,25 +95,6 @@ help: Remove unused `noqa` directive 24 | # Invalid (but external) 25 | d = 1 # noqa: V500 -RUF100 [*] Unused `noqa` directive (unknown: `V500`) - --> RUF100_0.py:25:12 - | -24 | # Invalid (but external) -25 | d = 1 # noqa: V500 - | ^^^^^^^^^^^^ -26 | -27 | # fmt: off - | -help: Remove unused `noqa` directive -22 | d = 1 # noqa: F841, V101 -23 | -24 | # Invalid (but external) - - d = 1 # noqa: V500 -25 + d = 1 -26 | -27 | # fmt: off -28 | # Invalid - no space before # - RUF100 [*] Unused `noqa` directive (unused: `E501`) --> RUF100_0.py:29:12 | @@ -272,25 +253,6 @@ help: Remove unused `noqa` directive 95 | 96 | def f(): -RUF100 [*] Unused `noqa` directive (unknown: `E50`) - --> RUF100_0.py:107:12 - | -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 - | ^^^^^^^^^^^^^^^^^ -108 | e = 1 # …noqa: E50 - | -help: Remove unused `noqa` directive -104 | -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character - - d = 1 # …noqa: F841, E50 -107 + d = 1 # noqa: F841 -108 | e = 1 # …noqa: E50 -109 | -110 | - F841 [*] Local variable `e` is assigned to but never used --> RUF100_0.py:108:5 | @@ -309,25 +271,7 @@ help: Remove assignment to unused variable `e` 110 | def f(): note: This is an unsafe fix and may change runtime behavior -RUF100 [*] Unused `noqa` directive (unknown: `E50`) - --> RUF100_0.py:108:12 - | -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 -108 | e = 1 # …noqa: E50 - | ^^^^^^^^^^^ - | -help: Remove unused `noqa` directive -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 - - e = 1 # …noqa: E50 -108 + e = 1 -109 | -110 | -111 | def f(): - -RUF100 [*] Unused `noqa` directive (duplicated: `F841`; unknown: `X200`) +RUF100 [*] Unused `noqa` directive (duplicated: `F841`) --> RUF100_0.py:118:12 | 116 | # Check duplicate code detection diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap index 4ff79c6ebc8c2..f4cec08d34ffa 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0_prefix.snap @@ -253,25 +253,6 @@ help: Remove unused `noqa` directive 95 | 96 | def f(): -RUF100 [*] Unused `noqa` directive (unknown: `E50`) - --> RUF100_0.py:107:12 - | -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 - | ^^^^^^^^^^^^^^^^^ -108 | e = 1 # …noqa: E50 - | -help: Remove unused `noqa` directive -104 | -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character - - d = 1 # …noqa: F841, E50 -107 + d = 1 # noqa: F841 -108 | e = 1 # …noqa: E50 -109 | -110 | - F841 [*] Local variable `e` is assigned to but never used --> RUF100_0.py:108:5 | @@ -290,25 +271,7 @@ help: Remove assignment to unused variable `e` 110 | def f(): note: This is an unsafe fix and may change runtime behavior -RUF100 [*] Unused `noqa` directive (unknown: `E50`) - --> RUF100_0.py:108:12 - | -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 -108 | e = 1 # …noqa: E50 - | ^^^^^^^^^^^ - | -help: Remove unused `noqa` directive -105 | def f(): -106 | # Invalid - nonexistent error code with multibyte character -107 | d = 1 # …noqa: F841, E50 - - e = 1 # …noqa: E50 -108 + e = 1 -109 | -110 | -111 | def f(): - -RUF100 [*] Unused `noqa` directive (duplicated: `F841`; unknown: `X200`) +RUF100 [*] Unused `noqa` directive (duplicated: `F841`) --> RUF100_0.py:118:12 | 116 | # Check duplicate code detection From 350983b168446dc4e6aefce43e4d33e6367683d2 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Tue, 24 Feb 2026 11:55:37 -0800 Subject: [PATCH 4/7] Remove new test case --- crates/ruff_linter/src/rules/ruff/mod.rs | 13 - ..._rule_code_external_rules_with_unused.snap | 343 ------------------ 2 files changed, 356 deletions(-) delete mode 100644 crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 1efdd71dfc619..939067fd24d41 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -517,19 +517,6 @@ mod tests { Ok(()) } - #[test] - fn invalid_rule_code_external_rules_with_unused() -> Result<()> { - let diagnostics = test_path( - Path::new("ruff/RUF102.py"), - &settings::LinterSettings { - external: vec!["V".to_string()], - ..settings::LinterSettings::for_rules(vec![Rule::InvalidRuleCode, Rule::UnusedNOQA]) - }, - )?; - assert_diagnostics!(diagnostics); - Ok(()) - } - #[test] fn ruff_per_file_ignores() -> Result<()> { let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap deleted file mode 100644 index d518397f509ea..0000000000000 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules_with_unused.snap +++ /dev/null @@ -1,343 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/ruff/mod.rs ---- -RUF102 [*] Invalid rule code in `# noqa`: INVALID123 - --> RUF102.py:2:12 - | -1 | # Invalid code -2 | import os # noqa: INVALID123 - | ^^^^^^^^^^^^^^^^^^ -3 | # External code -4 | import re # noqa: V123 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the `# noqa` comment -1 | # Invalid code - - import os # noqa: INVALID123 -2 + import os -3 | # External code -4 | import re # noqa: V123 -5 | # Valid noqa - -RUF100 [*] Unused `noqa` directive (non-enabled: `E402`) - --> RUF102.py:6:13 - | -4 | import re # noqa: V123 -5 | # Valid noqa -6 | import sys # noqa: E402 - | ^^^^^^^^^^^^ -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 -8 | from itertools import product # Preceeding comment # noqa: INVALID789 - | -help: Remove unused `noqa` directive -3 | # External code -4 | import re # noqa: V123 -5 | # Valid noqa - - import sys # noqa: E402 -6 + import sys -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment - -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) - --> RUF102.py:7:51 - | -5 | # Valid noqa -6 | import sys # noqa: E402 -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - | ^^^^^^^^^^^^^^^^^^^^^^^^ -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment - | -help: Remove unused `noqa` directive -4 | import re # noqa: V123 -5 | # Valid noqa -6 | import sys # noqa: E402 - - from functools import cache # Preceeding comment # noqa: F401, INVALID456 -7 + from functools import cache # Preceeding comment -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - -RUF102 [*] Invalid rule code in `# noqa`: INVALID456 - --> RUF102.py:7:65 - | -5 | # Valid noqa -6 | import sys # noqa: E402 -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - | ^^^^^^^^^^ -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID456` -4 | import re # noqa: V123 -5 | # Valid noqa -6 | import sys # noqa: E402 - - from functools import cache # Preceeding comment # noqa: F401, INVALID456 -7 + from functools import cache # Preceeding comment # noqa: F401 -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - -RUF102 [*] Invalid rule code in `# noqa`: INVALID789 - --> RUF102.py:8:53 - | - 6 | import sys # noqa: E402 - 7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - 8 | from itertools import product # Preceeding comment # noqa: INVALID789 - | ^^^^^^^^^^^^^^^^^^ - 9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the `# noqa` comment -5 | # Valid noqa -6 | import sys # noqa: E402 -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 - - from itertools import product # Preceeding comment # noqa: INVALID789 -8 + from itertools import product # Preceeding comment -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid - -RUF102 [*] Invalid rule code in `# noqa`: INVALID000 - --> RUF102.py:10:13 - | - 8 | from itertools import product # Preceeding comment # noqa: INVALID789 - 9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment - | ^^^^^^^^^^^^^^^^^^ -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the `# noqa` comment -7 | from functools import cache # Preceeding comment # noqa: F401, INVALID456 -8 | from itertools import product # Preceeding comment # noqa: INVALID789 -9 | # Succeeding comment - - import math # noqa: INVALID000 # Succeeding comment -10 + import math # Succeeding comment -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid - -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) - --> RUF102.py:12:26 - | -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 - | ^^^^^^^^^^^^^^^^^^^^^^^^ -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 - | -help: Remove unused `noqa` directive -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid - - from typing import List # noqa: F401, INVALID123 -12 + from typing import List -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing - -RUF102 [*] Invalid rule code in `# noqa`: INVALID123 - --> RUF102.py:12:40 - | -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 - | ^^^^^^^^^^ -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID123` -9 | # Succeeding comment -10 | import math # noqa: INVALID000 # Succeeding comment -11 | # Mixed valid and invalid - - from typing import List # noqa: F401, INVALID123 -12 + from typing import List # noqa: F401 -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing - -RUF100 [*] Unused `noqa` directive (non-enabled: `F401`) - --> RUF102.py:14:38 - | -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 - | -help: Remove unused `noqa` directive -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid - - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -14 + from collections import defaultdict -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types - -RUF102 [*] Invalid rule code in `# noqa`: INVALID100 - --> RUF102.py:14:46 - | -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 - | ^^^^^^^^^^ -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID100` -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid - - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -14 + from collections import defaultdict # noqa: INVALID200, F401 -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types - -RUF102 [*] Invalid rule code in `# noqa`: INVALID200 - --> RUF102.py:14:58 - | -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 - | ^^^^^^^^^^ -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID200` -11 | # Mixed valid and invalid -12 | from typing import List # noqa: F401, INVALID123 -13 | # Test for multiple invalid - - from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -14 + from collections import defaultdict # noqa: INVALID100, F401 -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types - -RUF100 [*] Unused `noqa` directive (non-enabled: `E402`, `F401`) - --> RUF102.py:16:30 - | -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 - | -help: Remove unused `noqa` directive -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing - - from itertools import chain # noqa: E402, INVALID300, F401 -16 + from itertools import chain -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 -19 | # Test for rule redirects - -RUF102 [*] Invalid rule code in `# noqa`: INVALID300 - --> RUF102.py:16:44 - | -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 - | ^^^^^^^^^^ -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID300` -13 | # Test for multiple invalid -14 | from collections import defaultdict # noqa: INVALID100, INVALID200, F401 -15 | # Test for preserving valid codes when fixing - - from itertools import chain # noqa: E402, INVALID300, F401 -16 + from itertools import chain # noqa: E402, F401 -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 -19 | # Test for rule redirects - -RUF100 [*] Unused `noqa` directive (non-enabled: `E402`) - --> RUF102.py:18:14 - | -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 - | -help: Remove unused `noqa` directive -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types - - import json # noqa: E402, INVALID400, V100 -18 + import json # noqa: V100 -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) - -RUF102 [*] Invalid rule code in `# noqa`: INVALID400 - --> RUF102.py:18:28 - | -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 - | ^^^^^^^^^^ -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the rule code `INVALID400` -15 | # Test for preserving valid codes when fixing -16 | from itertools import chain # noqa: E402, INVALID300, F401 -17 | # Test for mixed code types - - import json # noqa: E402, INVALID400, V100 -18 + import json # noqa: E402, V100 -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) - -RUF100 [*] Unused `noqa` directive (non-enabled: `TCH002`) - --> RUF102.py:20:22 - | -18 | import json # noqa: E402, INVALID400, V100 -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 - | ^^^^^^^^^^^^^^ -21 | # Invalid code with trailing reason (single comment) -22 | import pathlib # noqa: INVALID123 some reason - | -help: Remove unused `noqa` directive -17 | # Test for mixed code types -18 | import json # noqa: E402, INVALID400, V100 -19 | # Test for rule redirects - - import pandas as pd # noqa: TCH002 -20 + import pandas as pd -21 | # Invalid code with trailing reason (single comment) -22 | import pathlib # noqa: INVALID123 some reason - -RUF102 [*] Invalid rule code in `# noqa`: INVALID123 - --> RUF102.py:22:17 - | -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) -22 | import pathlib # noqa: INVALID123 some reason - | ^^^^^^^^^^^^^^^^^^ - | -help: Add non-Ruff rule codes to the `lint.external` configuration option -help: Remove the `# noqa` comment -19 | # Test for rule redirects -20 | import pandas as pd # noqa: TCH002 -21 | # Invalid code with trailing reason (single comment) - - import pathlib # noqa: INVALID123 some reason -22 + import pathlib From 4e50af4723b84c5209b53dd26051cb5c65d30474 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Tue, 24 Feb 2026 12:03:16 -0800 Subject: [PATCH 5/7] clippy --- crates/ruff_linter/src/suppression.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ruff_linter/src/suppression.rs b/crates/ruff_linter/src/suppression.rs index ec09f363dcf01..aff7a8e0c5b42 100644 --- a/crates/ruff_linter/src/suppression.rs +++ b/crates/ruff_linter/src/suppression.rs @@ -274,7 +274,6 @@ impl Suppressions { .iter() .map(ToString::to_string) .collect_vec(), - ..Default::default() }), kind: UnusedNOQAKind::Suppression, }, From 1ae50a78755ed82657a279130b55bc4a05c678fb Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Wed, 25 Feb 2026 15:22:44 -0800 Subject: [PATCH 6/7] Update rule docs to clarify use of RUF102 for unknown codes --- crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index d5686a68ed724..d6bab77743695 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -70,13 +70,11 @@ impl UnusedNOQAKind { /// pass /// ``` /// -/// ## Options +/// ## See also /// -/// This rule will flag rule codes that are unknown to Ruff, even if they are -/// valid for other tools. You can tell Ruff to ignore such codes by configuring -/// the list of known "external" rule codes with the following option: -/// -/// - `lint.external` +/// This rule ignores any codes that are unknown to Ruff, as it can't determine +/// if the codes are valid or used by other tools. Enable [`invalid-rule-code`][RUF102] +/// to flag any unknown rule codes. /// /// ## References /// - [Ruff error suppression](https://docs.astral.sh/ruff/linter/#error-suppression) From a51f8ba22e3cc3c61ad3f606e04483b13f07a787 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Wed, 25 Feb 2026 15:27:02 -0800 Subject: [PATCH 7/7] Add markdown link --- crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index d6bab77743695..b5e3f3062fc75 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -78,6 +78,8 @@ impl UnusedNOQAKind { /// /// ## References /// - [Ruff error suppression](https://docs.astral.sh/ruff/linter/#error-suppression) +/// +/// [RUF102]: https://docs.astral.sh/ruff/rules/invalid-rule-code/ #[derive(ViolationMetadata)] #[violation_metadata(stable_since = "v0.0.155")] pub(crate) struct UnusedNOQA {