mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Auto-generate CheckCodePrefix::fixables() (#916)
This commit is contained in:
parent
f299940452
commit
d19a8aa54d
3 changed files with 39 additions and 23 deletions
|
@ -130,6 +130,21 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
output.push('\n');
|
output.push('\n');
|
||||||
output.push('\n');
|
output.push('\n');
|
||||||
output.push_str(&scope.to_string());
|
output.push_str(&scope.to_string());
|
||||||
|
output.push('\n');
|
||||||
|
output.push('\n');
|
||||||
|
|
||||||
|
// Add the list of output categories (not generated).
|
||||||
|
output.push_str("pub const CATEGORIES: &[CheckCodePrefix] = &[");
|
||||||
|
output.push('\n');
|
||||||
|
for prefix in prefix_to_codes.keys() {
|
||||||
|
if prefix.chars().all(char::is_alphabetic) {
|
||||||
|
output.push_str(&format!("CheckCodePrefix::{prefix},"));
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.push_str("];");
|
||||||
|
output.push('\n');
|
||||||
|
output.push('\n');
|
||||||
|
|
||||||
// Write the output to `src/checks_gen.rs` (or stdout).
|
// Write the output to `src/checks_gen.rs` (or stdout).
|
||||||
if cli.dry_run {
|
if cli.dry_run {
|
||||||
|
|
|
@ -1603,3 +1603,25 @@ impl CheckCodePrefix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const CATEGORIES: &[CheckCodePrefix] = &[
|
||||||
|
CheckCodePrefix::A,
|
||||||
|
CheckCodePrefix::ANN,
|
||||||
|
CheckCodePrefix::B,
|
||||||
|
CheckCodePrefix::BLE,
|
||||||
|
CheckCodePrefix::C,
|
||||||
|
CheckCodePrefix::D,
|
||||||
|
CheckCodePrefix::E,
|
||||||
|
CheckCodePrefix::F,
|
||||||
|
CheckCodePrefix::FBT,
|
||||||
|
CheckCodePrefix::I,
|
||||||
|
CheckCodePrefix::M,
|
||||||
|
CheckCodePrefix::N,
|
||||||
|
CheckCodePrefix::Q,
|
||||||
|
CheckCodePrefix::RUF,
|
||||||
|
CheckCodePrefix::S,
|
||||||
|
CheckCodePrefix::T,
|
||||||
|
CheckCodePrefix::U,
|
||||||
|
CheckCodePrefix::W,
|
||||||
|
CheckCodePrefix::YTT,
|
||||||
|
];
|
||||||
|
|
|
@ -9,7 +9,7 @@ use once_cell::sync::Lazy;
|
||||||
use path_absolutize::path_dedot;
|
use path_absolutize::path_dedot;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::checks_gen::CheckCodePrefix;
|
use crate::checks_gen::{CheckCodePrefix, CATEGORIES};
|
||||||
use crate::settings::pyproject::load_options;
|
use crate::settings::pyproject::load_options;
|
||||||
use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion};
|
use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -117,28 +117,7 @@ impl Configuration {
|
||||||
.unwrap_or_else(|| vec![CheckCodePrefix::E, CheckCodePrefix::F]),
|
.unwrap_or_else(|| vec![CheckCodePrefix::E, CheckCodePrefix::F]),
|
||||||
extend_select: options.extend_select.unwrap_or_default(),
|
extend_select: options.extend_select.unwrap_or_default(),
|
||||||
fix: options.fix.unwrap_or_default(),
|
fix: options.fix.unwrap_or_default(),
|
||||||
fixable: options.fixable.unwrap_or_else(|| {
|
fixable: options.fixable.unwrap_or_else(|| CATEGORIES.to_vec()),
|
||||||
// TODO(charlie): Autogenerate this list.
|
|
||||||
vec![
|
|
||||||
CheckCodePrefix::A,
|
|
||||||
CheckCodePrefix::B,
|
|
||||||
CheckCodePrefix::BLE,
|
|
||||||
CheckCodePrefix::C,
|
|
||||||
CheckCodePrefix::D,
|
|
||||||
CheckCodePrefix::E,
|
|
||||||
CheckCodePrefix::F,
|
|
||||||
CheckCodePrefix::I,
|
|
||||||
CheckCodePrefix::M,
|
|
||||||
CheckCodePrefix::N,
|
|
||||||
CheckCodePrefix::Q,
|
|
||||||
CheckCodePrefix::RUF,
|
|
||||||
CheckCodePrefix::S,
|
|
||||||
CheckCodePrefix::T,
|
|
||||||
CheckCodePrefix::U,
|
|
||||||
CheckCodePrefix::W,
|
|
||||||
CheckCodePrefix::YTT,
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
unfixable: options.unfixable.unwrap_or_default(),
|
unfixable: options.unfixable.unwrap_or_default(),
|
||||||
ignore: options.ignore.unwrap_or_default(),
|
ignore: options.ignore.unwrap_or_default(),
|
||||||
line_length: options.line_length.unwrap_or(88),
|
line_length: options.line_length.unwrap_or(88),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue