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! {
|
quote! {
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum SuffixLength {
|
pub enum Specificity {
|
||||||
None,
|
All,
|
||||||
Zero,
|
Linter,
|
||||||
One,
|
Code1Char,
|
||||||
Two,
|
Code2Chars,
|
||||||
Three,
|
Code3Chars,
|
||||||
Four,
|
Code4Chars,
|
||||||
Five,
|
Code5Chars,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
@ -220,7 +220,7 @@ fn generate_impls<'a>(
|
||||||
let prefix = Ident::new(prefix_str, Span::call_site());
|
let prefix = Ident::new(prefix_str, Span::call_site());
|
||||||
if prefix_str == ALL {
|
if prefix_str == ALL {
|
||||||
quote! {
|
quote! {
|
||||||
#prefix_ident::#prefix => SuffixLength::None,
|
#prefix_ident::#prefix => Specificity::All,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut num_numeric = prefix_str.chars().filter(|char| char.is_numeric()).count();
|
let mut num_numeric = prefix_str.chars().filter(|char| char.is_numeric()).count();
|
||||||
|
|
@ -228,12 +228,12 @@ fn generate_impls<'a>(
|
||||||
num_numeric += 1;
|
num_numeric += 1;
|
||||||
}
|
}
|
||||||
let suffix_len = match num_numeric {
|
let suffix_len = match num_numeric {
|
||||||
0 => quote! { SuffixLength::Zero },
|
0 => quote! { Specificity::Linter },
|
||||||
1 => quote! { SuffixLength::One },
|
1 => quote! { Specificity::Code1Char },
|
||||||
2 => quote! { SuffixLength::Two },
|
2 => quote! { Specificity::Code2Chars },
|
||||||
3 => quote! { SuffixLength::Three },
|
3 => quote! { Specificity::Code3Chars },
|
||||||
4 => quote! { SuffixLength::Four },
|
4 => quote! { Specificity::Code4Chars },
|
||||||
5 => quote! { SuffixLength::Five },
|
5 => quote! { Specificity::Code5Chars },
|
||||||
_ => panic!("Invalid prefix: {prefix}"),
|
_ => panic!("Invalid prefix: {prefix}"),
|
||||||
};
|
};
|
||||||
quote! {
|
quote! {
|
||||||
|
|
@ -257,7 +257,7 @@ fn generate_impls<'a>(
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #prefix_ident {
|
impl #prefix_ident {
|
||||||
pub fn specificity(&self) -> SuffixLength {
|
pub fn specificity(&self) -> Specificity {
|
||||||
#[allow(clippy::match_same_arms)]
|
#[allow(clippy::match_same_arms)]
|
||||||
match self {
|
match self {
|
||||||
#(#specificity_match_arms)*
|
#(#specificity_match_arms)*
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use rustc_hash::FxHashSet;
|
||||||
use self::hashable::{HashableGlobMatcher, HashableGlobSet, HashableHashSet, HashableRegex};
|
use self::hashable::{HashableGlobMatcher, HashableGlobSet, HashableHashSet, HashableRegex};
|
||||||
use self::rule_table::RuleTable;
|
use self::rule_table::RuleTable;
|
||||||
use crate::cache::cache_dir;
|
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::{
|
use crate::rules::{
|
||||||
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_errmsg,
|
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_errmsg,
|
||||||
flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes,
|
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();
|
let mut rules: FxHashSet<Rule> = FxHashSet::default();
|
||||||
for spec in specs {
|
for spec in specs {
|
||||||
for specificity in [
|
for specificity in [
|
||||||
SuffixLength::None,
|
Specificity::All,
|
||||||
SuffixLength::Zero,
|
Specificity::Linter,
|
||||||
SuffixLength::One,
|
Specificity::Code1Char,
|
||||||
SuffixLength::Two,
|
Specificity::Code2Chars,
|
||||||
SuffixLength::Three,
|
Specificity::Code3Chars,
|
||||||
SuffixLength::Four,
|
Specificity::Code4Chars,
|
||||||
SuffixLength::Five,
|
Specificity::Code5Chars,
|
||||||
] {
|
] {
|
||||||
for selector in spec.select {
|
for selector in spec.select {
|
||||||
if selector.specificity() == specificity {
|
if selector.specificity() == specificity {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue