mirror of https://github.com/astral-sh/ruff
refactor: Rename SuffixLength enum to Specificity
This commit is contained in:
parent
ead5f948d3
commit
04300ce258
|
|
@ -148,14 +148,14 @@ pub fn expand<'a>(
|
|||
|
||||
quote! {
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum SuffixLength {
|
||||
None,
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
Four,
|
||||
Five,
|
||||
pub enum Specificity {
|
||||
All,
|
||||
Linter,
|
||||
Code1Char,
|
||||
Code2Chars,
|
||||
Code3Chars,
|
||||
Code4Chars,
|
||||
Code5Chars,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
|
@ -220,7 +220,7 @@ fn generate_impls<'a>(
|
|||
let prefix = Ident::new(prefix_str, Span::call_site());
|
||||
if prefix_str == ALL {
|
||||
quote! {
|
||||
#prefix_ident::#prefix => SuffixLength::None,
|
||||
#prefix_ident::#prefix => Specificity::All,
|
||||
}
|
||||
} else {
|
||||
let mut num_numeric = prefix_str.chars().filter(|char| char.is_numeric()).count();
|
||||
|
|
@ -228,12 +228,12 @@ fn generate_impls<'a>(
|
|||
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 },
|
||||
0 => quote! { Specificity::Linter },
|
||||
1 => quote! { Specificity::Code1Char },
|
||||
2 => quote! { Specificity::Code2Chars },
|
||||
3 => quote! { Specificity::Code3Chars },
|
||||
4 => quote! { Specificity::Code4Chars },
|
||||
5 => quote! { Specificity::Code5Chars },
|
||||
_ => panic!("Invalid prefix: {prefix}"),
|
||||
};
|
||||
quote! {
|
||||
|
|
@ -257,7 +257,7 @@ fn generate_impls<'a>(
|
|||
|
||||
quote! {
|
||||
impl #prefix_ident {
|
||||
pub fn specificity(&self) -> SuffixLength {
|
||||
pub fn specificity(&self) -> Specificity {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
match self {
|
||||
#(#specificity_match_arms)*
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use rustc_hash::FxHashSet;
|
|||
use self::hashable::{HashableGlobMatcher, HashableGlobSet, HashableHashSet, HashableRegex};
|
||||
use self::rule_table::RuleTable;
|
||||
use crate::cache::cache_dir;
|
||||
use crate::registry::{Rule, RuleSelector, SuffixLength, CATEGORIES, INCOMPATIBLE_CODES};
|
||||
use crate::registry::{Rule, RuleSelector, Specificity, CATEGORIES, INCOMPATIBLE_CODES};
|
||||
use crate::rules::{
|
||||
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_errmsg,
|
||||
flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes,
|
||||
|
|
@ -318,13 +318,13 @@ fn resolve_codes<'a>(specs: impl IntoIterator<Item = RuleCodeSpec<'a>>) -> FxHas
|
|||
let mut rules: FxHashSet<Rule> = FxHashSet::default();
|
||||
for spec in specs {
|
||||
for specificity in [
|
||||
SuffixLength::None,
|
||||
SuffixLength::Zero,
|
||||
SuffixLength::One,
|
||||
SuffixLength::Two,
|
||||
SuffixLength::Three,
|
||||
SuffixLength::Four,
|
||||
SuffixLength::Five,
|
||||
Specificity::All,
|
||||
Specificity::Linter,
|
||||
Specificity::Code1Char,
|
||||
Specificity::Code2Chars,
|
||||
Specificity::Code3Chars,
|
||||
Specificity::Code4Chars,
|
||||
Specificity::Code5Chars,
|
||||
] {
|
||||
for selector in spec.select {
|
||||
if selector.specificity() == specificity {
|
||||
|
|
|
|||
Loading…
Reference in New Issue