Skip to content

Commit

Permalink
Support prefix "PL" to select all of Pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-profile authored and charliermarsh committed Jan 22, 2023
1 parent 16d2ceb commit 87443e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions ruff.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@
"PIE8",
"PIE80",
"PIE807",
"PL",
"PLC",
"PLC0",
"PLC04",
Expand Down
12 changes: 11 additions & 1 deletion ruff_macros/src/rule_code_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub fn expand<'a>(
let mut prefix_to_codes: BTreeMap<String, BTreeSet<String>> = BTreeMap::default();

let mut all_codes = BTreeSet::new();
let mut pl_codes = BTreeSet::new();

for variant in variants {
let code_str = variant.to_string();
Expand All @@ -109,10 +110,14 @@ pub fn expand<'a>(
.or_default()
.insert(code_str.clone());
}
if code_str.starts_with("PL") {
pl_codes.insert(code_str.to_string());
}
all_codes.insert(code_str);
}

prefix_to_codes.insert(ALL.to_string(), all_codes);
prefix_to_codes.insert("PL".to_string(), pl_codes);

// Add any prefix aliases (e.g., "U" to "UP").
for (alias, rule_code) in PREFIX_REDIRECTS.iter() {
Expand Down Expand Up @@ -150,6 +155,7 @@ pub fn expand<'a>(
Two,
Three,
Four,
Five,
}

#[derive(
Expand Down Expand Up @@ -217,13 +223,17 @@ fn generate_impls<'a>(
#prefix_ident::#prefix => SuffixLength::None,
}
} else {
let num_numeric = prefix_str.chars().filter(|char| char.is_numeric()).count();
let mut num_numeric = prefix_str.chars().filter(|char| char.is_numeric()).count();
if prefix_str != "PL" && prefix_str.starts_with("PL") {
num_numeric += 1;
}
let suffix_len = match num_numeric {
0 => quote! { SuffixLength::Zero },
1 => quote! { SuffixLength::One },
2 => quote! { SuffixLength::Two },
3 => quote! { SuffixLength::Three },
4 => quote! { SuffixLength::Four },
5 => quote! { SuffixLength::Five },
_ => panic!("Invalid prefix: {prefix}"),
};
quote! {
Expand Down
1 change: 1 addition & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ fn resolve_codes<'a>(specs: impl IntoIterator<Item = RuleCodeSpec<'a>>) -> FxHas
SuffixLength::Two,
SuffixLength::Three,
SuffixLength::Four,
SuffixLength::Five,
] {
for selector in spec.select {
if selector.specificity() == specificity {
Expand Down

0 comments on commit 87443e6

Please sign in to comment.