mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-25 22:29:02 +00:00
Avoid including nursery rules in linter-level selectors (#5268)
## Summary Ensures that `--select PL` and `--select PLC` don't include `PLC1901`. Previously, `--select PL` _did_, because it's a "linter-level selector" (`--select PLC` is viewed as selecting the `C` prefix from `PL`), and we were missing this filtering path.
This commit is contained in:
parent
f194572be8
commit
e71f044f0d
1 changed files with 13 additions and 5 deletions
|
|
@ -192,7 +192,8 @@ fn rules_by_prefix(
|
||||||
|
|
||||||
for (code, rule) in rules {
|
for (code, rule) in rules {
|
||||||
// Nursery rules have to be explicitly selected, so we ignore them when looking at
|
// Nursery rules have to be explicitly selected, so we ignore them when looking at
|
||||||
// prefixes.
|
// prefix-level selectors (e.g., `--select SIM10`), but add the rule itself under
|
||||||
|
// its fully-qualified code (e.g., `--select SIM101`).
|
||||||
if is_nursery(&rule.group) {
|
if is_nursery(&rule.group) {
|
||||||
rules_by_prefix.insert(code.clone(), vec![(rule.path.clone(), rule.attrs.clone())]);
|
rules_by_prefix.insert(code.clone(), vec![(rule.path.clone(), rule.attrs.clone())]);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -329,7 +330,14 @@ fn generate_iter_impl(
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let mut linter_into_iter_match_arms = quote!();
|
let mut linter_into_iter_match_arms = quote!();
|
||||||
for (linter, map) in linter_to_rules {
|
for (linter, map) in linter_to_rules {
|
||||||
let rule_paths = map.values().map(|Rule { attrs, path, .. }| {
|
let rule_paths = map
|
||||||
|
.values()
|
||||||
|
.filter(|rule| {
|
||||||
|
// Nursery rules have to be explicitly selected, so we ignore them when looking at
|
||||||
|
// linter-level selectors (e.g., `--select SIM`).
|
||||||
|
!is_nursery(&rule.group)
|
||||||
|
})
|
||||||
|
.map(|Rule { attrs, path, .. }| {
|
||||||
let rule_name = path.segments.last().unwrap();
|
let rule_name = path.segments.last().unwrap();
|
||||||
quote!(#(#attrs)* Rule::#rule_name)
|
quote!(#(#attrs)* Rule::#rule_name)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue