mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
Use CheckCategory to drive default rules
This commit is contained in:
parent
bd4394aa89
commit
8a47ea91ba
2 changed files with 19 additions and 60 deletions
|
@ -8,55 +8,6 @@ use strum_macros::{AsRefStr, EnumIter, EnumString};
|
|||
use crate::ast::checkers::Primitive;
|
||||
use crate::ast::types::Range;
|
||||
|
||||
pub const DEFAULT_CHECK_CODES: [CheckCode; 43] = [
|
||||
// pycodestyle errors
|
||||
CheckCode::E402,
|
||||
CheckCode::E501,
|
||||
CheckCode::E711,
|
||||
CheckCode::E712,
|
||||
CheckCode::E713,
|
||||
CheckCode::E714,
|
||||
CheckCode::E721,
|
||||
CheckCode::E722,
|
||||
CheckCode::E731,
|
||||
CheckCode::E741,
|
||||
CheckCode::E742,
|
||||
CheckCode::E743,
|
||||
CheckCode::E902,
|
||||
CheckCode::E999,
|
||||
// pycodestyle warnings
|
||||
CheckCode::W292,
|
||||
// pyflakes
|
||||
CheckCode::F401,
|
||||
CheckCode::F402,
|
||||
CheckCode::F403,
|
||||
CheckCode::F404,
|
||||
CheckCode::F405,
|
||||
CheckCode::F406,
|
||||
CheckCode::F407,
|
||||
CheckCode::F541,
|
||||
CheckCode::F601,
|
||||
CheckCode::F602,
|
||||
CheckCode::F621,
|
||||
CheckCode::F622,
|
||||
CheckCode::F631,
|
||||
CheckCode::F632,
|
||||
CheckCode::F633,
|
||||
CheckCode::F634,
|
||||
CheckCode::F701,
|
||||
CheckCode::F702,
|
||||
CheckCode::F704,
|
||||
CheckCode::F706,
|
||||
CheckCode::F707,
|
||||
CheckCode::F722,
|
||||
CheckCode::F821,
|
||||
CheckCode::F822,
|
||||
CheckCode::F823,
|
||||
CheckCode::F831,
|
||||
CheckCode::F841,
|
||||
CheckCode::F901,
|
||||
];
|
||||
|
||||
#[derive(
|
||||
AsRefStr,
|
||||
EnumIter,
|
||||
|
@ -216,7 +167,7 @@ pub enum CheckCategory {
|
|||
Pycodestyle,
|
||||
Pydocstyle,
|
||||
Pyupgrade,
|
||||
Pep8Naming,
|
||||
PEP8Naming,
|
||||
Flake8Comprehensions,
|
||||
Flake8Bugbear,
|
||||
Flake8Builtins,
|
||||
|
@ -235,7 +186,7 @@ impl CheckCategory {
|
|||
CheckCategory::Flake8Print => "flake8-print",
|
||||
CheckCategory::Pyupgrade => "pyupgrade",
|
||||
CheckCategory::Pydocstyle => "pydocstyle",
|
||||
CheckCategory::Pep8Naming => "pep8-naming",
|
||||
CheckCategory::PEP8Naming => "pep8-naming",
|
||||
CheckCategory::Meta => "Meta rules",
|
||||
}
|
||||
}
|
||||
|
@ -690,11 +641,11 @@ impl CheckCode {
|
|||
CheckCode::D417 => CheckCategory::Pydocstyle,
|
||||
CheckCode::D418 => CheckCategory::Pydocstyle,
|
||||
CheckCode::D419 => CheckCategory::Pydocstyle,
|
||||
CheckCode::N801 => CheckCategory::Pep8Naming,
|
||||
CheckCode::N802 => CheckCategory::Pep8Naming,
|
||||
CheckCode::N803 => CheckCategory::Pep8Naming,
|
||||
CheckCode::N804 => CheckCategory::Pep8Naming,
|
||||
CheckCode::N805 => CheckCategory::Pep8Naming,
|
||||
CheckCode::N801 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N802 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N803 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N804 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N805 => CheckCategory::PEP8Naming,
|
||||
CheckCode::M001 => CheckCategory::Meta,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@ use glob::Pattern;
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::checks::{CheckCode, DEFAULT_CHECK_CODES};
|
||||
use crate::checks::{CheckCategory, CheckCode};
|
||||
use crate::fs;
|
||||
use crate::pyproject::{load_config, StrCheckCodePair};
|
||||
|
||||
|
@ -153,9 +154,16 @@ impl RawSettings {
|
|||
.map(|path| FilePattern::from_user(path, project_root))
|
||||
.collect(),
|
||||
extend_ignore: config.extend_ignore,
|
||||
select: config
|
||||
.select
|
||||
.unwrap_or_else(|| DEFAULT_CHECK_CODES.to_vec()),
|
||||
select: config.select.unwrap_or_else(|| {
|
||||
CheckCode::iter()
|
||||
.filter(|code| {
|
||||
matches!(
|
||||
code.category(),
|
||||
CheckCategory::Pycodestyle | CheckCategory::Pyflakes
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
extend_select: config.extend_select,
|
||||
ignore: config.ignore,
|
||||
line_length: config.line_length.unwrap_or(88),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue