Add test case covering external rules

This commit is contained in:
Amethyst Reese 2025-12-16 15:20:08 -08:00
parent 999a481e74
commit 43429e11ec
3 changed files with 17 additions and 1 deletions

View File

@ -95,3 +95,10 @@ def f():
value = 0 value = 0
# ruff: enable[F841, RQW320] # ruff: enable[F841, RQW320]
# ruff: enable[YF829] # ruff: enable[YF829]
def f():
# External rule codes should be ignored
# ruff: disable[TK421]
print("hello")
# ruff: enable[TK421]

View File

@ -316,7 +316,8 @@ mod tests {
Rule::InvalidRuleCode, Rule::InvalidRuleCode,
Rule::InvalidSuppressionComment, Rule::InvalidSuppressionComment,
Rule::UnmatchedSuppressionComment, Rule::UnmatchedSuppressionComment,
]), ])
.with_external_rules(&["TK421"]),
&settings::LinterSettings::for_rules(vec![ &settings::LinterSettings::for_rules(vec![
Rule::UnusedVariable, Rule::UnusedVariable,
Rule::AmbiguousVariableName, Rule::AmbiguousVariableName,
@ -325,6 +326,7 @@ mod tests {
Rule::InvalidSuppressionComment, Rule::InvalidSuppressionComment,
Rule::UnmatchedSuppressionComment, Rule::UnmatchedSuppressionComment,
]) ])
.with_external_rules(&["TK421"])
.with_preview_mode(), .with_preview_mode(),
); );
Ok(()) Ok(())

View File

@ -471,6 +471,13 @@ impl LinterSettings {
self 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. /// Resolve the [`TargetVersion`] to use for linting.
/// ///
/// This method respects the per-file version overrides in /// This method respects the per-file version overrides in