mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Change Ruff's error prefix to RUF (#592)
This commit is contained in:
parent
d3472104d0
commit
fbdc075e5c
10 changed files with 44 additions and 39 deletions
|
@ -500,8 +500,8 @@ The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` com
|
|||
|
||||
| Code | Name | Message | Fix |
|
||||
| ---- | ---- | ------- | --- |
|
||||
| X001 | AmbiguousUnicodeCharacterString | String contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||
| X002 | AmbiguousUnicodeCharacterDocstring | Docstring contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||
| RUF001 | AmbiguousUnicodeCharacterString | String contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||
| RUF002 | AmbiguousUnicodeCharacterDocstring | Docstring contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||
|
||||
### Meta rules
|
||||
|
||||
|
|
|
@ -11,8 +11,12 @@ fn main() {
|
|||
// Build up a map from prefix to matching CheckCodes.
|
||||
let mut prefix_to_codes: BTreeMap<String, BTreeSet<CheckCode>> = Default::default();
|
||||
for check_code in CheckCode::iter() {
|
||||
let as_ref = check_code.as_ref().to_string();
|
||||
for i in 1..=as_ref.len() {
|
||||
let as_ref: String = check_code.as_ref().to_string();
|
||||
let prefix_len = as_ref
|
||||
.chars()
|
||||
.take_while(|char| char.is_alphabetic())
|
||||
.count();
|
||||
for i in prefix_len..=as_ref.len() {
|
||||
let prefix = as_ref[..i].to_string();
|
||||
let entry = prefix_to_codes
|
||||
.entry(prefix)
|
||||
|
@ -81,11 +85,12 @@ fn main() {
|
|||
.vis("pub")
|
||||
.line("match self {");
|
||||
for (prefix, _) in &prefix_to_codes {
|
||||
let specificity = match prefix.len() {
|
||||
4 => "Explicit",
|
||||
3 => "Tens",
|
||||
2 => "Hundreds",
|
||||
1 => "Category",
|
||||
let num_numeric = prefix.chars().filter(|char| char.is_numeric()).count();
|
||||
let specificity = match num_numeric {
|
||||
3 => "Explicit",
|
||||
2 => "Tens",
|
||||
1 => "Hundreds",
|
||||
0 => "Category",
|
||||
_ => panic!("Invalid prefix: {}", prefix),
|
||||
};
|
||||
gen = gen.line(format!(
|
||||
|
|
|
@ -15,8 +15,8 @@ pub fn check_tokens(
|
|||
settings: &Settings,
|
||||
autofix: &fixer::Mode,
|
||||
) {
|
||||
let enforce_ambiguous_unicode_character =
|
||||
settings.enabled.contains(&CheckCode::X001) || settings.enabled.contains(&CheckCode::X002);
|
||||
let enforce_ambiguous_unicode_character = settings.enabled.contains(&CheckCode::RUF001)
|
||||
|| settings.enabled.contains(&CheckCode::RUF002);
|
||||
let enforce_quotes = settings.enabled.contains(&CheckCode::Q000)
|
||||
|| settings.enabled.contains(&CheckCode::Q001)
|
||||
|| settings.enabled.contains(&CheckCode::Q002)
|
||||
|
@ -31,7 +31,7 @@ pub fn check_tokens(
|
|||
false
|
||||
};
|
||||
|
||||
// X001, X002
|
||||
// RUF001, RUF002
|
||||
if enforce_ambiguous_unicode_character {
|
||||
if matches!(tok, Tok::String { .. }) {
|
||||
for check in rules::checks::ambiguous_unicode_character(
|
||||
|
|
|
@ -183,8 +183,8 @@ pub enum CheckCode {
|
|||
N817,
|
||||
N818,
|
||||
// Ruff
|
||||
X001,
|
||||
X002,
|
||||
RUF001,
|
||||
RUF002,
|
||||
// Meta
|
||||
M001,
|
||||
}
|
||||
|
@ -417,8 +417,8 @@ impl CheckCode {
|
|||
| CheckCode::Q002
|
||||
| CheckCode::Q003
|
||||
| CheckCode::W605
|
||||
| CheckCode::X001
|
||||
| CheckCode::X002 => &LintSource::Tokens,
|
||||
| CheckCode::RUF001
|
||||
| CheckCode::RUF002 => &LintSource::Tokens,
|
||||
CheckCode::E902 => &LintSource::FileSystem,
|
||||
_ => &LintSource::AST,
|
||||
}
|
||||
|
@ -621,8 +621,8 @@ impl CheckCode {
|
|||
}
|
||||
CheckCode::N818 => CheckKind::ErrorSuffixOnExceptionName("...".to_string()),
|
||||
// Ruff
|
||||
CheckCode::X001 => CheckKind::AmbiguousUnicodeCharacterString('𝐁', 'B'),
|
||||
CheckCode::X002 => CheckKind::AmbiguousUnicodeCharacterDocstring('𝐁', 'B'),
|
||||
CheckCode::RUF001 => CheckKind::AmbiguousUnicodeCharacterString('𝐁', 'B'),
|
||||
CheckCode::RUF002 => CheckKind::AmbiguousUnicodeCharacterDocstring('𝐁', 'B'),
|
||||
// Meta
|
||||
CheckCode::M001 => CheckKind::UnusedNOQA(None),
|
||||
}
|
||||
|
@ -776,8 +776,8 @@ impl CheckCode {
|
|||
CheckCode::N816 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N817 => CheckCategory::PEP8Naming,
|
||||
CheckCode::N818 => CheckCategory::PEP8Naming,
|
||||
CheckCode::X001 => CheckCategory::Ruff,
|
||||
CheckCode::X002 => CheckCategory::Ruff,
|
||||
CheckCode::RUF001 => CheckCategory::Ruff,
|
||||
CheckCode::RUF002 => CheckCategory::Ruff,
|
||||
CheckCode::M001 => CheckCategory::Meta,
|
||||
}
|
||||
}
|
||||
|
@ -944,8 +944,8 @@ impl CheckKind {
|
|||
CheckKind::CamelcaseImportedAsAcronym(..) => &CheckCode::N817,
|
||||
CheckKind::ErrorSuffixOnExceptionName(..) => &CheckCode::N818,
|
||||
// Ruff
|
||||
CheckKind::AmbiguousUnicodeCharacterString(..) => &CheckCode::X001,
|
||||
CheckKind::AmbiguousUnicodeCharacterDocstring(..) => &CheckCode::X002,
|
||||
CheckKind::AmbiguousUnicodeCharacterString(..) => &CheckCode::RUF001,
|
||||
CheckKind::AmbiguousUnicodeCharacterDocstring(..) => &CheckCode::RUF002,
|
||||
// Meta
|
||||
CheckKind::UnusedNOQA(_) => &CheckCode::M001,
|
||||
}
|
||||
|
|
|
@ -206,6 +206,11 @@ pub enum CheckCodePrefix {
|
|||
Q001,
|
||||
Q002,
|
||||
Q003,
|
||||
RUF,
|
||||
RUF0,
|
||||
RUF00,
|
||||
RUF001,
|
||||
RUF002,
|
||||
T,
|
||||
T2,
|
||||
T20,
|
||||
|
@ -229,11 +234,6 @@ pub enum CheckCodePrefix {
|
|||
W6,
|
||||
W60,
|
||||
W605,
|
||||
X,
|
||||
X0,
|
||||
X00,
|
||||
X001,
|
||||
X002,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
|
@ -839,6 +839,11 @@ impl CheckCodePrefix {
|
|||
CheckCodePrefix::Q001 => vec![CheckCode::Q001],
|
||||
CheckCodePrefix::Q002 => vec![CheckCode::Q002],
|
||||
CheckCodePrefix::Q003 => vec![CheckCode::Q003],
|
||||
CheckCodePrefix::RUF => vec![CheckCode::RUF001, CheckCode::RUF002],
|
||||
CheckCodePrefix::RUF0 => vec![CheckCode::RUF001, CheckCode::RUF002],
|
||||
CheckCodePrefix::RUF00 => vec![CheckCode::RUF001, CheckCode::RUF002],
|
||||
CheckCodePrefix::RUF001 => vec![CheckCode::RUF001],
|
||||
CheckCodePrefix::RUF002 => vec![CheckCode::RUF002],
|
||||
CheckCodePrefix::T => vec![CheckCode::T201, CheckCode::T203],
|
||||
CheckCodePrefix::T2 => vec![CheckCode::T201, CheckCode::T203],
|
||||
CheckCodePrefix::T20 => vec![CheckCode::T201, CheckCode::T203],
|
||||
|
@ -889,11 +894,6 @@ impl CheckCodePrefix {
|
|||
CheckCodePrefix::W6 => vec![CheckCode::W605],
|
||||
CheckCodePrefix::W60 => vec![CheckCode::W605],
|
||||
CheckCodePrefix::W605 => vec![CheckCode::W605],
|
||||
CheckCodePrefix::X => vec![CheckCode::X001, CheckCode::X002],
|
||||
CheckCodePrefix::X0 => vec![CheckCode::X001, CheckCode::X002],
|
||||
CheckCodePrefix::X00 => vec![CheckCode::X001, CheckCode::X002],
|
||||
CheckCodePrefix::X001 => vec![CheckCode::X001],
|
||||
CheckCodePrefix::X002 => vec![CheckCode::X002],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1100,6 +1100,11 @@ impl CheckCodePrefix {
|
|||
CheckCodePrefix::Q001 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::Q002 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::Q003 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::RUF => PrefixSpecificity::Category,
|
||||
CheckCodePrefix::RUF0 => PrefixSpecificity::Hundreds,
|
||||
CheckCodePrefix::RUF00 => PrefixSpecificity::Tens,
|
||||
CheckCodePrefix::RUF001 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::RUF002 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::T => PrefixSpecificity::Category,
|
||||
CheckCodePrefix::T2 => PrefixSpecificity::Hundreds,
|
||||
CheckCodePrefix::T20 => PrefixSpecificity::Tens,
|
||||
|
@ -1123,11 +1128,6 @@ impl CheckCodePrefix {
|
|||
CheckCodePrefix::W6 => PrefixSpecificity::Hundreds,
|
||||
CheckCodePrefix::W60 => PrefixSpecificity::Tens,
|
||||
CheckCodePrefix::W605 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::X => PrefixSpecificity::Category,
|
||||
CheckCodePrefix::X0 => PrefixSpecificity::Hundreds,
|
||||
CheckCodePrefix::X00 => PrefixSpecificity::Tens,
|
||||
CheckCodePrefix::X001 => PrefixSpecificity::Explicit,
|
||||
CheckCodePrefix::X002 => PrefixSpecificity::Explicit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,8 +441,8 @@ mod tests {
|
|||
#[test_case(CheckCode::W292, Path::new("W292_2.py"); "W292_2")]
|
||||
#[test_case(CheckCode::W605, Path::new("W605_0.py"); "W605_0")]
|
||||
#[test_case(CheckCode::W605, Path::new("W605_1.py"); "W605_1")]
|
||||
#[test_case(CheckCode::X001, Path::new("X001.py"); "X001")]
|
||||
#[test_case(CheckCode::X002, Path::new("X002.py"); "X002")]
|
||||
#[test_case(CheckCode::RUF001, Path::new("RUF001.py"); "RUF001")]
|
||||
#[test_case(CheckCode::RUF002, Path::new("RUF002.py"); "RUF002")]
|
||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy());
|
||||
let mut checks = check_path(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue