diff --git a/README.md b/README.md index 65326e1208..bc244718e7 100644 --- a/README.md +++ b/README.md @@ -1980,7 +1980,7 @@ recommended to only use `extend-ignore` when extending a **Default value**: `[]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: @@ -2005,7 +2005,7 @@ recommended to only use `extend-select` when extending a **Default value**: `[]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: @@ -2080,7 +2080,7 @@ A list of rule codes or prefixes to consider autofixable. **Default value**: `["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: @@ -2152,7 +2152,7 @@ specific prefixes. **Default value**: `[]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: @@ -2230,7 +2230,7 @@ exclude, when considering any matching files. **Default value**: `{}` -**Type**: `HashMap>` +**Type**: `HashMap>` **Example usage**: @@ -2294,7 +2294,7 @@ specific prefixes. **Default value**: `["E", "F"]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: @@ -2438,7 +2438,7 @@ A list of rule codes or prefixes to consider non-autofix-able. **Default value**: `[]` -**Type**: `Vec` +**Type**: `Vec` **Example usage**: diff --git a/ruff.schema.json b/ruff.schema.json index 866ddc9fe1..012e639aa0 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -73,7 +73,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "extend-select": { @@ -83,7 +83,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "external": { @@ -117,7 +117,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "flake8-annotations": { @@ -244,7 +244,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "ignore-init-module-imports": { @@ -315,7 +315,7 @@ "additionalProperties": { "type": "array", "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } } }, @@ -388,7 +388,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "show-source": { @@ -446,7 +446,7 @@ "null" ], "items": { - "$ref": "#/definitions/RuleCodePrefix" + "$ref": "#/definitions/RuleSelector" } }, "update-check": { @@ -1134,7 +1134,7 @@ } ] }, - "RuleCodePrefix": { + "RuleSelector": { "type": "string", "enum": [ "A", diff --git a/ruff_cli/src/cli.rs b/ruff_cli/src/cli.rs index 604ee43b6f..664e473882 100644 --- a/ruff_cli/src/cli.rs +++ b/ruff_cli/src/cli.rs @@ -4,7 +4,7 @@ use clap::{command, Parser}; use regex::Regex; use ruff::fs; use ruff::logging::LogLevel; -use ruff::registry::{Rule, RuleCodePrefix}; +use ruff::registry::{Rule, RuleSelector}; use ruff::resolver::ConfigProcessor; use ruff::settings::types::{ FilePattern, PatternPrefixPair, PerFileIgnore, PythonVersion, SerializationFormat, @@ -66,18 +66,18 @@ pub struct Cli { /// Comma-separated list of rule codes to enable (or ALL, to enable all /// rules). #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub select: Option>, + pub select: Option>, /// Like --select, but adds additional rule codes on top of the selected /// ones. #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub extend_select: Option>, + pub extend_select: Option>, /// Comma-separated list of rule codes to disable. #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub ignore: Option>, + pub ignore: Option>, /// Like --ignore, but adds additional rule codes on top of the ignored /// ones. #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub extend_ignore: Option>, + pub extend_ignore: Option>, /// List of paths, used to omit files and/or directories from analysis. #[arg(long, value_delimiter = ',', value_name = "FILE_PATTERN")] pub exclude: Option>, @@ -88,11 +88,11 @@ pub struct Cli { /// List of rule codes to treat as eligible for autofix. Only applicable /// when autofix itself is enabled (e.g., via `--fix`). #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub fixable: Option>, + pub fixable: Option>, /// List of rule codes to treat as ineligible for autofix. Only applicable /// when autofix itself is enabled (e.g., via `--fix`). #[arg(long, value_delimiter = ',', value_name = "RULE_CODE")] - pub unfixable: Option>, + pub unfixable: Option>, /// List of mappings from file pattern to code to exclude #[arg(long, value_delimiter = ',')] pub per_file_ignores: Option>, @@ -324,17 +324,17 @@ pub struct Overrides { pub dummy_variable_rgx: Option, pub exclude: Option>, pub extend_exclude: Option>, - pub extend_ignore: Option>, - pub extend_select: Option>, - pub fixable: Option>, - pub ignore: Option>, + pub extend_ignore: Option>, + pub extend_select: Option>, + pub fixable: Option>, + pub ignore: Option>, pub line_length: Option, pub per_file_ignores: Option>, pub respect_gitignore: Option, - pub select: Option>, + pub select: Option>, pub show_source: Option, pub target_version: Option, - pub unfixable: Option>, + pub unfixable: Option>, // TODO(charlie): Captured in pyproject.toml as a default, but not part of `Settings`. pub cache_dir: Option, pub fix: Option, @@ -435,7 +435,7 @@ pub fn extract_log_level(cli: &Arguments) -> LogLevel { /// Convert a list of `PatternPrefixPair` structs to `PerFileIgnore`. pub fn collect_per_file_ignores(pairs: Vec) -> Vec { - let mut per_file_ignores: FxHashMap> = FxHashMap::default(); + let mut per_file_ignores: FxHashMap> = FxHashMap::default(); for pair in pairs { per_file_ignores .entry(pair.pattern) diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index 7b38d48e24..9e9f348285 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -2,7 +2,7 @@ use anyhow::Result; use clap::Args; -use ruff::registry::{Linter, Prefixes, RuleCodePrefix}; +use ruff::registry::{Linter, Prefixes, RuleSelector}; use strum::IntoEnumIterator; use crate::utils::replace_readme_section; @@ -20,7 +20,7 @@ pub struct Cli { pub(crate) dry_run: bool, } -fn generate_table(table_out: &mut String, prefix: &RuleCodePrefix) { +fn generate_table(table_out: &mut String, prefix: &RuleSelector) { table_out.push_str("| Code | Name | Message | Fix |"); table_out.push('\n'); table_out.push_str("| ---- | ---- | ------- | --- |"); diff --git a/ruff_macros/src/define_rule_mapping.rs b/ruff_macros/src/define_rule_mapping.rs index 62fc4dc209..d142fcb3b6 100644 --- a/ruff_macros/src/define_rule_mapping.rs +++ b/ruff_macros/src/define_rule_mapping.rs @@ -56,7 +56,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream { let rulecodeprefix = super::rule_code_prefix::expand( &Ident::new("Rule", Span::call_site()), - &Ident::new("RuleCodePrefix", Span::call_site()), + &Ident::new("RuleSelector", Span::call_site()), mapping.entries.iter().map(|(code, ..)| code), |code| code_to_name[code], ); diff --git a/ruff_macros/src/rule_code_prefix.rs b/ruff_macros/src/rule_code_prefix.rs index 56bdb7bdf3..df07418615 100644 --- a/ruff_macros/src/rule_code_prefix.rs +++ b/ruff_macros/src/rule_code_prefix.rs @@ -7,8 +7,8 @@ use syn::Ident; const ALL: &str = "ALL"; -/// A hash map from deprecated `RuleCodePrefix` to latest -/// `RuleCodePrefix`. +/// A hash map from deprecated `RuleSelector` to latest +/// `RuleSelector`. pub static PREFIX_REDIRECTS: Lazy> = Lazy::new(|| { HashMap::from_iter([ // TODO(charlie): Remove by 2023-01-01. @@ -169,7 +169,7 @@ pub fn expand<'a>( #prefix_impl - /// A hash map from deprecated `RuleCodePrefix` to latest `RuleCodePrefix`. + /// A hash map from deprecated `RuleSelector` to latest `RuleSelector`. pub static PREFIX_REDIRECTS: ::once_cell::sync::Lazy<::rustc_hash::FxHashMap<&'static str, #prefix_ident>> = ::once_cell::sync::Lazy::new(|| { ::rustc_hash::FxHashMap::from_iter([ #(#prefix_redirects),* diff --git a/scripts/add_plugin.py b/scripts/add_plugin.py index 0f2dd91506..7b9e851b0a 100755 --- a/scripts/add_plugin.py +++ b/scripts/add_plugin.py @@ -78,7 +78,7 @@ mod tests { fp.write(f"{indent}{pascal_case(plugin)},") fp.write("\n") - elif line.strip() == "Linter::Ruff => Prefixes::Single(RuleCodePrefix::RUF),": + elif line.strip() == "Linter::Ruff => Prefixes::Single(RuleSelector::RUF),": prefix = 'todo!("Fill-in prefix after generating codes")' fp.write( f"{indent}Linter::{pascal_case(plugin)} => Prefixes::Single({prefix})," diff --git a/src/flake8_to_ruff/converter.rs b/src/flake8_to_ruff/converter.rs index 449cb00721..19e6def367 100644 --- a/src/flake8_to_ruff/converter.rs +++ b/src/flake8_to_ruff/converter.rs @@ -6,7 +6,7 @@ use colored::Colorize; use super::black::Black; use super::plugin::Plugin; use super::{parser, plugin}; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; use crate::rules::flake8_pytest_style::types::{ ParametrizeNameType, ParametrizeValuesRowType, ParametrizeValuesType, }; @@ -32,7 +32,7 @@ pub fn convert( .expect("Unable to find flake8 section in INI file"); // Extract all referenced rule code prefixes, to power plugin inference. - let mut referenced_codes: BTreeSet = BTreeSet::default(); + let mut referenced_codes: BTreeSet = BTreeSet::default(); for (key, value) in flake8 { if let Some(value) = value { match key.as_str() { @@ -392,7 +392,7 @@ mod tests { use super::super::plugin::Plugin; use super::convert; - use crate::registry::RuleCodePrefix; + use crate::registry::RuleSelector; use crate::rules::pydocstyle::settings::Convention; use crate::rules::{flake8_quotes, pydocstyle}; use crate::settings::options::Options; @@ -428,11 +428,7 @@ mod tests { per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, - ]), + select: Some(vec![RuleSelector::E, RuleSelector::F, RuleSelector::W]), show_source: None, src: None, target_version: None, @@ -495,11 +491,7 @@ mod tests { per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, - ]), + select: Some(vec![RuleSelector::E, RuleSelector::F, RuleSelector::W]), show_source: None, src: None, target_version: None, @@ -562,11 +554,7 @@ mod tests { per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, - ]), + select: Some(vec![RuleSelector::E, RuleSelector::F, RuleSelector::W]), show_source: None, src: None, target_version: None, @@ -629,11 +617,7 @@ mod tests { per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, - ]), + select: Some(vec![RuleSelector::E, RuleSelector::F, RuleSelector::W]), show_source: None, src: None, target_version: None, @@ -696,11 +680,7 @@ mod tests { per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, - ]), + select: Some(vec![RuleSelector::E, RuleSelector::F, RuleSelector::W]), show_source: None, src: None, target_version: None, @@ -772,10 +752,10 @@ mod tests { required_version: None, respect_gitignore: None, select: Some(vec![ - RuleCodePrefix::D, - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::W, + RuleSelector::D, + RuleSelector::E, + RuleSelector::F, + RuleSelector::W, ]), show_source: None, src: None, @@ -842,10 +822,10 @@ mod tests { required_version: None, respect_gitignore: None, select: Some(vec![ - RuleCodePrefix::E, - RuleCodePrefix::F, - RuleCodePrefix::Q, - RuleCodePrefix::W, + RuleSelector::E, + RuleSelector::F, + RuleSelector::Q, + RuleSelector::W, ]), show_source: None, src: None, diff --git a/src/flake8_to_ruff/parser.rs b/src/flake8_to_ruff/parser.rs index f90fa9c8be..810f8996ab 100644 --- a/src/flake8_to_ruff/parser.rs +++ b/src/flake8_to_ruff/parser.rs @@ -6,16 +6,16 @@ use once_cell::sync::Lazy; use regex::Regex; use rustc_hash::FxHashMap; -use crate::registry::{RuleCodePrefix, PREFIX_REDIRECTS}; +use crate::registry::{RuleSelector, PREFIX_REDIRECTS}; use crate::settings::types::PatternPrefixPair; use crate::warn_user; static COMMA_SEPARATED_LIST_RE: Lazy = Lazy::new(|| Regex::new(r"[,\s]").unwrap()); -/// Parse a comma-separated list of `RuleCodePrefix` values (e.g., +/// Parse a comma-separated list of `RuleSelector` values (e.g., /// "F401,E501"). -pub fn parse_prefix_codes(value: &str) -> Vec { - let mut codes: Vec = vec![]; +pub fn parse_prefix_codes(value: &str) -> Vec { + let mut codes: Vec = vec![]; for code in COMMA_SEPARATED_LIST_RE.split(value) { let code = code.trim(); if code.is_empty() { @@ -23,7 +23,7 @@ pub fn parse_prefix_codes(value: &str) -> Vec { } if let Some(code) = PREFIX_REDIRECTS.get(code) { codes.push(code.clone()); - } else if let Ok(code) = RuleCodePrefix::from_str(code) { + } else if let Ok(code) = RuleSelector::from_str(code) { codes.push(code); } else { warn_user!("Unsupported prefix code: {code}"); @@ -96,7 +96,7 @@ impl State { prefix: code.clone(), }); } - } else if let Ok(code) = RuleCodePrefix::from_str(code) { + } else if let Ok(code) = RuleSelector::from_str(code) { for filename in &self.filenames { codes.push(PatternPrefixPair { pattern: filename.clone(), @@ -190,8 +190,8 @@ pub fn parse_files_to_codes_mapping(value: &str) -> Result, -) -> FxHashMap> { - let mut per_file_ignores: FxHashMap> = FxHashMap::default(); +) -> FxHashMap> { + let mut per_file_ignores: FxHashMap> = FxHashMap::default(); for pair in pairs { per_file_ignores .entry(pair.pattern) @@ -206,33 +206,33 @@ mod tests { use anyhow::Result; use super::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings}; - use crate::registry::RuleCodePrefix; + use crate::registry::RuleSelector; use crate::settings::types::PatternPrefixPair; #[test] fn it_parses_prefix_codes() { let actual = parse_prefix_codes(""); - let expected: Vec = vec![]; + let expected: Vec = vec![]; assert_eq!(actual, expected); let actual = parse_prefix_codes(" "); - let expected: Vec = vec![]; + let expected: Vec = vec![]; assert_eq!(actual, expected); let actual = parse_prefix_codes("F401"); - let expected = vec![RuleCodePrefix::F401]; + let expected = vec![RuleSelector::F401]; assert_eq!(actual, expected); let actual = parse_prefix_codes("F401,"); - let expected = vec![RuleCodePrefix::F401]; + let expected = vec![RuleSelector::F401]; assert_eq!(actual, expected); let actual = parse_prefix_codes("F401,E501"); - let expected = vec![RuleCodePrefix::F401, RuleCodePrefix::E501]; + let expected = vec![RuleSelector::F401, RuleSelector::E501]; assert_eq!(actual, expected); let actual = parse_prefix_codes("F401, E501"); - let expected = vec![RuleCodePrefix::F401, RuleCodePrefix::E501]; + let expected = vec![RuleSelector::F401, RuleSelector::E501]; assert_eq!(actual, expected); } @@ -285,11 +285,11 @@ mod tests { let expected: Vec = vec![ PatternPrefixPair { pattern: "locust/test/*".to_string(), - prefix: RuleCodePrefix::F841, + prefix: RuleSelector::F841, }, PatternPrefixPair { pattern: "examples/*".to_string(), - prefix: RuleCodePrefix::F841, + prefix: RuleSelector::F841, }, ]; assert_eq!(actual, expected); @@ -305,23 +305,23 @@ mod tests { let expected: Vec = vec![ PatternPrefixPair { pattern: "t/*".to_string(), - prefix: RuleCodePrefix::D, + prefix: RuleSelector::D, }, PatternPrefixPair { pattern: "setup.py".to_string(), - prefix: RuleCodePrefix::D, + prefix: RuleSelector::D, }, PatternPrefixPair { pattern: "examples/*".to_string(), - prefix: RuleCodePrefix::D, + prefix: RuleSelector::D, }, PatternPrefixPair { pattern: "docs/*".to_string(), - prefix: RuleCodePrefix::D, + prefix: RuleSelector::D, }, PatternPrefixPair { pattern: "extra/*".to_string(), - prefix: RuleCodePrefix::D, + prefix: RuleSelector::D, }, ]; assert_eq!(actual, expected); @@ -343,47 +343,47 @@ mod tests { let expected: Vec = vec![ PatternPrefixPair { pattern: "scrapy/__init__.py".to_string(), - prefix: RuleCodePrefix::E402, + prefix: RuleSelector::E402, }, PatternPrefixPair { pattern: "scrapy/core/downloader/handlers/http.py".to_string(), - prefix: RuleCodePrefix::F401, + prefix: RuleSelector::F401, }, PatternPrefixPair { pattern: "scrapy/http/__init__.py".to_string(), - prefix: RuleCodePrefix::F401, + prefix: RuleSelector::F401, }, PatternPrefixPair { pattern: "scrapy/linkextractors/__init__.py".to_string(), - prefix: RuleCodePrefix::E402, + prefix: RuleSelector::E402, }, PatternPrefixPair { pattern: "scrapy/linkextractors/__init__.py".to_string(), - prefix: RuleCodePrefix::F401, + prefix: RuleSelector::F401, }, PatternPrefixPair { pattern: "scrapy/selector/__init__.py".to_string(), - prefix: RuleCodePrefix::F401, + prefix: RuleSelector::F401, }, PatternPrefixPair { pattern: "scrapy/spiders/__init__.py".to_string(), - prefix: RuleCodePrefix::E402, + prefix: RuleSelector::E402, }, PatternPrefixPair { pattern: "scrapy/spiders/__init__.py".to_string(), - prefix: RuleCodePrefix::F401, + prefix: RuleSelector::F401, }, PatternPrefixPair { pattern: "scrapy/utils/url.py".to_string(), - prefix: RuleCodePrefix::F403, + prefix: RuleSelector::F403, }, PatternPrefixPair { pattern: "scrapy/utils/url.py".to_string(), - prefix: RuleCodePrefix::F405, + prefix: RuleSelector::F405, }, PatternPrefixPair { pattern: "tests/test_loader.py".to_string(), - prefix: RuleCodePrefix::E741, + prefix: RuleSelector::E741, }, ]; assert_eq!(actual, expected); diff --git a/src/flake8_to_ruff/plugin.rs b/src/flake8_to_ruff/plugin.rs index a0c2d0063b..4f8475df97 100644 --- a/src/flake8_to_ruff/plugin.rs +++ b/src/flake8_to_ruff/plugin.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use anyhow::anyhow; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; #[derive(Clone, Ord, PartialOrd, Eq, PartialEq)] pub enum Plugin { @@ -98,32 +98,32 @@ impl fmt::Debug for Plugin { } impl Plugin { - pub fn prefix(&self) -> RuleCodePrefix { + pub fn prefix(&self) -> RuleSelector { match self { - Plugin::Flake8Annotations => RuleCodePrefix::ANN, - Plugin::Flake8Bandit => RuleCodePrefix::S, + Plugin::Flake8Annotations => RuleSelector::ANN, + Plugin::Flake8Bandit => RuleSelector::S, // TODO(charlie): Handle rename of `B` to `BLE`. - Plugin::Flake8BlindExcept => RuleCodePrefix::BLE, - Plugin::Flake8Bugbear => RuleCodePrefix::B, - Plugin::Flake8Builtins => RuleCodePrefix::A, - Plugin::Flake8Comprehensions => RuleCodePrefix::C4, - Plugin::Flake8Datetimez => RuleCodePrefix::DTZ, - Plugin::Flake8Debugger => RuleCodePrefix::T1, - Plugin::Flake8Docstrings => RuleCodePrefix::D, + Plugin::Flake8BlindExcept => RuleSelector::BLE, + Plugin::Flake8Bugbear => RuleSelector::B, + Plugin::Flake8Builtins => RuleSelector::A, + Plugin::Flake8Comprehensions => RuleSelector::C4, + Plugin::Flake8Datetimez => RuleSelector::DTZ, + Plugin::Flake8Debugger => RuleSelector::T1, + Plugin::Flake8Docstrings => RuleSelector::D, // TODO(charlie): Handle rename of `E` to `ERA`. - Plugin::Flake8Eradicate => RuleCodePrefix::ERA, - Plugin::Flake8ErrMsg => RuleCodePrefix::EM, - Plugin::Flake8ImplicitStrConcat => RuleCodePrefix::ISC, - Plugin::Flake8Print => RuleCodePrefix::T2, - Plugin::Flake8PytestStyle => RuleCodePrefix::PT, - Plugin::Flake8Quotes => RuleCodePrefix::Q, - Plugin::Flake8Return => RuleCodePrefix::RET, - Plugin::Flake8Simplify => RuleCodePrefix::SIM, - Plugin::Flake8TidyImports => RuleCodePrefix::TID25, - Plugin::McCabe => RuleCodePrefix::C9, - Plugin::PandasVet => RuleCodePrefix::PD, - Plugin::PEP8Naming => RuleCodePrefix::N, - Plugin::Pyupgrade => RuleCodePrefix::UP, + Plugin::Flake8Eradicate => RuleSelector::ERA, + Plugin::Flake8ErrMsg => RuleSelector::EM, + Plugin::Flake8ImplicitStrConcat => RuleSelector::ISC, + Plugin::Flake8Print => RuleSelector::T2, + Plugin::Flake8PytestStyle => RuleSelector::PT, + Plugin::Flake8Quotes => RuleSelector::Q, + Plugin::Flake8Return => RuleSelector::RET, + Plugin::Flake8Simplify => RuleSelector::SIM, + Plugin::Flake8TidyImports => RuleSelector::TID25, + Plugin::McCabe => RuleSelector::C9, + Plugin::PandasVet => RuleSelector::PD, + Plugin::PEP8Naming => RuleSelector::N, + Plugin::Pyupgrade => RuleSelector::UP, } } } @@ -249,7 +249,7 @@ pub fn infer_plugins_from_options(flake8: &HashMap>) -> V /// /// For example, if the user ignores `ANN101`, we should infer that /// `flake8-annotations` is active. -pub fn infer_plugins_from_codes(codes: &BTreeSet) -> Vec { +pub fn infer_plugins_from_codes(codes: &BTreeSet) -> Vec { [ Plugin::Flake8Annotations, Plugin::Flake8Bandit, @@ -287,10 +287,10 @@ pub fn infer_plugins_from_codes(codes: &BTreeSet) -> Vec .collect() } -/// Resolve the set of enabled `RuleCodePrefix` values for the given +/// Resolve the set of enabled `RuleSelector` values for the given /// plugins. -pub fn resolve_select(plugins: &[Plugin]) -> BTreeSet { - let mut select = BTreeSet::from([RuleCodePrefix::F, RuleCodePrefix::E, RuleCodePrefix::W]); +pub fn resolve_select(plugins: &[Plugin]) -> BTreeSet { + let mut select = BTreeSet::from([RuleSelector::F, RuleSelector::E, RuleSelector::W]); select.extend(plugins.iter().map(Plugin::prefix)); select } diff --git a/src/registry.rs b/src/registry.rs index eb2d38b621..a68e38b96c 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -473,8 +473,8 @@ pub enum Linter { } pub enum Prefixes { - Single(RuleCodePrefix), - Multiple(Vec<(RuleCodePrefix, &'static str)>), + Single(RuleSelector), + Multiple(Vec<(RuleSelector, &'static str)>), } impl Prefixes { @@ -494,50 +494,50 @@ include!(concat!(env!("OUT_DIR"), "/linter.rs")); impl Linter { pub fn prefixes(&self) -> Prefixes { match self { - Linter::Eradicate => Prefixes::Single(RuleCodePrefix::ERA), - Linter::Flake82020 => Prefixes::Single(RuleCodePrefix::YTT), - Linter::Flake8Annotations => Prefixes::Single(RuleCodePrefix::ANN), - Linter::Flake8Bandit => Prefixes::Single(RuleCodePrefix::S), - Linter::Flake8BlindExcept => Prefixes::Single(RuleCodePrefix::BLE), - Linter::Flake8BooleanTrap => Prefixes::Single(RuleCodePrefix::FBT), - Linter::Flake8Bugbear => Prefixes::Single(RuleCodePrefix::B), - Linter::Flake8Builtins => Prefixes::Single(RuleCodePrefix::A), - Linter::Flake8Comprehensions => Prefixes::Single(RuleCodePrefix::C4), - Linter::Flake8Datetimez => Prefixes::Single(RuleCodePrefix::DTZ), - Linter::Flake8Debugger => Prefixes::Single(RuleCodePrefix::T10), - Linter::Flake8ErrMsg => Prefixes::Single(RuleCodePrefix::EM), - Linter::Flake8ImplicitStrConcat => Prefixes::Single(RuleCodePrefix::ISC), - Linter::Flake8ImportConventions => Prefixes::Single(RuleCodePrefix::ICN), - Linter::Flake8Print => Prefixes::Single(RuleCodePrefix::T20), - Linter::Flake8PytestStyle => Prefixes::Single(RuleCodePrefix::PT), - Linter::Flake8Quotes => Prefixes::Single(RuleCodePrefix::Q), - Linter::Flake8Return => Prefixes::Single(RuleCodePrefix::RET), - Linter::Flake8Simplify => Prefixes::Single(RuleCodePrefix::SIM), - Linter::Flake8TidyImports => Prefixes::Single(RuleCodePrefix::TID), - Linter::Flake8UnusedArguments => Prefixes::Single(RuleCodePrefix::ARG), - Linter::Isort => Prefixes::Single(RuleCodePrefix::I), - Linter::McCabe => Prefixes::Single(RuleCodePrefix::C90), - Linter::PEP8Naming => Prefixes::Single(RuleCodePrefix::N), - Linter::PandasVet => Prefixes::Single(RuleCodePrefix::PD), + Linter::Eradicate => Prefixes::Single(RuleSelector::ERA), + Linter::Flake82020 => Prefixes::Single(RuleSelector::YTT), + Linter::Flake8Annotations => Prefixes::Single(RuleSelector::ANN), + Linter::Flake8Bandit => Prefixes::Single(RuleSelector::S), + Linter::Flake8BlindExcept => Prefixes::Single(RuleSelector::BLE), + Linter::Flake8BooleanTrap => Prefixes::Single(RuleSelector::FBT), + Linter::Flake8Bugbear => Prefixes::Single(RuleSelector::B), + Linter::Flake8Builtins => Prefixes::Single(RuleSelector::A), + Linter::Flake8Comprehensions => Prefixes::Single(RuleSelector::C4), + Linter::Flake8Datetimez => Prefixes::Single(RuleSelector::DTZ), + Linter::Flake8Debugger => Prefixes::Single(RuleSelector::T10), + Linter::Flake8ErrMsg => Prefixes::Single(RuleSelector::EM), + Linter::Flake8ImplicitStrConcat => Prefixes::Single(RuleSelector::ISC), + Linter::Flake8ImportConventions => Prefixes::Single(RuleSelector::ICN), + Linter::Flake8Print => Prefixes::Single(RuleSelector::T20), + Linter::Flake8PytestStyle => Prefixes::Single(RuleSelector::PT), + Linter::Flake8Quotes => Prefixes::Single(RuleSelector::Q), + Linter::Flake8Return => Prefixes::Single(RuleSelector::RET), + Linter::Flake8Simplify => Prefixes::Single(RuleSelector::SIM), + Linter::Flake8TidyImports => Prefixes::Single(RuleSelector::TID), + Linter::Flake8UnusedArguments => Prefixes::Single(RuleSelector::ARG), + Linter::Isort => Prefixes::Single(RuleSelector::I), + Linter::McCabe => Prefixes::Single(RuleSelector::C90), + Linter::PEP8Naming => Prefixes::Single(RuleSelector::N), + Linter::PandasVet => Prefixes::Single(RuleSelector::PD), Linter::Pycodestyle => Prefixes::Multiple(vec![ - (RuleCodePrefix::E, "Error"), - (RuleCodePrefix::W, "Warning"), + (RuleSelector::E, "Error"), + (RuleSelector::W, "Warning"), ]), - Linter::Pydocstyle => Prefixes::Single(RuleCodePrefix::D), - Linter::Pyflakes => Prefixes::Single(RuleCodePrefix::F), - Linter::PygrepHooks => Prefixes::Single(RuleCodePrefix::PGH), + Linter::Pydocstyle => Prefixes::Single(RuleSelector::D), + Linter::Pyflakes => Prefixes::Single(RuleSelector::F), + Linter::PygrepHooks => Prefixes::Single(RuleSelector::PGH), Linter::Pylint => Prefixes::Multiple(vec![ - (RuleCodePrefix::PLC, "Convention"), - (RuleCodePrefix::PLE, "Error"), - (RuleCodePrefix::PLR, "Refactor"), - (RuleCodePrefix::PLW, "Warning"), + (RuleSelector::PLC, "Convention"), + (RuleSelector::PLE, "Error"), + (RuleSelector::PLR, "Refactor"), + (RuleSelector::PLW, "Warning"), ]), - Linter::Pyupgrade => Prefixes::Single(RuleCodePrefix::UP), - Linter::Flake8Pie => Prefixes::Single(RuleCodePrefix::PIE), - Linter::Flake8Commas => Prefixes::Single(RuleCodePrefix::COM), - Linter::Flake8NoPep420 => Prefixes::Single(RuleCodePrefix::INP), - Linter::Flake8Executable => Prefixes::Single(RuleCodePrefix::EXE), - Linter::Ruff => Prefixes::Single(RuleCodePrefix::RUF), + Linter::Pyupgrade => Prefixes::Single(RuleSelector::UP), + Linter::Flake8Pie => Prefixes::Single(RuleSelector::PIE), + Linter::Flake8Commas => Prefixes::Single(RuleSelector::COM), + Linter::Flake8NoPep420 => Prefixes::Single(RuleSelector::INP), + Linter::Flake8Executable => Prefixes::Single(RuleSelector::EXE), + Linter::Ruff => Prefixes::Single(RuleSelector::RUF), } } } diff --git a/src/rules/pandas_vet/mod.rs b/src/rules/pandas_vet/mod.rs index 256509f77b..226f5f45b3 100644 --- a/src/rules/pandas_vet/mod.rs +++ b/src/rules/pandas_vet/mod.rs @@ -12,14 +12,14 @@ mod tests { use textwrap::dedent; use crate::linter::check_path; - use crate::registry::{Rule, RuleCodePrefix}; + use crate::registry::{Rule, RuleSelector}; use crate::settings::flags; use crate::source_code::{Indexer, Locator, Stylist}; use crate::{directives, rustpython_helpers, settings}; fn rule_code(contents: &str, expected: &[Rule]) -> Result<()> { let contents = dedent(contents); - let settings = settings::Settings::for_rules(RuleCodePrefix::PD.codes()); + let settings = settings::Settings::for_rules(RuleSelector::PD.codes()); let tokens: Vec = rustpython_helpers::tokenize(&contents); let locator = Locator::new(&contents); let stylist = Stylist::from_contents(&contents, &locator); diff --git a/src/rules/pydocstyle/settings.rs b/src/rules/pydocstyle/settings.rs index 27c4668bd1..24c55d0069 100644 --- a/src/rules/pydocstyle/settings.rs +++ b/src/rules/pydocstyle/settings.rs @@ -4,7 +4,7 @@ use ruff_macros::ConfigurationOptions; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] @@ -18,55 +18,55 @@ pub enum Convention { } impl Convention { - pub fn codes(self) -> &'static [RuleCodePrefix] { + pub fn codes(self) -> &'static [RuleSelector] { match self { Convention::Google => &[ // All errors except D203, D204, D213, D215, D400, D401, D404, D406, D407, D408, // D409 and D413. - RuleCodePrefix::D203, - RuleCodePrefix::D204, - RuleCodePrefix::D213, - RuleCodePrefix::D215, - RuleCodePrefix::D400, - RuleCodePrefix::D404, - RuleCodePrefix::D406, - RuleCodePrefix::D407, - RuleCodePrefix::D408, - RuleCodePrefix::D409, - RuleCodePrefix::D413, + RuleSelector::D203, + RuleSelector::D204, + RuleSelector::D213, + RuleSelector::D215, + RuleSelector::D400, + RuleSelector::D404, + RuleSelector::D406, + RuleSelector::D407, + RuleSelector::D408, + RuleSelector::D409, + RuleSelector::D413, ], Convention::Numpy => &[ // All errors except D107, D203, D212, D213, D402, D413, D415, D416, and D417. - RuleCodePrefix::D107, - RuleCodePrefix::D203, - RuleCodePrefix::D212, - RuleCodePrefix::D213, - RuleCodePrefix::D402, - RuleCodePrefix::D413, - RuleCodePrefix::D415, - RuleCodePrefix::D416, - RuleCodePrefix::D417, + RuleSelector::D107, + RuleSelector::D203, + RuleSelector::D212, + RuleSelector::D213, + RuleSelector::D402, + RuleSelector::D413, + RuleSelector::D415, + RuleSelector::D416, + RuleSelector::D417, ], Convention::Pep257 => &[ // All errors except D203, D212, D213, D214, D215, D404, D405, D406, D407, D408, // D409, D410, D411, D413, D415, D416 and D417. - RuleCodePrefix::D203, - RuleCodePrefix::D212, - RuleCodePrefix::D213, - RuleCodePrefix::D214, - RuleCodePrefix::D215, - RuleCodePrefix::D404, - RuleCodePrefix::D405, - RuleCodePrefix::D406, - RuleCodePrefix::D407, - RuleCodePrefix::D408, - RuleCodePrefix::D409, - RuleCodePrefix::D410, - RuleCodePrefix::D411, - RuleCodePrefix::D413, - RuleCodePrefix::D415, - RuleCodePrefix::D416, - RuleCodePrefix::D417, + RuleSelector::D203, + RuleSelector::D212, + RuleSelector::D213, + RuleSelector::D214, + RuleSelector::D215, + RuleSelector::D404, + RuleSelector::D405, + RuleSelector::D406, + RuleSelector::D407, + RuleSelector::D408, + RuleSelector::D409, + RuleSelector::D410, + RuleSelector::D411, + RuleSelector::D413, + RuleSelector::D415, + RuleSelector::D416, + RuleSelector::D417, ], } } diff --git a/src/rules/pyflakes/mod.rs b/src/rules/pyflakes/mod.rs index 597e6f702e..d3d8625425 100644 --- a/src/rules/pyflakes/mod.rs +++ b/src/rules/pyflakes/mod.rs @@ -15,7 +15,7 @@ mod tests { use textwrap::dedent; use crate::linter::{check_path, test_path}; - use crate::registry::{Rule, RuleCodePrefix}; + use crate::registry::{Rule, RuleSelector}; use crate::settings::flags; use crate::source_code::{Indexer, Locator, Stylist}; use crate::{directives, rustpython_helpers, settings}; @@ -209,7 +209,7 @@ mod tests { /// Note that all tests marked with `#[ignore]` should be considered TODOs. fn flakes(contents: &str, expected: &[Rule]) -> Result<()> { let contents = dedent(contents); - let settings = settings::Settings::for_rules(RuleCodePrefix::F.codes()); + let settings = settings::Settings::for_rules(RuleSelector::F.codes()); let tokens: Vec = rustpython_helpers::tokenize(&contents); let locator = Locator::new(&contents); let stylist = Stylist::from_contents(&contents, &locator); diff --git a/src/settings/configuration.rs b/src/settings/configuration.rs index 712c3e3118..2a2873250e 100644 --- a/src/settings/configuration.rs +++ b/src/settings/configuration.rs @@ -13,7 +13,7 @@ use shellexpand; use shellexpand::LookupError; use crate::fs; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, @@ -34,28 +34,28 @@ pub struct Configuration { pub exclude: Option>, pub extend: Option, pub extend_exclude: Vec, - pub extend_ignore: Vec>, - pub extend_select: Vec>, + pub extend_ignore: Vec>, + pub extend_select: Vec>, pub external: Option>, pub fix: Option, pub fix_only: Option, - pub fixable: Option>, + pub fixable: Option>, pub force_exclude: Option, pub format: Option, - pub ignore: Option>, + pub ignore: Option>, pub ignore_init_module_imports: Option, pub line_length: Option, pub namespace_packages: Option>, pub per_file_ignores: Option>, pub required_version: Option, pub respect_gitignore: Option, - pub select: Option>, + pub select: Option>, pub show_source: Option, pub src: Option>, pub target_version: Option, pub task_tags: Option>, pub typing_modules: Option>, - pub unfixable: Option>, + pub unfixable: Option>, pub update_check: Option, // Plugins pub flake8_annotations: Option, diff --git a/src/settings/defaults.rs b/src/settings/defaults.rs index fd1208a246..e2f4beabc8 100644 --- a/src/settings/defaults.rs +++ b/src/settings/defaults.rs @@ -6,14 +6,14 @@ use rustc_hash::FxHashSet; use super::hashable::{HashableGlobSet, HashableHashSet}; use super::types::{FilePattern, PythonVersion}; use super::Settings; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, pyupgrade, }; -pub const PREFIXES: &[RuleCodePrefix] = &[RuleCodePrefix::E, RuleCodePrefix::F]; +pub const PREFIXES: &[RuleSelector] = &[RuleSelector::E, RuleSelector::F]; pub const TARGET_VERSION: PythonVersion = PythonVersion::Py310; @@ -51,7 +51,7 @@ pub static EXCLUDE: Lazy> = Lazy::new(|| { impl Default for Settings { fn default() -> Self { Self { - rules: PREFIXES.iter().flat_map(RuleCodePrefix::codes).into(), + rules: PREFIXES.iter().flat_map(RuleSelector::codes).into(), allowed_confusables: FxHashSet::from_iter([]).into(), builtins: vec![], dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone().into(), diff --git a/src/settings/mod.rs b/src/settings/mod.rs index c86aad1bcc..44269b2651 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -14,7 +14,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, RuleCodePrefix, SuffixLength, CATEGORIES, INCOMPATIBLE_CODES}; +use crate::registry::{Rule, RuleSelector, SuffixLength, CATEGORIES, INCOMPATIBLE_CODES}; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, @@ -237,12 +237,12 @@ impl Settings { } fn build_rule_table( - fixable: Option>, - unfixable: Option>, - select: Option>, - ignore: Option>, - extend_select: &[Vec], - extend_ignore: &[Vec], + fixable: Option>, + unfixable: Option>, + select: Option>, + ignore: Option>, + extend_select: &[Vec], + extend_ignore: &[Vec], pydocstyle: &Option, ) -> RuleTable { let mut rules = RuleTable::empty(); @@ -313,8 +313,8 @@ pub fn resolve_per_file_ignores( #[derive(Debug)] struct RuleCodeSpec<'a> { - select: &'a [RuleCodePrefix], - ignore: &'a [RuleCodePrefix], + select: &'a [RuleSelector], + ignore: &'a [RuleSelector], } /// Given a set of selected and ignored prefixes, resolve the set of enabled @@ -361,13 +361,13 @@ fn validate_enabled(enabled: FxHashSet) -> FxHashSet { mod tests { use rustc_hash::FxHashSet; - use crate::registry::{Rule, RuleCodePrefix}; + use crate::registry::{Rule, RuleSelector}; use crate::settings::{resolve_codes, RuleCodeSpec}; #[test] fn rule_codes() { let actual = resolve_codes([RuleCodeSpec { - select: &[RuleCodePrefix::W], + select: &[RuleSelector::W], ignore: &[], }]); let expected = FxHashSet::from_iter([ @@ -378,33 +378,33 @@ mod tests { assert_eq!(actual, expected); let actual = resolve_codes([RuleCodeSpec { - select: &[RuleCodePrefix::W6], + select: &[RuleSelector::W6], ignore: &[], }]); let expected = FxHashSet::from_iter([Rule::InvalidEscapeSequence]); assert_eq!(actual, expected); let actual = resolve_codes([RuleCodeSpec { - select: &[RuleCodePrefix::W], - ignore: &[RuleCodePrefix::W292], + select: &[RuleSelector::W], + ignore: &[RuleSelector::W292], }]); let expected = FxHashSet::from_iter([Rule::DocLineTooLong, Rule::InvalidEscapeSequence]); assert_eq!(actual, expected); let actual = resolve_codes([RuleCodeSpec { - select: &[RuleCodePrefix::W605], - ignore: &[RuleCodePrefix::W605], + select: &[RuleSelector::W605], + ignore: &[RuleSelector::W605], }]); let expected = FxHashSet::from_iter([]); assert_eq!(actual, expected); let actual = resolve_codes([ RuleCodeSpec { - select: &[RuleCodePrefix::W], - ignore: &[RuleCodePrefix::W292], + select: &[RuleSelector::W], + ignore: &[RuleSelector::W292], }, RuleCodeSpec { - select: &[RuleCodePrefix::W292], + select: &[RuleSelector::W292], ignore: &[], }, ]); @@ -417,12 +417,12 @@ mod tests { let actual = resolve_codes([ RuleCodeSpec { - select: &[RuleCodePrefix::W], - ignore: &[RuleCodePrefix::W292], + select: &[RuleSelector::W], + ignore: &[RuleSelector::W292], }, RuleCodeSpec { - select: &[RuleCodePrefix::W292], - ignore: &[RuleCodePrefix::W], + select: &[RuleSelector::W292], + ignore: &[RuleSelector::W], }, ]); let expected = FxHashSet::from_iter([Rule::NoNewLineAtEndOfFile]); diff --git a/src/settings/options.rs b/src/settings/options.rs index 5c909003c1..96c46567ae 100644 --- a/src/settings/options.rs +++ b/src/settings/options.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHashMap; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::registry::RuleCodePrefix; +use crate::registry::RuleSelector; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, @@ -135,7 +135,7 @@ pub struct Options { pub extend_exclude: Option>, #[option( default = "[]", - value_type = "Vec", + value_type = "Vec", example = r#" # Skip unused variable rules (`F841`). extend-ignore = ["F841"] @@ -149,10 +149,10 @@ pub struct Options { /// would overwrite a more specific rule in `select`. It is /// recommended to only use `extend-ignore` when extending a /// `pyproject.toml` file via `extend`. - pub extend_ignore: Option>, + pub extend_ignore: Option>, #[option( default = "[]", - value_type = "Vec", + value_type = "Vec", example = r#" # On top of the default `select` (`E`, `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`). extend-select = ["B", "Q"] @@ -166,7 +166,7 @@ pub struct Options { /// would overwrite a more specific rule in `ignore`. It is /// recommended to only use `extend-select` when extending a /// `pyproject.toml` file via `extend`. - pub extend_select: Option>, + pub extend_select: Option>, #[option( default = "[]", value_type = "Vec", @@ -190,14 +190,14 @@ pub struct Options { pub fix_only: Option, #[option( default = r#"["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]"#, - value_type = "Vec", + value_type = "Vec", example = r#" # Only allow autofix behavior for `E` and `F` rules. fixable = ["E", "F"] "# )] /// A list of rule codes or prefixes to consider autofixable. - pub fixable: Option>, + pub fixable: Option>, #[option( default = r#""text""#, value_type = "SerializationType", @@ -232,7 +232,7 @@ pub struct Options { pub force_exclude: Option, #[option( default = "[]", - value_type = "Vec", + value_type = "Vec", example = r#" # Skip unused variable rules (`F841`). ignore = ["F841"] @@ -245,7 +245,7 @@ pub struct Options { /// When breaking ties between enabled and disabled rules (via `select` and /// `ignore`, respectively), more specific prefixes override less /// specific prefixes. - pub ignore: Option>, + pub ignore: Option>, #[option( default = "false", value_type = "bool", @@ -294,7 +294,7 @@ pub struct Options { pub respect_gitignore: Option, #[option( default = r#"["E", "F"]"#, - value_type = "Vec", + value_type = "Vec", example = r#" # On top of the defaults (`E`, `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`). select = ["E", "F", "B", "Q"] @@ -307,7 +307,7 @@ pub struct Options { /// When breaking ties between enabled and disabled rules (via `select` and /// `ignore`, respectively), more specific prefixes override less /// specific prefixes. - pub select: Option>, + pub select: Option>, #[option( default = "false", value_type = "bool", @@ -403,14 +403,14 @@ pub struct Options { pub typing_modules: Option>, #[option( default = "[]", - value_type = "Vec", + value_type = "Vec", example = r#" # Disable autofix for unused imports (`F401`). unfixable = ["F401"] "# )] /// A list of rule codes or prefixes to consider non-autofix-able. - pub unfixable: Option>, + pub unfixable: Option>, #[option( default = "false", value_type = "bool", @@ -470,7 +470,7 @@ pub struct Options { // Tables are required to go last. #[option( default = "{}", - value_type = "HashMap>", + value_type = "HashMap>", example = r#" # Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`. [tool.ruff.per-file-ignores] @@ -480,5 +480,5 @@ pub struct Options { )] /// A list of mappings from file pattern to rule codes or prefixes to /// exclude, when considering any matching files. - pub per_file_ignores: Option>>, + pub per_file_ignores: Option>>, } diff --git a/src/settings/pyproject.rs b/src/settings/pyproject.rs index f0210d7d5a..cab9770e43 100644 --- a/src/settings/pyproject.rs +++ b/src/settings/pyproject.rs @@ -129,7 +129,7 @@ mod tests { use anyhow::Result; use rustc_hash::FxHashMap; - use crate::registry::RuleCodePrefix; + use crate::registry::RuleSelector; use crate::rules::flake8_quotes::settings::Quote; use crate::rules::flake8_tidy_imports::banned_api::ApiBan; use crate::rules::flake8_tidy_imports::relative_imports::Strictness; @@ -369,7 +369,7 @@ select = ["E501"] per_file_ignores: None, required_version: None, respect_gitignore: None, - select: Some(vec![RuleCodePrefix::E501]), + select: Some(vec![RuleSelector::E501]), show_source: None, src: None, target_version: None, @@ -417,14 +417,14 @@ ignore = ["E501"] extend: None, extend_exclude: None, extend_ignore: None, - extend_select: Some(vec![RuleCodePrefix::RUF100]), + extend_select: Some(vec![RuleSelector::RUF100]), external: None, fix: None, fix_only: None, fixable: None, force_exclude: None, format: None, - ignore: Some(vec![RuleCodePrefix::E501]), + ignore: Some(vec![RuleSelector::E501]), ignore_init_module_imports: None, line_length: None, namespace_packages: None, @@ -534,7 +534,7 @@ other-attribute = 1 cache_dir: None, per_file_ignores: Some(FxHashMap::from_iter([( "__init__.py".to_string(), - vec![RuleCodePrefix::F401] + vec![RuleSelector::F401] )])), dummy_variable_rgx: None, respect_gitignore: None, diff --git a/src/settings/types.rs b/src/settings/types.rs index 92e3fa7e60..de0cde43da 100644 --- a/src/settings/types.rs +++ b/src/settings/types.rs @@ -12,7 +12,7 @@ use serde::{de, Deserialize, Deserializer, Serialize}; use super::hashable::HashableHashSet; use crate::fs; -use crate::registry::{Rule, RuleCodePrefix}; +use crate::registry::{Rule, RuleSelector}; #[derive( Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema, @@ -93,8 +93,8 @@ pub struct PerFileIgnore { } impl PerFileIgnore { - pub fn new(basename: String, absolute: PathBuf, prefixes: &[RuleCodePrefix]) -> Self { - let codes: FxHashSet<_> = prefixes.iter().flat_map(RuleCodePrefix::codes).collect(); + pub fn new(basename: String, absolute: PathBuf, prefixes: &[RuleSelector]) -> Self { + let codes: FxHashSet<_> = prefixes.iter().flat_map(RuleSelector::codes).collect(); Self { basename, absolute, @@ -106,7 +106,7 @@ impl PerFileIgnore { #[derive(Clone, Debug, PartialEq, Eq)] pub struct PatternPrefixPair { pub pattern: String, - pub prefix: RuleCodePrefix, + pub prefix: RuleSelector, } impl PatternPrefixPair { @@ -140,7 +140,7 @@ impl FromStr for PatternPrefixPair { (tokens[0].trim(), tokens[1].trim()) }; let pattern = pattern_str.into(); - let prefix = RuleCodePrefix::from_str(code_string)?; + let prefix = RuleSelector::from_str(code_string)?; Ok(Self { pattern, prefix }) } }