diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py b/crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py index 2eabfcde89..2a4b06898a 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py @@ -95,3 +95,10 @@ def f(): value = 0 # ruff: enable[F841, RQW320] # ruff: enable[YF829] + + +def f(): + # External rule codes should be ignored + # ruff: disable[TK421] + print("hello") + # ruff: enable[TK421] diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index ad18e24d59..9bc6363731 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -316,7 +316,8 @@ mod tests { Rule::InvalidRuleCode, Rule::InvalidSuppressionComment, Rule::UnmatchedSuppressionComment, - ]), + ]) + .with_external_rules(&["TK421"]), &settings::LinterSettings::for_rules(vec![ Rule::UnusedVariable, Rule::AmbiguousVariableName, @@ -325,6 +326,7 @@ mod tests { Rule::InvalidSuppressionComment, Rule::UnmatchedSuppressionComment, ]) + .with_external_rules(&["TK421"]) .with_preview_mode(), ); Ok(()) diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 5d5e35aa8d..2f22f91b6b 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -471,6 +471,13 @@ impl LinterSettings { self } + #[must_use] + pub fn with_external_rules(mut self, rules: &[&str]) -> Self { + self.external + .extend(rules.iter().map(std::string::ToString::to_string)); + self + } + /// Resolve the [`TargetVersion`] to use for linting. /// /// This method respects the per-file version overrides in