diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index 83f026a4624026..bef2073f3c858d 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -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 cf60acfcb63066..b5e3f3062fc75d 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, } @@ -71,16 +70,16 @@ 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) +/// +/// [RUF102]: https://docs.astral.sh/ruff/rules/invalid-rule-code/ #[derive(ViolationMetadata)] #[violation_metadata(stable_since = "v0.0.155")] pub(crate) struct UnusedNOQA { @@ -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 1da7089332bf77..f4cec08d34ffae 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 4ff79c6ebc8c23..f4cec08d34ffae 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 diff --git a/crates/ruff_linter/src/suppression.rs b/crates/ruff_linter/src/suppression.rs index ec09f363dcf016..aff7a8e0c5b42a 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, },