mirror of https://github.com/astral-sh/ruff
Add test case covering external rules
This commit is contained in:
parent
999a481e74
commit
43429e11ec
|
|
@ -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]
|
||||||
|
|
|
||||||
|
|
@ -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(())
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue