mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-22 16:22:52 +00:00
refactor: Rename RuleCodePrefix to RuleSelector
More accurate since the enum also encompasses: * ALL (which isn't a prefix at all) * fully-qualified rule codes (which aren't prefixes unless you say they're a prefix to the empty string but that's not intuitive)
This commit is contained in:
parent
7fc42f8f85
commit
b19258a243
20 changed files with 256 additions and 276 deletions
14
README.md
14
README.md
|
@ -1980,7 +1980,7 @@ recommended to only use `extend-ignore` when extending a
|
|||
|
||||
**Default value**: `[]`
|
||||
|
||||
**Type**: `Vec<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
@ -2005,7 +2005,7 @@ recommended to only use `extend-select` when extending a
|
|||
|
||||
**Default value**: `[]`
|
||||
|
||||
**Type**: `Vec<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**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<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
@ -2152,7 +2152,7 @@ specific prefixes.
|
|||
|
||||
**Default value**: `[]`
|
||||
|
||||
**Type**: `Vec<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
@ -2230,7 +2230,7 @@ exclude, when considering any matching files.
|
|||
|
||||
**Default value**: `{}`
|
||||
|
||||
**Type**: `HashMap<String, Vec<RuleCodePrefix>>`
|
||||
**Type**: `HashMap<String, Vec<RuleSelector>>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
@ -2294,7 +2294,7 @@ specific prefixes.
|
|||
|
||||
**Default value**: `["E", "F"]`
|
||||
|
||||
**Type**: `Vec<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
@ -2438,7 +2438,7 @@ A list of rule codes or prefixes to consider non-autofix-able.
|
|||
|
||||
**Default value**: `[]`
|
||||
|
||||
**Type**: `Vec<RuleCodePrefix>`
|
||||
**Type**: `Vec<RuleSelector>`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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<Vec<RuleCodePrefix>>,
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
/// 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<Vec<RuleCodePrefix>>,
|
||||
pub extend_select: Option<Vec<RuleSelector>>,
|
||||
/// Comma-separated list of rule codes to disable.
|
||||
#[arg(long, value_delimiter = ',', value_name = "RULE_CODE")]
|
||||
pub ignore: Option<Vec<RuleCodePrefix>>,
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
/// 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<Vec<RuleCodePrefix>>,
|
||||
pub extend_ignore: Option<Vec<RuleSelector>>,
|
||||
/// List of paths, used to omit files and/or directories from analysis.
|
||||
#[arg(long, value_delimiter = ',', value_name = "FILE_PATTERN")]
|
||||
pub exclude: Option<Vec<FilePattern>>,
|
||||
|
@ -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<Vec<RuleCodePrefix>>,
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
/// 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<Vec<RuleCodePrefix>>,
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
/// List of mappings from file pattern to code to exclude
|
||||
#[arg(long, value_delimiter = ',')]
|
||||
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||
|
@ -324,17 +324,17 @@ pub struct Overrides {
|
|||
pub dummy_variable_rgx: Option<Regex>,
|
||||
pub exclude: Option<Vec<FilePattern>>,
|
||||
pub extend_exclude: Option<Vec<FilePattern>>,
|
||||
pub extend_ignore: Option<Vec<RuleCodePrefix>>,
|
||||
pub extend_select: Option<Vec<RuleCodePrefix>>,
|
||||
pub fixable: Option<Vec<RuleCodePrefix>>,
|
||||
pub ignore: Option<Vec<RuleCodePrefix>>,
|
||||
pub extend_ignore: Option<Vec<RuleSelector>>,
|
||||
pub extend_select: Option<Vec<RuleSelector>>,
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
pub line_length: Option<usize>,
|
||||
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||
pub respect_gitignore: Option<bool>,
|
||||
pub select: Option<Vec<RuleCodePrefix>>,
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
pub show_source: Option<bool>,
|
||||
pub target_version: Option<PythonVersion>,
|
||||
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
// TODO(charlie): Captured in pyproject.toml as a default, but not part of `Settings`.
|
||||
pub cache_dir: Option<PathBuf>,
|
||||
pub fix: Option<bool>,
|
||||
|
@ -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<PatternPrefixPair>) -> Vec<PerFileIgnore> {
|
||||
let mut per_file_ignores: FxHashMap<String, Vec<RuleCodePrefix>> = FxHashMap::default();
|
||||
let mut per_file_ignores: FxHashMap<String, Vec<RuleSelector>> = FxHashMap::default();
|
||||
for pair in pairs {
|
||||
per_file_ignores
|
||||
.entry(pair.pattern)
|
||||
|
|
|
@ -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("| ---- | ---- | ------- | --- |");
|
||||
|
|
|
@ -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],
|
||||
);
|
||||
|
|
|
@ -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<HashMap<&'static str, &'static str>> = 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),*
|
||||
|
|
|
@ -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}),"
|
||||
|
|
|
@ -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<RuleCodePrefix> = BTreeSet::default();
|
||||
let mut referenced_codes: BTreeSet<RuleSelector> = 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,
|
||||
|
|
|
@ -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<Regex> = 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<RuleCodePrefix> {
|
||||
let mut codes: Vec<RuleCodePrefix> = vec![];
|
||||
pub fn parse_prefix_codes(value: &str) -> Vec<RuleSelector> {
|
||||
let mut codes: Vec<RuleSelector> = 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<RuleCodePrefix> {
|
|||
}
|
||||
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<Vec<PatternPrefixPair
|
|||
/// Collect a list of `PatternPrefixPair` structs as a `BTreeMap`.
|
||||
pub fn collect_per_file_ignores(
|
||||
pairs: Vec<PatternPrefixPair>,
|
||||
) -> FxHashMap<String, Vec<RuleCodePrefix>> {
|
||||
let mut per_file_ignores: FxHashMap<String, Vec<RuleCodePrefix>> = FxHashMap::default();
|
||||
) -> FxHashMap<String, Vec<RuleSelector>> {
|
||||
let mut per_file_ignores: FxHashMap<String, Vec<RuleSelector>> = 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<RuleCodePrefix> = vec![];
|
||||
let expected: Vec<RuleSelector> = vec![];
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
let actual = parse_prefix_codes(" ");
|
||||
let expected: Vec<RuleCodePrefix> = vec![];
|
||||
let expected: Vec<RuleSelector> = 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<PatternPrefixPair> = 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<PatternPrefixPair> = 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<PatternPrefixPair> = 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);
|
||||
|
|
|
@ -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<String, Option<String>>) -> V
|
|||
///
|
||||
/// For example, if the user ignores `ANN101`, we should infer that
|
||||
/// `flake8-annotations` is active.
|
||||
pub fn infer_plugins_from_codes(codes: &BTreeSet<RuleCodePrefix>) -> Vec<Plugin> {
|
||||
pub fn infer_plugins_from_codes(codes: &BTreeSet<RuleSelector>) -> Vec<Plugin> {
|
||||
[
|
||||
Plugin::Flake8Annotations,
|
||||
Plugin::Flake8Bandit,
|
||||
|
@ -287,10 +287,10 @@ pub fn infer_plugins_from_codes(codes: &BTreeSet<RuleCodePrefix>) -> Vec<Plugin>
|
|||
.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<RuleCodePrefix> {
|
||||
let mut select = BTreeSet::from([RuleCodePrefix::F, RuleCodePrefix::E, RuleCodePrefix::W]);
|
||||
pub fn resolve_select(plugins: &[Plugin]) -> BTreeSet<RuleSelector> {
|
||||
let mut select = BTreeSet::from([RuleSelector::F, RuleSelector::E, RuleSelector::W]);
|
||||
select.extend(plugins.iter().map(Plugin::prefix));
|
||||
select
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LexResult> = rustpython_helpers::tokenize(&contents);
|
||||
let locator = Locator::new(&contents);
|
||||
let stylist = Stylist::from_contents(&contents, &locator);
|
||||
|
|
|
@ -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,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LexResult> = rustpython_helpers::tokenize(&contents);
|
||||
let locator = Locator::new(&contents);
|
||||
let stylist = Stylist::from_contents(&contents, &locator);
|
||||
|
|
|
@ -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<Vec<FilePattern>>,
|
||||
pub extend: Option<PathBuf>,
|
||||
pub extend_exclude: Vec<FilePattern>,
|
||||
pub extend_ignore: Vec<Vec<RuleCodePrefix>>,
|
||||
pub extend_select: Vec<Vec<RuleCodePrefix>>,
|
||||
pub extend_ignore: Vec<Vec<RuleSelector>>,
|
||||
pub extend_select: Vec<Vec<RuleSelector>>,
|
||||
pub external: Option<Vec<String>>,
|
||||
pub fix: Option<bool>,
|
||||
pub fix_only: Option<bool>,
|
||||
pub fixable: Option<Vec<RuleCodePrefix>>,
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
pub force_exclude: Option<bool>,
|
||||
pub format: Option<SerializationFormat>,
|
||||
pub ignore: Option<Vec<RuleCodePrefix>>,
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
pub ignore_init_module_imports: Option<bool>,
|
||||
pub line_length: Option<usize>,
|
||||
pub namespace_packages: Option<Vec<PathBuf>>,
|
||||
pub per_file_ignores: Option<Vec<PerFileIgnore>>,
|
||||
pub required_version: Option<Version>,
|
||||
pub respect_gitignore: Option<bool>,
|
||||
pub select: Option<Vec<RuleCodePrefix>>,
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
pub show_source: Option<bool>,
|
||||
pub src: Option<Vec<PathBuf>>,
|
||||
pub target_version: Option<PythonVersion>,
|
||||
pub task_tags: Option<Vec<String>>,
|
||||
pub typing_modules: Option<Vec<String>>,
|
||||
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
pub update_check: Option<bool>,
|
||||
// Plugins
|
||||
pub flake8_annotations: Option<flake8_annotations::settings::Options>,
|
||||
|
|
|
@ -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<Vec<FilePattern>> = 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(),
|
||||
|
|
|
@ -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<Vec<RuleCodePrefix>>,
|
||||
unfixable: Option<Vec<RuleCodePrefix>>,
|
||||
select: Option<Vec<RuleCodePrefix>>,
|
||||
ignore: Option<Vec<RuleCodePrefix>>,
|
||||
extend_select: &[Vec<RuleCodePrefix>],
|
||||
extend_ignore: &[Vec<RuleCodePrefix>],
|
||||
fixable: Option<Vec<RuleSelector>>,
|
||||
unfixable: Option<Vec<RuleSelector>>,
|
||||
select: Option<Vec<RuleSelector>>,
|
||||
ignore: Option<Vec<RuleSelector>>,
|
||||
extend_select: &[Vec<RuleSelector>],
|
||||
extend_ignore: &[Vec<RuleSelector>],
|
||||
pydocstyle: &Option<pydocstyle::settings::Options>,
|
||||
) -> 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<Rule>) -> FxHashSet<Rule> {
|
|||
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]);
|
||||
|
|
|
@ -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<Vec<String>>,
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "Vec<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub extend_ignore: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "Vec<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub extend_select: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "Vec<String>",
|
||||
|
@ -190,14 +190,14 @@ pub struct Options {
|
|||
pub fix_only: Option<bool>,
|
||||
#[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<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = r#""text""#,
|
||||
value_type = "SerializationType",
|
||||
|
@ -232,7 +232,7 @@ pub struct Options {
|
|||
pub force_exclude: Option<bool>,
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "Vec<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = "false",
|
||||
value_type = "bool",
|
||||
|
@ -294,7 +294,7 @@ pub struct Options {
|
|||
pub respect_gitignore: Option<bool>,
|
||||
#[option(
|
||||
default = r#"["E", "F"]"#,
|
||||
value_type = "Vec<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = "false",
|
||||
value_type = "bool",
|
||||
|
@ -403,14 +403,14 @@ pub struct Options {
|
|||
pub typing_modules: Option<Vec<String>>,
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "Vec<RuleCodePrefix>",
|
||||
value_type = "Vec<RuleSelector>",
|
||||
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<Vec<RuleCodePrefix>>,
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
#[option(
|
||||
default = "false",
|
||||
value_type = "bool",
|
||||
|
@ -470,7 +470,7 @@ pub struct Options {
|
|||
// Tables are required to go last.
|
||||
#[option(
|
||||
default = "{}",
|
||||
value_type = "HashMap<String, Vec<RuleCodePrefix>>",
|
||||
value_type = "HashMap<String, Vec<RuleSelector>>",
|
||||
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<FxHashMap<String, Vec<RuleCodePrefix>>>,
|
||||
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue