From 87443e630193bbe728ddf93a424af47f3cbfd5da Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 21 Jan 2023 05:57:44 +0100 Subject: [PATCH] Support prefix "PL" to select all of Pylint --- ruff.schema.json | 1 + ruff_macros/src/rule_code_prefix.rs | 12 +++++++++++- src/settings/mod.rs | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ruff.schema.json b/ruff.schema.json index d32b6a3138..1883aa5b75 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1554,6 +1554,7 @@ "PIE8", "PIE80", "PIE807", + "PL", "PLC", "PLC0", "PLC04", diff --git a/ruff_macros/src/rule_code_prefix.rs b/ruff_macros/src/rule_code_prefix.rs index a69c9f7310..42660009c8 100644 --- a/ruff_macros/src/rule_code_prefix.rs +++ b/ruff_macros/src/rule_code_prefix.rs @@ -94,6 +94,7 @@ pub fn expand<'a>( let mut prefix_to_codes: BTreeMap> = BTreeMap::default(); let mut all_codes = BTreeSet::new(); + let mut pl_codes = BTreeSet::new(); for variant in variants { let code_str = variant.to_string(); @@ -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() { @@ -150,6 +155,7 @@ pub fn expand<'a>( Two, Three, Four, + Five, } #[derive( @@ -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! { diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 83eeb26943..b355bf076b 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -320,6 +320,7 @@ fn resolve_codes<'a>(specs: impl IntoIterator>) -> FxHas SuffixLength::Two, SuffixLength::Three, SuffixLength::Four, + SuffixLength::Five, ] { for selector in spec.select { if selector.specificity() == specificity {