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 |
|
| Code | Name | Message | Fix |
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| X001 | AmbiguousUnicodeCharacterString | String contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
| RUF001 | AmbiguousUnicodeCharacterString | String contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||||
| X002 | AmbiguousUnicodeCharacterDocstring | Docstring contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
| RUF002 | AmbiguousUnicodeCharacterDocstring | Docstring contains ambiguous unicode character '𝐁' (did you mean 'B'?) | 🛠 |
|
||||||
|
|
||||||
### Meta rules
|
### Meta rules
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,12 @@ fn main() {
|
||||||
// Build up a map from prefix to matching CheckCodes.
|
// Build up a map from prefix to matching CheckCodes.
|
||||||
let mut prefix_to_codes: BTreeMap<String, BTreeSet<CheckCode>> = Default::default();
|
let mut prefix_to_codes: BTreeMap<String, BTreeSet<CheckCode>> = Default::default();
|
||||||
for check_code in CheckCode::iter() {
|
for check_code in CheckCode::iter() {
|
||||||
let as_ref = check_code.as_ref().to_string();
|
let as_ref: String = check_code.as_ref().to_string();
|
||||||
for i in 1..=as_ref.len() {
|
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 prefix = as_ref[..i].to_string();
|
||||||
let entry = prefix_to_codes
|
let entry = prefix_to_codes
|
||||||
.entry(prefix)
|
.entry(prefix)
|
||||||
|
@ -81,11 +85,12 @@ fn main() {
|
||||||
.vis("pub")
|
.vis("pub")
|
||||||
.line("match self {");
|
.line("match self {");
|
||||||
for (prefix, _) in &prefix_to_codes {
|
for (prefix, _) in &prefix_to_codes {
|
||||||
let specificity = match prefix.len() {
|
let num_numeric = prefix.chars().filter(|char| char.is_numeric()).count();
|
||||||
4 => "Explicit",
|
let specificity = match num_numeric {
|
||||||
3 => "Tens",
|
3 => "Explicit",
|
||||||
2 => "Hundreds",
|
2 => "Tens",
|
||||||
1 => "Category",
|
1 => "Hundreds",
|
||||||
|
0 => "Category",
|
||||||
_ => panic!("Invalid prefix: {}", prefix),
|
_ => panic!("Invalid prefix: {}", prefix),
|
||||||
};
|
};
|
||||||
gen = gen.line(format!(
|
gen = gen.line(format!(
|
||||||
|
|
|
@ -15,8 +15,8 @@ pub fn check_tokens(
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
autofix: &fixer::Mode,
|
autofix: &fixer::Mode,
|
||||||
) {
|
) {
|
||||||
let enforce_ambiguous_unicode_character =
|
let enforce_ambiguous_unicode_character = settings.enabled.contains(&CheckCode::RUF001)
|
||||||
settings.enabled.contains(&CheckCode::X001) || settings.enabled.contains(&CheckCode::X002);
|
|| settings.enabled.contains(&CheckCode::RUF002);
|
||||||
let enforce_quotes = settings.enabled.contains(&CheckCode::Q000)
|
let enforce_quotes = settings.enabled.contains(&CheckCode::Q000)
|
||||||
|| settings.enabled.contains(&CheckCode::Q001)
|
|| settings.enabled.contains(&CheckCode::Q001)
|
||||||
|| settings.enabled.contains(&CheckCode::Q002)
|
|| settings.enabled.contains(&CheckCode::Q002)
|
||||||
|
@ -31,7 +31,7 @@ pub fn check_tokens(
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
// X001, X002
|
// RUF001, RUF002
|
||||||
if enforce_ambiguous_unicode_character {
|
if enforce_ambiguous_unicode_character {
|
||||||
if matches!(tok, Tok::String { .. }) {
|
if matches!(tok, Tok::String { .. }) {
|
||||||
for check in rules::checks::ambiguous_unicode_character(
|
for check in rules::checks::ambiguous_unicode_character(
|
||||||
|
|
|
@ -183,8 +183,8 @@ pub enum CheckCode {
|
||||||
N817,
|
N817,
|
||||||
N818,
|
N818,
|
||||||
// Ruff
|
// Ruff
|
||||||
X001,
|
RUF001,
|
||||||
X002,
|
RUF002,
|
||||||
// Meta
|
// Meta
|
||||||
M001,
|
M001,
|
||||||
}
|
}
|
||||||
|
@ -417,8 +417,8 @@ impl CheckCode {
|
||||||
| CheckCode::Q002
|
| CheckCode::Q002
|
||||||
| CheckCode::Q003
|
| CheckCode::Q003
|
||||||
| CheckCode::W605
|
| CheckCode::W605
|
||||||
| CheckCode::X001
|
| CheckCode::RUF001
|
||||||
| CheckCode::X002 => &LintSource::Tokens,
|
| CheckCode::RUF002 => &LintSource::Tokens,
|
||||||
CheckCode::E902 => &LintSource::FileSystem,
|
CheckCode::E902 => &LintSource::FileSystem,
|
||||||
_ => &LintSource::AST,
|
_ => &LintSource::AST,
|
||||||
}
|
}
|
||||||
|
@ -621,8 +621,8 @@ impl CheckCode {
|
||||||
}
|
}
|
||||||
CheckCode::N818 => CheckKind::ErrorSuffixOnExceptionName("...".to_string()),
|
CheckCode::N818 => CheckKind::ErrorSuffixOnExceptionName("...".to_string()),
|
||||||
// Ruff
|
// Ruff
|
||||||
CheckCode::X001 => CheckKind::AmbiguousUnicodeCharacterString('𝐁', 'B'),
|
CheckCode::RUF001 => CheckKind::AmbiguousUnicodeCharacterString('𝐁', 'B'),
|
||||||
CheckCode::X002 => CheckKind::AmbiguousUnicodeCharacterDocstring('𝐁', 'B'),
|
CheckCode::RUF002 => CheckKind::AmbiguousUnicodeCharacterDocstring('𝐁', 'B'),
|
||||||
// Meta
|
// Meta
|
||||||
CheckCode::M001 => CheckKind::UnusedNOQA(None),
|
CheckCode::M001 => CheckKind::UnusedNOQA(None),
|
||||||
}
|
}
|
||||||
|
@ -776,8 +776,8 @@ impl CheckCode {
|
||||||
CheckCode::N816 => CheckCategory::PEP8Naming,
|
CheckCode::N816 => CheckCategory::PEP8Naming,
|
||||||
CheckCode::N817 => CheckCategory::PEP8Naming,
|
CheckCode::N817 => CheckCategory::PEP8Naming,
|
||||||
CheckCode::N818 => CheckCategory::PEP8Naming,
|
CheckCode::N818 => CheckCategory::PEP8Naming,
|
||||||
CheckCode::X001 => CheckCategory::Ruff,
|
CheckCode::RUF001 => CheckCategory::Ruff,
|
||||||
CheckCode::X002 => CheckCategory::Ruff,
|
CheckCode::RUF002 => CheckCategory::Ruff,
|
||||||
CheckCode::M001 => CheckCategory::Meta,
|
CheckCode::M001 => CheckCategory::Meta,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -944,8 +944,8 @@ impl CheckKind {
|
||||||
CheckKind::CamelcaseImportedAsAcronym(..) => &CheckCode::N817,
|
CheckKind::CamelcaseImportedAsAcronym(..) => &CheckCode::N817,
|
||||||
CheckKind::ErrorSuffixOnExceptionName(..) => &CheckCode::N818,
|
CheckKind::ErrorSuffixOnExceptionName(..) => &CheckCode::N818,
|
||||||
// Ruff
|
// Ruff
|
||||||
CheckKind::AmbiguousUnicodeCharacterString(..) => &CheckCode::X001,
|
CheckKind::AmbiguousUnicodeCharacterString(..) => &CheckCode::RUF001,
|
||||||
CheckKind::AmbiguousUnicodeCharacterDocstring(..) => &CheckCode::X002,
|
CheckKind::AmbiguousUnicodeCharacterDocstring(..) => &CheckCode::RUF002,
|
||||||
// Meta
|
// Meta
|
||||||
CheckKind::UnusedNOQA(_) => &CheckCode::M001,
|
CheckKind::UnusedNOQA(_) => &CheckCode::M001,
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,11 @@ pub enum CheckCodePrefix {
|
||||||
Q001,
|
Q001,
|
||||||
Q002,
|
Q002,
|
||||||
Q003,
|
Q003,
|
||||||
|
RUF,
|
||||||
|
RUF0,
|
||||||
|
RUF00,
|
||||||
|
RUF001,
|
||||||
|
RUF002,
|
||||||
T,
|
T,
|
||||||
T2,
|
T2,
|
||||||
T20,
|
T20,
|
||||||
|
@ -229,11 +234,6 @@ pub enum CheckCodePrefix {
|
||||||
W6,
|
W6,
|
||||||
W60,
|
W60,
|
||||||
W605,
|
W605,
|
||||||
X,
|
|
||||||
X0,
|
|
||||||
X00,
|
|
||||||
X001,
|
|
||||||
X002,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
@ -839,6 +839,11 @@ impl CheckCodePrefix {
|
||||||
CheckCodePrefix::Q001 => vec![CheckCode::Q001],
|
CheckCodePrefix::Q001 => vec![CheckCode::Q001],
|
||||||
CheckCodePrefix::Q002 => vec![CheckCode::Q002],
|
CheckCodePrefix::Q002 => vec![CheckCode::Q002],
|
||||||
CheckCodePrefix::Q003 => vec![CheckCode::Q003],
|
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::T => vec![CheckCode::T201, CheckCode::T203],
|
||||||
CheckCodePrefix::T2 => vec![CheckCode::T201, CheckCode::T203],
|
CheckCodePrefix::T2 => vec![CheckCode::T201, CheckCode::T203],
|
||||||
CheckCodePrefix::T20 => vec![CheckCode::T201, CheckCode::T203],
|
CheckCodePrefix::T20 => vec![CheckCode::T201, CheckCode::T203],
|
||||||
|
@ -889,11 +894,6 @@ impl CheckCodePrefix {
|
||||||
CheckCodePrefix::W6 => vec![CheckCode::W605],
|
CheckCodePrefix::W6 => vec![CheckCode::W605],
|
||||||
CheckCodePrefix::W60 => vec![CheckCode::W605],
|
CheckCodePrefix::W60 => vec![CheckCode::W605],
|
||||||
CheckCodePrefix::W605 => 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::Q001 => PrefixSpecificity::Explicit,
|
||||||
CheckCodePrefix::Q002 => PrefixSpecificity::Explicit,
|
CheckCodePrefix::Q002 => PrefixSpecificity::Explicit,
|
||||||
CheckCodePrefix::Q003 => 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::T => PrefixSpecificity::Category,
|
||||||
CheckCodePrefix::T2 => PrefixSpecificity::Hundreds,
|
CheckCodePrefix::T2 => PrefixSpecificity::Hundreds,
|
||||||
CheckCodePrefix::T20 => PrefixSpecificity::Tens,
|
CheckCodePrefix::T20 => PrefixSpecificity::Tens,
|
||||||
|
@ -1123,11 +1128,6 @@ impl CheckCodePrefix {
|
||||||
CheckCodePrefix::W6 => PrefixSpecificity::Hundreds,
|
CheckCodePrefix::W6 => PrefixSpecificity::Hundreds,
|
||||||
CheckCodePrefix::W60 => PrefixSpecificity::Tens,
|
CheckCodePrefix::W60 => PrefixSpecificity::Tens,
|
||||||
CheckCodePrefix::W605 => PrefixSpecificity::Explicit,
|
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::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_0.py"); "W605_0")]
|
||||||
#[test_case(CheckCode::W605, Path::new("W605_1.py"); "W605_1")]
|
#[test_case(CheckCode::W605, Path::new("W605_1.py"); "W605_1")]
|
||||||
#[test_case(CheckCode::X001, Path::new("X001.py"); "X001")]
|
#[test_case(CheckCode::RUF001, Path::new("RUF001.py"); "RUF001")]
|
||||||
#[test_case(CheckCode::X002, Path::new("X002.py"); "X002")]
|
#[test_case(CheckCode::RUF002, Path::new("RUF002.py"); "RUF002")]
|
||||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||||
let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy());
|
let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy());
|
||||||
let mut checks = check_path(
|
let mut checks = check_path(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue