diff --git a/README.md b/README.md index 0172183aa7a26..3402d3d8b875c 100644 --- a/README.md +++ b/README.md @@ -399,7 +399,7 @@ For more, see [Pyflakes](https://pypi.org/project/pyflakes/2.5.0/) on PyPI. | F634 | IfTuple | If test is a tuple, which is always `True` | | | F701 | BreakOutsideLoop | `break` outside loop | | | F702 | ContinueOutsideLoop | `continue` not properly in loop | | -| F704 | YieldOutsideFunction | `yield` or `yield from` statement outside of a function | | +| F704 | YieldOutsideFunction | `yield` statement outside of a function | | | F706 | ReturnOutsideFunction | `return` statement outside of a function/method | | | F707 | DefaultExceptNotLast | An `except` block as not the last exception handler | | | F722 | ForwardAnnotationSyntaxError | Syntax error in forward annotation: `...` | | @@ -720,6 +720,14 @@ For more, see [mccabe](https://pypi.org/project/mccabe/0.7.0/) on PyPI. | ---- | ---- | ------- | --- | | C901 | FunctionIsTooComplex | `...` is too complex (10) | | +### Pylint + +For more, see [Pylint](https://pypi.org/project/pylint/2.15.7/) on PyPI. + +| Code | Name | Message | Fix | +| ---- | ---- | ------- | --- | +| PLE1142 | AwaitOutsideAsync | `await` should be used within an async function | | + ### Ruff-specific rules | Code | Name | Message | Fix | diff --git a/resources/test/fixtures/pylint/await_outside_async.py b/resources/test/fixtures/pylint/await_outside_async.py new file mode 100644 index 0000000000000..2bc1267615a4e --- /dev/null +++ b/resources/test/fixtures/pylint/await_outside_async.py @@ -0,0 +1,30 @@ +# pylint: disable=missing-docstring,unused-variable +import asyncio + +async def nested(): + return 42 + +async def main(): + nested() + print(await nested()) # This is okay + +def not_async(): + print(await nested()) # [await-outside-async] + + +async def func(i): + return i**2 + +async def okay_function(): + var = [await func(i) for i in range(5)] # This should be okay + + +# Test nested functions +async def func2(): + def inner_func(): + await asyncio.sleep(1) # [await-outside-async] + + +def outer_func(): + async def inner_func(): + await asyncio.sleep(1) diff --git a/ruff_dev/src/generate_check_code_prefix.rs b/ruff_dev/src/generate_check_code_prefix.rs index abbb248115f09..7e5cb959ebf74 100644 --- a/ruff_dev/src/generate_check_code_prefix.rs +++ b/ruff_dev/src/generate_check_code_prefix.rs @@ -57,18 +57,19 @@ pub fn main(cli: &Cli) -> Result<()> { gen = gen.push_variant(Variant::new(prefix.to_string())); } - // Create the `PrefixSpecificity` definition. + // Create the `SuffixLength` definition. scope - .new_enum("PrefixSpecificity") + .new_enum("SuffixLength") .vis("pub") .derive("PartialEq") .derive("Eq") .derive("PartialOrd") .derive("Ord") - .push_variant(Variant::new("Category")) - .push_variant(Variant::new("Hundreds")) - .push_variant(Variant::new("Tens")) - .push_variant(Variant::new("Explicit")); + .push_variant(Variant::new("Zero")) + .push_variant(Variant::new("One")) + .push_variant(Variant::new("Two")) + .push_variant(Variant::new("Three")) + .push_variant(Variant::new("Four")); // Create the `match` statement, to map from definition to relevant codes. let mut gen = scope @@ -95,21 +96,22 @@ pub fn main(cli: &Cli) -> Result<()> { .new_impl("CheckCodePrefix") .new_fn("specificity") .arg_ref_self() - .ret(Type::new("PrefixSpecificity")) + .ret(Type::new("SuffixLength")) .vis("pub") .line("#[allow(clippy::match_same_arms)]") .line("match self {"); for prefix in prefix_to_codes.keys() { let num_numeric = prefix.chars().filter(|char| char.is_numeric()).count(); let specificity = match num_numeric { - 3 => "Explicit", - 2 => "Tens", - 1 => "Hundreds", - 0 => "Category", + 0 => "Zero", + 1 => "One", + 2 => "Two", + 3 => "Three", + 4 => "Four", _ => panic!("Invalid prefix: {prefix}"), }; gen = gen.line(format!( - "CheckCodePrefix::{prefix} => PrefixSpecificity::{},", + "CheckCodePrefix::{prefix} => SuffixLength::{},", specificity )); } diff --git a/src/ast/types.rs b/src/ast/types.rs index 64aaf16bbfbdc..d8552a320a41c 100644 --- a/src/ast/types.rs +++ b/src/ast/types.rs @@ -30,12 +30,13 @@ impl Range { } } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct FunctionScope { + pub async_: bool, pub uses_locals: bool, } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct ClassScope<'a> { pub name: &'a str, pub bases: &'a [Expr], diff --git a/src/check_ast.rs b/src/check_ast.rs index 824a406add006..d26d9a1a9a04d 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -37,7 +37,7 @@ use crate::{ docstrings, flake8_2020, flake8_annotations, flake8_bandit, flake8_blind_except, flake8_boolean_trap, flake8_bugbear, flake8_builtins, flake8_comprehensions, flake8_debugger, flake8_print, flake8_tidy_imports, mccabe, pep8_naming, pycodestyle, pydocstyle, pyflakes, - pyupgrade, rules, + pylint, pyupgrade, rules, }; const GLOBAL_SCOPE_INDEX: usize = 0; @@ -1696,8 +1696,8 @@ where } } ExprKind::Yield { .. } => { - let scope = self.current_scope(); if self.settings.enabled.contains(&CheckCode::F704) { + let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.add_check(Check::new( CheckKind::YieldOutsideFunction(DeferralKeyword::Yield), @@ -1707,8 +1707,8 @@ where } } ExprKind::YieldFrom { .. } => { - let scope = self.current_scope(); if self.settings.enabled.contains(&CheckCode::F704) { + let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.add_check(Check::new( CheckKind::YieldOutsideFunction(DeferralKeyword::YieldFrom), @@ -1718,8 +1718,8 @@ where } } ExprKind::Await { .. } => { - let scope = self.current_scope(); if self.settings.enabled.contains(&CheckCode::F704) { + let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.add_check(Check::new( CheckKind::YieldOutsideFunction(DeferralKeyword::Await), @@ -1727,6 +1727,9 @@ where )); } } + if self.settings.enabled.contains(&CheckCode::PLE1142) { + pylint::plugins::await_outside_async(self, expr); + } } ExprKind::JoinedStr { values } => { if self.settings.enabled.contains(&CheckCode::F541) { @@ -2819,7 +2822,10 @@ impl<'a> Checker<'a> { self.parent_stack = parents; self.scope_stack = scopes; self.visible_scope = visibility; - self.push_scope(Scope::new(ScopeKind::Function(FunctionScope::default()))); + self.push_scope(Scope::new(ScopeKind::Function(FunctionScope { + async_: matches!(stmt.node, StmtKind::AsyncFunctionDef { .. }), + uses_locals: false, + }))); match &stmt.node { StmtKind::FunctionDef { body, args, .. } @@ -2945,14 +2951,9 @@ impl<'a> Checker<'a> { BTreeMap::new(); for (name, binding) in &scope.values { - let (full_name, context) = match &binding.kind { - BindingKind::Importation(_, full_name, context) - | BindingKind::SubmoduleImportation(_, full_name, context) - | BindingKind::FromImportation(_, full_name, context) => { - (full_name, context) - } - _ => continue, - }; + let (BindingKind::Importation(_, full_name, context) + | BindingKind::SubmoduleImportation(_, full_name, context) + | BindingKind::FromImportation(_, full_name, context)) = &binding.kind else { continue }; // Skip used exports from `__all__` if binding.used.is_some() diff --git a/src/checks.rs b/src/checks.rs index bf86c2cdf4e79..2c2a98f708d01 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -90,6 +90,8 @@ pub enum CheckCode { F831, F841, F901, + // pylint errors + PLE1142, // flake8-builtins A001, A002, @@ -300,6 +302,7 @@ pub enum CheckCategory { Flake82020, Flake8BlindExcept, McCabe, + Pylint, Ruff, Meta, } @@ -327,6 +330,7 @@ impl CheckCategory { CheckCategory::Pycodestyle => "pycodestyle", CheckCategory::Pydocstyle => "pydocstyle", CheckCategory::Pyflakes => "Pyflakes", + CheckCategory::Pylint => "Pylint", CheckCategory::Pyupgrade => "pyupgrade", CheckCategory::Ruff => "Ruff-specific rules", } @@ -370,6 +374,7 @@ impl CheckCategory { CheckCategory::Pycodestyle => Some("https://pypi.org/project/pycodestyle/2.9.1/"), CheckCategory::Pydocstyle => Some("https://pypi.org/project/pydocstyle/6.1.1/"), CheckCategory::Pyflakes => Some("https://pypi.org/project/pyflakes/2.5.0/"), + CheckCategory::Pylint => Some("https://pypi.org/project/pylint/2.15.7/"), CheckCategory::Pyupgrade => Some("https://pypi.org/project/pyupgrade/3.2.0/"), CheckCategory::Ruff => None, } @@ -471,6 +476,8 @@ pub enum CheckKind { UnusedImport(String, bool), UnusedVariable(String), YieldOutsideFunction(DeferralKeyword), + // pylint errors + AwaitOutsideAsync, // flake8-builtins BuiltinVariableShadowing(String), BuiltinArgumentShadowing(String), @@ -752,6 +759,8 @@ impl CheckCode { CheckCode::F831 => CheckKind::DuplicateArgumentName, CheckCode::F841 => CheckKind::UnusedVariable("...".to_string()), CheckCode::F901 => CheckKind::RaiseNotImplemented, + // pylint errors + CheckCode::PLE1142 => CheckKind::AwaitOutsideAsync, // flake8-builtins CheckCode::A001 => CheckKind::BuiltinVariableShadowing("...".to_string()), CheckCode::A002 => CheckKind::BuiltinArgumentShadowing("...".to_string()), @@ -1160,6 +1169,7 @@ impl CheckCode { CheckCode::N816 => CheckCategory::PEP8Naming, CheckCode::N817 => CheckCategory::PEP8Naming, CheckCode::N818 => CheckCategory::PEP8Naming, + CheckCode::PLE1142 => CheckCategory::Pylint, CheckCode::Q000 => CheckCategory::Flake8Quotes, CheckCode::Q001 => CheckCategory::Flake8Quotes, CheckCode::Q002 => CheckCategory::Flake8Quotes, @@ -1271,6 +1281,8 @@ impl CheckKind { // pycodestyle warnings CheckKind::NoNewLineAtEndOfFile => &CheckCode::W292, CheckKind::InvalidEscapeSequence(_) => &CheckCode::W605, + // pylint errors + CheckKind::AwaitOutsideAsync => &CheckCode::PLE1142, // flake8-builtins CheckKind::BuiltinVariableShadowing(_) => &CheckCode::A001, CheckKind::BuiltinArgumentShadowing(_) => &CheckCode::A002, @@ -1640,6 +1652,10 @@ impl CheckKind { CheckKind::InvalidEscapeSequence(char) => { format!("Invalid escape sequence: '\\{char}'") } + // pylint errors + CheckKind::AwaitOutsideAsync => { + "`await` should be used within an async function".to_string() + } // flake8-builtins CheckKind::BuiltinVariableShadowing(name) => { format!("Variable `{name}` is shadowing a python builtin") diff --git a/src/checks_gen.rs b/src/checks_gen.rs index f2989b25ec22c..efe3723d53c25 100644 --- a/src/checks_gen.rs +++ b/src/checks_gen.rs @@ -278,6 +278,11 @@ pub enum CheckCodePrefix { N816, N817, N818, + PLE, + PLE1, + PLE11, + PLE114, + PLE1142, Q, Q0, Q00, @@ -356,11 +361,12 @@ pub enum CheckCodePrefix { } #[derive(PartialEq, Eq, PartialOrd, Ord)] -pub enum PrefixSpecificity { - Category, - Hundreds, - Tens, - Explicit, +pub enum SuffixLength { + Zero, + One, + Two, + Three, + Four, } impl CheckCodePrefix { @@ -1142,6 +1148,11 @@ impl CheckCodePrefix { CheckCodePrefix::N816 => vec![CheckCode::N816], CheckCodePrefix::N817 => vec![CheckCode::N817], CheckCodePrefix::N818 => vec![CheckCode::N818], + CheckCodePrefix::PLE => vec![CheckCode::PLE1142], + CheckCodePrefix::PLE1 => vec![CheckCode::PLE1142], + CheckCodePrefix::PLE11 => vec![CheckCode::PLE1142], + CheckCodePrefix::PLE114 => vec![CheckCode::PLE1142], + CheckCodePrefix::PLE1142 => vec![CheckCode::PLE1142], CheckCodePrefix::Q => vec![ CheckCode::Q000, CheckCode::Q001, @@ -1330,355 +1341,360 @@ impl CheckCodePrefix { } impl CheckCodePrefix { - pub fn specificity(&self) -> PrefixSpecificity { + pub fn specificity(&self) -> SuffixLength { #[allow(clippy::match_same_arms)] match self { - CheckCodePrefix::A => PrefixSpecificity::Category, - CheckCodePrefix::A0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::A00 => PrefixSpecificity::Tens, - CheckCodePrefix::A001 => PrefixSpecificity::Explicit, - CheckCodePrefix::A002 => PrefixSpecificity::Explicit, - CheckCodePrefix::A003 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN => PrefixSpecificity::Category, - CheckCodePrefix::ANN0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::ANN00 => PrefixSpecificity::Tens, - CheckCodePrefix::ANN001 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN002 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN003 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::ANN10 => PrefixSpecificity::Tens, - CheckCodePrefix::ANN101 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN102 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::ANN20 => PrefixSpecificity::Tens, - CheckCodePrefix::ANN201 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN202 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN204 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN205 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN206 => PrefixSpecificity::Explicit, - CheckCodePrefix::ANN4 => PrefixSpecificity::Hundreds, - CheckCodePrefix::ANN40 => PrefixSpecificity::Tens, - CheckCodePrefix::ANN401 => PrefixSpecificity::Explicit, - CheckCodePrefix::B => PrefixSpecificity::Category, - CheckCodePrefix::B0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::B00 => PrefixSpecificity::Tens, - CheckCodePrefix::B002 => PrefixSpecificity::Explicit, - CheckCodePrefix::B003 => PrefixSpecificity::Explicit, - CheckCodePrefix::B004 => PrefixSpecificity::Explicit, - CheckCodePrefix::B005 => PrefixSpecificity::Explicit, - CheckCodePrefix::B006 => PrefixSpecificity::Explicit, - CheckCodePrefix::B007 => PrefixSpecificity::Explicit, - CheckCodePrefix::B008 => PrefixSpecificity::Explicit, - CheckCodePrefix::B009 => PrefixSpecificity::Explicit, - CheckCodePrefix::B01 => PrefixSpecificity::Tens, - CheckCodePrefix::B010 => PrefixSpecificity::Explicit, - CheckCodePrefix::B011 => PrefixSpecificity::Explicit, - CheckCodePrefix::B012 => PrefixSpecificity::Explicit, - CheckCodePrefix::B013 => PrefixSpecificity::Explicit, - CheckCodePrefix::B014 => PrefixSpecificity::Explicit, - CheckCodePrefix::B015 => PrefixSpecificity::Explicit, - CheckCodePrefix::B016 => PrefixSpecificity::Explicit, - CheckCodePrefix::B017 => PrefixSpecificity::Explicit, - CheckCodePrefix::B018 => PrefixSpecificity::Explicit, - CheckCodePrefix::B019 => PrefixSpecificity::Explicit, - CheckCodePrefix::B02 => PrefixSpecificity::Tens, - CheckCodePrefix::B020 => PrefixSpecificity::Explicit, - CheckCodePrefix::B021 => PrefixSpecificity::Explicit, - CheckCodePrefix::B022 => PrefixSpecificity::Explicit, - CheckCodePrefix::B023 => PrefixSpecificity::Explicit, - CheckCodePrefix::B024 => PrefixSpecificity::Explicit, - CheckCodePrefix::B025 => PrefixSpecificity::Explicit, - CheckCodePrefix::B026 => PrefixSpecificity::Explicit, - CheckCodePrefix::B027 => PrefixSpecificity::Explicit, - CheckCodePrefix::B9 => PrefixSpecificity::Hundreds, - CheckCodePrefix::B90 => PrefixSpecificity::Tens, - CheckCodePrefix::B904 => PrefixSpecificity::Explicit, - CheckCodePrefix::BLE => PrefixSpecificity::Category, - CheckCodePrefix::BLE0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::BLE00 => PrefixSpecificity::Tens, - CheckCodePrefix::BLE001 => PrefixSpecificity::Explicit, - CheckCodePrefix::C => PrefixSpecificity::Category, - CheckCodePrefix::C4 => PrefixSpecificity::Hundreds, - CheckCodePrefix::C40 => PrefixSpecificity::Tens, - CheckCodePrefix::C400 => PrefixSpecificity::Explicit, - CheckCodePrefix::C401 => PrefixSpecificity::Explicit, - CheckCodePrefix::C402 => PrefixSpecificity::Explicit, - CheckCodePrefix::C403 => PrefixSpecificity::Explicit, - CheckCodePrefix::C404 => PrefixSpecificity::Explicit, - CheckCodePrefix::C405 => PrefixSpecificity::Explicit, - CheckCodePrefix::C406 => PrefixSpecificity::Explicit, - CheckCodePrefix::C408 => PrefixSpecificity::Explicit, - CheckCodePrefix::C409 => PrefixSpecificity::Explicit, - CheckCodePrefix::C41 => PrefixSpecificity::Tens, - CheckCodePrefix::C410 => PrefixSpecificity::Explicit, - CheckCodePrefix::C411 => PrefixSpecificity::Explicit, - CheckCodePrefix::C413 => PrefixSpecificity::Explicit, - CheckCodePrefix::C414 => PrefixSpecificity::Explicit, - CheckCodePrefix::C415 => PrefixSpecificity::Explicit, - CheckCodePrefix::C416 => PrefixSpecificity::Explicit, - CheckCodePrefix::C417 => PrefixSpecificity::Explicit, - CheckCodePrefix::C9 => PrefixSpecificity::Hundreds, - CheckCodePrefix::C90 => PrefixSpecificity::Tens, - CheckCodePrefix::C901 => PrefixSpecificity::Explicit, - CheckCodePrefix::D => PrefixSpecificity::Category, - CheckCodePrefix::D1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::D10 => PrefixSpecificity::Tens, - CheckCodePrefix::D100 => PrefixSpecificity::Explicit, - CheckCodePrefix::D101 => PrefixSpecificity::Explicit, - CheckCodePrefix::D102 => PrefixSpecificity::Explicit, - CheckCodePrefix::D103 => PrefixSpecificity::Explicit, - CheckCodePrefix::D104 => PrefixSpecificity::Explicit, - CheckCodePrefix::D105 => PrefixSpecificity::Explicit, - CheckCodePrefix::D106 => PrefixSpecificity::Explicit, - CheckCodePrefix::D107 => PrefixSpecificity::Explicit, - CheckCodePrefix::D2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::D20 => PrefixSpecificity::Tens, - CheckCodePrefix::D200 => PrefixSpecificity::Explicit, - CheckCodePrefix::D201 => PrefixSpecificity::Explicit, - CheckCodePrefix::D202 => PrefixSpecificity::Explicit, - CheckCodePrefix::D203 => PrefixSpecificity::Explicit, - CheckCodePrefix::D204 => PrefixSpecificity::Explicit, - CheckCodePrefix::D205 => PrefixSpecificity::Explicit, - CheckCodePrefix::D206 => PrefixSpecificity::Explicit, - CheckCodePrefix::D207 => PrefixSpecificity::Explicit, - CheckCodePrefix::D208 => PrefixSpecificity::Explicit, - CheckCodePrefix::D209 => PrefixSpecificity::Explicit, - CheckCodePrefix::D21 => PrefixSpecificity::Tens, - CheckCodePrefix::D210 => PrefixSpecificity::Explicit, - CheckCodePrefix::D211 => PrefixSpecificity::Explicit, - CheckCodePrefix::D212 => PrefixSpecificity::Explicit, - CheckCodePrefix::D213 => PrefixSpecificity::Explicit, - CheckCodePrefix::D214 => PrefixSpecificity::Explicit, - CheckCodePrefix::D215 => PrefixSpecificity::Explicit, - CheckCodePrefix::D3 => PrefixSpecificity::Hundreds, - CheckCodePrefix::D30 => PrefixSpecificity::Tens, - CheckCodePrefix::D300 => PrefixSpecificity::Explicit, - CheckCodePrefix::D4 => PrefixSpecificity::Hundreds, - CheckCodePrefix::D40 => PrefixSpecificity::Tens, - CheckCodePrefix::D400 => PrefixSpecificity::Explicit, - CheckCodePrefix::D402 => PrefixSpecificity::Explicit, - CheckCodePrefix::D403 => PrefixSpecificity::Explicit, - CheckCodePrefix::D404 => PrefixSpecificity::Explicit, - CheckCodePrefix::D405 => PrefixSpecificity::Explicit, - CheckCodePrefix::D406 => PrefixSpecificity::Explicit, - CheckCodePrefix::D407 => PrefixSpecificity::Explicit, - CheckCodePrefix::D408 => PrefixSpecificity::Explicit, - CheckCodePrefix::D409 => PrefixSpecificity::Explicit, - CheckCodePrefix::D41 => PrefixSpecificity::Tens, - CheckCodePrefix::D410 => PrefixSpecificity::Explicit, - CheckCodePrefix::D411 => PrefixSpecificity::Explicit, - CheckCodePrefix::D412 => PrefixSpecificity::Explicit, - CheckCodePrefix::D413 => PrefixSpecificity::Explicit, - CheckCodePrefix::D414 => PrefixSpecificity::Explicit, - CheckCodePrefix::D415 => PrefixSpecificity::Explicit, - CheckCodePrefix::D416 => PrefixSpecificity::Explicit, - CheckCodePrefix::D417 => PrefixSpecificity::Explicit, - CheckCodePrefix::D418 => PrefixSpecificity::Explicit, - CheckCodePrefix::D419 => PrefixSpecificity::Explicit, - CheckCodePrefix::E => PrefixSpecificity::Category, - CheckCodePrefix::E4 => PrefixSpecificity::Hundreds, - CheckCodePrefix::E40 => PrefixSpecificity::Tens, - CheckCodePrefix::E402 => PrefixSpecificity::Explicit, - CheckCodePrefix::E5 => PrefixSpecificity::Hundreds, - CheckCodePrefix::E50 => PrefixSpecificity::Tens, - CheckCodePrefix::E501 => PrefixSpecificity::Explicit, - CheckCodePrefix::E7 => PrefixSpecificity::Hundreds, - CheckCodePrefix::E71 => PrefixSpecificity::Tens, - CheckCodePrefix::E711 => PrefixSpecificity::Explicit, - CheckCodePrefix::E712 => PrefixSpecificity::Explicit, - CheckCodePrefix::E713 => PrefixSpecificity::Explicit, - CheckCodePrefix::E714 => PrefixSpecificity::Explicit, - CheckCodePrefix::E72 => PrefixSpecificity::Tens, - CheckCodePrefix::E721 => PrefixSpecificity::Explicit, - CheckCodePrefix::E722 => PrefixSpecificity::Explicit, - CheckCodePrefix::E73 => PrefixSpecificity::Tens, - CheckCodePrefix::E731 => PrefixSpecificity::Explicit, - CheckCodePrefix::E74 => PrefixSpecificity::Tens, - CheckCodePrefix::E741 => PrefixSpecificity::Explicit, - CheckCodePrefix::E742 => PrefixSpecificity::Explicit, - CheckCodePrefix::E743 => PrefixSpecificity::Explicit, - CheckCodePrefix::E9 => PrefixSpecificity::Hundreds, - CheckCodePrefix::E90 => PrefixSpecificity::Tens, - CheckCodePrefix::E902 => PrefixSpecificity::Explicit, - CheckCodePrefix::E99 => PrefixSpecificity::Tens, - CheckCodePrefix::E999 => PrefixSpecificity::Explicit, - CheckCodePrefix::ERA => PrefixSpecificity::Category, - CheckCodePrefix::ERA0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::ERA00 => PrefixSpecificity::Tens, - CheckCodePrefix::ERA001 => PrefixSpecificity::Explicit, - CheckCodePrefix::F => PrefixSpecificity::Category, - CheckCodePrefix::F4 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F40 => PrefixSpecificity::Tens, - CheckCodePrefix::F401 => PrefixSpecificity::Explicit, - CheckCodePrefix::F402 => PrefixSpecificity::Explicit, - CheckCodePrefix::F403 => PrefixSpecificity::Explicit, - CheckCodePrefix::F404 => PrefixSpecificity::Explicit, - CheckCodePrefix::F405 => PrefixSpecificity::Explicit, - CheckCodePrefix::F406 => PrefixSpecificity::Explicit, - CheckCodePrefix::F407 => PrefixSpecificity::Explicit, - CheckCodePrefix::F5 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F50 => PrefixSpecificity::Tens, - CheckCodePrefix::F501 => PrefixSpecificity::Explicit, - CheckCodePrefix::F502 => PrefixSpecificity::Explicit, - CheckCodePrefix::F503 => PrefixSpecificity::Explicit, - CheckCodePrefix::F504 => PrefixSpecificity::Explicit, - CheckCodePrefix::F505 => PrefixSpecificity::Explicit, - CheckCodePrefix::F506 => PrefixSpecificity::Explicit, - CheckCodePrefix::F507 => PrefixSpecificity::Explicit, - CheckCodePrefix::F508 => PrefixSpecificity::Explicit, - CheckCodePrefix::F509 => PrefixSpecificity::Explicit, - CheckCodePrefix::F52 => PrefixSpecificity::Tens, - CheckCodePrefix::F521 => PrefixSpecificity::Explicit, - CheckCodePrefix::F522 => PrefixSpecificity::Explicit, - CheckCodePrefix::F523 => PrefixSpecificity::Explicit, - CheckCodePrefix::F524 => PrefixSpecificity::Explicit, - CheckCodePrefix::F525 => PrefixSpecificity::Explicit, - CheckCodePrefix::F54 => PrefixSpecificity::Tens, - CheckCodePrefix::F541 => PrefixSpecificity::Explicit, - CheckCodePrefix::F6 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F60 => PrefixSpecificity::Tens, - CheckCodePrefix::F601 => PrefixSpecificity::Explicit, - CheckCodePrefix::F602 => PrefixSpecificity::Explicit, - CheckCodePrefix::F62 => PrefixSpecificity::Tens, - CheckCodePrefix::F621 => PrefixSpecificity::Explicit, - CheckCodePrefix::F622 => PrefixSpecificity::Explicit, - CheckCodePrefix::F63 => PrefixSpecificity::Tens, - CheckCodePrefix::F631 => PrefixSpecificity::Explicit, - CheckCodePrefix::F632 => PrefixSpecificity::Explicit, - CheckCodePrefix::F633 => PrefixSpecificity::Explicit, - CheckCodePrefix::F634 => PrefixSpecificity::Explicit, - CheckCodePrefix::F7 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F70 => PrefixSpecificity::Tens, - CheckCodePrefix::F701 => PrefixSpecificity::Explicit, - CheckCodePrefix::F702 => PrefixSpecificity::Explicit, - CheckCodePrefix::F704 => PrefixSpecificity::Explicit, - CheckCodePrefix::F706 => PrefixSpecificity::Explicit, - CheckCodePrefix::F707 => PrefixSpecificity::Explicit, - CheckCodePrefix::F72 => PrefixSpecificity::Tens, - CheckCodePrefix::F722 => PrefixSpecificity::Explicit, - CheckCodePrefix::F8 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F82 => PrefixSpecificity::Tens, - CheckCodePrefix::F821 => PrefixSpecificity::Explicit, - CheckCodePrefix::F822 => PrefixSpecificity::Explicit, - CheckCodePrefix::F823 => PrefixSpecificity::Explicit, - CheckCodePrefix::F83 => PrefixSpecificity::Tens, - CheckCodePrefix::F831 => PrefixSpecificity::Explicit, - CheckCodePrefix::F84 => PrefixSpecificity::Tens, - CheckCodePrefix::F841 => PrefixSpecificity::Explicit, - CheckCodePrefix::F9 => PrefixSpecificity::Hundreds, - CheckCodePrefix::F90 => PrefixSpecificity::Tens, - CheckCodePrefix::F901 => PrefixSpecificity::Explicit, - CheckCodePrefix::FBT => PrefixSpecificity::Category, - CheckCodePrefix::FBT0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::FBT00 => PrefixSpecificity::Tens, - CheckCodePrefix::FBT001 => PrefixSpecificity::Explicit, - CheckCodePrefix::FBT002 => PrefixSpecificity::Explicit, - CheckCodePrefix::FBT003 => PrefixSpecificity::Explicit, - CheckCodePrefix::I => PrefixSpecificity::Category, - CheckCodePrefix::I0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::I00 => PrefixSpecificity::Tens, - CheckCodePrefix::I001 => PrefixSpecificity::Explicit, - CheckCodePrefix::I2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::I25 => PrefixSpecificity::Tens, - CheckCodePrefix::I252 => PrefixSpecificity::Explicit, - CheckCodePrefix::M => PrefixSpecificity::Category, - CheckCodePrefix::M0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::M00 => PrefixSpecificity::Tens, - CheckCodePrefix::M001 => PrefixSpecificity::Explicit, - CheckCodePrefix::N => PrefixSpecificity::Category, - CheckCodePrefix::N8 => PrefixSpecificity::Hundreds, - CheckCodePrefix::N80 => PrefixSpecificity::Tens, - CheckCodePrefix::N801 => PrefixSpecificity::Explicit, - CheckCodePrefix::N802 => PrefixSpecificity::Explicit, - CheckCodePrefix::N803 => PrefixSpecificity::Explicit, - CheckCodePrefix::N804 => PrefixSpecificity::Explicit, - CheckCodePrefix::N805 => PrefixSpecificity::Explicit, - CheckCodePrefix::N806 => PrefixSpecificity::Explicit, - CheckCodePrefix::N807 => PrefixSpecificity::Explicit, - CheckCodePrefix::N81 => PrefixSpecificity::Tens, - CheckCodePrefix::N811 => PrefixSpecificity::Explicit, - CheckCodePrefix::N812 => PrefixSpecificity::Explicit, - CheckCodePrefix::N813 => PrefixSpecificity::Explicit, - CheckCodePrefix::N814 => PrefixSpecificity::Explicit, - CheckCodePrefix::N815 => PrefixSpecificity::Explicit, - CheckCodePrefix::N816 => PrefixSpecificity::Explicit, - CheckCodePrefix::N817 => PrefixSpecificity::Explicit, - CheckCodePrefix::N818 => PrefixSpecificity::Explicit, - CheckCodePrefix::Q => PrefixSpecificity::Category, - CheckCodePrefix::Q0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::Q00 => PrefixSpecificity::Tens, - CheckCodePrefix::Q000 => PrefixSpecificity::Explicit, - 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::RUF003 => PrefixSpecificity::Explicit, - CheckCodePrefix::RUF1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::RUF10 => PrefixSpecificity::Tens, - CheckCodePrefix::RUF101 => PrefixSpecificity::Explicit, - CheckCodePrefix::S => PrefixSpecificity::Category, - CheckCodePrefix::S1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::S10 => PrefixSpecificity::Tens, - CheckCodePrefix::S101 => PrefixSpecificity::Explicit, - CheckCodePrefix::S102 => PrefixSpecificity::Explicit, - CheckCodePrefix::S104 => PrefixSpecificity::Explicit, - CheckCodePrefix::S105 => PrefixSpecificity::Explicit, - CheckCodePrefix::S106 => PrefixSpecificity::Explicit, - CheckCodePrefix::S107 => PrefixSpecificity::Explicit, - CheckCodePrefix::T => PrefixSpecificity::Category, - CheckCodePrefix::T1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::T10 => PrefixSpecificity::Tens, - CheckCodePrefix::T100 => PrefixSpecificity::Explicit, - CheckCodePrefix::T2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::T20 => PrefixSpecificity::Tens, - CheckCodePrefix::T201 => PrefixSpecificity::Explicit, - CheckCodePrefix::T203 => PrefixSpecificity::Explicit, - CheckCodePrefix::U => PrefixSpecificity::Category, - CheckCodePrefix::U0 => PrefixSpecificity::Hundreds, - CheckCodePrefix::U00 => PrefixSpecificity::Tens, - CheckCodePrefix::U001 => PrefixSpecificity::Explicit, - CheckCodePrefix::U003 => PrefixSpecificity::Explicit, - CheckCodePrefix::U004 => PrefixSpecificity::Explicit, - CheckCodePrefix::U005 => PrefixSpecificity::Explicit, - CheckCodePrefix::U006 => PrefixSpecificity::Explicit, - CheckCodePrefix::U007 => PrefixSpecificity::Explicit, - CheckCodePrefix::U008 => PrefixSpecificity::Explicit, - CheckCodePrefix::U009 => PrefixSpecificity::Explicit, - CheckCodePrefix::U01 => PrefixSpecificity::Tens, - CheckCodePrefix::U010 => PrefixSpecificity::Explicit, - CheckCodePrefix::U011 => PrefixSpecificity::Explicit, - CheckCodePrefix::U012 => PrefixSpecificity::Explicit, - CheckCodePrefix::U013 => PrefixSpecificity::Explicit, - CheckCodePrefix::U014 => PrefixSpecificity::Explicit, - CheckCodePrefix::U015 => PrefixSpecificity::Explicit, - CheckCodePrefix::W => PrefixSpecificity::Category, - CheckCodePrefix::W2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::W29 => PrefixSpecificity::Tens, - CheckCodePrefix::W292 => PrefixSpecificity::Explicit, - CheckCodePrefix::W6 => PrefixSpecificity::Hundreds, - CheckCodePrefix::W60 => PrefixSpecificity::Tens, - CheckCodePrefix::W605 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT => PrefixSpecificity::Category, - CheckCodePrefix::YTT1 => PrefixSpecificity::Hundreds, - CheckCodePrefix::YTT10 => PrefixSpecificity::Tens, - CheckCodePrefix::YTT101 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT102 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT103 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT2 => PrefixSpecificity::Hundreds, - CheckCodePrefix::YTT20 => PrefixSpecificity::Tens, - CheckCodePrefix::YTT201 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT202 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT203 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT204 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT3 => PrefixSpecificity::Hundreds, - CheckCodePrefix::YTT30 => PrefixSpecificity::Tens, - CheckCodePrefix::YTT301 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT302 => PrefixSpecificity::Explicit, - CheckCodePrefix::YTT303 => PrefixSpecificity::Explicit, + CheckCodePrefix::A => SuffixLength::Zero, + CheckCodePrefix::A0 => SuffixLength::One, + CheckCodePrefix::A00 => SuffixLength::Two, + CheckCodePrefix::A001 => SuffixLength::Three, + CheckCodePrefix::A002 => SuffixLength::Three, + CheckCodePrefix::A003 => SuffixLength::Three, + CheckCodePrefix::ANN => SuffixLength::Zero, + CheckCodePrefix::ANN0 => SuffixLength::One, + CheckCodePrefix::ANN00 => SuffixLength::Two, + CheckCodePrefix::ANN001 => SuffixLength::Three, + CheckCodePrefix::ANN002 => SuffixLength::Three, + CheckCodePrefix::ANN003 => SuffixLength::Three, + CheckCodePrefix::ANN1 => SuffixLength::One, + CheckCodePrefix::ANN10 => SuffixLength::Two, + CheckCodePrefix::ANN101 => SuffixLength::Three, + CheckCodePrefix::ANN102 => SuffixLength::Three, + CheckCodePrefix::ANN2 => SuffixLength::One, + CheckCodePrefix::ANN20 => SuffixLength::Two, + CheckCodePrefix::ANN201 => SuffixLength::Three, + CheckCodePrefix::ANN202 => SuffixLength::Three, + CheckCodePrefix::ANN204 => SuffixLength::Three, + CheckCodePrefix::ANN205 => SuffixLength::Three, + CheckCodePrefix::ANN206 => SuffixLength::Three, + CheckCodePrefix::ANN4 => SuffixLength::One, + CheckCodePrefix::ANN40 => SuffixLength::Two, + CheckCodePrefix::ANN401 => SuffixLength::Three, + CheckCodePrefix::B => SuffixLength::Zero, + CheckCodePrefix::B0 => SuffixLength::One, + CheckCodePrefix::B00 => SuffixLength::Two, + CheckCodePrefix::B002 => SuffixLength::Three, + CheckCodePrefix::B003 => SuffixLength::Three, + CheckCodePrefix::B004 => SuffixLength::Three, + CheckCodePrefix::B005 => SuffixLength::Three, + CheckCodePrefix::B006 => SuffixLength::Three, + CheckCodePrefix::B007 => SuffixLength::Three, + CheckCodePrefix::B008 => SuffixLength::Three, + CheckCodePrefix::B009 => SuffixLength::Three, + CheckCodePrefix::B01 => SuffixLength::Two, + CheckCodePrefix::B010 => SuffixLength::Three, + CheckCodePrefix::B011 => SuffixLength::Three, + CheckCodePrefix::B012 => SuffixLength::Three, + CheckCodePrefix::B013 => SuffixLength::Three, + CheckCodePrefix::B014 => SuffixLength::Three, + CheckCodePrefix::B015 => SuffixLength::Three, + CheckCodePrefix::B016 => SuffixLength::Three, + CheckCodePrefix::B017 => SuffixLength::Three, + CheckCodePrefix::B018 => SuffixLength::Three, + CheckCodePrefix::B019 => SuffixLength::Three, + CheckCodePrefix::B02 => SuffixLength::Two, + CheckCodePrefix::B020 => SuffixLength::Three, + CheckCodePrefix::B021 => SuffixLength::Three, + CheckCodePrefix::B022 => SuffixLength::Three, + CheckCodePrefix::B023 => SuffixLength::Three, + CheckCodePrefix::B024 => SuffixLength::Three, + CheckCodePrefix::B025 => SuffixLength::Three, + CheckCodePrefix::B026 => SuffixLength::Three, + CheckCodePrefix::B027 => SuffixLength::Three, + CheckCodePrefix::B9 => SuffixLength::One, + CheckCodePrefix::B90 => SuffixLength::Two, + CheckCodePrefix::B904 => SuffixLength::Three, + CheckCodePrefix::BLE => SuffixLength::Zero, + CheckCodePrefix::BLE0 => SuffixLength::One, + CheckCodePrefix::BLE00 => SuffixLength::Two, + CheckCodePrefix::BLE001 => SuffixLength::Three, + CheckCodePrefix::C => SuffixLength::Zero, + CheckCodePrefix::C4 => SuffixLength::One, + CheckCodePrefix::C40 => SuffixLength::Two, + CheckCodePrefix::C400 => SuffixLength::Three, + CheckCodePrefix::C401 => SuffixLength::Three, + CheckCodePrefix::C402 => SuffixLength::Three, + CheckCodePrefix::C403 => SuffixLength::Three, + CheckCodePrefix::C404 => SuffixLength::Three, + CheckCodePrefix::C405 => SuffixLength::Three, + CheckCodePrefix::C406 => SuffixLength::Three, + CheckCodePrefix::C408 => SuffixLength::Three, + CheckCodePrefix::C409 => SuffixLength::Three, + CheckCodePrefix::C41 => SuffixLength::Two, + CheckCodePrefix::C410 => SuffixLength::Three, + CheckCodePrefix::C411 => SuffixLength::Three, + CheckCodePrefix::C413 => SuffixLength::Three, + CheckCodePrefix::C414 => SuffixLength::Three, + CheckCodePrefix::C415 => SuffixLength::Three, + CheckCodePrefix::C416 => SuffixLength::Three, + CheckCodePrefix::C417 => SuffixLength::Three, + CheckCodePrefix::C9 => SuffixLength::One, + CheckCodePrefix::C90 => SuffixLength::Two, + CheckCodePrefix::C901 => SuffixLength::Three, + CheckCodePrefix::D => SuffixLength::Zero, + CheckCodePrefix::D1 => SuffixLength::One, + CheckCodePrefix::D10 => SuffixLength::Two, + CheckCodePrefix::D100 => SuffixLength::Three, + CheckCodePrefix::D101 => SuffixLength::Three, + CheckCodePrefix::D102 => SuffixLength::Three, + CheckCodePrefix::D103 => SuffixLength::Three, + CheckCodePrefix::D104 => SuffixLength::Three, + CheckCodePrefix::D105 => SuffixLength::Three, + CheckCodePrefix::D106 => SuffixLength::Three, + CheckCodePrefix::D107 => SuffixLength::Three, + CheckCodePrefix::D2 => SuffixLength::One, + CheckCodePrefix::D20 => SuffixLength::Two, + CheckCodePrefix::D200 => SuffixLength::Three, + CheckCodePrefix::D201 => SuffixLength::Three, + CheckCodePrefix::D202 => SuffixLength::Three, + CheckCodePrefix::D203 => SuffixLength::Three, + CheckCodePrefix::D204 => SuffixLength::Three, + CheckCodePrefix::D205 => SuffixLength::Three, + CheckCodePrefix::D206 => SuffixLength::Three, + CheckCodePrefix::D207 => SuffixLength::Three, + CheckCodePrefix::D208 => SuffixLength::Three, + CheckCodePrefix::D209 => SuffixLength::Three, + CheckCodePrefix::D21 => SuffixLength::Two, + CheckCodePrefix::D210 => SuffixLength::Three, + CheckCodePrefix::D211 => SuffixLength::Three, + CheckCodePrefix::D212 => SuffixLength::Three, + CheckCodePrefix::D213 => SuffixLength::Three, + CheckCodePrefix::D214 => SuffixLength::Three, + CheckCodePrefix::D215 => SuffixLength::Three, + CheckCodePrefix::D3 => SuffixLength::One, + CheckCodePrefix::D30 => SuffixLength::Two, + CheckCodePrefix::D300 => SuffixLength::Three, + CheckCodePrefix::D4 => SuffixLength::One, + CheckCodePrefix::D40 => SuffixLength::Two, + CheckCodePrefix::D400 => SuffixLength::Three, + CheckCodePrefix::D402 => SuffixLength::Three, + CheckCodePrefix::D403 => SuffixLength::Three, + CheckCodePrefix::D404 => SuffixLength::Three, + CheckCodePrefix::D405 => SuffixLength::Three, + CheckCodePrefix::D406 => SuffixLength::Three, + CheckCodePrefix::D407 => SuffixLength::Three, + CheckCodePrefix::D408 => SuffixLength::Three, + CheckCodePrefix::D409 => SuffixLength::Three, + CheckCodePrefix::D41 => SuffixLength::Two, + CheckCodePrefix::D410 => SuffixLength::Three, + CheckCodePrefix::D411 => SuffixLength::Three, + CheckCodePrefix::D412 => SuffixLength::Three, + CheckCodePrefix::D413 => SuffixLength::Three, + CheckCodePrefix::D414 => SuffixLength::Three, + CheckCodePrefix::D415 => SuffixLength::Three, + CheckCodePrefix::D416 => SuffixLength::Three, + CheckCodePrefix::D417 => SuffixLength::Three, + CheckCodePrefix::D418 => SuffixLength::Three, + CheckCodePrefix::D419 => SuffixLength::Three, + CheckCodePrefix::E => SuffixLength::Zero, + CheckCodePrefix::E4 => SuffixLength::One, + CheckCodePrefix::E40 => SuffixLength::Two, + CheckCodePrefix::E402 => SuffixLength::Three, + CheckCodePrefix::E5 => SuffixLength::One, + CheckCodePrefix::E50 => SuffixLength::Two, + CheckCodePrefix::E501 => SuffixLength::Three, + CheckCodePrefix::E7 => SuffixLength::One, + CheckCodePrefix::E71 => SuffixLength::Two, + CheckCodePrefix::E711 => SuffixLength::Three, + CheckCodePrefix::E712 => SuffixLength::Three, + CheckCodePrefix::E713 => SuffixLength::Three, + CheckCodePrefix::E714 => SuffixLength::Three, + CheckCodePrefix::E72 => SuffixLength::Two, + CheckCodePrefix::E721 => SuffixLength::Three, + CheckCodePrefix::E722 => SuffixLength::Three, + CheckCodePrefix::E73 => SuffixLength::Two, + CheckCodePrefix::E731 => SuffixLength::Three, + CheckCodePrefix::E74 => SuffixLength::Two, + CheckCodePrefix::E741 => SuffixLength::Three, + CheckCodePrefix::E742 => SuffixLength::Three, + CheckCodePrefix::E743 => SuffixLength::Three, + CheckCodePrefix::E9 => SuffixLength::One, + CheckCodePrefix::E90 => SuffixLength::Two, + CheckCodePrefix::E902 => SuffixLength::Three, + CheckCodePrefix::E99 => SuffixLength::Two, + CheckCodePrefix::E999 => SuffixLength::Three, + CheckCodePrefix::ERA => SuffixLength::Zero, + CheckCodePrefix::ERA0 => SuffixLength::One, + CheckCodePrefix::ERA00 => SuffixLength::Two, + CheckCodePrefix::ERA001 => SuffixLength::Three, + CheckCodePrefix::F => SuffixLength::Zero, + CheckCodePrefix::F4 => SuffixLength::One, + CheckCodePrefix::F40 => SuffixLength::Two, + CheckCodePrefix::F401 => SuffixLength::Three, + CheckCodePrefix::F402 => SuffixLength::Three, + CheckCodePrefix::F403 => SuffixLength::Three, + CheckCodePrefix::F404 => SuffixLength::Three, + CheckCodePrefix::F405 => SuffixLength::Three, + CheckCodePrefix::F406 => SuffixLength::Three, + CheckCodePrefix::F407 => SuffixLength::Three, + CheckCodePrefix::F5 => SuffixLength::One, + CheckCodePrefix::F50 => SuffixLength::Two, + CheckCodePrefix::F501 => SuffixLength::Three, + CheckCodePrefix::F502 => SuffixLength::Three, + CheckCodePrefix::F503 => SuffixLength::Three, + CheckCodePrefix::F504 => SuffixLength::Three, + CheckCodePrefix::F505 => SuffixLength::Three, + CheckCodePrefix::F506 => SuffixLength::Three, + CheckCodePrefix::F507 => SuffixLength::Three, + CheckCodePrefix::F508 => SuffixLength::Three, + CheckCodePrefix::F509 => SuffixLength::Three, + CheckCodePrefix::F52 => SuffixLength::Two, + CheckCodePrefix::F521 => SuffixLength::Three, + CheckCodePrefix::F522 => SuffixLength::Three, + CheckCodePrefix::F523 => SuffixLength::Three, + CheckCodePrefix::F524 => SuffixLength::Three, + CheckCodePrefix::F525 => SuffixLength::Three, + CheckCodePrefix::F54 => SuffixLength::Two, + CheckCodePrefix::F541 => SuffixLength::Three, + CheckCodePrefix::F6 => SuffixLength::One, + CheckCodePrefix::F60 => SuffixLength::Two, + CheckCodePrefix::F601 => SuffixLength::Three, + CheckCodePrefix::F602 => SuffixLength::Three, + CheckCodePrefix::F62 => SuffixLength::Two, + CheckCodePrefix::F621 => SuffixLength::Three, + CheckCodePrefix::F622 => SuffixLength::Three, + CheckCodePrefix::F63 => SuffixLength::Two, + CheckCodePrefix::F631 => SuffixLength::Three, + CheckCodePrefix::F632 => SuffixLength::Three, + CheckCodePrefix::F633 => SuffixLength::Three, + CheckCodePrefix::F634 => SuffixLength::Three, + CheckCodePrefix::F7 => SuffixLength::One, + CheckCodePrefix::F70 => SuffixLength::Two, + CheckCodePrefix::F701 => SuffixLength::Three, + CheckCodePrefix::F702 => SuffixLength::Three, + CheckCodePrefix::F704 => SuffixLength::Three, + CheckCodePrefix::F706 => SuffixLength::Three, + CheckCodePrefix::F707 => SuffixLength::Three, + CheckCodePrefix::F72 => SuffixLength::Two, + CheckCodePrefix::F722 => SuffixLength::Three, + CheckCodePrefix::F8 => SuffixLength::One, + CheckCodePrefix::F82 => SuffixLength::Two, + CheckCodePrefix::F821 => SuffixLength::Three, + CheckCodePrefix::F822 => SuffixLength::Three, + CheckCodePrefix::F823 => SuffixLength::Three, + CheckCodePrefix::F83 => SuffixLength::Two, + CheckCodePrefix::F831 => SuffixLength::Three, + CheckCodePrefix::F84 => SuffixLength::Two, + CheckCodePrefix::F841 => SuffixLength::Three, + CheckCodePrefix::F9 => SuffixLength::One, + CheckCodePrefix::F90 => SuffixLength::Two, + CheckCodePrefix::F901 => SuffixLength::Three, + CheckCodePrefix::FBT => SuffixLength::Zero, + CheckCodePrefix::FBT0 => SuffixLength::One, + CheckCodePrefix::FBT00 => SuffixLength::Two, + CheckCodePrefix::FBT001 => SuffixLength::Three, + CheckCodePrefix::FBT002 => SuffixLength::Three, + CheckCodePrefix::FBT003 => SuffixLength::Three, + CheckCodePrefix::I => SuffixLength::Zero, + CheckCodePrefix::I0 => SuffixLength::One, + CheckCodePrefix::I00 => SuffixLength::Two, + CheckCodePrefix::I001 => SuffixLength::Three, + CheckCodePrefix::I2 => SuffixLength::One, + CheckCodePrefix::I25 => SuffixLength::Two, + CheckCodePrefix::I252 => SuffixLength::Three, + CheckCodePrefix::M => SuffixLength::Zero, + CheckCodePrefix::M0 => SuffixLength::One, + CheckCodePrefix::M00 => SuffixLength::Two, + CheckCodePrefix::M001 => SuffixLength::Three, + CheckCodePrefix::N => SuffixLength::Zero, + CheckCodePrefix::N8 => SuffixLength::One, + CheckCodePrefix::N80 => SuffixLength::Two, + CheckCodePrefix::N801 => SuffixLength::Three, + CheckCodePrefix::N802 => SuffixLength::Three, + CheckCodePrefix::N803 => SuffixLength::Three, + CheckCodePrefix::N804 => SuffixLength::Three, + CheckCodePrefix::N805 => SuffixLength::Three, + CheckCodePrefix::N806 => SuffixLength::Three, + CheckCodePrefix::N807 => SuffixLength::Three, + CheckCodePrefix::N81 => SuffixLength::Two, + CheckCodePrefix::N811 => SuffixLength::Three, + CheckCodePrefix::N812 => SuffixLength::Three, + CheckCodePrefix::N813 => SuffixLength::Three, + CheckCodePrefix::N814 => SuffixLength::Three, + CheckCodePrefix::N815 => SuffixLength::Three, + CheckCodePrefix::N816 => SuffixLength::Three, + CheckCodePrefix::N817 => SuffixLength::Three, + CheckCodePrefix::N818 => SuffixLength::Three, + CheckCodePrefix::PLE => SuffixLength::Zero, + CheckCodePrefix::PLE1 => SuffixLength::One, + CheckCodePrefix::PLE11 => SuffixLength::Two, + CheckCodePrefix::PLE114 => SuffixLength::Three, + CheckCodePrefix::PLE1142 => SuffixLength::Four, + CheckCodePrefix::Q => SuffixLength::Zero, + CheckCodePrefix::Q0 => SuffixLength::One, + CheckCodePrefix::Q00 => SuffixLength::Two, + CheckCodePrefix::Q000 => SuffixLength::Three, + CheckCodePrefix::Q001 => SuffixLength::Three, + CheckCodePrefix::Q002 => SuffixLength::Three, + CheckCodePrefix::Q003 => SuffixLength::Three, + CheckCodePrefix::RUF => SuffixLength::Zero, + CheckCodePrefix::RUF0 => SuffixLength::One, + CheckCodePrefix::RUF00 => SuffixLength::Two, + CheckCodePrefix::RUF001 => SuffixLength::Three, + CheckCodePrefix::RUF002 => SuffixLength::Three, + CheckCodePrefix::RUF003 => SuffixLength::Three, + CheckCodePrefix::RUF1 => SuffixLength::One, + CheckCodePrefix::RUF10 => SuffixLength::Two, + CheckCodePrefix::RUF101 => SuffixLength::Three, + CheckCodePrefix::S => SuffixLength::Zero, + CheckCodePrefix::S1 => SuffixLength::One, + CheckCodePrefix::S10 => SuffixLength::Two, + CheckCodePrefix::S101 => SuffixLength::Three, + CheckCodePrefix::S102 => SuffixLength::Three, + CheckCodePrefix::S104 => SuffixLength::Three, + CheckCodePrefix::S105 => SuffixLength::Three, + CheckCodePrefix::S106 => SuffixLength::Three, + CheckCodePrefix::S107 => SuffixLength::Three, + CheckCodePrefix::T => SuffixLength::Zero, + CheckCodePrefix::T1 => SuffixLength::One, + CheckCodePrefix::T10 => SuffixLength::Two, + CheckCodePrefix::T100 => SuffixLength::Three, + CheckCodePrefix::T2 => SuffixLength::One, + CheckCodePrefix::T20 => SuffixLength::Two, + CheckCodePrefix::T201 => SuffixLength::Three, + CheckCodePrefix::T203 => SuffixLength::Three, + CheckCodePrefix::U => SuffixLength::Zero, + CheckCodePrefix::U0 => SuffixLength::One, + CheckCodePrefix::U00 => SuffixLength::Two, + CheckCodePrefix::U001 => SuffixLength::Three, + CheckCodePrefix::U003 => SuffixLength::Three, + CheckCodePrefix::U004 => SuffixLength::Three, + CheckCodePrefix::U005 => SuffixLength::Three, + CheckCodePrefix::U006 => SuffixLength::Three, + CheckCodePrefix::U007 => SuffixLength::Three, + CheckCodePrefix::U008 => SuffixLength::Three, + CheckCodePrefix::U009 => SuffixLength::Three, + CheckCodePrefix::U01 => SuffixLength::Two, + CheckCodePrefix::U010 => SuffixLength::Three, + CheckCodePrefix::U011 => SuffixLength::Three, + CheckCodePrefix::U012 => SuffixLength::Three, + CheckCodePrefix::U013 => SuffixLength::Three, + CheckCodePrefix::U014 => SuffixLength::Three, + CheckCodePrefix::U015 => SuffixLength::Three, + CheckCodePrefix::W => SuffixLength::Zero, + CheckCodePrefix::W2 => SuffixLength::One, + CheckCodePrefix::W29 => SuffixLength::Two, + CheckCodePrefix::W292 => SuffixLength::Three, + CheckCodePrefix::W6 => SuffixLength::One, + CheckCodePrefix::W60 => SuffixLength::Two, + CheckCodePrefix::W605 => SuffixLength::Three, + CheckCodePrefix::YTT => SuffixLength::Zero, + CheckCodePrefix::YTT1 => SuffixLength::One, + CheckCodePrefix::YTT10 => SuffixLength::Two, + CheckCodePrefix::YTT101 => SuffixLength::Three, + CheckCodePrefix::YTT102 => SuffixLength::Three, + CheckCodePrefix::YTT103 => SuffixLength::Three, + CheckCodePrefix::YTT2 => SuffixLength::One, + CheckCodePrefix::YTT20 => SuffixLength::Two, + CheckCodePrefix::YTT201 => SuffixLength::Three, + CheckCodePrefix::YTT202 => SuffixLength::Three, + CheckCodePrefix::YTT203 => SuffixLength::Three, + CheckCodePrefix::YTT204 => SuffixLength::Three, + CheckCodePrefix::YTT3 => SuffixLength::One, + CheckCodePrefix::YTT30 => SuffixLength::Two, + CheckCodePrefix::YTT301 => SuffixLength::Three, + CheckCodePrefix::YTT302 => SuffixLength::Three, + CheckCodePrefix::YTT303 => SuffixLength::Three, } } } @@ -1697,6 +1713,7 @@ pub const CATEGORIES: &[CheckCodePrefix] = &[ CheckCodePrefix::I, CheckCodePrefix::M, CheckCodePrefix::N, + CheckCodePrefix::PLE, CheckCodePrefix::Q, CheckCodePrefix::RUF, CheckCodePrefix::S, diff --git a/src/lib.rs b/src/lib.rs index 4c72f9eb05951..db2cc9cc6494f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,7 @@ pub mod printer; mod pycodestyle; mod pydocstyle; mod pyflakes; +mod pylint; mod python; mod pyupgrade; mod rules; diff --git a/src/pylint/mod.rs b/src/pylint/mod.rs new file mode 100644 index 0000000000000..2ddd359159fbc --- /dev/null +++ b/src/pylint/mod.rs @@ -0,0 +1,28 @@ +pub mod plugins; + +#[cfg(test)] +mod tests { + use std::path::Path; + + use anyhow::Result; + use test_case::test_case; + + use crate::checks::CheckCode; + use crate::linter::test_path; + use crate::Settings; + + #[test_case(Path::new("await_outside_async.py"))] + fn checks(path: &Path) -> Result<()> { + let snapshot = format!("{}", path.to_string_lossy()); + let mut checks = test_path( + Path::new("./resources/test/fixtures/pylint") + .join(path) + .as_path(), + &Settings::for_rules(vec![CheckCode::PLE1142]), + true, + )?; + checks.sort_by_key(|check| check.location); + insta::assert_yaml_snapshot!(snapshot, checks); + Ok(()) + } +} diff --git a/src/pylint/plugins.rs b/src/pylint/plugins.rs new file mode 100644 index 0000000000000..e9a1908387edd --- /dev/null +++ b/src/pylint/plugins.rs @@ -0,0 +1,26 @@ +use rustpython_ast::Expr; + +use crate::ast::types::{FunctionScope, Range, ScopeKind}; +use crate::check_ast::Checker; +use crate::checks::CheckKind; +use crate::Check; + +/// PLE1142 +pub fn await_outside_async(checker: &mut Checker, expr: &Expr) { + if !checker + .current_scopes() + .find_map(|scope| { + if let ScopeKind::Function(FunctionScope { async_, .. }) = &scope.kind { + Some(*async_) + } else { + None + } + }) + .unwrap_or(true) + { + checker.add_check(Check::new( + CheckKind::AwaitOutsideAsync, + Range::from_located(expr), + )); + } +} diff --git a/src/pylint/snapshots/ruff__pylint__tests__await_outside_async.py.snap b/src/pylint/snapshots/ruff__pylint__tests__await_outside_async.py.snap new file mode 100644 index 0000000000000..8d587b69f49e3 --- /dev/null +++ b/src/pylint/snapshots/ruff__pylint__tests__await_outside_async.py.snap @@ -0,0 +1,21 @@ +--- +source: src/pylint/mod.rs +expression: checks +--- +- kind: AwaitOutsideAsync + location: + row: 12 + column: 10 + end_location: + row: 12 + column: 24 + fix: ~ +- kind: AwaitOutsideAsync + location: + row: 25 + column: 8 + end_location: + row: 25 + column: 30 + fix: ~ + diff --git a/src/settings/mod.rs b/src/settings/mod.rs index e81973ce45064..b8bc4287a26f4 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -13,7 +13,7 @@ use regex::Regex; use rustc_hash::FxHashSet; use crate::checks::CheckCode; -use crate::checks_gen::{CheckCodePrefix, PrefixSpecificity}; +use crate::checks_gen::{CheckCodePrefix, SuffixLength}; use crate::settings::configuration::Configuration; use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion, SerializationFormat}; use crate::{ @@ -214,10 +214,11 @@ pub fn resolve_per_file_ignores( fn resolve_codes(select: &[CheckCodePrefix], ignore: &[CheckCodePrefix]) -> FxHashSet { let mut codes: FxHashSet = FxHashSet::default(); for specificity in [ - PrefixSpecificity::Category, - PrefixSpecificity::Hundreds, - PrefixSpecificity::Tens, - PrefixSpecificity::Explicit, + SuffixLength::Zero, + SuffixLength::One, + SuffixLength::Two, + SuffixLength::Three, + SuffixLength::Four, ] { for prefix in select { if prefix.specificity() == specificity {