Rename remaining `use-*` rules (#3661)

This commit is contained in:
Charlie Marsh 2023-03-22 11:36:01 -04:00 committed by GitHub
parent 875f61cb62
commit 242dd3dae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 44 additions and 43 deletions

View File

@ -5,3 +5,4 @@ uses-*
rewrite-*
prefer-*
consider-*
use-*

View File

@ -1718,8 +1718,8 @@ where
flake8_pytest_style::rules::assert_in_exception_handler(handlers),
);
}
if self.settings.rules.enabled(Rule::UseContextlibSuppress) {
flake8_simplify::rules::use_contextlib_suppress(
if self.settings.rules.enabled(Rule::SuppressibleException) {
flake8_simplify::rules::suppressible_exception(
self, stmt, body, handlers, orelse, finalbody,
);
}
@ -2267,9 +2267,9 @@ where
if self
.settings
.rules
.enabled(Rule::UsePriorToGlobalDeclaration)
.enabled(Rule::LoadBeforeGlobalDeclaration)
{
pylint::rules::use_prior_to_global_declaration(self, id, expr);
pylint::rules::load_before_global_declaration(self, id, expr);
}
}
ExprKind::Attribute { attr, value, .. } => {

View File

@ -168,7 +168,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pylint, "E0101") => Rule::ReturnInInit,
(Pylint, "E0116") => Rule::ContinueInFinally,
(Pylint, "E0117") => Rule::NonlocalWithoutBinding,
(Pylint, "E0118") => Rule::UsePriorToGlobalDeclaration,
(Pylint, "E0118") => Rule::LoadBeforeGlobalDeclaration,
(Pylint, "E0604") => Rule::InvalidAllObject,
(Pylint, "E0605") => Rule::InvalidAllFormat,
(Pylint, "E1142") => Rule::AwaitOutsideAsync,
@ -327,7 +327,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Simplify, "101") => Rule::DuplicateIsinstanceCall,
(Flake8Simplify, "102") => Rule::CollapsibleIf,
(Flake8Simplify, "103") => Rule::NeedlessBool,
(Flake8Simplify, "105") => Rule::UseContextlibSuppress,
(Flake8Simplify, "105") => Rule::SuppressibleException,
(Flake8Simplify, "107") => Rule::ReturnInTryExceptFinally,
(Flake8Simplify, "108") => Rule::IfElseBlockInsteadOfIfExp,
(Flake8Simplify, "109") => Rule::CompareWithTuple,

View File

@ -167,7 +167,7 @@ ruff_macros::register_rules!(
rules::pylint::rules::UselessImportAlias,
rules::pylint::rules::UnnecessaryDirectLambdaCall,
rules::pylint::rules::NonlocalWithoutBinding,
rules::pylint::rules::UsePriorToGlobalDeclaration,
rules::pylint::rules::LoadBeforeGlobalDeclaration,
rules::pylint::rules::AwaitOutsideAsync,
rules::pylint::rules::PropertyWithParameters,
rules::pylint::rules::ReturnInInit,
@ -299,7 +299,7 @@ ruff_macros::register_rules!(
rules::flake8_simplify::rules::DuplicateIsinstanceCall,
rules::flake8_simplify::rules::CollapsibleIf,
rules::flake8_simplify::rules::NeedlessBool,
rules::flake8_simplify::rules::UseContextlibSuppress,
rules::flake8_simplify::rules::SuppressibleException,
rules::flake8_simplify::rules::ReturnInTryExceptFinally,
rules::flake8_simplify::rules::IfElseBlockInsteadOfIfExp,
rules::flake8_simplify::rules::CompareWithTuple,

View File

@ -16,7 +16,7 @@ mod tests {
#[test_case(Rule::DuplicateIsinstanceCall, Path::new("SIM101.py"); "SIM101")]
#[test_case(Rule::CollapsibleIf, Path::new("SIM102.py"); "SIM102")]
#[test_case(Rule::NeedlessBool, Path::new("SIM103.py"); "SIM103")]
#[test_case(Rule::UseContextlibSuppress, Path::new("SIM105.py"); "SIM105")]
#[test_case(Rule::SuppressibleException, Path::new("SIM105.py"); "SIM105")]
#[test_case(Rule::ReturnInTryExceptFinally, Path::new("SIM107.py"); "SIM107")]
#[test_case(Rule::IfElseBlockInsteadOfIfExp, Path::new("SIM108.py"); "SIM108")]
#[test_case(Rule::CompareWithTuple, Path::new("SIM109.py"); "SIM109")]

View File

@ -24,7 +24,7 @@ pub use open_file_with_context_handler::{
};
pub use reimplemented_builtin::{convert_for_loop_to_any_all, ReimplementedBuiltin};
pub use return_in_try_except_finally::{return_in_try_except_finally, ReturnInTryExceptFinally};
pub use use_contextlib_suppress::{use_contextlib_suppress, UseContextlibSuppress};
pub use suppressible_exception::{suppressible_exception, SuppressibleException};
pub use yoda_conditions::{yoda_conditions, YodaConditions};
mod ast_bool_op;
@ -39,5 +39,5 @@ mod key_in_dict;
mod open_file_with_context_handler;
mod reimplemented_builtin;
mod return_in_try_except_finally;
mod use_contextlib_suppress;
mod suppressible_exception;
mod yoda_conditions;

View File

@ -9,19 +9,19 @@ use ruff_python_ast::types::Range;
use crate::checkers::ast::Checker;
#[violation]
pub struct UseContextlibSuppress {
pub struct SuppressibleException {
pub exception: String,
}
impl Violation for UseContextlibSuppress {
impl Violation for SuppressibleException {
#[derive_message_formats]
fn message(&self) -> String {
let UseContextlibSuppress { exception } = self;
let SuppressibleException { exception } = self;
format!("Use `contextlib.suppress({exception})` instead of try-except-pass")
}
}
/// SIM105
pub fn use_contextlib_suppress(
pub fn suppressible_exception(
checker: &mut Checker,
stmt: &Stmt,
body: &[Stmt],
@ -63,7 +63,7 @@ pub fn use_contextlib_suppress(
handler_names.join(", ")
};
checker.diagnostics.push(Diagnostic::new(
UseContextlibSuppress { exception },
SuppressibleException { exception },
Range::from(stmt),
));
}

View File

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_simplify/mod.rs
expression: diagnostics
---
- kind:
name: UseContextlibSuppress
name: SuppressibleException
body: "Use `contextlib.suppress(ValueError)` instead of try-except-pass"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UseContextlibSuppress
name: SuppressibleException
body: "Use `contextlib.suppress(ValueError, OSError)` instead of try-except-pass"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UseContextlibSuppress
name: SuppressibleException
body: "Use `contextlib.suppress(Exception)` instead of try-except-pass"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UseContextlibSuppress
name: SuppressibleException
body: "Use `contextlib.suppress(a.Error, b.Error)` instead of try-except-pass"
suggestion: ~
fixable: false

View File

@ -60,7 +60,7 @@ mod tests {
#[test_case(Rule::TooManyReturnStatements, Path::new("too_many_return_statements.py"); "PLR0911")]
#[test_case(Rule::TooManyStatements, Path::new("too_many_statements.py"); "PLR0915")]
#[test_case(Rule::UnnecessaryDirectLambdaCall, Path::new("unnecessary_direct_lambda_call.py"); "PLC3002")]
#[test_case(Rule::UsePriorToGlobalDeclaration, Path::new("use_prior_to_global_declaration.py"); "PLE0118")]
#[test_case(Rule::LoadBeforeGlobalDeclaration, Path::new("load_before_global_declaration.py"); "PLE0118")]
#[test_case(Rule::UselessElseOnLoop, Path::new("useless_else_on_loop.py"); "PLW0120")]
#[test_case(Rule::UselessImportAlias, Path::new("import_aliasing.py"); "PLC0414")]
#[test_case(Rule::UselessReturn, Path::new("useless_return.py"); "PLR1711")]

View File

@ -8,20 +8,20 @@ use ruff_python_ast::types::Range;
use crate::checkers::ast::Checker;
#[violation]
pub struct UsePriorToGlobalDeclaration {
pub struct LoadBeforeGlobalDeclaration {
pub name: String,
pub line: usize,
}
impl Violation for UsePriorToGlobalDeclaration {
impl Violation for LoadBeforeGlobalDeclaration {
#[derive_message_formats]
fn message(&self) -> String {
let UsePriorToGlobalDeclaration { name, line } = self;
let LoadBeforeGlobalDeclaration { name, line } = self;
format!("Name `{name}` is used prior to global declaration on line {line}")
}
}
/// PLE0118
pub fn use_prior_to_global_declaration(checker: &mut Checker, name: &str, expr: &Expr) {
pub fn load_before_global_declaration(checker: &mut Checker, name: &str, expr: &Expr) {
let globals = match &checker.ctx.scope().kind {
ScopeKind::Class(class_def) => &class_def.globals,
ScopeKind::Function(function_def) => &function_def.globals,
@ -30,7 +30,7 @@ pub fn use_prior_to_global_declaration(checker: &mut Checker, name: &str, expr:
if let Some(stmt) = globals.get(name) {
if expr.location < stmt.location {
checker.diagnostics.push(Diagnostic::new(
UsePriorToGlobalDeclaration {
LoadBeforeGlobalDeclaration {
name: name.to_string(),
line: stmt.location.row(),
},

View File

@ -18,6 +18,9 @@ pub use invalid_string_characters::{
invalid_string_characters, InvalidCharacterBackspace, InvalidCharacterEsc, InvalidCharacterNul,
InvalidCharacterSub, InvalidCharacterZeroWidthSpace,
};
pub use load_before_global_declaration::{
load_before_global_declaration, LoadBeforeGlobalDeclaration,
};
pub use logging::{logging_call, LoggingTooFewArgs, LoggingTooManyArgs};
pub use magic_value_comparison::{magic_value_comparison, MagicValueComparison};
pub use manual_import_from::{manual_from_import, ManualFromImport};
@ -34,9 +37,6 @@ pub use too_many_statements::{too_many_statements, TooManyStatements};
pub use unnecessary_direct_lambda_call::{
unnecessary_direct_lambda_call, UnnecessaryDirectLambdaCall,
};
pub use use_prior_to_global_declaration::{
use_prior_to_global_declaration, UsePriorToGlobalDeclaration,
};
pub use useless_else_on_loop::{useless_else_on_loop, UselessElseOnLoop};
pub use useless_import_alias::{useless_import_alias, UselessImportAlias};
pub use useless_return::{useless_return, UselessReturn};
@ -59,6 +59,7 @@ mod invalid_all_object;
mod invalid_envvar_default;
mod invalid_envvar_value;
mod invalid_string_characters;
mod load_before_global_declaration;
mod logging;
mod magic_value_comparison;
mod manual_import_from;
@ -73,7 +74,6 @@ mod too_many_branches;
mod too_many_return_statements;
mod too_many_statements;
mod unnecessary_direct_lambda_call;
mod use_prior_to_global_declaration;
mod useless_else_on_loop;
mod useless_import_alias;
mod useless_return;

View File

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/pylint/mod.rs
expression: diagnostics
---
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 7"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 17"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 25"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 35"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 43"
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 53"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 61"
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 71"
suggestion: ~
fixable: false
@ -107,7 +107,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 79"
suggestion: ~
fixable: false
@ -120,7 +120,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 89"
suggestion: ~
fixable: false
@ -133,7 +133,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 97"
suggestion: ~
fixable: false
@ -146,7 +146,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 107"
suggestion: ~
fixable: false
@ -159,7 +159,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: UsePriorToGlobalDeclaration
name: LoadBeforeGlobalDeclaration
body: "Name `x` is used prior to global declaration on line 114"
suggestion: ~
fixable: false