diff --git a/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs b/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs index a042f7506bfaa..84b233f94481a 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs @@ -9,7 +9,7 @@ use crate::rules::{ }; /// Run lint rules over the [`Binding`]s. -pub(crate) fn bindings(checker: &mut Checker) { +pub(crate) fn bindings(checker: &Checker) { if !checker.any_enabled(&[ Rule::AssignmentInAssert, Rule::InvalidAllFormat, @@ -48,22 +48,22 @@ pub(crate) fn bindings(checker: &mut Checker) { pyflakes::fixes::remove_exception_handler_assignment(binding, checker.locator) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::InvalidAllFormat) { if let Some(diagnostic) = pylint::rules::invalid_all_format(binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::InvalidAllObject) { if let Some(diagnostic) = pylint::rules::invalid_all_object(binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::NonAsciiName) { if let Some(diagnostic) = pylint::rules::non_ascii_name(binding, checker.locator) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::UnconventionalImportAlias) { @@ -72,61 +72,61 @@ pub(crate) fn bindings(checker: &mut Checker) { binding, &checker.settings.flake8_import_conventions.aliases, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::UnaliasedCollectionsAbcSetImport) { if let Some(diagnostic) = flake8_pyi::rules::unaliased_collections_abc_set_import(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if !checker.source_type.is_stub() && checker.enabled(Rule::UnquotedTypeAlias) { if let Some(diagnostics) = flake8_type_checking::rules::unquoted_type_alias(checker, binding) { - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } } if checker.enabled(Rule::UnsortedDunderSlots) { if let Some(diagnostic) = ruff::rules::sort_dunder_slots(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::UsedDummyVariable) { if let Some(diagnostic) = ruff::rules::used_dummy_variable(checker, binding, binding_id) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::AssignmentInAssert) { if let Some(diagnostic) = ruff::rules::assignment_in_assert(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::PytestUnittestRaisesAssertion) { if let Some(diagnostic) = flake8_pytest_style::rules::unittest_raises_assertion_binding(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::ForLoopWrites) { if let Some(diagnostic) = refurb::rules::for_loop_writes_binding(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CustomTypeVarForSelf) { if let Some(diagnostic) = flake8_pyi::rules::custom_type_var_instead_of_self(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::PrivateTypeParameter) { if let Some(diagnostic) = pyupgrade::rules::private_type_parameter(checker, binding) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/comprehension.rs b/crates/ruff_linter/src/checkers/ast/analyze/comprehension.rs index b136791652793..750501e4b3ba5 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/comprehension.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/comprehension.rs @@ -5,7 +5,7 @@ use crate::codes::Rule; use crate::rules::{flake8_simplify, pylint, refurb}; /// Run lint rules over a [`Comprehension`] syntax nodes. -pub(crate) fn comprehension(comprehension: &Comprehension, checker: &mut Checker) { +pub(crate) fn comprehension(comprehension: &Comprehension, checker: &Checker) { if checker.enabled(Rule::InDictKeys) { flake8_simplify::rules::key_in_dict_comprehension(checker, comprehension); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 3fba765c52f44..2f2bb7bf13308 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -13,7 +13,7 @@ use crate::rules::{ }; /// Run lint rules over all deferred scopes in the [`SemanticModel`]. -pub(crate) fn deferred_scopes(checker: &mut Checker) { +pub(crate) fn deferred_scopes(checker: &Checker) { if !checker.any_enabled(&[ Rule::AsyncioDanglingTask, Rule::BadStaticmethodArgument, @@ -85,12 +85,11 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { vec![] }; - let mut diagnostics: Vec = vec![]; for scope_id in checker.analyze.scopes.iter().rev().copied() { let scope = &checker.semantic.scopes[scope_id]; if checker.enabled(Rule::UndefinedLocal) { - pyflakes::rules::undefined_local(checker, scope_id, scope, &mut diagnostics); + pyflakes::rules::undefined_local(checker, scope_id, scope); } if checker.enabled(Rule::GlobalVariableNotAssigned) { @@ -112,7 +111,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { .map(|id| checker.semantic.reference(*id)) .all(ResolvedReference::is_load) { - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pylint::rules::GlobalVariableNotAssigned { name: (*name).to_string(), }, @@ -146,7 +145,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { if scope.kind.is_generator() { continue; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pylint::rules::RedefinedArgumentFromLocal { name: name.to_string(), }, @@ -186,7 +185,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { continue; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::ImportShadowedByLoopVar { name: name.to_string(), row: checker.compute_source_row(shadowed.start()), @@ -347,7 +346,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { diagnostic.set_fix(fix.clone()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -356,55 +355,47 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { || matches!(scope.kind, ScopeKind::Module | ScopeKind::Function(_)) { if checker.enabled(Rule::UnusedPrivateTypeVar) { - flake8_pyi::rules::unused_private_type_var(checker, scope, &mut diagnostics); + flake8_pyi::rules::unused_private_type_var(checker, scope); } if checker.enabled(Rule::UnusedPrivateProtocol) { - flake8_pyi::rules::unused_private_protocol(checker, scope, &mut diagnostics); + flake8_pyi::rules::unused_private_protocol(checker, scope); } if checker.enabled(Rule::UnusedPrivateTypeAlias) { - flake8_pyi::rules::unused_private_type_alias(checker, scope, &mut diagnostics); + flake8_pyi::rules::unused_private_type_alias(checker, scope); } if checker.enabled(Rule::UnusedPrivateTypedDict) { - flake8_pyi::rules::unused_private_typed_dict(checker, scope, &mut diagnostics); + flake8_pyi::rules::unused_private_typed_dict(checker, scope); } } if checker.enabled(Rule::AsyncioDanglingTask) { - ruff::rules::asyncio_dangling_binding(scope, &checker.semantic, &mut diagnostics); + ruff::rules::asyncio_dangling_binding(scope, checker); } if let Some(class_def) = scope.kind.as_class() { if checker.enabled(Rule::BuiltinAttributeShadowing) { flake8_builtins::rules::builtin_attribute_shadowing( - checker, - scope_id, - scope, - class_def, - &mut diagnostics, + checker, scope_id, scope, class_def, ); } if checker.enabled(Rule::FunctionCallInDataclassDefaultArgument) { - ruff::rules::function_call_in_dataclass_default( - checker, - class_def, - &mut diagnostics, - ); + ruff::rules::function_call_in_dataclass_default(checker, class_def); } if checker.enabled(Rule::MutableClassDefault) { - ruff::rules::mutable_class_default(checker, class_def, &mut diagnostics); + ruff::rules::mutable_class_default(checker, class_def); } if checker.enabled(Rule::MutableDataclassDefault) { - ruff::rules::mutable_dataclass_default(checker, class_def, &mut diagnostics); + ruff::rules::mutable_dataclass_default(checker, class_def); } } if matches!(scope.kind, ScopeKind::Function(_) | ScopeKind::Lambda(_)) { if checker.enabled(Rule::UnusedVariable) { - pyflakes::rules::unused_variable(checker, scope, &mut diagnostics); + pyflakes::rules::unused_variable(checker, scope); } if checker.enabled(Rule::UnusedAnnotation) { - pyflakes::rules::unused_annotation(checker, scope, &mut diagnostics); + pyflakes::rules::unused_annotation(checker, scope); } if !checker.source_type.is_stub() { @@ -415,11 +406,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { Rule::UnusedMethodArgument, Rule::UnusedStaticMethodArgument, ]) { - flake8_unused_arguments::rules::unused_arguments( - checker, - scope, - &mut diagnostics, - ); + flake8_unused_arguments::rules::unused_arguments(checker, scope); } } } @@ -428,11 +415,7 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { if !checker.source_type.is_stub() && checker.enabled(Rule::RuntimeImportInTypeCheckingBlock) { - flake8_type_checking::rules::runtime_import_in_type_checking_block( - checker, - scope, - &mut diagnostics, - ); + flake8_type_checking::rules::runtime_import_in_type_checking_block(checker, scope); } if enforce_typing_only_imports { let runtime_imports: Vec<&Binding> = checker @@ -447,47 +430,45 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { checker, scope, &runtime_imports, - &mut diagnostics, ); } if checker.enabled(Rule::UnusedImport) { - pyflakes::rules::unused_import(checker, scope, &mut diagnostics); + pyflakes::rules::unused_import(checker, scope); } if checker.enabled(Rule::ImportPrivateName) { - pylint::rules::import_private_name(checker, scope, &mut diagnostics); + pylint::rules::import_private_name(checker, scope); } } if scope.kind.is_function() { if checker.enabled(Rule::NoSelfUse) { - pylint::rules::no_self_use(checker, scope_id, scope, &mut diagnostics); + pylint::rules::no_self_use(checker, scope_id, scope); } if checker.enabled(Rule::TooManyLocals) { - pylint::rules::too_many_locals(checker, scope, &mut diagnostics); + pylint::rules::too_many_locals(checker, scope); } if checker.enabled(Rule::SingledispatchMethod) { - pylint::rules::singledispatch_method(checker, scope, &mut diagnostics); + pylint::rules::singledispatch_method(checker, scope); } if checker.enabled(Rule::SingledispatchmethodFunction) { - pylint::rules::singledispatchmethod_function(checker, scope, &mut diagnostics); + pylint::rules::singledispatchmethod_function(checker, scope); } if checker.enabled(Rule::BadStaticmethodArgument) { - pylint::rules::bad_staticmethod_argument(checker, scope, &mut diagnostics); + pylint::rules::bad_staticmethod_argument(checker, scope); } if checker.any_enabled(&[ Rule::InvalidFirstArgumentNameForClassMethod, Rule::InvalidFirstArgumentNameForMethod, ]) { - pep8_naming::rules::invalid_first_argument_name(checker, scope, &mut diagnostics); + pep8_naming::rules::invalid_first_argument_name(checker, scope); } } } - checker.diagnostics.extend(diagnostics); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs index bf3aac864b31a..aeef48346d276 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs @@ -139,13 +139,11 @@ pub(crate) fn definitions(checker: &mut Checker) { &checker.semantic, ) }) { - checker - .diagnostics - .extend(flake8_annotations::rules::definition( - checker, - definition, - *visibility, - )); + checker.report_diagnostics(flake8_annotations::rules::definition( + checker, + definition, + *visibility, + )); } overloaded_name = flake8_annotations::helpers::overloaded_name(definition, &checker.semantic); diff --git a/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs b/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs index 0c3d6372ab225..9a68550216776 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs @@ -8,7 +8,7 @@ use crate::rules::{ }; /// Run lint rules over an [`ExceptHandler`] syntax node. -pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &mut Checker) { +pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &Checker) { match except_handler { ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, @@ -23,7 +23,7 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &mut Check except_handler, checker.locator, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::RaiseWithoutFromInsideExcept) { diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index da191fb7f17fb..89aee1e4cde5d 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -21,7 +21,7 @@ use crate::rules::{ use crate::settings::types::PythonVersion; /// Run lint rules over an [`Expr`] syntax node. -pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { +pub(crate) fn expression(expr: &Expr, checker: &Checker) { match expr { Expr::Subscript(subscript @ ast::ExprSubscript { value, slice, .. }) => { // Ex) Optional[...], Union[...] @@ -201,7 +201,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { check_two_starred_expressions, expr.range(), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -515,7 +515,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { match pyflakes::format::FormatSummary::try_from(string_value.to_str()) { Err(e) => { if checker.enabled(Rule::StringDotFormatInvalidFormat) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::StringDotFormatInvalidFormat { message: pyflakes::format::error_to_string(&e), }, @@ -925,7 +925,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { } if checker.enabled(Rule::PytestPatchWithLambda) { if let Some(diagnostic) = flake8_pytest_style::rules::patch_with_lambda(call) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.any_enabled(&[ @@ -1281,7 +1281,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { .. }) => { if checker.enabled(Rule::PercentFormatUnsupportedFormatCharacter) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::PercentFormatUnsupportedFormatCharacter { char: c, }, @@ -1291,7 +1291,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { } Err(e) => { if checker.enabled(Rule::PercentFormatInvalidFormat) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::PercentFormatInvalidFormat { message: e.to_string(), }, @@ -1365,7 +1365,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { checker.locator, checker.settings, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CollectionLiteralConcatenation) { diff --git a/crates/ruff_linter/src/checkers/ast/analyze/module.rs b/crates/ruff_linter/src/checkers/ast/analyze/module.rs index e80e052b55b3c..cb897ebf266f7 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/module.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/module.rs @@ -5,7 +5,7 @@ use crate::codes::Rule; use crate::rules::{flake8_bugbear, ruff}; /// Run lint rules over a module. -pub(crate) fn module(suite: &Suite, checker: &mut Checker) { +pub(crate) fn module(suite: &Suite, checker: &Checker) { if checker.enabled(Rule::FStringDocstring) { flake8_bugbear::rules::f_string_docstring(checker, suite); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/parameter.rs b/crates/ruff_linter/src/checkers/ast/analyze/parameter.rs index 02bb30068a9e5..253dc603517c9 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/parameter.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/parameter.rs @@ -6,7 +6,7 @@ use crate::codes::Rule; use crate::rules::{flake8_builtins, pycodestyle}; /// Run lint rules over a [`Parameter`] syntax node. -pub(crate) fn parameter(parameter: &Parameter, checker: &mut Checker) { +pub(crate) fn parameter(parameter: &Parameter, checker: &Checker) { if checker.enabled(Rule::AmbiguousVariableName) { pycodestyle::rules::ambiguous_variable_name( checker, diff --git a/crates/ruff_linter/src/checkers/ast/analyze/parameters.rs b/crates/ruff_linter/src/checkers/ast/analyze/parameters.rs index 41d525197bd67..a9d2c949b7962 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/parameters.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/parameters.rs @@ -5,7 +5,7 @@ use crate::codes::Rule; use crate::rules::{flake8_bugbear, flake8_pyi, ruff}; /// Run lint rules over a [`Parameters`] syntax node. -pub(crate) fn parameters(parameters: &Parameters, checker: &mut Checker) { +pub(crate) fn parameters(parameters: &Parameters, checker: &Checker) { if checker.enabled(Rule::FunctionCallInDefaultArgument) { flake8_bugbear::rules::function_call_in_argument_default(checker, parameters); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index 87ba76c6550d7..3d11635edda6b 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -39,7 +39,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if !checker.semantic.scope_id.is_global() { for name in names { if checker.semantic.nonlocal(name).is_none() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pylint::rules::NonlocalWithoutBinding { name: name.to_string(), }, @@ -59,7 +59,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &mut checker.semantic.current_statements().skip(1), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -69,7 +69,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &mut checker.semantic.current_statements().skip(1), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -99,7 +99,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } if checker.enabled(Rule::AmbiguousFunctionName) { if let Some(diagnostic) = pycodestyle::rules::ambiguous_function_name(name) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::InvalidBoolReturnType) { @@ -128,7 +128,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, &checker.semantic, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.source_type.is_stub() { @@ -187,7 +187,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { name, &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::GlobalStatement) { @@ -239,7 +239,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { body, checker.settings.mccabe.max_complexity, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::HardcodedPasswordDefault) { @@ -265,7 +265,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { body, checker.settings.pylint.max_returns, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::TooManyBranches) { @@ -274,7 +274,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { body, checker.settings.pylint.max_branches, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::TooManyStatements) { @@ -283,7 +283,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { body, checker.settings.pylint.max_statements, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.any_enabled(&[ @@ -351,9 +351,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } #[cfg(any(feature = "test-rules", test))] if checker.enabled(Rule::UnreachableCode) { - checker - .diagnostics - .extend(pylint::rules::in_function(name, body)); + checker.report_diagnostics(pylint::rules::in_function(name, body)); } if checker.enabled(Rule::ReimplementedOperator) { refurb::rules::reimplemented_operator(checker, &function_def.into()); @@ -456,7 +454,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } if checker.enabled(Rule::AmbiguousClassName) { if let Some(diagnostic) = pycodestyle::rules::ambiguous_class_name(name) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::InvalidClassName) { @@ -465,7 +463,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { name, &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::ErrorSuffixOnExceptionName) { @@ -475,7 +473,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { name, &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if !checker.source_type.is_stub() { @@ -615,7 +613,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if let Some(diagnostic) = flake8_debugger::rules::debugger_import(stmt, None, &alias.name) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::BannedApi) { @@ -642,7 +640,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if let Some(diagnostic) = pylint::rules::import_self(alias, checker.module.qualified_name()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if let Some(asname) = &alias.asname { @@ -657,7 +655,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::LowercaseImportedAsNonLowercase) { @@ -670,7 +668,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsLowercase) { @@ -683,7 +681,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsConstant) { @@ -694,14 +692,14 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsAcronym) { if let Some(diagnostic) = pep8_naming::rules::camelcase_imported_as_acronym( name, asname, alias, stmt, checker, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -715,7 +713,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.flake8_import_conventions.banned_aliases, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -725,7 +723,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &alias.name, alias.asname.as_deref(), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::BuiltinImportShadowing) { @@ -841,7 +839,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if let Some(diagnostic) = flake8_pytest_style::rules::import_from(stmt, module, level) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.source_type.is_stub() { @@ -856,7 +854,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } if checker.enabled(Rule::LateFutureImport) { if checker.semantic.seen_futures_boundary() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::LateFutureImport, stmt.range(), )); @@ -865,7 +863,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } else if &alias.name == "*" { if checker.enabled(Rule::UndefinedLocalWithNestedImportStarUsage) { if !matches!(checker.semantic.current_scope().kind, ScopeKind::Module) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::UndefinedLocalWithNestedImportStarUsage { name: helpers::format_import_from(level, module).to_string(), }, @@ -874,7 +872,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } } if checker.enabled(Rule::UndefinedLocalWithImportStar) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::UndefinedLocalWithImportStar { name: helpers::format_import_from(level, module).to_string(), }, @@ -891,14 +889,14 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker.module.qualified_name(), checker.settings.flake8_tidy_imports.ban_relative_imports, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::Debugger) { if let Some(diagnostic) = flake8_debugger::rules::debugger_import(stmt, module, &alias.name) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::BannedImportAlias) { @@ -913,7 +911,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.flake8_import_conventions.banned_aliases, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -928,7 +926,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::LowercaseImportedAsNonLowercase) { @@ -941,7 +939,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsLowercase) { @@ -954,7 +952,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsConstant) { @@ -965,7 +963,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &checker.settings.pep8_naming.ignore_names, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::CamelcaseImportedAsAcronym) { @@ -976,7 +974,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, checker, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if !checker.source_type.is_stub() { @@ -996,7 +994,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { names, checker.module.qualified_name(), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::BannedImportFrom) { @@ -1005,7 +1003,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { &helpers::format_import_from(level, module), &checker.settings.flake8_import_conventions.banned_from, ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::ByteStringUsage) { @@ -1174,7 +1172,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } if checker.any_enabled(&[Rule::BadVersionInfoComparison, Rule::BadVersionInfoOrder]) { fn bad_version_info_comparison( - checker: &mut Checker, + checker: &Checker, test: &Expr, has_else_clause: bool, ) { @@ -1221,9 +1219,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { ) => { if !checker.semantic.in_type_checking_block() { if checker.enabled(Rule::Assert) { - checker - .diagnostics - .push(flake8_bandit::rules::assert_used(stmt)); + checker.report_diagnostic(flake8_bandit::rules::assert_used(stmt)); } } if checker.enabled(Rule::AssertTuple) { @@ -1440,7 +1436,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if let Some(diagnostic) = pyflakes::rules::default_except_not_last(handlers, checker.locator) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.any_enabled(&[ @@ -1537,7 +1533,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } if checker.enabled(Rule::PandasDfVariableName) { if let Some(diagnostic) = pandas_vet::rules::assignment_to_df(targets) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker @@ -1735,7 +1731,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if let Some(diagnostic) = ruff::rules::asyncio_dangling_task(value, checker.semantic()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::RepeatedAppend) { diff --git a/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs b/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs index 88d040acfb473..acd25d9fc73c8 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs @@ -5,7 +5,7 @@ use crate::codes::Rule; use crate::rules::{flake8_bandit, flake8_pyi, flake8_quotes, pycodestyle, ruff}; /// Run lint rules over a [`StringLike`] syntax nodes. -pub(crate) fn string_like(string_like: StringLike, checker: &mut Checker) { +pub(crate) fn string_like(string_like: StringLike, checker: &Checker) { if checker.any_enabled(&[ Rule::AmbiguousUnicodeCharacterString, Rule::AmbiguousUnicodeCharacterDocstring, diff --git a/crates/ruff_linter/src/checkers/ast/analyze/suite.rs b/crates/ruff_linter/src/checkers/ast/analyze/suite.rs index c004ce85ca7f1..f5b56f1081ae9 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/suite.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/suite.rs @@ -6,7 +6,7 @@ use crate::rules::flake8_pie; use crate::rules::refurb; /// Run lint rules over a suite of [`Stmt`] syntax nodes. -pub(crate) fn suite(suite: &[Stmt], checker: &mut Checker) { +pub(crate) fn suite(suite: &[Stmt], checker: &Checker) { if checker.enabled(Rule::UnnecessaryPlaceholder) { flake8_pie::rules::unnecessary_placeholder(checker, suite); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/unresolved_references.rs b/crates/ruff_linter/src/checkers/ast/analyze/unresolved_references.rs index 2eace392dfc30..dbe2c540ef4d8 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/unresolved_references.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/unresolved_references.rs @@ -7,7 +7,7 @@ use crate::codes::Rule; use crate::rules::pyflakes; /// Run lint rules over all [`UnresolvedReference`] entities in the [`SemanticModel`]. -pub(crate) fn unresolved_references(checker: &mut Checker) { +pub(crate) fn unresolved_references(checker: &Checker) { if !checker.any_enabled(&[Rule::UndefinedLocalWithImportStarUsage, Rule::UndefinedName]) { return; } @@ -15,7 +15,7 @@ pub(crate) fn unresolved_references(checker: &mut Checker) { for reference in checker.semantic.unresolved_references() { if reference.is_wildcard_import() { if checker.enabled(Rule::UndefinedLocalWithImportStarUsage) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::UndefinedLocalWithImportStarUsage { name: reference.name(checker.source()).to_string(), }, @@ -42,7 +42,7 @@ pub(crate) fn unresolved_references(checker: &mut Checker) { let symbol_name = reference.name(checker.source()); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( pyflakes::rules::UndefinedName { name: symbol_name.to_string(), minor_version_builtin_added: version_builtin_was_added(symbol_name), diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 5a83839838b53..1bd965aab638d 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -9,11 +9,6 @@ //! parent scopes have been fully traversed. Individual rules may also perform internal traversals //! of the AST. //! -//! While the [`Checker`] is typically passed by mutable reference to the individual lint rule -//! implementations, most of its constituent components are intended to be treated immutably, with -//! the exception of the [`Diagnostic`] vector, which is intended to be mutated by the individual -//! lint rules. In the future, this should be formalized in the API. -//! //! The individual [`Visitor`] implementations within the [`Checker`] typically proceed in four //! steps: //! @@ -31,7 +26,7 @@ use std::path::Path; use itertools::Itertools; use log::debug; -use rustc_hash::FxHashMap; +use rustc_hash::{FxHashMap, FxHashSet}; use ruff_diagnostics::{Diagnostic, IsolationLevel}; use ruff_notebook::{CellOffsets, NotebookIndex}; @@ -221,9 +216,9 @@ pub(crate) struct Checker<'a> { /// A set of deferred nodes to be analyzed after the AST traversal (e.g., `for` loops). analyze: deferred::Analyze, /// The cumulative set of diagnostics computed across all lint rules. - pub(crate) diagnostics: Vec, + diagnostics: RefCell>, /// The list of names already seen by flake8-bugbear diagnostics, to avoid duplicate violations. - pub(crate) flake8_bugbear_seen: Vec, + flake8_bugbear_seen: RefCell>, /// The end offset of the last visited statement. last_stmt_end: TextSize, /// A state describing if a docstring is expected or not. @@ -271,8 +266,8 @@ impl<'a> Checker<'a> { semantic, visit: deferred::Visit::default(), analyze: deferred::Analyze::default(), - diagnostics: Vec::default(), - flake8_bugbear_seen: Vec::default(), + diagnostics: RefCell::default(), + flake8_bugbear_seen: RefCell::default(), cell_offsets, notebook_index, last_stmt_end: TextSize::default(), @@ -362,6 +357,30 @@ impl<'a> Checker<'a> { self.indexer.comment_ranges() } + /// Push a new [`Diagnostic`] to the collection in the [`Checker`] + pub(crate) fn report_diagnostic(&self, diagnostic: Diagnostic) { + let mut diagnostics = self.diagnostics.borrow_mut(); + diagnostics.push(diagnostic); + } + + /// Extend the collection of [`Diagnostic`] objects in the [`Checker`] + pub(crate) fn report_diagnostics(&self, diagnostics: I) + where + I: IntoIterator, + { + let mut checker_diagnostics = self.diagnostics.borrow_mut(); + checker_diagnostics.extend(diagnostics); + } + + /// Adds a [`TextRange`] to the set of ranges of variable names + /// flagged in `flake8-bugbear` violations so far. + /// + /// Returns whether the value was newly inserted. + pub(crate) fn insert_flake8_bugbear_range(&self, range: TextRange) -> bool { + let mut ranges = self.flake8_bugbear_seen.borrow_mut(); + ranges.insert(range) + } + /// Returns the [`Tokens`] for the parsed type annotation if the checker is in a typing context /// or the parsed source code. pub(crate) fn tokens(&self) -> &'a Tokens { @@ -476,9 +495,9 @@ impl<'a> Checker<'a> { } /// Push `diagnostic` if the checker is not in a `@no_type_check` context. - pub(crate) fn push_type_diagnostic(&mut self, diagnostic: Diagnostic) { + pub(crate) fn report_type_diagnostic(&self, diagnostic: Diagnostic) { if !self.semantic.in_no_type_check() { - self.diagnostics.push(diagnostic); + self.report_diagnostic(diagnostic); } } } @@ -2419,7 +2438,7 @@ impl<'a> Checker<'a> { self.semantic.restore(snapshot); if self.enabled(Rule::ForwardAnnotationSyntaxError) { - self.push_type_diagnostic(Diagnostic::new( + self.report_type_diagnostic(Diagnostic::new( pyflakes::rules::ForwardAnnotationSyntaxError { parse_error: parse_error.error.to_string(), }, @@ -2561,7 +2580,7 @@ impl<'a> Checker<'a> { } else { if self.semantic.global_scope().uses_star_imports() { if self.enabled(Rule::UndefinedLocalWithImportStarUsage) { - self.diagnostics.push( + self.diagnostics.get_mut().push( Diagnostic::new( pyflakes::rules::UndefinedLocalWithImportStarUsage { name: name.to_string(), @@ -2576,7 +2595,7 @@ impl<'a> Checker<'a> { if self.settings.preview.is_enabled() || !self.path.ends_with("__init__.py") { - self.diagnostics.push( + self.diagnostics.get_mut().push( Diagnostic::new( pyflakes::rules::UndefinedExport { name: name.to_string(), @@ -2700,13 +2719,13 @@ pub(crate) fn check_ast( analyze::deferred_lambdas(&mut checker); analyze::deferred_for_loops(&mut checker); analyze::definitions(&mut checker); - analyze::bindings(&mut checker); - analyze::unresolved_references(&mut checker); + analyze::bindings(&checker); + analyze::unresolved_references(&checker); // Reset the scope to module-level, and check all consumed scopes. checker.semantic.scope_id = ScopeId::global(); checker.analyze.scopes.push(ScopeId::global()); - analyze::deferred_scopes(&mut checker); + analyze::deferred_scopes(&checker); - checker.diagnostics + checker.diagnostics.take() } diff --git a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs index d8a9ec437c5f8..b0b7c9c3ad382 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs @@ -50,7 +50,7 @@ impl Violation for AirflowDagNoScheduleArgument { } /// AIR301 -pub(crate) fn dag_no_schedule_argument(checker: &mut Checker, expr: &Expr) { +pub(crate) fn dag_no_schedule_argument(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; } @@ -86,5 +86,5 @@ pub(crate) fn dag_no_schedule_argument(checker: &mut Checker, expr: &Expr) { // Produce a diagnostic when the `schedule` keyword argument is not found. let diagnostic = Diagnostic::new(AirflowDagNoScheduleArgument, expr.range()); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs index 4bd5420bd89b8..9f8db2a23e384 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/moved_to_provider_in_3.rs @@ -83,7 +83,7 @@ impl Violation for Airflow3MovedToProvider { } /// AIR303 -pub(crate) fn moved_to_provider_in_3(checker: &mut Checker, expr: &Expr) { +pub(crate) fn moved_to_provider_in_3(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; } @@ -112,7 +112,7 @@ enum Replacement { }, } -fn check_names_moved_to_provider(checker: &mut Checker, expr: &Expr, ranged: TextRange) { +fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRange) { let Some(qualified_name) = checker.semantic().resolve_qualified_name(expr) else { return; }; @@ -1018,7 +1018,7 @@ fn check_names_moved_to_provider(checker: &mut Checker, expr: &Expr, ranged: Tex }, _ => return, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3MovedToProvider { deprecated: qualified_name.to_string(), replacement, diff --git a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs index 70ffce94c9c4c..46fa3b69099f2 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs @@ -80,7 +80,7 @@ enum Replacement { } /// AIR302 -pub(crate) fn airflow_3_removal_expr(checker: &mut Checker, expr: &Expr) { +pub(crate) fn airflow_3_removal_expr(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; } @@ -117,10 +117,7 @@ pub(crate) fn airflow_3_removal_expr(checker: &mut Checker, expr: &Expr) { } /// AIR302 -pub(crate) fn airflow_3_removal_function_def( - checker: &mut Checker, - function_def: &StmtFunctionDef, -) { +pub(crate) fn airflow_3_removal_function_def(checker: &Checker, function_def: &StmtFunctionDef) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; } @@ -156,7 +153,7 @@ const REMOVED_CONTEXT_KEYS: [&str; 12] = [ /// # 'execution_date' is removed in Airflow 3.0 /// pass /// ``` -fn check_function_parameters(checker: &mut Checker, function_def: &StmtFunctionDef) { +fn check_function_parameters(checker: &Checker, function_def: &StmtFunctionDef) { if !is_airflow_task(function_def, checker.semantic()) && !is_execute_method_inherits_from_airflow_operator(function_def, checker.semantic()) { @@ -166,7 +163,7 @@ fn check_function_parameters(checker: &mut Checker, function_def: &StmtFunctionD for param in function_def.parameters.iter_non_variadic_params() { let param_name = param.name(); if REMOVED_CONTEXT_KEYS.contains(¶m_name.as_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: param_name.to_string(), replacement: Replacement::None, @@ -186,29 +183,25 @@ fn check_function_parameters(checker: &mut Checker, function_def: &StmtFunctionD /// /// DAG(schedule_interval="@daily") /// ``` -fn check_call_arguments( - checker: &mut Checker, - qualified_name: &QualifiedName, - arguments: &Arguments, -) { +fn check_call_arguments(checker: &Checker, qualified_name: &QualifiedName, arguments: &Arguments) { match qualified_name.segments() { ["airflow", .., "DAG" | "dag"] => { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "schedule_interval", Some("schedule"), )); - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "timetable", Some("schedule"), )); - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "sla_miss_callback", None, )); - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "fail_stop", Some("fail_fast"), @@ -217,7 +210,7 @@ fn check_call_arguments( _ => { if is_airflow_auth_manager(qualified_name.segments()) { if !arguments.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: String::from("appbuilder"), replacement: Replacement::Message( @@ -228,44 +221,42 @@ fn check_call_arguments( )); } } else if is_airflow_task_handler(qualified_name.segments()) { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "filename_template", None, )); } else if is_airflow_operator(qualified_name.segments()) { - checker - .diagnostics - .extend(diagnostic_for_argument(arguments, "sla", None)); - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument(arguments, "sla", None)); + checker.report_diagnostics(diagnostic_for_argument( arguments, "task_concurrency", Some("max_active_tis_per_dag"), )); match qualified_name.segments() { ["airflow", .., "operators", "trigger_dagrun", "TriggerDagRunOperator"] => { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "execution_date", Some("logical_date"), )); } ["airflow", .., "operators", "datetime", "BranchDateTimeOperator"] => { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "use_task_execution_day", Some("use_task_logical_date"), )); } ["airflow", .., "operators", "weekday", "DayOfWeekSensor"] => { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "use_task_execution_day", Some("use_task_logical_date"), )); } ["airflow", .., "operators", "weekday", "BranchDayOfWeekOperator"] => { - checker.diagnostics.extend(diagnostic_for_argument( + checker.report_diagnostics(diagnostic_for_argument( arguments, "use_task_execution_day", Some("use_task_logical_date"), @@ -288,7 +279,7 @@ fn check_call_arguments( /// info = DatasetLineageInfo() /// info.dataset /// ``` -fn check_class_attribute(checker: &mut Checker, attribute_expr: &ExprAttribute) { +fn check_class_attribute(checker: &Checker, attribute_expr: &ExprAttribute) { let ExprAttribute { value, attr, .. } = attribute_expr; let Some(qualname) = typing::resolve_assignment(value, checker.semantic()) else { @@ -312,7 +303,7 @@ fn check_class_attribute(checker: &mut Checker, attribute_expr: &ExprAttribute) }; if let Some(replacement) = replacement { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: attr.to_string(), replacement, @@ -350,7 +341,7 @@ fn check_class_attribute(checker: &mut Checker, attribute_expr: &ExprAttribute) /// def my_task(**context): /// context.get("conf") # 'conf' is removed in Airflow 3.0 /// ``` -fn check_context_key_usage_in_call(checker: &mut Checker, call_expr: &ExprCall) { +fn check_context_key_usage_in_call(checker: &Checker, call_expr: &ExprCall) { if !in_airflow_task_function(checker.semantic()) { return; } @@ -386,7 +377,7 @@ fn check_context_key_usage_in_call(checker: &mut Checker, call_expr: &ExprCall) continue; }; if value == removed_key { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: removed_key.to_string(), replacement: Replacement::None, @@ -399,7 +390,7 @@ fn check_context_key_usage_in_call(checker: &mut Checker, call_expr: &ExprCall) /// Check if a subscript expression accesses a removed Airflow context variable. /// If a removed key is found, push a corresponding diagnostic. -fn check_context_key_usage_in_subscript(checker: &mut Checker, subscript: &ExprSubscript) { +fn check_context_key_usage_in_subscript(checker: &Checker, subscript: &ExprSubscript) { if !in_airflow_task_function(checker.semantic()) { return; } @@ -427,7 +418,7 @@ fn check_context_key_usage_in_subscript(checker: &mut Checker, subscript: &ExprS } if REMOVED_CONTEXT_KEYS.contains(&key.to_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: key.to_string(), replacement: Replacement::None, @@ -463,7 +454,7 @@ fn is_kwarg_parameter(semantic: &SemanticModel, name: &ExprName) -> bool { /// manager = DatasetManager() /// manager.register_datsaet_change() /// ``` -fn check_method(checker: &mut Checker, call_expr: &ExprCall) { +fn check_method(checker: &Checker, call_expr: &ExprCall) { let Expr::Attribute(ExprAttribute { attr, value, .. }) = &*call_expr.func else { return; }; @@ -528,7 +519,7 @@ fn check_method(checker: &mut Checker, call_expr: &ExprCall) { } }; if let Some(replacement) = replacement { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: attr.to_string(), replacement, @@ -552,7 +543,7 @@ fn check_method(checker: &mut Checker, call_expr: &ExprCall) { /// # Or, directly /// SubDagOperator() /// ``` -fn check_name(checker: &mut Checker, expr: &Expr, range: TextRange) { +fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { let Some(qualified_name) = checker.semantic().resolve_qualified_name(expr) else { return; }; @@ -876,7 +867,7 @@ fn check_name(checker: &mut Checker, expr: &Expr, range: TextRange) { _ => return, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: qualified_name.to_string(), replacement, @@ -897,7 +888,7 @@ fn check_name(checker: &mut Checker, expr: &Expr, range: TextRange) { /// executors = "some.third.party.executor" /// ``` fn check_airflow_plugin_extension( - checker: &mut Checker, + checker: &Checker, expr: &Expr, name: &str, class_def: &StmtClassDef, @@ -914,7 +905,7 @@ fn check_airflow_plugin_extension( ) }) }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Airflow3Removal { deprecated: name.to_string(), replacement: Replacement::Message( diff --git a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs index dc018d613ee75..f75418818fa8c 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs @@ -45,7 +45,7 @@ impl Violation for AirflowVariableNameTaskIdMismatch { } /// AIR001 -pub(crate) fn variable_name_task_id(checker: &mut Checker, targets: &[Expr], value: &Expr) { +pub(crate) fn variable_name_task_id(checker: &Checker, targets: &[Expr], value: &Expr) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; } @@ -116,5 +116,5 @@ pub(crate) fn variable_name_task_id(checker: &mut Checker, targets: &[Expr], val }, target.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs index 206106a3f0c99..16b6c5c4bf88d 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs @@ -88,7 +88,7 @@ impl Violation for FastApiNonAnnotatedDependency { /// FAST002 pub(crate) fn fastapi_non_annotated_dependency( - checker: &mut Checker, + checker: &Checker, function_def: &ast::StmtFunctionDef, ) { if !checker.semantic().seen_module(Modules::FASTAPI) @@ -219,7 +219,7 @@ impl<'a> DependencyCall<'a> { /// necessary to determine this while generating the fix, thus the need to return an updated /// `seen_default` here. fn create_diagnostic( - checker: &mut Checker, + checker: &Checker, parameter: &DependencyParameter, dependency_call: Option, mut seen_default: bool, @@ -304,7 +304,7 @@ fn create_diagnostic( } diagnostic.try_set_optional_fix(|| fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); seen_default } diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs index e1b38bbb37995..fa5181d34aa4d 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs @@ -74,10 +74,7 @@ impl AlwaysFixableViolation for FastApiRedundantResponseModel { } /// FAST001 -pub(crate) fn fastapi_redundant_response_model( - checker: &mut Checker, - function_def: &StmtFunctionDef, -) { +pub(crate) fn fastapi_redundant_response_model(checker: &Checker, function_def: &StmtFunctionDef) { if !checker.semantic().seen_module(Modules::FASTAPI) { return; } @@ -98,7 +95,7 @@ pub(crate) fn fastapi_redundant_response_model( ) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs index 0940ad3e6e6e9..7cf69ee8c40b9 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs @@ -105,7 +105,7 @@ impl Violation for FastApiUnusedPathParameter { /// FAST003 pub(crate) fn fastapi_unused_path_parameter( - checker: &mut Checker, + checker: &Checker, function_def: &ast::StmtFunctionDef, ) { if !checker.semantic().seen_module(Modules::FASTAPI) { @@ -163,7 +163,6 @@ pub(crate) fn fastapi_unused_path_parameter( } // Check if any of the path parameters are not in the function signature. - let mut diagnostics = vec![]; for (path_param, range) in path_params { // Ignore invalid identifiers (e.g., `user-id`, as opposed to `user_id`) if !is_identifier(path_param) { @@ -203,10 +202,8 @@ pub(crate) fn fastapi_unused_path_parameter( checker.locator().contents(), ))); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } - - checker.diagnostics.extend(diagnostics); } /// Returns an iterator over the non-positional-only, non-variadic parameters of a function. diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs index ec2ca7fd936ce..1a055108c35c1 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs @@ -223,7 +223,7 @@ impl Violation for SysVersionCmpStr10 { } /// YTT103, YTT201, YTT203, YTT204, YTT302 -pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr]) { +pub(crate) fn compare(checker: &Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr]) { match left { Expr::Subscript(ast::ExprSubscript { value, slice, .. }) if is_sys(value, "version_info", checker.semantic()) => @@ -243,9 +243,10 @@ pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[CmpOp], compara ) = (ops, comparators) { if *n == 3 && checker.enabled(Rule::SysVersionInfo0Eq3) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionInfo0Eq3, left.range())); + checker.report_diagnostic(Diagnostic::new( + SysVersionInfo0Eq3, + left.range(), + )); } } } else if *i == 1 { @@ -258,9 +259,10 @@ pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[CmpOp], compara ) = (ops, comparators) { if checker.enabled(Rule::SysVersionInfo1CmpInt) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionInfo1CmpInt, left.range())); + checker.report_diagnostic(Diagnostic::new( + SysVersionInfo1CmpInt, + left.range(), + )); } } } @@ -279,9 +281,10 @@ pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[CmpOp], compara ) = (ops, comparators) { if checker.enabled(Rule::SysVersionInfoMinorCmpInt) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionInfoMinorCmpInt, left.range())); + checker.report_diagnostic(Diagnostic::new( + SysVersionInfoMinorCmpInt, + left.range(), + )); } } } @@ -297,14 +300,10 @@ pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[CmpOp], compara { if value.len() == 1 { if checker.enabled(Rule::SysVersionCmpStr10) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionCmpStr10, left.range())); + checker.report_diagnostic(Diagnostic::new(SysVersionCmpStr10, left.range())); } } else if checker.enabled(Rule::SysVersionCmpStr3) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionCmpStr3, left.range())); + checker.report_diagnostic(Diagnostic::new(SysVersionCmpStr3, left.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs index e92b619a2a208..2e42a4ff78e64 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs @@ -46,7 +46,7 @@ impl Violation for SixPY3 { } /// YTT202 -pub(crate) fn name_or_attribute(checker: &mut Checker, expr: &Expr) { +pub(crate) fn name_or_attribute(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::SIX) { return; } @@ -56,8 +56,6 @@ pub(crate) fn name_or_attribute(checker: &mut Checker, expr: &Expr) { .resolve_qualified_name(expr) .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["six", "PY3"])) { - checker - .diagnostics - .push(Diagnostic::new(SixPY3, expr.range())); + checker.report_diagnostic(Diagnostic::new(SixPY3, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs index e853aba6144e6..3412dcf1f4d58 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs @@ -168,7 +168,7 @@ impl Violation for SysVersionSlice1 { } /// YTT101, YTT102, YTT301, YTT303 -pub(crate) fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) { +pub(crate) fn subscript(checker: &Checker, value: &Expr, slice: &Expr) { if is_sys(value, "version", checker.semantic()) { match slice { Expr::Slice(ast::ExprSlice { @@ -183,13 +183,9 @@ pub(crate) fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) { }) = upper.as_ref() { if *i == 1 && checker.enabled(Rule::SysVersionSlice1) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionSlice1, value.range())); + checker.report_diagnostic(Diagnostic::new(SysVersionSlice1, value.range())); } else if *i == 3 && checker.enabled(Rule::SysVersionSlice3) { - checker - .diagnostics - .push(Diagnostic::new(SysVersionSlice3, value.range())); + checker.report_diagnostic(Diagnostic::new(SysVersionSlice3, value.range())); } } } @@ -199,13 +195,9 @@ pub(crate) fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) { .. }) => { if *i == 2 && checker.enabled(Rule::SysVersion2) { - checker - .diagnostics - .push(Diagnostic::new(SysVersion2, value.range())); + checker.report_diagnostic(Diagnostic::new(SysVersion2, value.range())); } else if *i == 0 && checker.enabled(Rule::SysVersion0) { - checker - .diagnostics - .push(Diagnostic::new(SysVersion0, value.range())); + checker.report_diagnostic(Diagnostic::new(SysVersion0, value.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs index caf27b393d04a..065f5da16abf0 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs @@ -51,7 +51,7 @@ impl Violation for AsyncBusyWait { } /// ASYNC110 -pub(crate) fn async_busy_wait(checker: &mut Checker, while_stmt: &ast::StmtWhile) { +pub(crate) fn async_busy_wait(checker: &Checker, while_stmt: &ast::StmtWhile) { // The body should be a single `await` call. let [stmt] = while_stmt.body.as_slice() else { return; @@ -74,7 +74,7 @@ pub(crate) fn async_busy_wait(checker: &mut Checker, while_stmt: &ast::StmtWhile qualified_name.segments(), ["trio" | "anyio", "sleep" | "sleep_until"] | ["asyncio", "sleep"] ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AsyncBusyWait { module: AsyncModule::try_from(&qualified_name).unwrap(), }, diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs index 172b219dc349f..79c34e75ab6e9 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs @@ -87,10 +87,7 @@ impl Violation for AsyncFunctionWithTimeout { } /// ASYNC109 -pub(crate) fn async_function_with_timeout( - checker: &mut Checker, - function_def: &ast::StmtFunctionDef, -) { +pub(crate) fn async_function_with_timeout(checker: &Checker, function_def: &ast::StmtFunctionDef) { // Detect `async` calls with a `timeout` argument. if !function_def.is_async { return; @@ -115,7 +112,7 @@ pub(crate) fn async_function_with_timeout( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AsyncFunctionWithTimeout { module }, timeout.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs index d97d33afcb389..fe263f565d510 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for AsyncZeroSleep { } /// ASYNC115 -pub(crate) fn async_zero_sleep(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn async_zero_sleep(checker: &Checker, call: &ExprCall) { if !(checker.semantic().seen_module(Modules::TRIO) || checker.semantic().seen_module(Modules::ANYIO)) { @@ -103,6 +103,6 @@ pub(crate) fn async_zero_sleep(checker: &mut Checker, call: &ExprCall) { let arg_edit = Edit::range_replacement("()".to_string(), call.arguments.range()); Ok(Fix::safe_edits(import_edit, [reference_edit, arg_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs index 2ca475961985c..322f49a80f490 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs @@ -62,7 +62,7 @@ fn is_blocking_http_call(qualified_name: &QualifiedName) -> bool { } /// ASYNC210 -pub(crate) fn blocking_http_call(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn blocking_http_call(checker: &Checker, call: &ExprCall) { if checker.semantic().in_async_context() { if checker .semantic() @@ -70,7 +70,7 @@ pub(crate) fn blocking_http_call(checker: &mut Checker, call: &ExprCall) { .as_ref() .is_some_and(is_blocking_http_call) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BlockingHttpCallInAsyncFunction, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs index 3f8ac8ba7b7b6..0752d55146ec2 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs @@ -44,7 +44,7 @@ impl Violation for BlockingOpenCallInAsyncFunction { } /// ASYNC230 -pub(crate) fn blocking_open_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn blocking_open_call(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().in_async_context() { return; } @@ -52,7 +52,7 @@ pub(crate) fn blocking_open_call(checker: &mut Checker, call: &ast::ExprCall) { if is_open_call(&call.func, checker.semantic()) || is_open_call_from_pathlib(call.func.as_ref(), checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BlockingOpenCallInAsyncFunction, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs index 31ff6117539e3..693a345ba66ed 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs @@ -112,7 +112,7 @@ impl Violation for WaitForProcessInAsyncFunction { } /// ASYNC220, ASYNC221, ASYNC222 -pub(crate) fn blocking_process_invocation(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn blocking_process_invocation(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().in_async_context() { return; } @@ -146,7 +146,7 @@ pub(crate) fn blocking_process_invocation(checker: &mut Checker, call: &ast::Exp }; let diagnostic = Diagnostic::new::(diagnostic_kind, call.func.range()); if checker.enabled(diagnostic.kind.rule()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs index 36583e385ab85..de96e7ba8a121 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs @@ -43,7 +43,7 @@ fn is_blocking_sleep(qualified_name: &QualifiedName) -> bool { } /// ASYNC251 -pub(crate) fn blocking_sleep(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn blocking_sleep(checker: &Checker, call: &ExprCall) { if checker.semantic().in_async_context() { if checker .semantic() @@ -51,7 +51,7 @@ pub(crate) fn blocking_sleep(checker: &mut Checker, call: &ExprCall) { .as_ref() .is_some_and(is_blocking_sleep) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BlockingSleepInAsyncFunction, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs index 9c9b94a103db1..d3034ecd10c96 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs @@ -53,7 +53,7 @@ impl Violation for CancelScopeNoCheckpoint { /// ASYNC100 pub(crate) fn cancel_scope_no_checkpoint( - checker: &mut Checker, + checker: &Checker, with_stmt: &StmtWith, with_items: &[WithItem], ) { @@ -98,7 +98,7 @@ pub(crate) fn cancel_scope_no_checkpoint( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CancelScopeNoCheckpoint { method_name }, with_stmt.range, )); diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs b/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs index b86449db06578..ae623a4514867 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs @@ -56,7 +56,7 @@ impl Violation for LongSleepNotForever { } /// ASYNC116 -pub(crate) fn long_sleep_not_forever(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn long_sleep_not_forever(checker: &Checker, call: &ExprCall) { if !(checker.semantic().seen_module(Modules::TRIO) || checker.semantic().seen_module(Modules::ANYIO)) { @@ -127,5 +127,5 @@ pub(crate) fn long_sleep_not_forever(checker: &mut Checker, call: &ExprCall) { let arg_edit = Edit::range_replacement("()".to_string(), call.arguments.range()); Ok(Fix::unsafe_edits(import_edit, [reference_edit, arg_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs index 8315a71b5215b..1665c9c41c74a 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs @@ -51,7 +51,7 @@ impl Violation for TrioSyncCall { } /// ASYNC105 -pub(crate) fn sync_call(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn sync_call(checker: &Checker, call: &ExprCall) { if !checker.semantic().seen_module(Modules::TRIO) { return; } @@ -91,5 +91,5 @@ pub(crate) fn sync_call(checker: &mut Checker, call: &ExprCall) { call.func.start(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs index 4318ab99d647c..b4a768dfc5b88 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs @@ -61,7 +61,7 @@ enum Reason { } /// S103 -pub(crate) fn bad_file_permissions(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn bad_file_permissions(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::OS) { return; } @@ -78,7 +78,7 @@ pub(crate) fn bad_file_permissions(checker: &mut Checker, call: &ast::ExprCall) // The mask is a valid integer value -- check for overly permissive permissions. Ok(Some(mask)) => { if (mask & WRITE_WORLD > 0) || (mask & EXECUTE_GROUP > 0) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadFilePermissions { reason: Reason::Permissive(mask), }, @@ -88,7 +88,7 @@ pub(crate) fn bad_file_permissions(checker: &mut Checker, call: &ast::ExprCall) } // The mask is an invalid integer value (i.e., it's out of range). Err(_) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadFilePermissions { reason: Reason::Invalid, }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs index 1972e5b6b55bf..b3c9266b60260 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs @@ -44,7 +44,7 @@ impl Violation for DjangoExtra { } /// S610 -pub(crate) fn django_extra(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn django_extra(checker: &Checker, call: &ast::ExprCall) { let Expr::Attribute(ExprAttribute { attr, .. }) = call.func.as_ref() else { return; }; @@ -54,9 +54,7 @@ pub(crate) fn django_extra(checker: &mut Checker, call: &ast::ExprCall) { } if is_call_insecure(call) { - checker - .diagnostics - .push(Diagnostic::new(DjangoExtra, call.arguments.range())); + checker.report_diagnostic(Diagnostic::new(DjangoExtra, call.arguments.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs index 78578c5ccb0d3..eacabbe8d3141 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs @@ -35,7 +35,7 @@ impl Violation for DjangoRawSql { } /// S611 -pub(crate) fn django_raw_sql(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn django_raw_sql(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -55,9 +55,7 @@ pub(crate) fn django_raw_sql(checker: &mut Checker, call: &ast::ExprCall) { .find_argument_value("sql", 0) .is_some_and(Expr::is_string_literal_expr) { - checker - .diagnostics - .push(Diagnostic::new(DjangoRawSql, call.func.range())); + checker.report_diagnostic(Diagnostic::new(DjangoRawSql, call.func.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs index a25b60daa01f7..4376b4b2ffbc1 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs @@ -32,10 +32,8 @@ impl Violation for ExecBuiltin { } /// S102 -pub(crate) fn exec_used(checker: &mut Checker, func: &Expr) { +pub(crate) fn exec_used(checker: &Checker, func: &Expr) { if checker.semantic().match_builtin_expr(func, "exec") { - checker - .diagnostics - .push(Diagnostic::new(ExecBuiltin, func.range())); + checker.report_diagnostic(Diagnostic::new(ExecBuiltin, func.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs index 960e742a94d5b..348b504f7beb9 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs @@ -47,7 +47,7 @@ impl Violation for FlaskDebugTrue { } /// S201 -pub(crate) fn flask_debug_true(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn flask_debug_true(checker: &Checker, call: &ExprCall) { let Expr::Attribute(ExprAttribute { attr, value, .. }) = call.func.as_ref() else { return; }; @@ -67,8 +67,6 @@ pub(crate) fn flask_debug_true(checker: &mut Checker, call: &ExprCall) { if typing::resolve_assignment(value, checker.semantic()) .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["flask", "Flask"])) { - checker - .diagnostics - .push(Diagnostic::new(FlaskDebugTrue, debug_argument.range())); + checker.report_diagnostic(Diagnostic::new(FlaskDebugTrue, debug_argument.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs index a1e4739d84dce..f79868f0326be 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs @@ -37,13 +37,12 @@ impl Violation for HardcodedBindAllInterfaces { } /// S104 -pub(crate) fn hardcoded_bind_all_interfaces(checker: &mut Checker, string: StringLike) { +pub(crate) fn hardcoded_bind_all_interfaces(checker: &Checker, string: StringLike) { match string { StringLike::String(ast::ExprStringLiteral { value, .. }) => { if value == "0.0.0.0" { checker - .diagnostics - .push(Diagnostic::new(HardcodedBindAllInterfaces, string.range())); + .report_diagnostic(Diagnostic::new(HardcodedBindAllInterfaces, string.range())); } } StringLike::FString(ast::ExprFString { value, .. }) => { @@ -51,15 +50,16 @@ pub(crate) fn hardcoded_bind_all_interfaces(checker: &mut Checker, string: Strin match part { ast::FStringPart::Literal(literal) => { if &**literal == "0.0.0.0" { - checker - .diagnostics - .push(Diagnostic::new(HardcodedBindAllInterfaces, literal.range())); + checker.report_diagnostic(Diagnostic::new( + HardcodedBindAllInterfaces, + literal.range(), + )); } } ast::FStringPart::FString(f_string) => { for literal in f_string.elements.literals() { if &**literal == "0.0.0.0" { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HardcodedBindAllInterfaces, literal.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs index 1f7c25d2e2ba7..32d501bb4bd07 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs @@ -69,13 +69,13 @@ fn check_password_kwarg(parameter: &Parameter, default: &Expr) -> Option Option<&str> { /// S105 pub(crate) fn compare_to_hardcoded_password_string( - checker: &mut Checker, + checker: &Checker, left: &Expr, comparators: &[Expr], ) { - checker - .diagnostics - .extend(comparators.iter().filter_map(|comp| { - string_literal(comp).filter(|string| !string.is_empty())?; - let name = password_target(left)?; - Some(Diagnostic::new( - HardcodedPasswordString { - name: name.to_string(), - }, - comp.range(), - )) - })); + checker.report_diagnostics(comparators.iter().filter_map(|comp| { + string_literal(comp).filter(|string| !string.is_empty())?; + let name = password_target(left)?; + Some(Diagnostic::new( + HardcodedPasswordString { + name: name.to_string(), + }, + comp.range(), + )) + })); } /// S105 -pub(crate) fn assign_hardcoded_password_string( - checker: &mut Checker, - value: &Expr, - targets: &[Expr], -) { +pub(crate) fn assign_hardcoded_password_string(checker: &Checker, value: &Expr, targets: &[Expr]) { if string_literal(value) .filter(|string| !string.is_empty()) .is_some() { for target in targets { if let Some(name) = password_target(target) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HardcodedPasswordString { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs index bd88da10724ec..0515d62d31afb 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs @@ -55,7 +55,7 @@ impl Violation for HardcodedSQLExpression { } /// S608 -pub(crate) fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) { +pub(crate) fn hardcoded_sql_expression(checker: &Checker, expr: &Expr) { let content = match expr { // "select * from table where val = " + "str" + ... Expr::BinOp(ast::ExprBinOp { @@ -105,9 +105,7 @@ pub(crate) fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) { }; if SQL_REGEX.is_match(&content) { - checker - .diagnostics - .push(Diagnostic::new(HardcodedSQLExpression, expr.range())); + checker.report_diagnostic(Diagnostic::new(HardcodedSQLExpression, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs index 911bfc5b922de..f04a458e00efd 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs @@ -56,7 +56,7 @@ impl Violation for HardcodedTempFile { } /// S108 -pub(crate) fn hardcoded_tmp_directory(checker: &mut Checker, string: StringLike) { +pub(crate) fn hardcoded_tmp_directory(checker: &Checker, string: StringLike) { match string { StringLike::String(ast::ExprStringLiteral { value, .. }) => { check(checker, value.to_str(), string.range()); @@ -79,7 +79,7 @@ pub(crate) fn hardcoded_tmp_directory(checker: &mut Checker, string: StringLike) } } -fn check(checker: &mut Checker, value: &str, range: TextRange) { +fn check(checker: &Checker, value: &str, range: TextRange) { if !checker .settings .flake8_bandit @@ -102,7 +102,7 @@ fn check(checker: &mut Checker, value: &str, range: TextRange) { } } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HardcodedTempFile { string: value.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs index 6828c1c6d2a1c..85283dc7eb13e 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs @@ -64,7 +64,7 @@ impl Violation for HashlibInsecureHashFunction { } /// S324 -pub(crate) fn hashlib_insecure_hash_functions(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn hashlib_insecure_hash_functions(checker: &Checker, call: &ast::ExprCall) { if !checker .semantic() .seen_module(Modules::HASHLIB | Modules::CRYPT) @@ -105,7 +105,7 @@ pub(crate) fn hashlib_insecure_hash_functions(checker: &mut Checker, call: &ast: } fn detect_insecure_hashlib_calls( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, hashlib_call: HashlibCall, ) { @@ -128,7 +128,7 @@ fn detect_insecure_hashlib_calls( hash_func_name, "md4" | "md5" | "sha" | "sha1" | "MD4" | "MD5" | "SHA" | "SHA1" ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HashlibInsecureHashFunction { library: "hashlib".to_string(), string: hash_func_name.to_string(), @@ -138,7 +138,7 @@ fn detect_insecure_hashlib_calls( } } HashlibCall::WeakHash(func_name) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HashlibInsecureHashFunction { library: "hashlib".to_string(), string: (*func_name).to_string(), @@ -149,7 +149,7 @@ fn detect_insecure_hashlib_calls( } } -fn detect_insecure_crypt_calls(checker: &mut Checker, call: &ast::ExprCall) { +fn detect_insecure_crypt_calls(checker: &Checker, call: &ast::ExprCall) { let Some(method) = checker .semantic() .resolve_qualified_name(&call.func) @@ -173,7 +173,7 @@ fn detect_insecure_crypt_calls(checker: &mut Checker, call: &ast::ExprCall) { qualified_name.segments(), ["crypt", "METHOD_CRYPT" | "METHOD_MD5" | "METHOD_BLOWFISH"] ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( HashlibInsecureHashFunction { library: "crypt".to_string(), string: qualified_name.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs index 478aecb423a5e..7891f9388feb3 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs @@ -56,7 +56,7 @@ impl Violation for Jinja2AutoescapeFalse { } /// S701 -pub(crate) fn jinja2_autoescape_false(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn jinja2_autoescape_false(checker: &Checker, call: &ast::ExprCall) { if checker .semantic() .resolve_qualified_name(&call.func) @@ -70,20 +70,20 @@ pub(crate) fn jinja2_autoescape_false(checker: &mut Checker, call: &ast::ExprCal Expr::Call(ast::ExprCall { func, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { if id != "select_autoescape" { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Jinja2AutoescapeFalse { value: true }, keyword.range(), )); } } } - _ => checker.diagnostics.push(Diagnostic::new( + _ => checker.report_diagnostic(Diagnostic::new( Jinja2AutoescapeFalse { value: true }, keyword.range(), )), } } else { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Jinja2AutoescapeFalse { value: false }, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs index b10b2aa26b2f2..c4f140040f30e 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs @@ -35,7 +35,7 @@ impl Violation for LoggingConfigInsecureListen { } /// S612 -pub(crate) fn logging_config_insecure_listen(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn logging_config_insecure_listen(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::LOGGING) { return; } @@ -51,7 +51,7 @@ pub(crate) fn logging_config_insecure_listen(checker: &mut Checker, call: &ast:: return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( LoggingConfigInsecureListen, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs index a0b1ff20d4883..1698f003e0241 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs @@ -42,7 +42,7 @@ impl Violation for MakoTemplates { } /// S702 -pub(crate) fn mako_templates(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn mako_templates(checker: &Checker, call: &ast::ExprCall) { if checker .semantic() .resolve_qualified_name(&call.func) @@ -50,8 +50,6 @@ pub(crate) fn mako_templates(checker: &mut Checker, call: &ast::ExprCall) { matches!(qualified_name.segments(), ["mako", "template", "Template"]) }) { - checker - .diagnostics - .push(Diagnostic::new(MakoTemplates, call.func.range())); + checker.report_diagnostic(Diagnostic::new(MakoTemplates, call.func.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs index f4f5f55ffe576..11b18dc3c8422 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs @@ -37,7 +37,7 @@ impl Violation for ParamikoCall { } /// S601 -pub(crate) fn paramiko_call(checker: &mut Checker, func: &Expr) { +pub(crate) fn paramiko_call(checker: &Checker, func: &Expr) { if checker .semantic() .resolve_qualified_name(func) @@ -45,8 +45,6 @@ pub(crate) fn paramiko_call(checker: &mut Checker, func: &Expr) { matches!(qualified_name.segments(), ["paramiko", "exec_command"]) }) { - checker - .diagnostics - .push(Diagnostic::new(ParamikoCall, func.range())); + checker.report_diagnostic(Diagnostic::new(ParamikoCall, func.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs index a2b7358999e6a..69309cb25bfcc 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs @@ -46,7 +46,7 @@ impl Violation for RequestWithNoCertValidation { } /// S501 -pub(crate) fn request_with_no_cert_validation(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn request_with_no_cert_validation(checker: &Checker, call: &ast::ExprCall) { if let Some(target) = checker .semantic() .resolve_qualified_name(&call.func) @@ -61,7 +61,7 @@ pub(crate) fn request_with_no_cert_validation(checker: &mut Checker, call: &ast: { if let Some(keyword) = call.arguments.find_keyword("verify") { if is_const_false(&keyword.value) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RequestWithNoCertValidation { string: target.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs index 641e5b267946a..91c684093da98 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs @@ -51,7 +51,7 @@ impl Violation for RequestWithoutTimeout { } /// S113 -pub(crate) fn request_without_timeout(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn request_without_timeout(checker: &Checker, call: &ast::ExprCall) { if let Some(module) = checker .semantic() .resolve_qualified_name(&call.func) @@ -67,13 +67,13 @@ pub(crate) fn request_without_timeout(checker: &mut Checker, call: &ast::ExprCal { if let Some(keyword) = call.arguments.find_keyword("timeout") { if keyword.value.is_none_literal_expr() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RequestWithoutTimeout { implicit: false, module: module.to_string() }, keyword.range(), )); } } else if module == "requests" { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RequestWithoutTimeout { implicit: true, module: module.to_string() }, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs index b8854a91e1b59..d837996353938 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs @@ -288,7 +288,7 @@ impl Violation for UnixCommandWildcardInjection { } /// S602, S603, S604, S605, S606, S607, S609 -pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn shell_injection(checker: &Checker, call: &ast::ExprCall) { let call_kind = get_call_kind(&call.func, checker.semantic()); let shell_keyword = find_shell_keyword(&call.arguments, checker.semantic()); @@ -300,7 +300,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { truthiness: truthiness @ (Truthiness::True | Truthiness::Truthy), }) => { if checker.enabled(Rule::SubprocessPopenWithShellEqualsTrue) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SubprocessPopenWithShellEqualsTrue { safety: Safety::from(arg), is_exact: matches!(truthiness, Truthiness::True), @@ -315,7 +315,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { Truthiness::False | Truthiness::Falsey | Truthiness::None | Truthiness::Unknown, }) => { if checker.enabled(Rule::SubprocessWithoutShellEqualsTrue) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SubprocessWithoutShellEqualsTrue, call.func.range(), )); @@ -324,7 +324,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { // S603 None => { if checker.enabled(Rule::SubprocessWithoutShellEqualsTrue) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SubprocessWithoutShellEqualsTrue, call.func.range(), )); @@ -338,7 +338,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { { // S604 if checker.enabled(Rule::CallWithShellEqualsTrue) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CallWithShellEqualsTrue { is_exact: matches!(truthiness, Truthiness::True), }, @@ -351,7 +351,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { if checker.enabled(Rule::StartProcessWithAShell) { if matches!(call_kind, Some(CallKind::Shell)) { if let Some(arg) = call.arguments.args.first() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StartProcessWithAShell { safety: Safety::from(arg), }, @@ -364,9 +364,7 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { // S606 if checker.enabled(Rule::StartProcessWithNoShell) { if matches!(call_kind, Some(CallKind::NoShell)) { - checker - .diagnostics - .push(Diagnostic::new(StartProcessWithNoShell, call.func.range())); + checker.report_diagnostic(Diagnostic::new(StartProcessWithNoShell, call.func.range())); } } @@ -375,9 +373,10 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { if call_kind.is_some() { if let Some(arg) = call.arguments.args.first() { if is_partial_path(arg) { - checker - .diagnostics - .push(Diagnostic::new(StartProcessWithPartialPath, arg.range())); + checker.report_diagnostic(Diagnostic::new( + StartProcessWithPartialPath, + arg.range(), + )); } } } @@ -398,9 +397,10 @@ pub(crate) fn shell_injection(checker: &mut Checker, call: &ast::ExprCall) { { if let Some(arg) = call.arguments.args.first() { if is_wildcard_command(arg) { - checker - .diagnostics - .push(Diagnostic::new(UnixCommandWildcardInjection, arg.range())); + checker.report_diagnostic(Diagnostic::new( + UnixCommandWildcardInjection, + arg.range(), + )); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs index 21c3638ae84c8..143c6bcd741d1 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs @@ -41,7 +41,7 @@ impl Violation for SnmpInsecureVersion { } /// S508 -pub(crate) fn snmp_insecure_version(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn snmp_insecure_version(checker: &Checker, call: &ast::ExprCall) { if checker .semantic() .resolve_qualified_name(&call.func) @@ -60,9 +60,7 @@ pub(crate) fn snmp_insecure_version(checker: &mut Checker, call: &ast::ExprCall) .. }) ) { - checker - .diagnostics - .push(Diagnostic::new(SnmpInsecureVersion, keyword.range())); + checker.report_diagnostic(Diagnostic::new(SnmpInsecureVersion, keyword.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs index 23231f1b7c700..4f159283724cc 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs @@ -40,7 +40,7 @@ impl Violation for SnmpWeakCryptography { } /// S509 -pub(crate) fn snmp_weak_cryptography(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn snmp_weak_cryptography(checker: &Checker, call: &ast::ExprCall) { if call.arguments.len() < 3 { if checker .semantic() @@ -52,9 +52,7 @@ pub(crate) fn snmp_weak_cryptography(checker: &mut Checker, call: &ast::ExprCall ) }) { - checker - .diagnostics - .push(Diagnostic::new(SnmpWeakCryptography, call.func.range())); + checker.report_diagnostic(Diagnostic::new(SnmpWeakCryptography, call.func.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs index ab990527c2f4c..e3153d271f7eb 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs @@ -44,7 +44,7 @@ impl Violation for SSHNoHostKeyVerification { } /// S507 -pub(crate) fn ssh_no_host_key_verification(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn ssh_no_host_key_verification(checker: &Checker, call: &ExprCall) { let Expr::Attribute(ExprAttribute { attr, value, .. }) = call.func.as_ref() else { return; }; @@ -78,7 +78,7 @@ pub(crate) fn ssh_no_host_key_verification(checker: &mut Checker, call: &ExprCal ["paramiko", "client", "SSHClient"] | ["paramiko", "SSHClient"] ) }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SSHNoHostKeyVerification, policy_argument.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs index ca565b2e5df63..1782d9097eef7 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs @@ -48,7 +48,7 @@ impl Violation for SslInsecureVersion { } /// S502 -pub(crate) fn ssl_insecure_version(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn ssl_insecure_version(checker: &Checker, call: &ExprCall) { let Some(keyword) = checker .semantic() .resolve_qualified_name(call.func.as_ref()) @@ -68,7 +68,7 @@ pub(crate) fn ssl_insecure_version(checker: &mut Checker, call: &ExprCall) { match &keyword.value { Expr::Name(ast::ExprName { id, .. }) => { if is_insecure_protocol(id) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SslInsecureVersion { protocol: id.to_string(), }, @@ -78,7 +78,7 @@ pub(crate) fn ssl_insecure_version(checker: &mut Checker, call: &ExprCall) { } Expr::Attribute(ast::ExprAttribute { attr, .. }) => { if is_insecure_protocol(attr) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SslInsecureVersion { protocol: attr.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs index 710cda5c116eb..a630787f9c248 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs @@ -48,7 +48,7 @@ impl Violation for SslWithBadDefaults { } /// S503 -pub(crate) fn ssl_with_bad_defaults(checker: &mut Checker, function_def: &StmtFunctionDef) { +pub(crate) fn ssl_with_bad_defaults(checker: &Checker, function_def: &StmtFunctionDef) { for default in function_def .parameters .iter_non_variadic_params() @@ -57,7 +57,7 @@ pub(crate) fn ssl_with_bad_defaults(checker: &mut Checker, function_def: &StmtFu match default { Expr::Name(ast::ExprName { id, range, .. }) => { if is_insecure_protocol(id.as_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SslWithBadDefaults { protocol: id.to_string(), }, @@ -67,7 +67,7 @@ pub(crate) fn ssl_with_bad_defaults(checker: &mut Checker, function_def: &StmtFu } Expr::Attribute(ast::ExprAttribute { attr, range, .. }) => { if is_insecure_protocol(attr.as_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SslWithBadDefaults { protocol: attr.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs index 7623270692f10..9ae61d2a75f29 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs @@ -36,16 +36,14 @@ impl Violation for SslWithNoVersion { } /// S504 -pub(crate) fn ssl_with_no_version(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn ssl_with_no_version(checker: &Checker, call: &ExprCall) { if checker .semantic() .resolve_qualified_name(call.func.as_ref()) .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["ssl", "wrap_socket"])) { if call.arguments.find_keyword("ssl_version").is_none() { - checker - .diagnostics - .push(Diagnostic::new(SslWithNoVersion, call.range())); + checker.report_diagnostic(Diagnostic::new(SslWithNoVersion, call.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs index 5866f55588e6e..bc4e50d1e585c 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs @@ -908,7 +908,7 @@ impl Violation for SuspiciousFTPLibUsage { } } -pub(crate) fn suspicious_function_call(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn suspicious_function_call(checker: &Checker, call: &ExprCall) { suspicious_function( checker, call.func.as_ref(), @@ -917,7 +917,7 @@ pub(crate) fn suspicious_function_call(checker: &mut Checker, call: &ExprCall) { ); } -pub(crate) fn suspicious_function_reference(checker: &mut Checker, func: &Expr) { +pub(crate) fn suspicious_function_reference(checker: &Checker, func: &Expr) { if checker.settings.preview.is_disabled() { return; } @@ -953,7 +953,7 @@ pub(crate) fn suspicious_function_reference(checker: &mut Checker, func: &Expr) /// S301, S302, S303, S304, S305, S306, S307, S308, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S323 fn suspicious_function( - checker: &mut Checker, + checker: &Checker, func: &Expr, arguments: Option<&Arguments>, range: TextRange, @@ -1176,12 +1176,12 @@ fn suspicious_function( let diagnostic = Diagnostic::new(diagnostic_kind, range); if checker.enabled(diagnostic.kind.rule()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// S308 -pub(crate) fn suspicious_function_decorator(checker: &mut Checker, decorator: &Decorator) { +pub(crate) fn suspicious_function_decorator(checker: &Checker, decorator: &Decorator) { // In preview mode, references are handled collectively by `suspicious_function_reference` if checker.settings.preview.is_disabled() { suspicious_function(checker, &decorator.expression, None, decorator.range); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs index 8a62aa71770b4..82108586fd5eb 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs @@ -351,7 +351,7 @@ impl Violation for SuspiciousPyghmiImport { } /// S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S415 -pub(crate) fn suspicious_imports(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn suspicious_imports(checker: &Checker, stmt: &Stmt) { // Skip stub files. if checker.source_type.is_stub() { return; @@ -602,13 +602,9 @@ pub(crate) fn suspicious_imports(checker: &mut Checker, stmt: &Stmt) { }; } -fn check_and_push_diagnostic( - checker: &mut Checker, - diagnostic_kind: DiagnosticKind, - range: TextRange, -) { +fn check_and_push_diagnostic(checker: &Checker, diagnostic_kind: DiagnosticKind, range: TextRange) { let diagnostic = Diagnostic::new::(diagnostic_kind, range); if checker.enabled(diagnostic.kind.rule()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs index 7f1f72817d106..5d91dabe97024 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs @@ -48,7 +48,7 @@ impl Violation for TarfileUnsafeMembers { } /// S202 -pub(crate) fn tarfile_unsafe_members(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn tarfile_unsafe_members(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::TARFILE) { return; } @@ -70,7 +70,5 @@ pub(crate) fn tarfile_unsafe_members(checker: &mut Checker, call: &ast::ExprCall return; } - checker - .diagnostics - .push(Diagnostic::new(TarfileUnsafeMembers, call.func.range())); + checker.report_diagnostic(Diagnostic::new(TarfileUnsafeMembers, call.func.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs index 87f1692f76d90..fa846af54e1f1 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs @@ -53,7 +53,7 @@ impl Violation for TryExceptContinue { /// S112 pub(crate) fn try_except_continue( - checker: &mut Checker, + checker: &Checker, except_handler: &ExceptHandler, type_: Option<&Expr>, body: &[Stmt], @@ -61,9 +61,7 @@ pub(crate) fn try_except_continue( ) { if matches!(body, [Stmt::Continue(_)]) { if check_typed_exception || is_untyped_exception(type_, checker.semantic()) { - checker - .diagnostics - .push(Diagnostic::new(TryExceptContinue, except_handler.range())); + checker.report_diagnostic(Diagnostic::new(TryExceptContinue, except_handler.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs index 0b4dcbaabd812..693d99ac0a231 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs @@ -49,7 +49,7 @@ impl Violation for TryExceptPass { /// S110 pub(crate) fn try_except_pass( - checker: &mut Checker, + checker: &Checker, except_handler: &ExceptHandler, type_: Option<&Expr>, body: &[Stmt], @@ -57,9 +57,7 @@ pub(crate) fn try_except_pass( ) { if matches!(body, [Stmt::Pass(_)]) { if check_typed_exception || is_untyped_exception(type_, checker.semantic()) { - checker - .diagnostics - .push(Diagnostic::new(TryExceptPass, except_handler.range())); + checker.report_diagnostic(Diagnostic::new(TryExceptPass, except_handler.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs index d9c9e2c10fa34..f0268ebecf0f2 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs @@ -59,7 +59,7 @@ impl Violation for UnsafeYAMLLoad { } /// S506 -pub(crate) fn unsafe_yaml_load(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unsafe_yaml_load(checker: &Checker, call: &ast::ExprCall) { if checker .semantic() .resolve_qualified_name(&call.func) @@ -82,13 +82,13 @@ pub(crate) fn unsafe_yaml_load(checker: &mut Checker, call: &ast::ExprCall) { Expr::Name(ast::ExprName { id, .. }) => Some(id.to_string()), _ => None, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnsafeYAMLLoad { loader }, loader_arg.range(), )); } } else { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnsafeYAMLLoad { loader: None }, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs index 04facbc188a66..14ba54b1ee860 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs @@ -49,13 +49,13 @@ impl Violation for WeakCryptographicKey { } /// S505 -pub(crate) fn weak_cryptographic_key(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn weak_cryptographic_key(checker: &Checker, call: &ExprCall) { let Some((cryptographic_key, range)) = extract_cryptographic_key(checker, call) else { return; }; if cryptographic_key.is_vulnerable() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( WeakCryptographicKey { cryptographic_key }, range, )); @@ -98,7 +98,7 @@ impl Display for CryptographicKey { } fn extract_cryptographic_key( - checker: &mut Checker, + checker: &Checker, call: &ExprCall, ) -> Option<(CryptographicKey, TextRange)> { let qualified_name = checker.semantic().resolve_qualified_name(&call.func)?; diff --git a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs index 88fa267ec28cf..dfe793960e54a 100644 --- a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs +++ b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs @@ -76,7 +76,7 @@ impl Violation for BlindExcept { /// BLE001 pub(crate) fn blind_except( - checker: &mut Checker, + checker: &Checker, type_: Option<&Expr>, name: Option<&str>, body: &[Stmt], @@ -107,7 +107,7 @@ pub(crate) fn blind_except( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BlindExcept { name: builtin_exception_type.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs index ba51e47b8cce9..fe9292936a825 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs @@ -101,7 +101,7 @@ impl Violation for BooleanDefaultValuePositionalArgument { /// FBT002 pub(crate) fn boolean_default_value_positional_argument( - checker: &mut Checker, + checker: &Checker, name: &str, decorator_list: &[Decorator], parameters: &Parameters, @@ -131,7 +131,7 @@ pub(crate) fn boolean_default_value_positional_argument( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BooleanDefaultValuePositionalArgument, param.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs index 76c6d39fefc49..e758e0d49a647 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs @@ -51,7 +51,7 @@ impl Violation for BooleanPositionalValueInCall { } } -pub(crate) fn boolean_positional_value_in_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn boolean_positional_value_in_call(checker: &Checker, call: &ast::ExprCall) { if allow_boolean_trap(call, checker) { return; } @@ -61,8 +61,6 @@ pub(crate) fn boolean_positional_value_in_call(checker: &mut Checker, call: &ast .iter() .filter(|arg| arg.is_boolean_literal_expr()) { - checker - .diagnostics - .push(Diagnostic::new(BooleanPositionalValueInCall, arg.range())); + checker.report_diagnostic(Diagnostic::new(BooleanPositionalValueInCall, arg.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs index 062c021805092..d7de29798345f 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs @@ -110,7 +110,7 @@ impl Violation for BooleanTypeHintPositionalArgument { /// FBT001 pub(crate) fn boolean_type_hint_positional_argument( - checker: &mut Checker, + checker: &Checker, name: &str, decorator_list: &[Decorator], parameters: &Parameters, @@ -157,7 +157,7 @@ pub(crate) fn boolean_type_hint_positional_argument( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BooleanTypeHintPositionalArgument, parameter.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs index 158edc082bbd6..6c82b0a4f162e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs @@ -144,7 +144,7 @@ fn is_empty_body(body: &[Stmt]) -> bool { /// B024 /// B027 pub(crate) fn abstract_base_class( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, name: &str, arguments: Option<&Arguments>, @@ -196,7 +196,7 @@ pub(crate) fn abstract_base_class( && is_empty_body(body) && !is_overload(decorator_list, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( EmptyMethodWithoutAbstractDecorator { name: format!("{name}.{method_name}"), }, @@ -206,7 +206,7 @@ pub(crate) fn abstract_base_class( } if checker.enabled(Rule::AbstractBaseClassWithoutAbstractMethod) { if !has_abstract_method { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AbstractBaseClassWithoutAbstractMethod { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs index dcddda06f5743..ec1e6db5ff967 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs @@ -74,7 +74,7 @@ fn assertion_error(msg: Option<&Expr>) -> Stmt { } /// B011 -pub(crate) fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option<&Expr>) { +pub(crate) fn assert_false(checker: &Checker, stmt: &Stmt, test: &Expr, msg: Option<&Expr>) { if !is_const_false(test) { return; } @@ -84,5 +84,5 @@ pub(crate) fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: checker.generator().stmt(&assertion_error(msg)), stmt.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs index 98f741a00c707..a69bc70209e59 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs @@ -57,7 +57,7 @@ impl fmt::Display for ExceptionKind { } /// B017 -pub(crate) fn assert_raises_exception(checker: &mut Checker, items: &[WithItem]) { +pub(crate) fn assert_raises_exception(checker: &Checker, items: &[WithItem]) { for item in items { let Expr::Call(ast::ExprCall { func, @@ -99,7 +99,7 @@ pub(crate) fn assert_raises_exception(checker: &mut Checker, items: &[WithItem]) continue; }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AssertRaisesException { exception }, item.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs index 1cebc3bff7019..57c374be1ebec 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs @@ -50,7 +50,7 @@ impl Violation for AssignmentToOsEnviron { } /// B003 -pub(crate) fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) { +pub(crate) fn assignment_to_os_environ(checker: &Checker, targets: &[Expr]) { let [target] = targets else { return; }; @@ -66,7 +66,5 @@ pub(crate) fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) if id != "os" { return; } - checker - .diagnostics - .push(Diagnostic::new(AssignmentToOsEnviron, target.range())); + checker.report_diagnostic(Diagnostic::new(AssignmentToOsEnviron, target.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/batched_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/batched_without_explicit_strict.rs index 34893b109f375..a3de409969c20 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/batched_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/batched_without_explicit_strict.rs @@ -58,7 +58,7 @@ impl Violation for BatchedWithoutExplicitStrict { } /// B911 -pub(crate) fn batched_without_explicit_strict(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn batched_without_explicit_strict(checker: &Checker, call: &ExprCall) { if checker.settings.target_version < PythonVersion::Py313 { return; } @@ -87,5 +87,5 @@ pub(crate) fn batched_without_explicit_strict(checker: &mut Checker, call: &Expr } let diagnostic = Diagnostic::new(BatchedWithoutExplicitStrict, call.range); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs index c10405a2357bf..8fbfc9a1f3e03 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs @@ -74,7 +74,7 @@ impl Violation for CachedInstanceMethod { } /// B019 -pub(crate) fn cached_instance_method(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn cached_instance_method(checker: &Checker, function_def: &ast::StmtFunctionDef) { let scope = checker.semantic().current_scope(); // Parent scope _must_ be a class. @@ -102,9 +102,7 @@ pub(crate) fn cached_instance_method(checker: &mut Checker, function_def: &ast:: return; } - checker - .diagnostics - .push(Diagnostic::new(CachedInstanceMethod, decorator.range())); + checker.report_diagnostic(Diagnostic::new(CachedInstanceMethod, decorator.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/class_as_data_structure.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/class_as_data_structure.rs index 6903a026b4434..29ac873cfdcc3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/class_as_data_structure.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/class_as_data_structure.rs @@ -44,7 +44,7 @@ impl Violation for ClassAsDataStructure { } /// B903 -pub(crate) fn class_as_data_structure(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn class_as_data_structure(checker: &Checker, class_def: &ast::StmtClassDef) { // skip stub files if checker.source_type.is_stub() { return; @@ -105,9 +105,7 @@ pub(crate) fn class_as_data_structure(checker: &mut Checker, class_def: &ast::St } if has_dunder_init && public_methods == 1 { - checker - .diagnostics - .push(Diagnostic::new(ClassAsDataStructure, class_def.range())); + checker.report_diagnostic(Diagnostic::new(ClassAsDataStructure, class_def.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index 976fe26d31810..04e19bddfc68e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -120,7 +120,7 @@ fn type_pattern(elts: Vec<&Expr>) -> Expr { /// B014 fn duplicate_handler_exceptions<'a>( - checker: &mut Checker, + checker: &Checker, expr: &'a Expr, elts: &'a [Expr], ) -> FxHashMap, &'a Expr> { @@ -167,7 +167,7 @@ fn duplicate_handler_exceptions<'a>( }, expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -175,7 +175,7 @@ fn duplicate_handler_exceptions<'a>( } /// B025 -pub(crate) fn duplicate_exceptions(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn duplicate_exceptions(checker: &Checker, handlers: &[ExceptHandler]) { let mut seen: FxHashSet = FxHashSet::default(); let mut duplicates: FxHashMap> = FxHashMap::default(); for handler in handlers { @@ -217,7 +217,7 @@ pub(crate) fn duplicate_exceptions(checker: &mut Checker, handlers: &[ExceptHand .current_statement() .as_try_stmt() .is_some_and(|try_stmt| try_stmt.is_star); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( DuplicateTryBlockException { name: name.segments().join("."), is_star, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs index a48603a6cc370..5d7f64a386b8a 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs @@ -55,7 +55,7 @@ impl Violation for DuplicateValue { } /// B033 -pub(crate) fn duplicate_value(checker: &mut Checker, set: &ast::ExprSet) { +pub(crate) fn duplicate_value(checker: &Checker, set: &ast::ExprSet) { let mut seen_values: FxHashMap = FxHashMap::default(); for (index, value) in set.iter().enumerate() { if value.is_literal_expr() { @@ -72,7 +72,7 @@ pub(crate) fn duplicate_value(checker: &mut Checker, set: &ast::ExprSet) { remove_member(set, index, checker.locator().contents()).map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } }; } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs index d43fc889e211b..25f5714ce92a9 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs @@ -50,7 +50,7 @@ impl Violation for ExceptWithEmptyTuple { } /// B029 -pub(crate) fn except_with_empty_tuple(checker: &mut Checker, except_handler: &ExceptHandler) { +pub(crate) fn except_with_empty_tuple(checker: &Checker, except_handler: &ExceptHandler) { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) = except_handler; let Some(type_) = type_ else { @@ -66,7 +66,7 @@ pub(crate) fn except_with_empty_tuple(checker: &mut Checker, except_handler: &Ex .current_statement() .as_try_stmt() .is_some_and(|try_stmt| try_stmt.is_star); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ExceptWithEmptyTuple { is_star }, except_handler.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs index 13f9f544fa00f..6bb7b13c55d47 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs @@ -53,10 +53,7 @@ impl Violation for ExceptWithNonExceptionClasses { } /// B030 -pub(crate) fn except_with_non_exception_classes( - checker: &mut Checker, - except_handler: &ExceptHandler, -) { +pub(crate) fn except_with_non_exception_classes(checker: &Checker, except_handler: &ExceptHandler) { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) = except_handler; let Some(type_) = type_ else { @@ -72,7 +69,7 @@ pub(crate) fn except_with_non_exception_classes( .current_statement() .as_try_stmt() .is_some_and(|try_stmt| try_stmt.is_star); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ExceptWithNonExceptionClasses { is_star }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs index 4a2cb94fbb60f..0e5ef87dda3c0 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs @@ -41,7 +41,7 @@ impl Violation for FStringDocstring { } /// B021 -pub(crate) fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn f_string_docstring(checker: &Checker, body: &[Stmt]) { let Some(stmt) = body.first() else { return; }; @@ -51,7 +51,5 @@ pub(crate) fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) { if !value.is_f_string_expr() { return; } - checker - .diagnostics - .push(Diagnostic::new(FStringDocstring, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new(FStringDocstring, stmt.identifier())); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs index d8c88b1184605..74816eba634a8 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs @@ -128,7 +128,7 @@ impl Visitor<'_> for ArgumentDefaultVisitor<'_, '_> { } /// B008 -pub(crate) fn function_call_in_argument_default(checker: &mut Checker, parameters: &Parameters) { +pub(crate) fn function_call_in_argument_default(checker: &Checker, parameters: &Parameters) { // Map immutable calls to (module, member) format. let extend_immutable_calls: Vec = checker .settings @@ -150,6 +150,6 @@ pub(crate) fn function_call_in_argument_default(checker: &mut Checker, parameter } for (check, range) in visitor.diagnostics { - checker.diagnostics.push(Diagnostic::new(check, range)); + checker.report_diagnostic(Diagnostic::new(check, range)); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs index e795be0466cf6..e17d6030853de 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs @@ -277,7 +277,7 @@ impl<'a> Visitor<'a> for AssignedNamesVisitor<'a> { } /// B023 -pub(crate) fn function_uses_loop_variable(checker: &mut Checker, node: &Node) { +pub(crate) fn function_uses_loop_variable(checker: &Checker, node: &Node) { // Identify any "suspicious" variables. These are defined as variables that are // referenced in a function or lambda body, but aren't bound as arguments. let suspicious_variables = { @@ -304,9 +304,8 @@ pub(crate) fn function_uses_loop_variable(checker: &mut Checker, node: &Node) { // loop, flag it. for name in suspicious_variables { if reassigned_in_loop.contains(&name.id.as_str()) { - if !checker.flake8_bugbear_seen.contains(&name.range()) { - checker.flake8_bugbear_seen.push(name.range()); - checker.diagnostics.push(Diagnostic::new( + if checker.insert_flake8_bugbear_range(name.range()) { + checker.report_diagnostic(Diagnostic::new( FunctionUsesLoopVariable { name: name.id.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index b0b4b728a2dcd..87af7d6400f89 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -48,12 +48,7 @@ impl AlwaysFixableViolation for GetAttrWithConstant { } /// B009 -pub(crate) fn getattr_with_constant( - checker: &mut Checker, - expr: &Expr, - func: &Expr, - args: &[Expr], -) { +pub(crate) fn getattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { let [obj, arg] = args else { return; }; @@ -93,5 +88,5 @@ pub(crate) fn getattr_with_constant( ), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs index afabc56a208e4..e2293a9c3c6c3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs @@ -53,10 +53,10 @@ impl Violation for JumpStatementInFinally { } } -fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) { +fn walk_stmt(checker: &Checker, body: &[Stmt], f: fn(&Stmt) -> bool) { for stmt in body { if f(stmt) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( JumpStatementInFinally { name: match stmt { Stmt::Break(_) => "break", @@ -89,7 +89,7 @@ fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) { } /// B012 -pub(crate) fn jump_statement_in_finally(checker: &mut Checker, finalbody: &[Stmt]) { +pub(crate) fn jump_statement_in_finally(checker: &Checker, finalbody: &[Stmt]) { walk_stmt(checker, finalbody, |stmt| { matches!(stmt, Stmt::Break(_) | Stmt::Continue(_) | Stmt::Return(_)) }); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs index f4f806abfc3c2..646e05ec93468 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs @@ -53,7 +53,7 @@ impl Violation for LoopIteratorMutation { } /// B909 -pub(crate) fn loop_iterator_mutation(checker: &mut Checker, stmt_for: &StmtFor) { +pub(crate) fn loop_iterator_mutation(checker: &Checker, stmt_for: &StmtFor) { let StmtFor { target, iter, @@ -110,9 +110,7 @@ pub(crate) fn loop_iterator_mutation(checker: &mut Checker, stmt_for: &StmtFor) let name = UnqualifiedName::from_expr(iter) .map(|name| name.to_string()) .map(SourceCodeSnippet::new); - checker - .diagnostics - .push(Diagnostic::new(LoopIteratorMutation { name }, *mutation)); + checker.report_diagnostic(Diagnostic::new(LoopIteratorMutation { name }, *mutation)); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs index 5df33bec7759a..b0247efd0bb21 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs @@ -50,7 +50,7 @@ impl Violation for LoopVariableOverridesIterator { } /// B020 -pub(crate) fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, iter: &Expr) { +pub(crate) fn loop_variable_overrides_iterator(checker: &Checker, target: &Expr, iter: &Expr) { let target_names = { let mut target_finder = NameFinder::default(); target_finder.visit_expr(target); @@ -64,7 +64,7 @@ pub(crate) fn loop_variable_overrides_iterator(checker: &mut Checker, target: &E for (name, expr) in target_names { if iter_names.contains_key(name) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( LoopVariableOverridesIterator { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index 219a444c4fc7d..d9ca9ae9e0b36 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -85,7 +85,7 @@ impl Violation for MutableArgumentDefault { } /// B006 -pub(crate) fn mutable_argument_default(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn mutable_argument_default(checker: &Checker, function_def: &ast::StmtFunctionDef) { // Skip stub files if checker.source_type.is_stub() { return; @@ -124,7 +124,7 @@ pub(crate) fn mutable_argument_default(checker: &mut Checker, function_def: &ast ) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs index 1c2087cd342f1..db829a28f40e9 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs @@ -68,7 +68,7 @@ impl Violation for MutableContextvarDefault { } /// B039 -pub(crate) fn mutable_contextvar_default(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn mutable_contextvar_default(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::CONTEXTVARS) { return; } @@ -102,8 +102,6 @@ pub(crate) fn mutable_contextvar_default(checker: &mut Checker, call: &ast::Expr matches!(qualified_name.segments(), ["contextvars", "ContextVar"]) }) { - checker - .diagnostics - .push(Diagnostic::new(MutableContextvarDefault, default.range())); + checker.report_diagnostic(Diagnostic::new(MutableContextvarDefault, default.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs index 69962a28d523a..73c41f4709767 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for NoExplicitStacklevel { } /// B028 -pub(crate) fn no_explicit_stacklevel(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn no_explicit_stacklevel(checker: &Checker, call: &ast::ExprCall) { if !checker .semantic() .resolve_qualified_name(&call.func) @@ -88,5 +88,5 @@ pub(crate) fn no_explicit_stacklevel(checker: &mut Checker, call: &ast::ExprCall diagnostic.set_fix(Fix::unsafe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs index 221da07133ee6..933aac58216e5 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs @@ -37,10 +37,8 @@ impl Violation for RaiseLiteral { } /// B016 -pub(crate) fn raise_literal(checker: &mut Checker, expr: &Expr) { +pub(crate) fn raise_literal(checker: &Checker, expr: &Expr) { if expr.is_literal_expr() { - checker - .diagnostics - .push(Diagnostic::new(RaiseLiteral, expr.range())); + checker.report_diagnostic(Diagnostic::new(RaiseLiteral, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs index b989606154da0..e33d5ff595ea7 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs @@ -68,7 +68,7 @@ impl Violation for RaiseWithoutFromInsideExcept { /// B904 pub(crate) fn raise_without_from_inside_except( - checker: &mut Checker, + checker: &Checker, name: Option<&str>, body: &[Stmt], ) { @@ -106,7 +106,7 @@ pub(crate) fn raise_without_from_inside_except( .as_try_stmt() .is_some_and(|try_stmt| try_stmt.is_star); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RaiseWithoutFromInsideExcept { is_star }, range, )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs index 285b23b7d8ba5..5dc1ac79f2287 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs @@ -56,7 +56,7 @@ impl Violation for ReSubPositionalArgs { } /// B034 -pub(crate) fn re_sub_positional_args(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn re_sub_positional_args(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::RE) { return; } @@ -75,7 +75,7 @@ pub(crate) fn re_sub_positional_args(checker: &mut Checker, call: &ast::ExprCall }; if call.arguments.args.len() > method.num_args() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ReSubPositionalArgs { method }, call.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs index c2a5d091d28c0..b21e50f896c55 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs @@ -53,10 +53,7 @@ impl AlwaysFixableViolation for RedundantTupleInExceptionHandler { } /// B013 -pub(crate) fn redundant_tuple_in_exception_handler( - checker: &mut Checker, - handlers: &[ExceptHandler], -) { +pub(crate) fn redundant_tuple_in_exception_handler(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_: Some(type_), @@ -103,6 +100,6 @@ pub(crate) fn redundant_tuple_in_exception_handler( ), type_.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs index e04ce11eef252..d5b4e13140ab2 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs @@ -91,7 +91,7 @@ impl Violation for ReturnInGenerator { } /// B901 -pub(crate) fn return_in_generator(checker: &mut Checker, function_def: &StmtFunctionDef) { +pub(crate) fn return_in_generator(checker: &Checker, function_def: &StmtFunctionDef) { if function_def.name.id == "__await__" { return; } @@ -101,9 +101,7 @@ pub(crate) fn return_in_generator(checker: &mut Checker, function_def: &StmtFunc if visitor.has_yield { if let Some(return_) = visitor.return_ { - checker - .diagnostics - .push(Diagnostic::new(ReturnInGenerator, return_)); + checker.report_diagnostic(Diagnostic::new(ReturnInGenerator, return_)); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs index 58121f42b06bb..18487040d1ab7 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs @@ -307,7 +307,7 @@ impl<'a> Visitor<'a> for GroupNameFinder<'a> { /// B031 pub(crate) fn reuse_of_groupby_generator( - checker: &mut Checker, + checker: &Checker, target: &Expr, body: &[Stmt], iter: &Expr, @@ -339,8 +339,6 @@ pub(crate) fn reuse_of_groupby_generator( finder.visit_stmt(stmt); } for expr in finder.exprs { - checker - .diagnostics - .push(Diagnostic::new(ReuseOfGroupbyGenerator, expr.range())); + checker.report_diagnostic(Diagnostic::new(ReuseOfGroupbyGenerator, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index bd4a6aad12524..976722f22939f 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -61,12 +61,7 @@ fn assignment(obj: &Expr, name: &str, value: &Expr, generator: Generator) -> Str } /// B010 -pub(crate) fn setattr_with_constant( - checker: &mut Checker, - expr: &Expr, - func: &Expr, - args: &[Expr], -) { +pub(crate) fn setattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { let [obj, name, value] = args else { return; }; @@ -100,7 +95,7 @@ pub(crate) fn setattr_with_constant( assignment(obj, name.to_str(), value, checker.generator()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs index dc453fb480cd3..5b9844ec537da 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs @@ -57,7 +57,7 @@ impl Violation for StarArgUnpackingAfterKeywordArg { /// B026 pub(crate) fn star_arg_unpacking_after_keyword_arg( - checker: &mut Checker, + checker: &Checker, args: &[Expr], keywords: &[Keyword], ) { @@ -71,7 +71,7 @@ pub(crate) fn star_arg_unpacking_after_keyword_arg( if arg.start() <= keyword.start() { continue; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StarArgUnpackingAfterKeywordArg, arg.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs index 5f9653708600d..951f64ce1c6cd 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs @@ -47,7 +47,7 @@ impl Violation for StaticKeyDictComprehension { } /// RUF011 -pub(crate) fn static_key_dict_comprehension(checker: &mut Checker, dict_comp: &ast::ExprDictComp) { +pub(crate) fn static_key_dict_comprehension(checker: &Checker, dict_comp: &ast::ExprDictComp) { // Collect the bound names in the comprehension's generators. let names = { let mut visitor = StoredNameFinder::default(); @@ -58,7 +58,7 @@ pub(crate) fn static_key_dict_comprehension(checker: &mut Checker, dict_comp: &a }; if is_constant(&dict_comp.key, &names) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StaticKeyDictComprehension { key: SourceCodeSnippet::from_str(checker.locator().slice(dict_comp.key.as_ref())), }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs index d102c6605a1b5..78a1c15c2ea96 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs @@ -56,7 +56,7 @@ impl Violation for StripWithMultiCharacters { /// B005 pub(crate) fn strip_with_multi_characters( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -73,8 +73,6 @@ pub(crate) fn strip_with_multi_characters( }; if value.chars().count() > 1 && !value.chars().all_unique() { - checker - .diagnostics - .push(Diagnostic::new(StripWithMultiCharacters, expr.range())); + checker.report_diagnostic(Diagnostic::new(StripWithMultiCharacters, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs index 6781125fe1799..bd44c8d4f88b3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs @@ -51,7 +51,7 @@ impl Violation for UnaryPrefixIncrementDecrement { /// B002 pub(crate) fn unary_prefix_increment_decrement( - checker: &mut Checker, + checker: &Checker, expr: &Expr, op: UnaryOp, operand: &Expr, @@ -61,7 +61,7 @@ pub(crate) fn unary_prefix_increment_decrement( }; match (op, nested_op) { (UnaryOp::UAdd, UnaryOp::UAdd) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnaryPrefixIncrementDecrement { operator: UnaryPrefixOperatorType::Increment, }, @@ -69,7 +69,7 @@ pub(crate) fn unary_prefix_increment_decrement( )); } (UnaryOp::USub, UnaryOp::USub) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnaryPrefixIncrementDecrement { operator: UnaryPrefixOperatorType::Decrement, }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs index fd390154b0e0b..2c7fa1358959f 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs @@ -35,7 +35,7 @@ impl Violation for UnintentionalTypeAnnotation { /// B032 pub(crate) fn unintentional_type_annotation( - checker: &mut Checker, + checker: &Checker, target: &Expr, value: Option<&Expr>, stmt: &Stmt, @@ -47,16 +47,16 @@ pub(crate) fn unintentional_type_annotation( Expr::Subscript(ast::ExprSubscript { value, .. }) => { if value.is_name_expr() { checker - .diagnostics - .push(Diagnostic::new(UnintentionalTypeAnnotation, stmt.range())); + .report_diagnostic(Diagnostic::new(UnintentionalTypeAnnotation, stmt.range())); } } Expr::Attribute(ast::ExprAttribute { value, .. }) => { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { if id != "self" { - checker - .diagnostics - .push(Diagnostic::new(UnintentionalTypeAnnotation, stmt.range())); + checker.report_diagnostic(Diagnostic::new( + UnintentionalTypeAnnotation, + stmt.range(), + )); } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index 23186b2a37fd4..d138540d66c7e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -51,7 +51,7 @@ impl Violation for UnreliableCallableCheck { /// B004 pub(crate) fn unreliable_callable_check( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -87,5 +87,5 @@ pub(crate) fn unreliable_callable_check( Ok(Fix::safe_edits(binding_edit, import_edit)) }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs index 363dd128a0942..5b750bc3c829c 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs @@ -76,7 +76,7 @@ impl Violation for UnusedLoopControlVariable { } /// B007 -pub(crate) fn unused_loop_control_variable(checker: &mut Checker, stmt_for: &ast::StmtFor) { +pub(crate) fn unused_loop_control_variable(checker: &Checker, stmt_for: &ast::StmtFor) { let control_names = { let mut finder = StoredNameFinder::default(); finder.visit_expr(stmt_for.target.as_ref()); @@ -147,7 +147,7 @@ pub(crate) fn unused_loop_control_variable(checker: &mut Checker, stmt_for: &ast } } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs index a51cd1ca49414..7c8132b902c29 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs @@ -57,7 +57,7 @@ impl Violation for UselessComparison { } /// B015 -pub(crate) fn useless_comparison(checker: &mut Checker, expr: &Expr) { +pub(crate) fn useless_comparison(checker: &Checker, expr: &Expr) { if expr.is_compare_expr() { let semantic = checker.semantic(); @@ -78,7 +78,7 @@ pub(crate) fn useless_comparison(checker: &mut Checker, expr: &Expr) { .and_then(Stmt::as_expr_stmt) .is_some_and(|last_stmt| &*last_stmt.value == expr) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UselessComparison { at: ComparisonLocationAt::EndOfFunction, }, @@ -88,7 +88,7 @@ pub(crate) fn useless_comparison(checker: &mut Checker, expr: &Expr) { } } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UselessComparison { at: ComparisonLocationAt::MiddleBody, }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs index b507acfdf1b54..dde13b5636721 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs @@ -50,7 +50,7 @@ impl Violation for UselessContextlibSuppress { /// B022 pub(crate) fn useless_contextlib_suppress( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -63,8 +63,6 @@ pub(crate) fn useless_contextlib_suppress( matches!(qualified_name.segments(), ["contextlib", "suppress"]) }) { - checker - .diagnostics - .push(Diagnostic::new(UselessContextlibSuppress, expr.range())); + checker.report_diagnostic(Diagnostic::new(UselessContextlibSuppress, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs index bc6e7b293a4ea..4cde035f3f6c3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs @@ -71,7 +71,7 @@ impl Violation for UselessExpression { } /// B018 -pub(crate) fn useless_expression(checker: &mut Checker, value: &Expr) { +pub(crate) fn useless_expression(checker: &Checker, value: &Expr) { // Ignore comparisons, as they're handled by `useless_comparison`. if value.is_compare_expr() { return; @@ -100,7 +100,7 @@ pub(crate) fn useless_expression(checker: &mut Checker, value: &Expr) { // Flag attributes as useless expressions, even if they're attached to calls or other // expressions. if value.is_attribute_expr() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UselessExpression { kind: Kind::Attribute, }, @@ -110,7 +110,7 @@ pub(crate) fn useless_expression(checker: &mut Checker, value: &Expr) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UselessExpression { kind: Kind::Expression, }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index 9d512b577b16e..1cfae1b806b8d 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for ZipWithoutExplicitStrict { } /// B905 -pub(crate) fn zip_without_explicit_strict(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn zip_without_explicit_strict(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); if semantic.match_builtin_expr(&call.func, "zip") @@ -63,7 +63,7 @@ pub(crate) fn zip_without_explicit_strict(checker: &mut Checker, call: &ast::Exp .iter() .any(|arg| is_infinite_iterable(arg, semantic)) { - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new(ZipWithoutExplicitStrict, call.range()).with_fix(Fix::applicable_edit( add_argument( "strict=False", diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs index d546e14e8029c..8683222d02361 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs @@ -63,7 +63,7 @@ impl Violation for BuiltinArgumentShadowing { } /// A002 -pub(crate) fn builtin_argument_shadowing(checker: &mut Checker, parameter: &Parameter) { +pub(crate) fn builtin_argument_shadowing(checker: &Checker, parameter: &Parameter) { if shadows_builtin( parameter.name(), checker.source_type, @@ -92,7 +92,7 @@ pub(crate) fn builtin_argument_shadowing(checker: &mut Checker, parameter: &Para return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BuiltinArgumentShadowing { name: parameter.name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs index a4cb7a04a24d6..c151c117ca3ab 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs @@ -84,7 +84,6 @@ pub(crate) fn builtin_attribute_shadowing( scope_id: ScopeId, scope: &Scope, class_def: &ast::StmtClassDef, - diagnostics: &mut Vec, ) { for (name, binding_id) in scope.all_bindings() { let binding = checker.semantic().binding(binding_id); @@ -136,7 +135,7 @@ pub(crate) fn builtin_attribute_shadowing( == Some(scope_id) }) { - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BuiltinAttributeShadowing { kind, name: name.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs index 2bcde2c90da9c..bdebcbf035106 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs @@ -55,7 +55,7 @@ impl Violation for BuiltinImportShadowing { } /// A004 -pub(crate) fn builtin_import_shadowing(checker: &mut Checker, alias: &Alias) { +pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) { let name = alias.asname.as_ref().unwrap_or(&alias.name); if shadows_builtin( name.as_str(), @@ -63,7 +63,7 @@ pub(crate) fn builtin_import_shadowing(checker: &mut Checker, alias: &Alias) { &checker.settings.flake8_builtins.builtins_ignorelist, checker.settings.target_version, ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BuiltinImportShadowing { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs index 2a2c3cc2eeb13..28d8461ed5845 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs @@ -34,7 +34,7 @@ impl Violation for BuiltinLambdaArgumentShadowing { } /// A006 -pub(crate) fn builtin_lambda_argument_shadowing(checker: &mut Checker, lambda: &ExprLambda) { +pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &ExprLambda) { let Some(parameters) = lambda.parameters.as_ref() else { return; }; @@ -46,7 +46,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &mut Checker, lambda: & &checker.settings.flake8_builtins.builtins_ignorelist, checker.settings.target_version, ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BuiltinLambdaArgumentShadowing { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs index 120f7616c3493..ecd919327ca39 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs @@ -58,14 +58,14 @@ impl Violation for BuiltinVariableShadowing { } /// A001 -pub(crate) fn builtin_variable_shadowing(checker: &mut Checker, name: &str, range: TextRange) { +pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: TextRange) { if shadows_builtin( name, checker.source_type, &checker.settings.flake8_builtins.builtins_ignorelist, checker.settings.target_version, ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BuiltinVariableShadowing { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index 6262b932b11a0..70794a9304988 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -58,7 +58,7 @@ impl AlwaysFixableViolation for UnnecessaryCallAroundSorted { /// C413 pub(crate) fn unnecessary_call_around_sorted( - checker: &mut Checker, + checker: &Checker, expr: &Expr, outer_func: &Expr, args: &[Expr], @@ -94,7 +94,7 @@ pub(crate) fn unnecessary_call_around_sorted( }; Ok(Fix::applicable_edit(edit, applicability)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index c5b43ff389951..dc16511336005 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -58,7 +58,7 @@ impl AlwaysFixableViolation for UnnecessaryCollectionCall { /// C408 pub(crate) fn unnecessary_collection_call( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, settings: &Settings, ) { @@ -129,7 +129,7 @@ pub(crate) fn unnecessary_collection_call( }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index 3aec76d71a938..a9d411feee839 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -75,7 +75,7 @@ impl AlwaysFixableViolation for UnnecessaryComprehension { } /// Add diagnostic for C416 based on the expression node id. -fn add_diagnostic(checker: &mut Checker, expr: &Expr) { +fn add_diagnostic(checker: &Checker, expr: &Expr) { let Some(comprehension_kind) = ComprehensionKind::try_from_expr(expr) else { return; }; @@ -95,12 +95,12 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) { fixes::fix_unnecessary_comprehension(expr, checker.locator(), checker.stylist()) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// C416 pub(crate) fn unnecessary_dict_comprehension( - checker: &mut Checker, + checker: &Checker, expr: &Expr, key: &Expr, value: &Expr, @@ -135,7 +135,7 @@ pub(crate) fn unnecessary_dict_comprehension( /// C416 pub(crate) fn unnecessary_list_set_comprehension( - checker: &mut Checker, + checker: &Checker, expr: &Expr, elt: &Expr, generators: &[Comprehension], diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs index 2bfb81acf8e67..aa3826dd042bc 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs @@ -88,7 +88,7 @@ impl Violation for UnnecessaryComprehensionInCall { /// C419 pub(crate) fn unnecessary_comprehension_in_call( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -174,7 +174,7 @@ pub(crate) fn unnecessary_comprehension_in_call( diagnostic.set_fix(Fix::unsafe_edits(collection_start, [collection_end])); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Return `true` if the [`Expr`] contains an `await` expression. diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs index c6533ebec6459..e30843c1b3e33 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs @@ -58,7 +58,7 @@ impl Violation for UnnecessaryDictComprehensionForIterable { /// C420 pub(crate) fn unnecessary_dict_comprehension_for_iterable( - checker: &mut Checker, + checker: &Checker, dict_comp: &ast::ExprDictComp, ) { let [generator] = dict_comp.generators.as_slice() else { @@ -132,7 +132,7 @@ pub(crate) fn unnecessary_dict_comprehension_for_iterable( ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns `true` if the expression can be shared across multiple values. diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index 73bad332fc953..4ce5712802e90 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -68,7 +68,7 @@ impl AlwaysFixableViolation for UnnecessaryDoubleCastOrProcess { /// C414 pub(crate) fn unnecessary_double_cast_or_process( - checker: &mut Checker, + checker: &Checker, expr: &Expr, outer_func: &Expr, args: &[Expr], @@ -140,6 +140,6 @@ pub(crate) fn unnecessary_double_cast_or_process( ) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index cd17c6a796d82..6b03d813b87b6 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -47,7 +47,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorDict { /// C402 (`dict((x, y) for x, y in iterable)`) pub(crate) fn unnecessary_generator_dict( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -73,5 +73,5 @@ pub(crate) fn unnecessary_generator_dict( let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, expr.range()); diagnostic .try_set_fix(|| fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::unsafe_edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index c242f241d1216..cc389e1f4d1ce 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -66,7 +66,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorList { } /// C400 (`list(generator)`) -pub(crate) fn unnecessary_generator_list(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_generator_list(checker: &Checker, call: &ast::ExprCall) { let Some(argument) = helpers::exactly_one_argument_with_matching_function( "list", &call.func, @@ -102,7 +102,7 @@ pub(crate) fn unnecessary_generator_list(checker: &mut Checker, call: &ast::Expr ); let iterator = format!("list({})", checker.locator().slice(generator.iter.range())); let fix = Fix::unsafe_edit(Edit::range_replacement(iterator, call.range())); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); return; } } @@ -156,5 +156,5 @@ pub(crate) fn unnecessary_generator_list(checker: &mut Checker, call: &ast::Expr Fix::unsafe_edits(call_start, [call_end]) } }; - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index 5711b2696fc5c..193d975737c2e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -67,7 +67,7 @@ impl AlwaysFixableViolation for UnnecessaryGeneratorSet { } /// C401 (`set(generator)`) -pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_generator_set(checker: &Checker, call: &ast::ExprCall) { let Some(argument) = helpers::exactly_one_argument_with_matching_function( "set", &call.func, @@ -105,7 +105,7 @@ pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprC iterator, call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); return; } } @@ -163,5 +163,5 @@ pub(crate) fn unnecessary_generator_set(checker: &mut Checker, call: &ast::ExprC Fix::unsafe_edits(call_start, [call_end]) } }; - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index e4e67a5406d0c..f5d3bf84b5b98 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UnnecessaryListCall { } /// C411 -pub(crate) fn unnecessary_list_call(checker: &mut Checker, expr: &Expr, call: &ExprCall) { +pub(crate) fn unnecessary_list_call(checker: &Checker, expr: &Expr, call: &ExprCall) { let ExprCall { func, arguments, @@ -79,5 +79,5 @@ pub(crate) fn unnecessary_list_call(checker: &mut Checker, expr: &Expr, call: &E fixes::fix_unnecessary_list_call(expr, checker.locator(), checker.stylist()) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index eaa7cdf5dbe74..183a065d75598 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for UnnecessaryListComprehensionDict { /// C404 (`dict([...])`) pub(crate) fn unnecessary_list_comprehension_dict( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -72,5 +72,5 @@ pub(crate) fn unnecessary_list_comprehension_dict( diagnostic.try_set_fix(|| { fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 6a1792eb8f01b..693e45f4c8df4 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UnnecessaryListComprehensionSet { } /// C403 (`set([...])`) -pub(crate) fn unnecessary_list_comprehension_set(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_list_comprehension_set(checker: &Checker, call: &ast::ExprCall) { let Some(argument) = helpers::exactly_one_argument_with_matching_function( "set", &call.func, @@ -90,5 +90,5 @@ pub(crate) fn unnecessary_list_comprehension_set(checker: &mut Checker, call: &a let replacement = Edit::range_replacement(checker.source()[span].to_string(), replacement_range); let fix = Fix::unsafe_edits(call_start, [call_end, replacement]); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index 0240e053d6137..c47e445766198 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for UnnecessaryLiteralDict { /// C406 (`dict([(1, 2)])`) pub(crate) fn unnecessary_literal_dict( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -81,7 +81,7 @@ pub(crate) fn unnecessary_literal_dict( let mut diagnostic = Diagnostic::new(UnnecessaryLiteralDict { obj_type: kind }, expr.range()); diagnostic .try_set_fix(|| fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::unsafe_edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 603d00aeae508..85fdfcee9b9fe 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for UnnecessaryLiteralSet { } /// C405 (`set([1, 2])`) -pub(crate) fn unnecessary_literal_set(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_literal_set(checker: &Checker, call: &ast::ExprCall) { let Some(argument) = helpers::exactly_one_argument_with_matching_function( "set", &call.func, @@ -125,7 +125,7 @@ pub(crate) fn unnecessary_literal_set(checker: &mut Checker, call: &ast::ExprCal } }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index fab2b7042a5e7..37e377f9bca74 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinDictCall { } /// C418 -pub(crate) fn unnecessary_literal_within_dict_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_literal_within_dict_call(checker: &Checker, call: &ast::ExprCall) { if !call.arguments.keywords.is_empty() { return; } @@ -89,7 +89,7 @@ pub(crate) fn unnecessary_literal_within_dict_call(checker: &mut Checker, call: Fix::unsafe_edits(call_start, [call_end]) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index 056277a3054fa..97e52666d70a8 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -63,7 +63,7 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinListCall { } /// C410 -pub(crate) fn unnecessary_literal_within_list_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_literal_within_list_call(checker: &Checker, call: &ast::ExprCall) { if !call.arguments.keywords.is_empty() { return; } @@ -119,7 +119,7 @@ pub(crate) fn unnecessary_literal_within_list_call(checker: &mut Checker, call: } }; - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index 0cec64136ce4c..d39d3d473313d 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -82,7 +82,7 @@ impl AlwaysFixableViolation for UnnecessaryLiteralWithinTupleCall { /// C409 pub(crate) fn unnecessary_literal_within_tuple_call( - checker: &mut Checker, + checker: &Checker, expr: &Expr, call: &ast::ExprCall, ) { @@ -165,7 +165,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call( _ => return, } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 5053201f1ed6c..89da8a12d8795 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -64,7 +64,7 @@ impl Violation for UnnecessaryMap { } /// C417 -pub(crate) fn unnecessary_map(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_map(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let (func, arguments) = (&call.func, &call.arguments); @@ -149,7 +149,7 @@ pub(crate) fn unnecessary_map(checker: &mut Checker, call: &ast::ExprCall) { ) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn is_list_set_or_dict(func: &Expr, semantic: &SemanticModel) -> bool { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index 7662b16bc047a..e7bae7b70057f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -40,7 +40,7 @@ impl Violation for UnnecessarySubscriptReversal { } /// C415 -pub(crate) fn unnecessary_subscript_reversal(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_subscript_reversal(checker: &Checker, call: &ast::ExprCall) { let Some(first_arg) = call.arguments.args.first() else { return; }; @@ -86,7 +86,7 @@ pub(crate) fn unnecessary_subscript_reversal(checker: &mut Checker, call: &ast:: if !matches!(function_name, "reversed" | "set" | "sorted") { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnnecessarySubscriptReversal { func: function_name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs index fde4eecde3c1f..2238f8f3464cb 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs @@ -58,7 +58,7 @@ impl Violation for CallDateFromtimestamp { } } -pub(crate) fn call_date_fromtimestamp(checker: &mut Checker, func: &Expr, location: TextRange) { +pub(crate) fn call_date_fromtimestamp(checker: &Checker, func: &Expr, location: TextRange) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -73,8 +73,6 @@ pub(crate) fn call_date_fromtimestamp(checker: &mut Checker, func: &Expr, locati ) }) { - checker - .diagnostics - .push(Diagnostic::new(CallDateFromtimestamp, location)); + checker.report_diagnostic(Diagnostic::new(CallDateFromtimestamp, location)); } } diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs index ad1d6702f51d7..af1f1f9797754 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs @@ -57,7 +57,7 @@ impl Violation for CallDateToday { } } -pub(crate) fn call_date_today(checker: &mut Checker, func: &Expr, location: TextRange) { +pub(crate) fn call_date_today(checker: &Checker, func: &Expr, location: TextRange) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -69,8 +69,6 @@ pub(crate) fn call_date_today(checker: &mut Checker, func: &Expr, location: Text matches!(qualified_name.segments(), ["datetime", "date", "today"]) }) { - checker - .diagnostics - .push(Diagnostic::new(CallDateToday, location)); + checker.report_diagnostic(Diagnostic::new(CallDateToday, location)); } } diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs index b8df928d19ba0..919a31291c982 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs @@ -69,7 +69,7 @@ impl Violation for CallDatetimeFromtimestamp { } } -pub(crate) fn call_datetime_fromtimestamp(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn call_datetime_fromtimestamp(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -97,7 +97,7 @@ pub(crate) fn call_datetime_fromtimestamp(checker: &mut Checker, call: &ast::Exp None => DatetimeModuleAntipattern::NoTzArgumentPassed, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CallDatetimeFromtimestamp(antipattern), call.range, )); diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs index 9a5f8a399f3c7..ee43f3a8d48ce 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs @@ -67,7 +67,7 @@ impl Violation for CallDatetimeNowWithoutTzinfo { } } -pub(crate) fn call_datetime_now_without_tzinfo(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn call_datetime_now_without_tzinfo(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -92,7 +92,7 @@ pub(crate) fn call_datetime_now_without_tzinfo(checker: &mut Checker, call: &ast None => DatetimeModuleAntipattern::NoTzArgumentPassed, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CallDatetimeNowWithoutTzinfo(antipattern), call.range, )); diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs index 30eeb8359d36a..708cb4a575f33 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs @@ -84,7 +84,7 @@ impl Violation for CallDatetimeStrptimeWithoutZone { } /// DTZ007 -pub(crate) fn call_datetime_strptime_without_zone(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn call_datetime_strptime_without_zone(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -139,7 +139,7 @@ pub(crate) fn call_datetime_strptime_without_zone(checker: &mut Checker, call: & semantic.current_expression_grandparent(), semantic.current_expression_parent(), ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CallDatetimeStrptimeWithoutZone(antipattern), call.range, )); diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs index 7bdcd9f74476b..ac00434b622bb 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs @@ -56,7 +56,7 @@ impl Violation for CallDatetimeToday { } } -pub(crate) fn call_datetime_today(checker: &mut Checker, func: &Expr, location: TextRange) { +pub(crate) fn call_datetime_today(checker: &Checker, func: &Expr, location: TextRange) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -75,7 +75,5 @@ pub(crate) fn call_datetime_today(checker: &mut Checker, func: &Expr, location: return; } - checker - .diagnostics - .push(Diagnostic::new(CallDatetimeToday, location)); + checker.report_diagnostic(Diagnostic::new(CallDatetimeToday, location)); } diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs index 4514302bc2870..c427a23155b43 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs @@ -60,11 +60,7 @@ impl Violation for CallDatetimeUtcfromtimestamp { } } -pub(crate) fn call_datetime_utcfromtimestamp( - checker: &mut Checker, - func: &Expr, - location: TextRange, -) { +pub(crate) fn call_datetime_utcfromtimestamp(checker: &Checker, func: &Expr, location: TextRange) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -86,7 +82,5 @@ pub(crate) fn call_datetime_utcfromtimestamp( return; } - checker - .diagnostics - .push(Diagnostic::new(CallDatetimeUtcfromtimestamp, location)); + checker.report_diagnostic(Diagnostic::new(CallDatetimeUtcfromtimestamp, location)); } diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs index 1e474ff159909..4cc5fd39a4593 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs @@ -60,7 +60,7 @@ impl Violation for CallDatetimeUtcnow { } /// DTZ003 -pub(crate) fn call_datetime_utcnow(checker: &mut Checker, func: &Expr, location: TextRange) { +pub(crate) fn call_datetime_utcnow(checker: &Checker, func: &Expr, location: TextRange) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -82,7 +82,5 @@ pub(crate) fn call_datetime_utcnow(checker: &mut Checker, func: &Expr, location: return; } - checker - .diagnostics - .push(Diagnostic::new(CallDatetimeUtcnow, location)); + checker.report_diagnostic(Diagnostic::new(CallDatetimeUtcnow, location)); } diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs index 6fd99e9a7ec1b..fe19b624fdb4c 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs @@ -63,7 +63,7 @@ impl Violation for CallDatetimeWithoutTzinfo { } } -pub(crate) fn call_datetime_without_tzinfo(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn call_datetime_without_tzinfo(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DATETIME) { return; } @@ -86,7 +86,7 @@ pub(crate) fn call_datetime_without_tzinfo(checker: &mut Checker, call: &ast::Ex None => DatetimeModuleAntipattern::NoTzArgumentPassed, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CallDatetimeWithoutTzinfo(antipattern), call.range, )); diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs index 56ade9ced28c1..0038a3ed080be 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs @@ -53,7 +53,7 @@ impl Violation for DatetimeMinMax { } /// DTZ901 -pub(crate) fn datetime_max_min(checker: &mut Checker, expr: &Expr) { +pub(crate) fn datetime_max_min(checker: &Checker, expr: &Expr) { let semantic = checker.semantic(); if !semantic.seen_module(Modules::DATETIME) { @@ -74,9 +74,7 @@ pub(crate) fn datetime_max_min(checker: &mut Checker, expr: &Expr) { return; } - checker - .diagnostics - .push(Diagnostic::new(DatetimeMinMax { min_max }, expr.range())); + checker.report_diagnostic(Diagnostic::new(DatetimeMinMax { min_max }, expr.range())); } /// Check if the current expression has the pattern `foo.replace(tzinfo=bar)` or `foo.time()`. diff --git a/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs b/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs index cee0fbe9b8d86..7477cfdc89657 100644 --- a/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs +++ b/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs @@ -47,7 +47,7 @@ impl Violation for Debugger { } /// Checks for the presence of a debugger call. -pub(crate) fn debugger_call(checker: &mut Checker, expr: &Expr, func: &Expr) { +pub(crate) fn debugger_call(checker: &Checker, expr: &Expr, func: &Expr) { if let Some(using_type) = checker .semantic() @@ -60,9 +60,7 @@ pub(crate) fn debugger_call(checker: &mut Checker, expr: &Expr, func: &Expr) { } }) { - checker - .diagnostics - .push(Diagnostic::new(Debugger { using_type }, expr.range())); + checker.report_diagnostic(Diagnostic::new(Debugger { using_type }, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs index a2c2962b32ff8..0d4c62a5d4da3 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs @@ -48,7 +48,7 @@ impl Violation for DjangoAllWithModelForm { } /// DJ007 -pub(crate) fn all_with_model_form(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn all_with_model_form(checker: &Checker, class_def: &ast::StmtClassDef) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -78,17 +78,19 @@ pub(crate) fn all_with_model_form(checker: &mut Checker, class_def: &ast::StmtCl match value.as_ref() { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => { if value == "__all__" { - checker - .diagnostics - .push(Diagnostic::new(DjangoAllWithModelForm, element.range())); + checker.report_diagnostic(Diagnostic::new( + DjangoAllWithModelForm, + element.range(), + )); return; } } Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => { if value == "__all__".as_bytes() { - checker - .diagnostics - .push(Diagnostic::new(DjangoAllWithModelForm, element.range())); + checker.report_diagnostic(Diagnostic::new( + DjangoAllWithModelForm, + element.range(), + )); return; } } diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs index 0441edb209bd3..8225330146f15 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs @@ -46,7 +46,7 @@ impl Violation for DjangoExcludeWithModelForm { } /// DJ006 -pub(crate) fn exclude_with_model_form(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn exclude_with_model_form(checker: &Checker, class_def: &ast::StmtClassDef) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -71,9 +71,10 @@ pub(crate) fn exclude_with_model_form(checker: &mut Checker, class_def: &ast::St continue; }; if id == "exclude" { - checker - .diagnostics - .push(Diagnostic::new(DjangoExcludeWithModelForm, target.range())); + checker.report_diagnostic(Diagnostic::new( + DjangoExcludeWithModelForm, + target.range(), + )); return; } } diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs b/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs index c4677d031f4da..3df458484dace 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs @@ -44,7 +44,7 @@ impl Violation for DjangoLocalsInRenderFunction { } /// DJ003 -pub(crate) fn locals_in_render_function(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn locals_in_render_function(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -61,7 +61,7 @@ pub(crate) fn locals_in_render_function(checker: &mut Checker, call: &ast::ExprC if let Some(argument) = call.arguments.find_argument_value("context", 2) { if is_locals_call(argument, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( DjangoLocalsInRenderFunction, argument.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs index 294d79e94d4d2..80a208def2c98 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs @@ -51,7 +51,7 @@ impl Violation for DjangoModelWithoutDunderStr { } /// DJ008 -pub(crate) fn model_without_dunder_str(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn model_without_dunder_str(checker: &Checker, class_def: &ast::StmtClassDef) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -64,7 +64,7 @@ pub(crate) fn model_without_dunder_str(checker: &mut Checker, class_def: &ast::S return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( DjangoModelWithoutDunderStr, class_def.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs b/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs index 72801f22025a9..d5a2b51d3d603 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs @@ -51,7 +51,7 @@ impl Violation for DjangoNonLeadingReceiverDecorator { } /// DJ013 -pub(crate) fn non_leading_receiver_decorator(checker: &mut Checker, decorator_list: &[Decorator]) { +pub(crate) fn non_leading_receiver_decorator(checker: &Checker, decorator_list: &[Decorator]) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -70,7 +70,7 @@ pub(crate) fn non_leading_receiver_decorator(checker: &mut Checker, decorator_li }) }); if i > 0 && is_receiver && !seen_receiver { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( DjangoNonLeadingReceiverDecorator, decorator.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs index 9d103c6c1de99..4ddbd80cbf689 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs @@ -54,7 +54,7 @@ impl Violation for DjangoNullableModelStringField { } /// DJ001 -pub(crate) fn nullable_model_string_field(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn nullable_model_string_field(checker: &Checker, body: &[Stmt]) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -64,7 +64,7 @@ pub(crate) fn nullable_model_string_field(checker: &mut Checker, body: &[Stmt]) continue; }; if let Some(field_name) = is_nullable_field(value, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( DjangoNullableModelStringField { field_name: field_name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs index f5ac17c4837df..71a2a5a2a5bd1 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs @@ -80,10 +80,7 @@ impl Violation for DjangoUnorderedBodyContentInModel { } /// DJ012 -pub(crate) fn unordered_body_content_in_model( - checker: &mut Checker, - class_def: &ast::StmtClassDef, -) { +pub(crate) fn unordered_body_content_in_model(checker: &Checker, class_def: &ast::StmtClassDef) { if !checker.semantic().seen_module(Modules::DJANGO) { return; } @@ -120,7 +117,7 @@ pub(crate) fn unordered_body_content_in_model( }, element.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else { element_types.push(element_type); } diff --git a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs index 42bbf9067fbf8..9c55e2fad3602 100644 --- a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs @@ -175,7 +175,7 @@ impl Violation for DotFormatInException { } /// EM101, EM102, EM103 -pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr) { +pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) { if let Expr::Call(ast::ExprCall { arguments: Arguments { args, .. }, .. @@ -200,7 +200,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr checker.locator(), )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -217,7 +217,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr checker.locator(), )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } // Check for .format() calls. @@ -240,7 +240,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr checker.locator(), )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs index e4c721417e0c3..ec6c93b9063be 100644 --- a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs @@ -84,7 +84,7 @@ impl AlwaysFixableViolation for FutureRequiredTypeAnnotation { } /// FA102 -pub(crate) fn future_required_type_annotation(checker: &mut Checker, expr: &Expr, reason: Reason) { +pub(crate) fn future_required_type_annotation(checker: &Checker, expr: &Expr, reason: Reason) { let mut diagnostic = Diagnostic::new(FutureRequiredTypeAnnotation { reason }, expr.range()); let required_import = NameImport::ImportFrom(MemberNameImport::member( "__future__".to_string(), @@ -95,5 +95,5 @@ pub(crate) fn future_required_type_annotation(checker: &mut Checker, expr: &Expr .importer() .add_import(&required_import, TextSize::default()), )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs index 8a6b1f00636ba..591a3ea79b132 100644 --- a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs @@ -77,14 +77,14 @@ impl Violation for FutureRewritableTypeAnnotation { } /// FA100 -pub(crate) fn future_rewritable_type_annotation(checker: &mut Checker, expr: &Expr) { +pub(crate) fn future_rewritable_type_annotation(checker: &Checker, expr: &Expr) { let name = checker .semantic() .resolve_qualified_name(expr) .map(|binding| binding.to_string()); if let Some(name) = name { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( FutureRewritableTypeAnnotation { name }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs index c6fe3312695b1..3368577ad24bc 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs @@ -51,12 +51,10 @@ impl Violation for FStringInGetTextFuncCall { } /// INT001 -pub(crate) fn f_string_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) { +pub(crate) fn f_string_in_gettext_func_call(checker: &Checker, args: &[Expr]) { if let Some(first) = args.first() { if first.is_f_string_expr() { - checker - .diagnostics - .push(Diagnostic::new(FStringInGetTextFuncCall {}, first.range())); + checker.report_diagnostic(Diagnostic::new(FStringInGetTextFuncCall {}, first.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs index eb8534a2fa0ec..cc4c313d8d0b4 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs @@ -51,14 +51,15 @@ impl Violation for FormatInGetTextFuncCall { } /// INT002 -pub(crate) fn format_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) { +pub(crate) fn format_in_gettext_func_call(checker: &Checker, args: &[Expr]) { if let Some(first) = args.first() { if let Expr::Call(ast::ExprCall { func, .. }) = &first { if let Expr::Attribute(ast::ExprAttribute { attr, .. }) = func.as_ref() { if attr == "format" { - checker - .diagnostics - .push(Diagnostic::new(FormatInGetTextFuncCall {}, first.range())); + checker.report_diagnostic(Diagnostic::new( + FormatInGetTextFuncCall {}, + first.range(), + )); } } } diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs index 8e243618916e4..0ec7f381f9ac1 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs @@ -51,7 +51,7 @@ impl Violation for PrintfInGetTextFuncCall { } /// INT003 -pub(crate) fn printf_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) { +pub(crate) fn printf_in_gettext_func_call(checker: &Checker, args: &[Expr]) { if let Some(first) = args.first() { if let Expr::BinOp(ast::ExprBinOp { op: Operator::Mod { .. }, @@ -61,8 +61,7 @@ pub(crate) fn printf_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) { if left.is_string_literal_expr() { checker - .diagnostics - .push(Diagnostic::new(PrintfInGetTextFuncCall {}, first.range())); + .report_diagnostic(Diagnostic::new(PrintfInGetTextFuncCall {}, first.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs index 037ab40cb3879..8b9f4a1d69206 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs @@ -54,7 +54,7 @@ impl Violation for DirectLoggerInstantiation { } /// LOG001 -pub(crate) fn direct_logger_instantiation(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn direct_logger_instantiation(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::LOGGING) { return; } @@ -74,6 +74,6 @@ pub(crate) fn direct_logger_instantiation(checker: &mut Checker, call: &ast::Exp let reference_edit = Edit::range_replacement(binding, call.func.range()); Ok(Fix::unsafe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_except_handler.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_except_handler.rs index f3ba34f443216..019c4fe42b730 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_except_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_except_handler.rs @@ -59,7 +59,7 @@ impl Violation for ExcInfoOutsideExceptHandler { } } -pub(crate) fn exc_info_outside_except_handler(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn exc_info_outside_except_handler(checker: &Checker, call: &ExprCall) { let semantic = checker.semantic(); if !outside_handlers(call.start(), semantic) { @@ -114,5 +114,5 @@ pub(crate) fn exc_info_outside_except_handler(checker: &mut Checker, call: &Expr Ok(Fix::unsafe_edit(edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs index eb7d92d1237e7..c32a9a5fade94 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs @@ -41,7 +41,7 @@ impl Violation for ExceptionWithoutExcInfo { } /// LOG007 -pub(crate) fn exception_without_exc_info(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn exception_without_exc_info(checker: &Checker, call: &ExprCall) { match call.func.as_ref() { Expr::Attribute(ast::ExprAttribute { attr, .. }) => { if !matches!( @@ -74,13 +74,11 @@ pub(crate) fn exception_without_exc_info(checker: &mut Checker, call: &ExprCall) } if exc_info_arg_is_falsey(call, checker) { - checker - .diagnostics - .push(Diagnostic::new(ExceptionWithoutExcInfo, call.range())); + checker.report_diagnostic(Diagnostic::new(ExceptionWithoutExcInfo, call.range())); } } -fn exc_info_arg_is_falsey(call: &ExprCall, checker: &mut Checker) -> bool { +fn exc_info_arg_is_falsey(call: &ExprCall, checker: &Checker) -> bool { call.arguments .find_keyword("exc_info") .map(|keyword| &keyword.value) diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs index 5a1a8eea3cee6..60d1d9b69cfe1 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs @@ -57,7 +57,7 @@ impl Violation for InvalidGetLoggerArgument { } /// LOG002 -pub(crate) fn invalid_get_logger_argument(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn invalid_get_logger_argument(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::LOGGING) { return; } @@ -91,5 +91,5 @@ pub(crate) fn invalid_get_logger_argument(checker: &mut Checker, call: &ast::Exp expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/log_exception_outside_except_handler.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/log_exception_outside_except_handler.rs index efff87606448a..4da3294353779 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/log_exception_outside_except_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/log_exception_outside_except_handler.rs @@ -60,7 +60,7 @@ impl Violation for LogExceptionOutsideExceptHandler { } /// LOG004 -pub(crate) fn log_exception_outside_except_handler(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn log_exception_outside_except_handler(checker: &Checker, call: &ExprCall) { let semantic = checker.semantic(); if !outside_handlers(call.start(), semantic) { @@ -105,5 +105,5 @@ pub(crate) fn log_exception_outside_except_handler(checker: &mut Checker, call: diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs index dab4d2a47e2ce..8bd3dc8359e41 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs @@ -44,7 +44,7 @@ impl Violation for RootLoggerCall { } /// LOG015 -pub(crate) fn root_logger_call(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn root_logger_call(checker: &Checker, call: &ExprCall) { let semantic = checker.semantic(); if !semantic.seen_module(Modules::LOGGING) { @@ -65,7 +65,7 @@ pub(crate) fn root_logger_call(checker: &mut Checker, call: &ExprCall) { }; let diagnostic = Diagnostic::new(kind, call.range); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[inline] diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs index 82466c4157632..444d53d1f69d3 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs @@ -49,7 +49,7 @@ impl Violation for UndocumentedWarn { } /// LOG009 -pub(crate) fn undocumented_warn(checker: &mut Checker, expr: &Expr) { +pub(crate) fn undocumented_warn(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::LOGGING) { return; } @@ -69,6 +69,6 @@ pub(crate) fn undocumented_warn(checker: &mut Checker, expr: &Expr) { let reference_edit = Edit::range_replacement(binding, expr.range()); Ok(Fix::safe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs index 518e3e8225431..a053b4514fb12 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs @@ -42,22 +42,18 @@ fn is_reserved_attr(attr: &str) -> bool { } /// Check logging messages for violations. -fn check_msg(checker: &mut Checker, msg: &Expr) { +fn check_msg(checker: &Checker, msg: &Expr) { match msg { // Check for string concatenation and percent format. Expr::BinOp(ast::ExprBinOp { op, .. }) => match op { Operator::Add => { if checker.enabled(Rule::LoggingStringConcat) { - checker - .diagnostics - .push(Diagnostic::new(LoggingStringConcat, msg.range())); + checker.report_diagnostic(Diagnostic::new(LoggingStringConcat, msg.range())); } } Operator::Mod => { if checker.enabled(Rule::LoggingPercentFormat) { - checker - .diagnostics - .push(Diagnostic::new(LoggingPercentFormat, msg.range())); + checker.report_diagnostic(Diagnostic::new(LoggingPercentFormat, msg.range())); } } _ => {} @@ -65,9 +61,7 @@ fn check_msg(checker: &mut Checker, msg: &Expr) { // Check for f-strings. Expr::FString(_) => { if checker.enabled(Rule::LoggingFString) { - checker - .diagnostics - .push(Diagnostic::new(LoggingFString, msg.range())); + checker.report_diagnostic(Diagnostic::new(LoggingFString, msg.range())); } } // Check for .format() calls. @@ -76,8 +70,7 @@ fn check_msg(checker: &mut Checker, msg: &Expr) { if let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func.as_ref() { if attr == "format" && value.is_literal_expr() { checker - .diagnostics - .push(Diagnostic::new(LoggingStringFormat, msg.range())); + .report_diagnostic(Diagnostic::new(LoggingStringFormat, msg.range())); } } } @@ -87,7 +80,7 @@ fn check_msg(checker: &mut Checker, msg: &Expr) { } /// Check contents of the `extra` argument to logging calls. -fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) { +fn check_log_record_attr_clash(checker: &Checker, extra: &Keyword) { match &extra.value { Expr::Dict(dict) => { for invalid_key in dict.iter_keys().filter_map(|key| { @@ -98,7 +91,7 @@ fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) { None } }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( LoggingExtraAttrClash(invalid_key.value.to_string()), invalid_key.range(), )); @@ -113,7 +106,7 @@ fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) { for keyword in keywords { if let Some(attr) = &keyword.arg { if is_reserved_attr(attr) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( LoggingExtraAttrClash(attr.to_string()), keyword.range(), )); @@ -145,7 +138,7 @@ impl LoggingCallType { } /// Check logging calls for violations. -pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { // Determine the call type (e.g., `info` vs. `exception`) and the range of the attribute. let (logging_call_type, range) = match call.func.as_ref() { Expr::Attribute(ast::ExprAttribute { value: _, attr, .. }) => { @@ -196,7 +189,7 @@ pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) { "warning".to_string(), range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -219,16 +212,15 @@ pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) { match logging_level { LoggingLevel::Error => { if checker.enabled(Rule::LoggingExcInfo) { - checker - .diagnostics - .push(Diagnostic::new(LoggingExcInfo, range)); + checker.report_diagnostic(Diagnostic::new(LoggingExcInfo, range)); } } LoggingLevel::Exception => { if checker.enabled(Rule::LoggingRedundantExcInfo) { - checker - .diagnostics - .push(Diagnostic::new(LoggingRedundantExcInfo, exc_info.range())); + checker.report_diagnostic(Diagnostic::new( + LoggingRedundantExcInfo, + exc_info.range(), + )); } } _ => {} diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs index 3e5d2a0156381..cd92c32d2ea6d 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for DuplicateClassFieldDefinition { } /// PIE794 -pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn duplicate_class_field_definition(checker: &Checker, body: &[Stmt]) { let mut seen_targets: FxHashSet<&str> = FxHashSet::default(); for stmt in body { // Extract the property name from the assignment statement. @@ -105,7 +105,7 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St diagnostic.set_fix(Fix::unsafe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 836912df74b71..763c0584b1fde 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -67,7 +67,7 @@ impl AlwaysFixableViolation for MultipleStartsEndsWith { } /// PIE810 -pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { +pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { let Expr::BoolOp(ast::ExprBoolOp { op: BoolOp::Or, values, @@ -219,7 +219,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { checker.generator().expr(&bool_op), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs index d74fb09ca9051..bf967c3297793 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs @@ -54,7 +54,7 @@ impl Violation for NonUniqueEnums { } /// PIE796 -pub(crate) fn non_unique_enums(checker: &mut Checker, parent: &Stmt, body: &[Stmt]) { +pub(crate) fn non_unique_enums(checker: &Checker, parent: &Stmt, body: &[Stmt]) { let semantic = checker.semantic(); let Stmt::ClassDef(parent) = parent else { @@ -98,7 +98,7 @@ pub(crate) fn non_unique_enums(checker: &mut Checker, parent: &Stmt, body: &[Stm }, stmt.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs index ce04478051b14..76e08db4247a3 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs @@ -58,7 +58,7 @@ impl Violation for ReimplementedContainerBuiltin { } /// PIE807 -pub(crate) fn reimplemented_container_builtin(checker: &mut Checker, expr: &ExprLambda) { +pub(crate) fn reimplemented_container_builtin(checker: &Checker, expr: &ExprLambda) { let ExprLambda { parameters, body, @@ -84,7 +84,7 @@ pub(crate) fn reimplemented_container_builtin(checker: &mut Checker, expr: &Expr let binding_edit = Edit::range_replacement(binding, expr.range()); Ok(Fix::safe_edits(binding_edit, import_edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs index 43bfaec38733d..f0f9ba7c598c9 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs @@ -56,7 +56,7 @@ impl Violation for UnnecessaryDictKwargs { } /// PIE804 -pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_dict_kwargs(checker: &Checker, call: &ast::ExprCall) { let mut duplicate_keywords = None; for keyword in &*call.arguments.keywords { // keyword is a spread operator (indicated by None). @@ -75,9 +75,7 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCal format!("**{}", checker.locator().slice(value)), keyword.range(), ); - checker - .diagnostics - .push(diagnostic.with_fix(Fix::safe_edit(edit))); + checker.report_diagnostic(diagnostic.with_fix(Fix::safe_edit(edit))); continue; } @@ -141,7 +139,7 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCal } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs index c88aef8353695..71d7e79f89676 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs @@ -82,7 +82,7 @@ impl AlwaysFixableViolation for UnnecessaryPlaceholder { } /// PIE790 -pub(crate) fn unnecessary_placeholder(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn unnecessary_placeholder(checker: &Checker, body: &[Stmt]) { if body.len() < 2 { return; } @@ -115,7 +115,7 @@ pub(crate) fn unnecessary_placeholder(checker: &mut Checker, body: &[Stmt]) { /// Add a diagnostic for the given statement. fn add_diagnostic( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, next_stmt: Option<&Stmt>, placeholder_kind: Placeholder, @@ -145,7 +145,7 @@ fn add_diagnostic( stmt.range(), ); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } #[derive(Debug, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index 1deb7376370ce..8c2dc82b577ca 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for UnnecessaryRangeStart { } /// PIE808 -pub(crate) fn unnecessary_range_start(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_range_start(checker: &Checker, call: &ast::ExprCall) { // `range` doesn't accept keyword arguments. if !call.arguments.keywords.is_empty() { return; @@ -80,5 +80,5 @@ pub(crate) fn unnecessary_range_start(checker: &mut Checker, call: &ast::ExprCal ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs index f5d867ecfc25b..948ce36b25e81 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs @@ -44,7 +44,7 @@ impl Violation for UnnecessarySpread { } /// PIE800 -pub(crate) fn unnecessary_spread(checker: &mut Checker, dict: &ast::ExprDict) { +pub(crate) fn unnecessary_spread(checker: &Checker, dict: &ast::ExprDict) { // The first "end" is the start of the dictionary, immediately following the open bracket. let mut prev_end = dict.start() + TextSize::from(1); for ast::DictItem { key, value } in dict { @@ -56,7 +56,7 @@ pub(crate) fn unnecessary_spread(checker: &mut Checker, dict: &ast::ExprDict) { if let Some(fix) = unnecessary_spread_fix(inner, prev_end, checker.tokens()) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } prev_end = value.end(); diff --git a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs index 09e7c81357a43..59ce9542cd728 100644 --- a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs @@ -96,7 +96,7 @@ impl Violation for PPrint { } /// T201, T203 -pub(crate) fn print_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn print_call(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let Some(qualified_name) = semantic.resolve_qualified_name(&call.func) else { @@ -140,5 +140,5 @@ pub(crate) fn print_call(checker: &mut Checker, call: &ast::ExprCall) { ); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs index f129fa6e389e9..ba189c2bf7d4d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for AnyEqNeAnnotation { } /// PYI032 -pub(crate) fn any_eq_ne_annotation(checker: &mut Checker, name: &str, parameters: &Parameters) { +pub(crate) fn any_eq_ne_annotation(checker: &Checker, name: &str, parameters: &Parameters) { if !matches!(name, "__eq__" | "__ne__") { return; } @@ -100,5 +100,5 @@ pub(crate) fn any_eq_ne_annotation(checker: &mut Checker, name: &str, parameters let binding_edit = Edit::range_replacement(binding, annotation.range()); Ok(Fix::safe_edits(binding_edit, import_edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs index c4f97c1bf4016..809cc13ac76da 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs @@ -88,10 +88,7 @@ impl Violation for GeneratorReturnFromIterMethod { } /// PYI058 -pub(crate) fn bad_generator_return_type( - function_def: &ast::StmtFunctionDef, - checker: &mut Checker, -) { +pub(crate) fn bad_generator_return_type(function_def: &ast::StmtFunctionDef, checker: &Checker) { if function_def.is_async { return; } @@ -232,7 +229,7 @@ pub(crate) fn bad_generator_return_type( ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns `true` if the [`ast::Expr`] is a `None` literal or a `typing.Any` expression. diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs index 4b0954fa3c039..10a6da538b0b0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs @@ -109,11 +109,7 @@ impl Violation for BadVersionInfoOrder { } /// PYI006, PYI066 -pub(crate) fn bad_version_info_comparison( - checker: &mut Checker, - test: &Expr, - has_else_clause: bool, -) { +pub(crate) fn bad_version_info_comparison(checker: &Checker, test: &Expr, has_else_clause: bool) { let Expr::Compare(ast::ExprCompare { left, ops, @@ -147,16 +143,12 @@ pub(crate) fn bad_version_info_comparison( && (checker.source_type.is_stub() || checker.settings.preview.is_enabled()) { if has_else_clause { - checker - .diagnostics - .push(Diagnostic::new(BadVersionInfoOrder, test.range())); + checker.report_diagnostic(Diagnostic::new(BadVersionInfoOrder, test.range())); } } } else { if checker.enabled(Rule::BadVersionInfoComparison) { - checker - .diagnostics - .push(Diagnostic::new(BadVersionInfoComparison, test.range())); + checker.report_diagnostic(Diagnostic::new(BadVersionInfoComparison, test.range())); }; } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs index 7da5b0b348ec6..5fb9f3f82fd7d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs @@ -58,7 +58,7 @@ impl std::fmt::Display for ByteStringOrigin { } /// PYI057 -pub(crate) fn bytestring_attribute(checker: &mut Checker, attribute: &Expr) { +pub(crate) fn bytestring_attribute(checker: &Checker, attribute: &Expr) { let semantic = checker.semantic(); if !semantic .seen @@ -74,14 +74,14 @@ pub(crate) fn bytestring_attribute(checker: &mut Checker, attribute: &Expr) { ["collections", "abc", "ByteString"] => ByteStringOrigin::CollectionsAbc, _ => return, }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ByteStringUsage { origin }, attribute.range(), )); } /// PYI057 -pub(crate) fn bytestring_import(checker: &mut Checker, import_from: &ast::StmtImportFrom) { +pub(crate) fn bytestring_import(checker: &Checker, import_from: &ast::StmtImportFrom) { let ast::StmtImportFrom { names, module, .. } = import_from; let module_id = match module { @@ -97,9 +97,7 @@ pub(crate) fn bytestring_import(checker: &mut Checker, import_from: &ast::StmtIm for name in names { if name.name.as_str() == "ByteString" { - checker - .diagnostics - .push(Diagnostic::new(ByteStringUsage { origin }, name.range())); + checker.report_diagnostic(Diagnostic::new(ByteStringUsage { origin }, name.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs index 8192184d1b656..78fc8acfae102 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs @@ -50,7 +50,7 @@ impl Violation for CollectionsNamedTuple { } /// PYI024 -pub(crate) fn collections_named_tuple(checker: &mut Checker, expr: &Expr) { +pub(crate) fn collections_named_tuple(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::COLLECTIONS) { return; } @@ -62,8 +62,6 @@ pub(crate) fn collections_named_tuple(checker: &mut Checker, expr: &Expr) { matches!(qualified_name.segments(), ["collections", "namedtuple"]) }) { - checker - .diagnostics - .push(Diagnostic::new(CollectionsNamedTuple, expr.range())); + checker.report_diagnostic(Diagnostic::new(CollectionsNamedTuple, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs index 508868d613caa..29769a69583a6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs @@ -52,11 +52,9 @@ impl Violation for ComplexAssignmentInStub { } /// PYI017 -pub(crate) fn complex_assignment_in_stub(checker: &mut Checker, stmt: &StmtAssign) { +pub(crate) fn complex_assignment_in_stub(checker: &Checker, stmt: &StmtAssign) { if matches!(stmt.targets.as_slice(), [Expr::Name(_)]) { return; } - checker - .diagnostics - .push(Diagnostic::new(ComplexAssignmentInStub, stmt.range)); + checker.report_diagnostic(Diagnostic::new(ComplexAssignmentInStub, stmt.range)); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs index be20c05c42599..980601e5d999a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs @@ -43,21 +43,17 @@ impl Violation for ComplexIfStatementInStub { } /// PYI002 -pub(crate) fn complex_if_statement_in_stub(checker: &mut Checker, test: &Expr) { +pub(crate) fn complex_if_statement_in_stub(checker: &Checker, test: &Expr) { let Expr::Compare(ast::ExprCompare { left, comparators, .. }) = test else { - checker - .diagnostics - .push(Diagnostic::new(ComplexIfStatementInStub, test.range())); + checker.report_diagnostic(Diagnostic::new(ComplexIfStatementInStub, test.range())); return; }; if comparators.len() != 1 { - checker - .diagnostics - .push(Diagnostic::new(ComplexIfStatementInStub, test.range())); + checker.report_diagnostic(Diagnostic::new(ComplexIfStatementInStub, test.range())); return; } @@ -78,7 +74,5 @@ pub(crate) fn complex_if_statement_in_stub(checker: &mut Checker, test: &Expr) { return; } - checker - .diagnostics - .push(Diagnostic::new(ComplexIfStatementInStub, test.range())); + checker.report_diagnostic(Diagnostic::new(ComplexIfStatementInStub, test.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs index c7529fbad3809..586219b0d7352 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for DocstringInStub { /// PYI021 pub(crate) fn docstring_in_stubs( - checker: &mut Checker, + checker: &Checker, definition: &Definition, docstring: Option<&ExprStringLiteral>, ) { @@ -66,5 +66,5 @@ pub(crate) fn docstring_in_stubs( let fix = Fix::unsafe_edit(edit); let diagnostic = Diagnostic::new(DocstringInStub, docstring_range).with_fix(fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs index d5c7125bd219b..c3190e0fb1242 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for DuplicateLiteralMember { } /// PYI062 -pub(crate) fn duplicate_literal_member<'a>(checker: &mut Checker, expr: &'a Expr) { +pub(crate) fn duplicate_literal_member<'a>(checker: &Checker, expr: &'a Expr) { let mut seen_nodes: HashSet, _> = FxHashSet::default(); let mut unique_nodes: Vec<&Expr> = Vec::new(); let mut diagnostics: Vec = Vec::new(); @@ -109,5 +109,5 @@ pub(crate) fn duplicate_literal_member<'a>(checker: &mut Checker, expr: &'a Expr } }; - checker.diagnostics.append(&mut diagnostics); + checker.report_diagnostics(diagnostics); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs index 633af40ecab71..f4e02b222faaf 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -61,7 +61,7 @@ impl Violation for DuplicateUnionMember { } /// PYI016 -pub(crate) fn duplicate_union_member<'a>(checker: &mut Checker, expr: &'a Expr) { +pub(crate) fn duplicate_union_member<'a>(checker: &Checker, expr: &'a Expr) { let mut seen_nodes: HashSet, _> = FxHashSet::default(); let mut unique_nodes: Vec<&Expr> = Vec::new(); let mut diagnostics: Vec = Vec::new(); @@ -129,7 +129,7 @@ pub(crate) fn duplicate_union_member<'a>(checker: &mut Checker, expr: &'a Expr) } // Add all diagnostics to the checker - checker.diagnostics.append(&mut diagnostics); + checker.report_diagnostics(diagnostics); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs index f1e06cd632b30..cda0183aeb228 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs @@ -43,7 +43,7 @@ impl Violation for EllipsisInNonEmptyClassBody { } /// PYI013 -pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn ellipsis_in_non_empty_class_body(checker: &Checker, body: &[Stmt]) { // If the class body contains a single statement, then it's fine for it to be an ellipsis. if body.len() == 1 { return; @@ -61,7 +61,7 @@ pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[St diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs index 8959cae0075cf..1202d5cbe2ac0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs @@ -116,7 +116,7 @@ enum ErrorKind { } /// PYI036 -pub(crate) fn bad_exit_annotation(checker: &mut Checker, function: &StmtFunctionDef) { +pub(crate) fn bad_exit_annotation(checker: &Checker, function: &StmtFunctionDef) { let StmtFunctionDef { is_async, decorator_list, @@ -167,7 +167,7 @@ pub(crate) fn bad_exit_annotation(checker: &mut Checker, function: &StmtFunction .skip(3) .filter(|parameter| parameter.default.is_none()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadExitAnnotation { func_kind, error_kind: ErrorKind::ArgsAfterFirstFourMustHaveDefault, @@ -182,7 +182,7 @@ pub(crate) fn bad_exit_annotation(checker: &mut Checker, function: &StmtFunction .iter() .filter(|arg| arg.default.is_none()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadExitAnnotation { func_kind, error_kind: ErrorKind::AllKwargsMustHaveDefault, @@ -196,7 +196,7 @@ pub(crate) fn bad_exit_annotation(checker: &mut Checker, function: &StmtFunction /// Determine whether a "short" argument list (i.e., an argument list with less than four elements) /// contains a star-args argument annotated with `object`. If not, report an error. -fn check_short_args_list(checker: &mut Checker, parameters: &Parameters, func_kind: FuncKind) { +fn check_short_args_list(checker: &Checker, parameters: &Parameters, func_kind: FuncKind) { if let Some(varargs) = ¶meters.vararg { if let Some(annotation) = varargs .annotation() @@ -220,10 +220,10 @@ fn check_short_args_list(checker: &mut Checker, parameters: &Parameters, func_ki Ok(Fix::safe_edits(binding_edit, import_edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadExitAnnotation { func_kind, error_kind: ErrorKind::MissingArgs, @@ -236,7 +236,7 @@ fn check_short_args_list(checker: &mut Checker, parameters: &Parameters, func_ki /// Determines whether the positional arguments of an `__exit__` or `__aexit__` method /// (that is not decorated with `@typing.overload`) are annotated correctly. fn check_positional_args_for_non_overloaded_method( - checker: &mut Checker, + checker: &Checker, non_self_positional_params: &[&ParameterWithDefault], kind: FuncKind, ) { @@ -270,7 +270,7 @@ fn check_positional_args_for_non_overloaded_method( continue; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadExitAnnotation { func_kind: kind, error_kind: error_info, @@ -283,7 +283,7 @@ fn check_positional_args_for_non_overloaded_method( /// Determines whether the positional arguments of an `__exit__` or `__aexit__` method /// overload are annotated correctly. fn check_positional_args_for_overloaded_method( - checker: &mut Checker, + checker: &Checker, non_self_positional_args: &[&ParameterWithDefault], kind: FuncKind, parent_class_def: &StmtClassDef, @@ -409,7 +409,7 @@ fn check_positional_args_for_overloaded_method( } // Okay, neither of them match... - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadExitAnnotation { func_kind: kind, error_kind: ErrorKind::UnrecognizedExitOverload, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs index f8a0662dd129f..f35b378916f83 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs @@ -34,7 +34,7 @@ impl Violation for FutureAnnotationsInStub { } /// PYI044 -pub(crate) fn from_future_import(checker: &mut Checker, target: &StmtImportFrom) { +pub(crate) fn from_future_import(checker: &Checker, target: &StmtImportFrom) { let StmtImportFrom { range, module: Some(module_name), @@ -72,5 +72,5 @@ pub(crate) fn from_future_import(checker: &mut Checker, target: &StmtImportFrom) }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs index af36e505afba9..7d5ef5ca81f44 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs @@ -64,7 +64,7 @@ impl Violation for GenericNotLastBaseClass { } /// PYI059 -pub(crate) fn generic_not_last_base_class(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn generic_not_last_base_class(checker: &Checker, class_def: &ast::StmtClassDef) { let Some(bases) = class_def.arguments.as_deref() else { return; }; @@ -99,7 +99,7 @@ pub(crate) fn generic_not_last_base_class(checker: &mut Checker, class_def: &ast diagnostic.try_set_fix(|| generate_fix(generic_base, bases, checker)); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn generate_fix( diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs index a5b5c4a66bd89..398cc349bc63b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs @@ -86,7 +86,7 @@ impl Violation for IterMethodReturnIterable { } /// PYI045 -pub(crate) fn iter_method_return_iterable(checker: &mut Checker, definition: &Definition) { +pub(crate) fn iter_method_return_iterable(checker: &Checker, definition: &Definition) { let Definition::Member(Member { kind: MemberKind::Method(function), .. @@ -125,7 +125,7 @@ pub(crate) fn iter_method_return_iterable(checker: &mut Checker, definition: &De } }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( IterMethodReturnIterable { is_async }, returns.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs index 23494e01cf53a..e1a3dbbfe4595 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs @@ -54,7 +54,7 @@ impl Violation for NoReturnArgumentAnnotationInStub { } /// PYI050 -pub(crate) fn no_return_argument_annotation(checker: &mut Checker, parameters: &ast::Parameters) { +pub(crate) fn no_return_argument_annotation(checker: &Checker, parameters: &ast::Parameters) { // Ex) def func(arg: NoReturn): ... // Ex) def func(arg: NoReturn, /): ... // Ex) def func(*, arg: NoReturn): ... @@ -65,7 +65,7 @@ pub(crate) fn no_return_argument_annotation(checker: &mut Checker, parameters: & .filter_map(ast::AnyParameterRef::annotation) { if is_no_return(annotation, checker) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NoReturnArgumentAnnotationInStub { module: if checker.settings.target_version >= Py311 { TypingModule::Typing diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs index 1b6f512f3f046..f853baa539189 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for NonEmptyStubBody { } /// PYI010 -pub(crate) fn non_empty_stub_body(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn non_empty_stub_body(checker: &Checker, body: &[Stmt]) { // Ignore multi-statement bodies (covered by PYI048). let [stmt] = body else { return; @@ -70,5 +70,5 @@ pub(crate) fn non_empty_stub_body(checker: &mut Checker, body: &[Stmt]) { "...".to_string(), stmt.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs index 3d4155af83767..ae1b520b55880 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -108,7 +108,7 @@ impl Violation for NonSelfReturnType { /// PYI034 pub(crate) fn non_self_return_type( - checker: &mut Checker, + checker: &Checker, stmt: &ast::Stmt, is_async: bool, name: &str, @@ -187,7 +187,7 @@ pub(crate) fn non_self_return_type( /// Add a diagnostic for the given method. fn add_diagnostic( - checker: &mut Checker, + checker: &Checker, stmt: &ast::Stmt, returns: &ast::Expr, class_def: &ast::StmtClassDef, @@ -203,11 +203,11 @@ fn add_diagnostic( diagnostic.try_set_fix(|| replace_with_self_fix(checker, stmt, returns, class_def)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn replace_with_self_fix( - checker: &mut Checker, + checker: &Checker, stmt: &ast::Stmt, returns: &ast::Expr, class_def: &ast::StmtClassDef, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs index d9ca48e1417cb..d353ac9517faa 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for NumericLiteralTooLong { } /// PYI054 -pub(crate) fn numeric_literal_too_long(checker: &mut Checker, expr: &Expr) { +pub(crate) fn numeric_literal_too_long(checker: &Checker, expr: &Expr) { if expr.range().len() <= TextSize::new(10) { return; } @@ -55,5 +55,5 @@ pub(crate) fn numeric_literal_too_long(checker: &mut Checker, expr: &Expr) { "...".to_string(), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs index f1c9c0d54f457..5c1363d17a093 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs @@ -41,7 +41,7 @@ impl AlwaysFixableViolation for PassInClassBody { } /// PYI012 -pub(crate) fn pass_in_class_body(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn pass_in_class_body(checker: &Checker, class_def: &ast::StmtClassDef) { // `pass` is required in these situations (or handled by `pass_statement_stub_body`). if class_def.body.len() < 2 { return; @@ -57,6 +57,6 @@ pub(crate) fn pass_in_class_body(checker: &mut Checker, class_def: &ast::StmtCla diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs index cedd0251f8d1a..27782c434227d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs @@ -39,7 +39,7 @@ impl AlwaysFixableViolation for PassStatementStubBody { } /// PYI009 -pub(crate) fn pass_statement_stub_body(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn pass_statement_stub_body(checker: &Checker, body: &[Stmt]) { let [Stmt::Pass(pass)] = body else { return; }; @@ -49,5 +49,5 @@ pub(crate) fn pass_statement_stub_body(checker: &mut Checker, body: &[Stmt]) { "...".to_string(), pass.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs index 6eae403344669..69c02d489b6e9 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs @@ -54,10 +54,7 @@ impl Violation for Pep484StylePositionalOnlyParameter { } /// PYI063 -pub(crate) fn pep_484_positional_parameter( - checker: &mut Checker, - function_def: &ast::StmtFunctionDef, -) { +pub(crate) fn pep_484_positional_parameter(checker: &Checker, function_def: &ast::StmtFunctionDef) { // PEP 570 was introduced in Python 3.8. if checker.settings.target_version < PythonVersion::Py38 { return; @@ -90,7 +87,7 @@ pub(crate) fn pep_484_positional_parameter( if let Some(arg) = function_def.parameters.args.get(skip) { if is_old_style_positional_only(arg) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( Pep484StylePositionalOnlyParameter, arg.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs index 7b908f131ff3c..6f3e1d6dbf3e2 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs @@ -59,7 +59,7 @@ impl Violation for UnprefixedTypeParam { } /// PYI001 -pub(crate) fn prefix_type_params(checker: &mut Checker, value: &Expr, targets: &[Expr]) { +pub(crate) fn prefix_type_params(checker: &Checker, value: &Expr, targets: &[Expr]) { // If the typing modules were never imported, we'll never match below. if !checker.semantic().seen_typing() { return; @@ -106,7 +106,5 @@ pub(crate) fn prefix_type_params(checker: &mut Checker, value: &Expr, targets: & return; }; - checker - .diagnostics - .push(Diagnostic::new(UnprefixedTypeParam { kind }, value.range())); + checker.report_diagnostic(Diagnostic::new(UnprefixedTypeParam { kind }, value.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs index 99bbc83710051..44059eb02cfde 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs @@ -43,11 +43,11 @@ impl AlwaysFixableViolation for QuotedAnnotationInStub { } /// PYI020 -pub(crate) fn quoted_annotation_in_stub(checker: &mut Checker, annotation: &str, range: TextRange) { +pub(crate) fn quoted_annotation_in_stub(checker: &Checker, annotation: &str, range: TextRange) { let mut diagnostic = Diagnostic::new(QuotedAnnotationInStub, range); diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( annotation.to_string(), range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs index 767d33a797834..47016c98b3da1 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs @@ -56,7 +56,7 @@ impl Violation for RedundantFinalLiteral { } /// PYI064 -pub(crate) fn redundant_final_literal(checker: &mut Checker, ann_assign: &ast::StmtAnnAssign) { +pub(crate) fn redundant_final_literal(checker: &Checker, ann_assign: &ast::StmtAnnAssign) { if !checker.semantic().seen_typing() { return; } @@ -114,7 +114,7 @@ pub(crate) fn redundant_final_literal(checker: &mut Checker, ann_assign: &ast::S diagnostic.set_fix(generate_fix(annotation, Some(literal), checker.locator())); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Generate a fix to convert a `Final[Literal[...]]` annotation to a `Final` annotation. diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs index d0e579c547e2a..bfcfcef7ca2ac 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs @@ -58,7 +58,7 @@ impl Violation for RedundantLiteralUnion { } /// PYI051 -pub(crate) fn redundant_literal_union<'a>(checker: &mut Checker, union: &'a Expr) { +pub(crate) fn redundant_literal_union<'a>(checker: &Checker, union: &'a Expr) { let mut typing_literal_exprs = Vec::new(); let mut builtin_types_in_union = FxHashSet::default(); @@ -90,7 +90,7 @@ pub(crate) fn redundant_literal_union<'a>(checker: &mut Checker, union: &'a Expr }; if builtin_types_in_union.contains(&literal_type) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RedundantLiteralUnion { literal: SourceCodeSnippet::from_str( checker.locator().slice(typing_literal_expr), diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs index db0f6f5abf0cd..a5304251fb48a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs @@ -70,7 +70,7 @@ impl Violation for RedundantNoneLiteral { } /// PYI061 -pub(crate) fn redundant_none_literal<'a>(checker: &mut Checker, literal_expr: &'a Expr) { +pub(crate) fn redundant_none_literal<'a>(checker: &Checker, literal_expr: &'a Expr) { let semantic = checker.semantic(); if !semantic.seen_typing() { @@ -127,7 +127,7 @@ pub(crate) fn redundant_none_literal<'a>(checker: &mut Checker, literal_expr: &' if let Some(ref fix) = fix { diagnostic.set_fix(fix.clone()); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs index 0b9145d3f3f7a..6164bfa87b152 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs @@ -81,13 +81,13 @@ impl Violation for RedundantNumericUnion { } /// PYI041 -pub(crate) fn redundant_numeric_union(checker: &mut Checker, parameters: &Parameters) { +pub(crate) fn redundant_numeric_union(checker: &Checker, parameters: &Parameters) { for annotation in parameters.iter().filter_map(AnyParameterRef::annotation) { check_annotation(checker, annotation); } } -fn check_annotation<'a>(checker: &mut Checker, annotation: &'a Expr) { +fn check_annotation<'a>(checker: &Checker, annotation: &'a Expr) { let mut numeric_flags = NumericFlags::empty(); let mut find_numeric_type = |expr: &Expr, _parent: &Expr| { @@ -166,7 +166,7 @@ fn check_annotation<'a>(checker: &mut Checker, annotation: &'a Expr) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, Eq, PartialEq)] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs index 8c7dfff302932..5eb431cb23a1d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -486,7 +486,7 @@ fn is_annotatable_type_alias(value: &Expr, semantic: &SemanticModel) -> bool { } /// PYI011 -pub(crate) fn typed_argument_simple_defaults(checker: &mut Checker, parameters: &Parameters) { +pub(crate) fn typed_argument_simple_defaults(checker: &Checker, parameters: &Parameters) { for parameter in parameters.iter_non_variadic_params() { let Some(default) = parameter.default() else { continue; @@ -505,14 +505,14 @@ pub(crate) fn typed_argument_simple_defaults(checker: &mut Checker, parameters: default.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } } /// PYI014 -pub(crate) fn argument_simple_defaults(checker: &mut Checker, parameters: &Parameters) { +pub(crate) fn argument_simple_defaults(checker: &Checker, parameters: &Parameters) { for parameter in parameters.iter_non_variadic_params() { let Some(default) = parameter.default() else { continue; @@ -531,14 +531,14 @@ pub(crate) fn argument_simple_defaults(checker: &mut Checker, parameters: &Param default.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } } /// PYI015 -pub(crate) fn assignment_default_in_stub(checker: &mut Checker, targets: &[Expr], value: &Expr) { +pub(crate) fn assignment_default_in_stub(checker: &Checker, targets: &[Expr], value: &Expr) { let [target] = targets else { return; }; @@ -563,12 +563,12 @@ pub(crate) fn assignment_default_in_stub(checker: &mut Checker, targets: &[Expr] "...".to_string(), value.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// PYI015 pub(crate) fn annotated_assignment_default_in_stub( - checker: &mut Checker, + checker: &Checker, target: &Expr, value: &Expr, annotation: &Expr, @@ -597,15 +597,11 @@ pub(crate) fn annotated_assignment_default_in_stub( "...".to_string(), value.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// PYI052 -pub(crate) fn unannotated_assignment_in_stub( - checker: &mut Checker, - targets: &[Expr], - value: &Expr, -) { +pub(crate) fn unannotated_assignment_in_stub(checker: &Checker, targets: &[Expr], value: &Expr) { let [target] = targets else { return; }; @@ -631,7 +627,7 @@ pub(crate) fn unannotated_assignment_in_stub( return; } } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnannotatedAssignmentInStub { name: id.to_string(), }, @@ -640,11 +636,7 @@ pub(crate) fn unannotated_assignment_in_stub( } /// PYI035 -pub(crate) fn unassigned_special_variable_in_stub( - checker: &mut Checker, - target: &Expr, - stmt: &Stmt, -) { +pub(crate) fn unassigned_special_variable_in_stub(checker: &Checker, target: &Expr, stmt: &Stmt) { let Expr::Name(ast::ExprName { id, .. }) = target else { return; }; @@ -653,7 +645,7 @@ pub(crate) fn unassigned_special_variable_in_stub( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnassignedSpecialVariableInStub { name: id.to_string(), }, @@ -662,7 +654,7 @@ pub(crate) fn unassigned_special_variable_in_stub( } /// PYI026 -pub(crate) fn type_alias_without_annotation(checker: &mut Checker, value: &Expr, targets: &[Expr]) { +pub(crate) fn type_alias_without_annotation(checker: &Checker, value: &Expr, targets: &[Expr]) { let [target] = targets else { return; }; @@ -700,5 +692,5 @@ pub(crate) fn type_alias_without_annotation(checker: &mut Checker, value: &Expr, [import_edit], )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs index 60202d9d2f0bd..b4cbe3d21285a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for StrOrReprDefinedInStub { } /// PYI029 -pub(crate) fn str_or_repr_defined_in_stub(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn str_or_repr_defined_in_stub(checker: &Checker, stmt: &Stmt) { let Stmt::FunctionDef(ast::StmtFunctionDef { name, decorator_list, @@ -94,5 +94,5 @@ pub(crate) fn str_or_repr_defined_in_stub(checker: &mut Checker, stmt: &Stmt) { diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_parent_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index 5ec88d60fab4d..1a9ad3a325d69 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -47,7 +47,7 @@ impl AlwaysFixableViolation for StringOrBytesTooLong { } /// PYI053 -pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike) { +pub(crate) fn string_or_bytes_too_long(checker: &Checker, string: StringLike) { let semantic = checker.semantic(); // Ignore docstrings. @@ -77,7 +77,7 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike "...".to_string(), string.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Count the number of visible characters in an f-string. This accounts for diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs index a4456cc6536a5..680f215cc14de 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs @@ -39,9 +39,9 @@ impl Violation for StubBodyMultipleStatements { } /// PYI048 -pub(crate) fn stub_body_multiple_statements(checker: &mut Checker, stmt: &Stmt, body: &[Stmt]) { +pub(crate) fn stub_body_multiple_statements(checker: &Checker, stmt: &Stmt, body: &[Stmt]) { if body.len() > 1 { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StubBodyMultipleStatements, stmt.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs index dee8c3525d816..d9646910c004d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs @@ -101,13 +101,13 @@ fn is_t_suffixed_type_alias(name: &str) -> bool { } /// PYI042 -pub(crate) fn snake_case_type_alias(checker: &mut Checker, target: &Expr) { +pub(crate) fn snake_case_type_alias(checker: &Checker, target: &Expr) { if let Expr::Name(ast::ExprName { id, range, .. }) = target { if !is_snake_case_type_alias(id) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SnakeCaseTypeAlias { name: id.to_string(), }, @@ -117,13 +117,13 @@ pub(crate) fn snake_case_type_alias(checker: &mut Checker, target: &Expr) { } /// PYI043 -pub(crate) fn t_suffixed_type_alias(checker: &mut Checker, target: &Expr) { +pub(crate) fn t_suffixed_type_alias(checker: &Checker, target: &Expr) { if let Expr::Name(ast::ExprName { id, range, .. }) = target { if !is_t_suffixed_type_alias(id) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TSuffixedTypeAlias { name: id.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs index 301f2b702fa4e..a2fd4f27b666b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs @@ -52,7 +52,7 @@ impl Violation for UnnecessaryLiteralUnion { } /// PYI030 -pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Expr) { +pub(crate) fn unnecessary_literal_union<'a>(checker: &Checker, expr: &'a Expr) { let mut literal_exprs = Vec::new(); let mut other_exprs = Vec::new(); @@ -164,5 +164,5 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp } }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs index c4abd33083080..4ad46eb85b1f3 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs @@ -58,7 +58,7 @@ impl Violation for UnnecessaryTypeUnion { } /// PYI055 -pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) { +pub(crate) fn unnecessary_type_union<'a>(checker: &Checker, union: &'a Expr) { let semantic = checker.semantic(); // The `|` operator isn't always safe to allow to runtime-evaluated annotations. @@ -219,7 +219,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &mut Checker, union: &'a Expr) )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs index 6f747eea25cd6..22446ac78cf9b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs @@ -89,7 +89,7 @@ impl Violation for UnrecognizedPlatformName { } /// PYI007, PYI008 -pub(crate) fn unrecognized_platform(checker: &mut Checker, test: &Expr) { +pub(crate) fn unrecognized_platform(checker: &Checker, test: &Expr) { let Expr::Compare(ast::ExprCompare { left, ops, @@ -115,9 +115,7 @@ pub(crate) fn unrecognized_platform(checker: &mut Checker, test: &Expr) { // "in" might also make sense but we don't currently have one. if !matches!(op, CmpOp::Eq | CmpOp::NotEq) { if checker.enabled(Rule::UnrecognizedPlatformCheck) { - checker - .diagnostics - .push(Diagnostic::new(UnrecognizedPlatformCheck, test.range())); + checker.report_diagnostic(Diagnostic::new(UnrecognizedPlatformCheck, test.range())); } return; } @@ -127,7 +125,7 @@ pub(crate) fn unrecognized_platform(checker: &mut Checker, test: &Expr) { // This protects against typos. if checker.enabled(Rule::UnrecognizedPlatformName) { if !matches!(value.to_str(), "linux" | "win32" | "cygwin" | "darwin") { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnrecognizedPlatformName { platform: value.to_string(), }, @@ -137,9 +135,7 @@ pub(crate) fn unrecognized_platform(checker: &mut Checker, test: &Expr) { } } else { if checker.enabled(Rule::UnrecognizedPlatformCheck) { - checker - .diagnostics - .push(Diagnostic::new(UnrecognizedPlatformCheck, test.range())); + checker.report_diagnostic(Diagnostic::new(UnrecognizedPlatformCheck, test.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs index 7bd9f7d143762..9588fe350f44b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs @@ -121,7 +121,7 @@ impl Violation for WrongTupleLengthVersionComparison { } /// PYI003, PYI004, PYI005 -pub(crate) fn unrecognized_version_info(checker: &mut Checker, test: &Expr) { +pub(crate) fn unrecognized_version_info(checker: &Checker, test: &Expr) { let Expr::Compare(ast::ExprCompare { left, ops, @@ -148,15 +148,13 @@ pub(crate) fn unrecognized_version_info(checker: &mut Checker, test: &Expr) { version_check(checker, expected, test, *op, comparator); } else { if checker.enabled(Rule::UnrecognizedVersionInfoCheck) { - checker - .diagnostics - .push(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); + checker.report_diagnostic(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); } } } fn version_check( - checker: &mut Checker, + checker: &Checker, expected: ExpectedComparator, test: &Expr, op: CmpOp, @@ -167,8 +165,7 @@ fn version_check( if !is_int_constant(comparator) { if checker.enabled(Rule::UnrecognizedVersionInfoCheck) { checker - .diagnostics - .push(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); + .report_diagnostic(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); } } return; @@ -177,9 +174,7 @@ fn version_check( // Tuple comparison, e.g., `sys.version_info == (3, 4)`. let Expr::Tuple(tuple) = comparator else { if checker.enabled(Rule::UnrecognizedVersionInfoCheck) { - checker - .diagnostics - .push(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); + checker.report_diagnostic(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); } return; }; @@ -188,17 +183,13 @@ fn version_check( // All tuple elements must be integers, e.g., `sys.version_info == (3, 4)` instead of // `sys.version_info == (3.0, 4)`. if checker.enabled(Rule::UnrecognizedVersionInfoCheck) { - checker - .diagnostics - .push(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); + checker.report_diagnostic(Diagnostic::new(UnrecognizedVersionInfoCheck, test.range())); } } else if tuple.len() > 2 { // Must compare against major and minor version only, e.g., `sys.version_info == (3, 4)` // instead of `sys.version_info == (3, 4, 0)`. if checker.enabled(Rule::PatchVersionComparison) { - checker - .diagnostics - .push(Diagnostic::new(PatchVersionComparison, test.range())); + checker.report_diagnostic(Diagnostic::new(PatchVersionComparison, test.range())); } } @@ -211,7 +202,7 @@ fn version_check( }; if tuple.len() != expected_length { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( WrongTupleLengthVersionComparison { expected_length }, test.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs index d51e67a28728b..625c9803fc49f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs @@ -54,7 +54,7 @@ impl Violation for UnsupportedMethodCallOnAll { } /// PYI056 -pub(crate) fn unsupported_method_call_on_all(checker: &mut Checker, func: &Expr) { +pub(crate) fn unsupported_method_call_on_all(checker: &Checker, func: &Expr) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func else { return; }; @@ -67,7 +67,7 @@ pub(crate) fn unsupported_method_call_on_all(checker: &mut Checker, func: &Expr) if !is_unsupported_method(attr.as_str()) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnsupportedMethodCallOnAll { name: attr.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs index df0f1e0796371..47575512308ee 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs @@ -178,11 +178,7 @@ impl Violation for UnusedPrivateTypedDict { } /// PYI018 -pub(crate) fn unused_private_type_var( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_private_type_var(checker: &Checker, scope: &Scope) { for binding in scope .binding_ids() .map(|binding_id| checker.semantic().binding(binding_id)) @@ -242,16 +238,12 @@ pub(crate) fn unused_private_type_var( diagnostic.set_fix(Fix::unsafe_edit(edit)); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// PYI046 -pub(crate) fn unused_private_protocol( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_private_protocol(checker: &Checker, scope: &Scope) { for binding in scope .binding_ids() .map(|binding_id| checker.semantic().binding(binding_id)) @@ -279,7 +271,7 @@ pub(crate) fn unused_private_protocol( continue; } - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnusedPrivateProtocol { name: class_def.name.to_string(), }, @@ -289,11 +281,7 @@ pub(crate) fn unused_private_protocol( } /// PYI047 -pub(crate) fn unused_private_type_alias( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_private_type_alias(checker: &Checker, scope: &Scope) { let semantic = checker.semantic(); for binding in scope @@ -315,7 +303,7 @@ pub(crate) fn unused_private_type_alias( continue; }; - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnusedPrivateTypeAlias { name: alias_name.to_string(), }, @@ -345,11 +333,7 @@ fn extract_type_alias_name<'a>(stmt: &'a ast::Stmt, semantic: &SemanticModel) -> } /// PYI049 -pub(crate) fn unused_private_typed_dict( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_private_typed_dict(checker: &Checker, scope: &Scope) { let semantic = checker.semantic(); for binding in scope @@ -374,7 +358,7 @@ pub(crate) fn unused_private_typed_dict( continue; }; - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnusedPrivateTypedDict { name: class_name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs index fc078f516e1cc..2460db7492e11 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs @@ -268,7 +268,7 @@ fn check_assert_in_except(name: &str, body: &[Stmt]) -> Vec { /// PT009 pub(crate) fn unittest_assertion( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -309,7 +309,7 @@ pub(crate) fn unittest_assertion( } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// ## What it does @@ -367,7 +367,7 @@ impl Violation for PytestUnittestRaisesAssertion { } /// PT027 -pub(crate) fn unittest_raises_assertion_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unittest_raises_assertion_call(checker: &Checker, call: &ast::ExprCall) { // Bindings in `with` statements are handled by `unittest_raises_assertion_bindings`. if let Stmt::With(ast::StmtWith { items, .. }) = checker.semantic().current_statement() { let call_ref = AnyNodeRef::from(call); @@ -380,7 +380,7 @@ pub(crate) fn unittest_raises_assertion_call(checker: &mut Checker, call: &ast:: } if let Some(diagnostic) = unittest_raises_assertion(call, vec![], checker) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -587,30 +587,24 @@ fn to_pytest_raises_args<'a>( } /// PT015 -pub(crate) fn assert_falsy(checker: &mut Checker, stmt: &Stmt, test: &Expr) { +pub(crate) fn assert_falsy(checker: &Checker, stmt: &Stmt, test: &Expr) { let truthiness = Truthiness::from_expr(test, |id| checker.semantic().has_builtin_binding(id)); if truthiness.into_bool() == Some(false) { - checker - .diagnostics - .push(Diagnostic::new(PytestAssertAlwaysFalse, stmt.range())); + checker.report_diagnostic(Diagnostic::new(PytestAssertAlwaysFalse, stmt.range())); } } /// PT017 -pub(crate) fn assert_in_exception_handler(checker: &mut Checker, handlers: &[ExceptHandler]) { - checker - .diagnostics - .extend(handlers.iter().flat_map(|handler| match handler { - ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { - name, body, .. - }) => { - if let Some(name) = name { - check_assert_in_except(name, body) - } else { - Vec::new() - } +pub(crate) fn assert_in_exception_handler(checker: &Checker, handlers: &[ExceptHandler]) { + checker.report_diagnostics(handlers.iter().flat_map(|handler| match handler { + ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { name, body, .. }) => { + if let Some(name) = name { + check_assert_in_except(name, body) + } else { + Vec::new() } - })); + } + })); } #[derive(Copy, Clone)] @@ -830,12 +824,7 @@ fn fix_composite_condition(stmt: &Stmt, locator: &Locator, stylist: &Stylist) -> } /// PT018 -pub(crate) fn composite_condition( - checker: &mut Checker, - stmt: &Stmt, - test: &Expr, - msg: Option<&Expr>, -) { +pub(crate) fn composite_condition(checker: &Checker, stmt: &Stmt, test: &Expr, msg: Option<&Expr>) { let composite = is_composite_condition(test); if matches!(composite, CompositionKind::Simple | CompositionKind::Mixed) { let mut diagnostic = Diagnostic::new(PytestCompositeAssertion, stmt.range()); @@ -851,6 +840,6 @@ pub(crate) fn composite_condition( .map(Fix::unsafe_edit) }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs index 1d756f237d9b9..1702f25b1ea55 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs @@ -55,7 +55,7 @@ impl Violation for PytestFailWithoutMessage { } } -pub(crate) fn fail_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn fail_call(checker: &Checker, call: &ast::ExprCall) { if is_pytest_fail(&call.func, checker.semantic()) { // Allow either `pytest.fail(reason="...")` (introduced in pytest 7.0) or // `pytest.fail(msg="...")` (deprecated in pytest 7.0) @@ -65,9 +65,7 @@ pub(crate) fn fail_call(checker: &mut Checker, call: &ast::ExprCall) { .or_else(|| call.arguments.find_argument_value("msg", 0)) .map_or(true, is_empty_or_null_string) { - checker - .diagnostics - .push(Diagnostic::new(PytestFailWithoutMessage, call.func.range())); + checker.report_diagnostic(Diagnostic::new(PytestFailWithoutMessage, call.func.range())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs index e900b280bcae9..f655665060634 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs @@ -664,7 +664,7 @@ fn fixture_decorator<'a>( } fn pytest_fixture_parentheses( - checker: &mut Checker, + checker: &Checker, decorator: &Decorator, fix: Fix, expected: Parentheses, @@ -675,11 +675,11 @@ fn pytest_fixture_parentheses( decorator.range(), ); diagnostic.set_fix(fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// PT001, PT002, PT003 -fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &Decorator) { +fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decorator) { match &decorator.expression { Expr::Call(ast::ExprCall { func, @@ -704,7 +704,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D if checker.enabled(Rule::PytestFixturePositionalArgs) { if !arguments.args.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestFixturePositionalArgs { function: func_name.to_string(), }, @@ -727,7 +727,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D ) .map(Fix::unsafe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -753,7 +753,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D } /// PT022 -fn check_fixture_returns(checker: &mut Checker, name: &str, body: &[Stmt], returns: Option<&Expr>) { +fn check_fixture_returns(checker: &Checker, name: &str, body: &[Stmt], returns: Option<&Expr>) { let mut visitor = SkipFunctionsVisitor::default(); for stmt in body { @@ -802,16 +802,16 @@ fn check_fixture_returns(checker: &mut Checker, name: &str, body: &[Stmt], retur } else { diagnostic.set_fix(Fix::safe_edit(yield_edit)); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// PT019 -fn check_test_function_args(checker: &mut Checker, parameters: &Parameters) { +fn check_test_function_args(checker: &Checker, parameters: &Parameters) { for parameter in parameters.iter_non_variadic_params() { let name = parameter.name(); if name.starts_with('_') { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestFixtureParamWithoutValue { name: name.to_string(), }, @@ -822,9 +822,9 @@ fn check_test_function_args(checker: &mut Checker, parameters: &Parameters) { } /// PT020 -fn check_fixture_decorator_name(checker: &mut Checker, decorator: &Decorator) { +fn check_fixture_decorator_name(checker: &Checker, decorator: &Decorator) { if is_pytest_yield_fixture(decorator, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestDeprecatedYieldFixture, decorator.range(), )); @@ -832,7 +832,7 @@ fn check_fixture_decorator_name(checker: &mut Checker, decorator: &Decorator) { } /// PT021 -fn check_fixture_addfinalizer(checker: &mut Checker, parameters: &Parameters, body: &[Stmt]) { +fn check_fixture_addfinalizer(checker: &Checker, parameters: &Parameters, body: &[Stmt]) { if !parameters.includes("request") { return; } @@ -844,7 +844,7 @@ fn check_fixture_addfinalizer(checker: &mut Checker, parameters: &Parameters, bo } if let Some(addfinalizer) = visitor.addfinalizer_call { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestFixtureFinalizerCallback, addfinalizer.range(), )); @@ -852,7 +852,7 @@ fn check_fixture_addfinalizer(checker: &mut Checker, parameters: &Parameters, bo } /// PT024, PT025 -fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) { +fn check_fixture_marks(checker: &Checker, decorators: &[Decorator]) { for (expr, marker) in get_mark_decorators(decorators) { if checker.enabled(Rule::PytestUnnecessaryAsyncioMarkOnFixture) { if marker == "asyncio" { @@ -860,7 +860,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) { Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range()); let range = checker.locator().full_lines_range(expr.range()); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(range))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -870,14 +870,14 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) { Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range()); let line_range = checker.locator().full_lines_range(expr.range()); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(line_range))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } } pub(crate) fn fixture( - checker: &mut Checker, + checker: &Checker, name: &str, parameters: &Parameters, returns: Option<&Expr>, diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs index 8365526a566fd..e538db57da29f 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs @@ -119,7 +119,7 @@ impl AlwaysFixableViolation for PytestUseFixturesWithoutParameters { } fn pytest_mark_parentheses( - checker: &mut Checker, + checker: &Checker, decorator: &Decorator, marker: &str, fix: Fix, @@ -135,10 +135,10 @@ fn pytest_mark_parentheses( decorator.range(), ); diagnostic.set_fix(fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } -fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, marker: &str) { +fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str) { match &decorator.expression { Expr::Call(ast::ExprCall { func, @@ -184,7 +184,7 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, marker: } } -fn check_useless_usefixtures(checker: &mut Checker, decorator: &Decorator, marker: &str) { +fn check_useless_usefixtures(checker: &Checker, decorator: &Decorator, marker: &str) { if marker != "usefixtures" { return; } @@ -206,10 +206,10 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Decorator, marke let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range()); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_deletion(decorator.range()))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } -pub(crate) fn marks(checker: &mut Checker, decorators: &[Decorator]) { +pub(crate) fn marks(checker: &Checker, decorators: &[Decorator]) { let enforce_parentheses = checker.enabled(Rule::PytestIncorrectMarkParenthesesStyle); let enforce_useless_usefixtures = checker.enabled(Rule::PytestUseFixturesWithoutParameters); diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index fa26390f340f4..44e54842cc57b 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -331,7 +331,7 @@ fn get_parametrize_name_range( } /// PT006 -fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr) { +fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr) { let names_type = checker.settings.flake8_pytest_style.parametrize_names_type; match expr { @@ -373,7 +373,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & format!("({})", checker.generator().expr(&node)), name_range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } types::ParametrizeNameType::List => { let name_range = get_parametrize_name_range( @@ -408,7 +408,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & checker.generator().expr(&node), name_range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } types::ParametrizeNameType::Csv => {} } @@ -437,7 +437,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & checker.generator().expr(&node), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } types::ParametrizeNameType::Csv => { let mut diagnostic = Diagnostic::new( @@ -455,7 +455,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } }; @@ -484,7 +484,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & format!("({})", checker.generator().expr(&node)), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } types::ParametrizeNameType::Csv => { let mut diagnostic = Diagnostic::new( @@ -502,7 +502,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } }; @@ -512,7 +512,7 @@ fn check_names(checker: &mut Checker, call: &ExprCall, expr: &Expr, argvalues: & } /// PT007 -fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) { +fn check_values(checker: &Checker, names: &Expr, values: &Expr) { let values_type = checker.settings.flake8_pytest_style.parametrize_values_type; let values_row_type = checker @@ -568,7 +568,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) { ); Fix::unsafe_edits(values_start, [values_end]) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } if is_multi_named { @@ -616,7 +616,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) { Fix::unsafe_edits(values_start, [values_end]) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } if is_multi_named { @@ -648,7 +648,7 @@ fn trailing_comma(element: &Expr, source: &str, max_index: TextSize) -> TextSize } /// PT014 -fn check_duplicates(checker: &mut Checker, values: &Expr) { +fn check_duplicates(checker: &Checker, values: &Expr) { let (Expr::List(ast::ExprList { elts, .. }) | Expr::Tuple(ast::ExprTuple { elts, .. })) = values else { @@ -677,14 +677,14 @@ fn check_duplicates(checker: &mut Checker, values: &Expr) { diagnostic.set_fix(Fix::unsafe_edit(Edit::range_deletion(deletion_range))); } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); }) .or_insert(index); prev = Some(element); } } -fn handle_single_name(checker: &mut Checker, argnames: &Expr, value: &Expr, argvalues: &Expr) { +fn handle_single_name(checker: &Checker, argnames: &Expr, value: &Expr, argvalues: &Expr) { let mut diagnostic = Diagnostic::new( PytestParametrizeNamesWrongType { single_argument: true, @@ -728,7 +728,7 @@ fn handle_single_name(checker: &mut Checker, argnames: &Expr, value: &Expr, argv Fix::safe_edits(argnames_edit, argvalues_edits) }; diagnostic.set_fix(fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Generate [`Edit`]s to unpack single-element lists or tuples in the given [`Expr`]. @@ -764,7 +764,7 @@ fn unpack_single_element_items(checker: &Checker, expr: &Expr) -> Vec { } fn handle_value_rows( - checker: &mut Checker, + checker: &Checker, elts: &[Expr], values_type: types::ParametrizeValuesType, values_row_type: types::ParametrizeValuesRowType, @@ -811,7 +811,7 @@ fn handle_value_rows( let elt_end = Edit::replacement("]".into(), start, elt.end()); Fix::unsafe_edits(elt_start, [elt_end]) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } Expr::List(ast::ExprList { elts, .. }) => { @@ -855,7 +855,7 @@ fn handle_value_rows( ); Fix::unsafe_edits(elt_start, [elt_end]) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } _ => {} @@ -863,7 +863,7 @@ fn handle_value_rows( } } -pub(crate) fn parametrize(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn parametrize(checker: &Checker, call: &ExprCall) { if !is_pytest_parametrize(call, checker.semantic()) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs index 15f41487406d9..ebaf2e722afbb 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs @@ -172,11 +172,11 @@ const fn is_non_trivial_with_body(body: &[Stmt]) -> bool { } } -pub(crate) fn raises_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn raises_call(checker: &Checker, call: &ast::ExprCall) { if is_pytest_raises(&call.func, checker.semantic()) { if checker.enabled(Rule::PytestRaisesWithoutException) { if call.arguments.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestRaisesWithoutException, call.func.range(), )); @@ -197,12 +197,7 @@ pub(crate) fn raises_call(checker: &mut Checker, call: &ast::ExprCall) { } } -pub(crate) fn complex_raises( - checker: &mut Checker, - stmt: &Stmt, - items: &[WithItem], - body: &[Stmt], -) { +pub(crate) fn complex_raises(checker: &Checker, stmt: &Stmt, items: &[WithItem], body: &[Stmt]) { let raises_called = items.iter().any(|item| match &item.context_expr { Expr::Call(ast::ExprCall { func, .. }) => is_pytest_raises(func, checker.semantic()), _ => false, @@ -230,7 +225,7 @@ pub(crate) fn complex_raises( }; if is_too_complex { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestRaisesWithMultipleStatements, stmt.range(), )); @@ -239,7 +234,7 @@ pub(crate) fn complex_raises( } /// PT011 -fn exception_needs_match(checker: &mut Checker, exception: &Expr) { +fn exception_needs_match(checker: &Checker, exception: &Expr) { if let Some(qualified_name) = checker .semantic() .resolve_qualified_name(exception) @@ -260,7 +255,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) { .then_some(qualified_name) }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestRaisesTooBroad { exception: qualified_name, }, diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/test_functions.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/test_functions.rs index ace23d9634aa8..39ae6e247c749 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/test_functions.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/test_functions.rs @@ -50,10 +50,7 @@ impl Violation for PytestParameterWithDefaultArgument { } /// PT028 -pub(crate) fn parameter_with_default_argument( - checker: &mut Checker, - function_def: &StmtFunctionDef, -) { +pub(crate) fn parameter_with_default_argument(checker: &Checker, function_def: &StmtFunctionDef) { if !is_likely_pytest_test(function_def, checker) { return; } @@ -67,6 +64,6 @@ pub(crate) fn parameter_with_default_argument( let diagnostic = Diagnostic::new(kind, default.range()); let edit = Edit::deletion(parameter.parameter.end(), parameter.end()); let fix = Fix::display_only_edit(edit); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs index 086b46212451b..df92a3e653af8 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs @@ -171,11 +171,11 @@ const fn is_non_trivial_with_body(body: &[Stmt]) -> bool { } /// PT029, PT030 -pub(crate) fn warns_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn warns_call(checker: &Checker, call: &ast::ExprCall) { if is_pytest_warns(&call.func, checker.semantic()) { if checker.enabled(Rule::PytestWarnsWithoutWarning) { if call.arguments.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestWarnsWithoutWarning, call.func.range(), )); @@ -197,7 +197,7 @@ pub(crate) fn warns_call(checker: &mut Checker, call: &ast::ExprCall) { } /// PT031 -pub(crate) fn complex_warns(checker: &mut Checker, stmt: &Stmt, items: &[WithItem], body: &[Stmt]) { +pub(crate) fn complex_warns(checker: &Checker, stmt: &Stmt, items: &[WithItem], body: &[Stmt]) { let warns_called = items.iter().any(|item| match &item.context_expr { Expr::Call(ast::ExprCall { func, .. }) => is_pytest_warns(func, checker.semantic()), _ => false, @@ -225,7 +225,7 @@ pub(crate) fn complex_warns(checker: &mut Checker, stmt: &Stmt, items: &[WithIte }; if is_too_complex { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestWarnsWithMultipleStatements, stmt.range(), )); @@ -234,7 +234,7 @@ pub(crate) fn complex_warns(checker: &mut Checker, stmt: &Stmt, items: &[WithIte } /// PT030 -fn warning_needs_match(checker: &mut Checker, warning: &Expr) { +fn warning_needs_match(checker: &Checker, warning: &Expr) { if let Some(qualified_name) = checker .semantic() @@ -256,7 +256,7 @@ fn warning_needs_match(checker: &mut Checker, warning: &Expr) { .then_some(qualified_name) }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PytestWarnsTooBroad { warning: qualified_name, }, diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs index bf9b354be6edd..a76469f0b32da 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for AvoidableEscapedQuote { } /// Q003 -pub(crate) fn avoidable_escaped_quote(checker: &mut Checker, string_like: StringLike) { +pub(crate) fn avoidable_escaped_quote(checker: &Checker, string_like: StringLike) { if checker.semantic().in_pep_257_docstring() || checker.semantic().in_string_type_definition() // This rule has support for strings nested inside another f-strings but they're checked @@ -75,7 +75,7 @@ pub(crate) fn avoidable_escaped_quote(checker: &mut Checker, string_like: String } } - checker.diagnostics.extend(rule_checker.into_diagnostics()); + checker.report_diagnostics(rule_checker.into_diagnostics()); } /// Checks for `Q003` violations using the [`Visitor`] implementation. diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs index 7d2cc9874039e..764df33109724 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs @@ -250,7 +250,7 @@ fn text_ends_at_quote(locator: &Locator, range: TextRange, quote: Quote) -> bool } /// Q002 -fn docstring(checker: &mut Checker, range: TextRange) { +fn docstring(checker: &Checker, range: TextRange) { let quotes_settings = &checker.settings.flake8_quotes; let locator = checker.locator(); @@ -261,7 +261,7 @@ fn docstring(checker: &mut Checker, range: TextRange) { { // Fixing this would result in a one-sided multi-line docstring, which would // introduce a syntax error. - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadQuotesDocstring { preferred_quote: quotes_settings.docstring_quotes, }, @@ -298,11 +298,11 @@ fn docstring(checker: &mut Checker, range: TextRange) { fixed_contents, range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Q000, Q001 -fn strings(checker: &mut Checker, sequence: &[TextRange]) { +fn strings(checker: &Checker, sequence: &[TextRange]) { let quotes_settings = &checker.settings.flake8_quotes; let locator = checker.locator(); @@ -373,7 +373,7 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) { fixed_contents, *range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else if trivia.last_quote_char != quotes_settings.inline_quotes.as_char() // If we're not using the preferred type, only allow use to avoid escapes. && !relax_quote @@ -391,7 +391,7 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) { // ```python // ''"assert" ' SAM macro definitions ''' // ``` - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadQuotesInlineString { preferred_quote: quotes_settings.inline_quotes, }, @@ -406,7 +406,7 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) { // ```python // ''"assert" ' SAM macro definitions ''' // ``` - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadQuotesInlineString { preferred_quote: quotes_settings.inline_quotes, }, @@ -433,13 +433,13 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) { fixed_contents, *range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } /// Generate `flake8-quote` diagnostics from a token stream. -pub(crate) fn check_string_quotes(checker: &mut Checker, string_like: StringLike) { +pub(crate) fn check_string_quotes(checker: &Checker, string_like: StringLike) { // Ignore if the string is part of a forward reference. For example, // `x: "Literal['foo', 'bar']"`. if checker.semantic().in_string_type_definition() { diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs index 22f5e8eba8f5a..5789d77a644b9 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs @@ -46,7 +46,7 @@ impl AlwaysFixableViolation for UnnecessaryEscapedQuote { } /// Q004 -pub(crate) fn unnecessary_escaped_quote(checker: &mut Checker, string_like: StringLike) { +pub(crate) fn unnecessary_escaped_quote(checker: &Checker, string_like: StringLike) { if checker.semantic().in_pep_257_docstring() { return; } @@ -61,7 +61,7 @@ pub(crate) fn unnecessary_escaped_quote(checker: &mut Checker, string_like: Stri string_literal.range(), AnyStringFlags::from(string_literal.flags), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } ast::StringLikePart::Bytes(bytes_literal) => { @@ -70,12 +70,12 @@ pub(crate) fn unnecessary_escaped_quote(checker: &mut Checker, string_like: Stri bytes_literal.range(), AnyStringFlags::from(bytes_literal.flags), ) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } ast::StringLikePart::FString(f_string) => { if let Some(diagnostic) = check_f_string(locator, f_string) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs index 16cb02e00bac9..07390d0350561 100644 --- a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs @@ -53,7 +53,7 @@ impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException { } /// RSE102 -pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: &Expr) { +pub(crate) fn unnecessary_paren_on_raise_exception(checker: &Checker, expr: &Expr) { let Expr::Call(ast::ExprCall { func, arguments, @@ -141,7 +141,7 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index fe0acbd62b67c..2cd869848c560 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -366,7 +366,7 @@ impl Violation for SuperfluousElseBreak { } /// RET501 -fn unnecessary_return_none(checker: &mut Checker, decorator_list: &[Decorator], stack: &Stack) { +fn unnecessary_return_none(checker: &Checker, decorator_list: &[Decorator], stack: &Stack) { for stmt in &stack.returns { let Some(expr) = stmt.value.as_deref() else { continue; @@ -389,12 +389,12 @@ fn unnecessary_return_none(checker: &mut Checker, decorator_list: &[Decorator], "return".to_string(), stmt.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// RET502 -fn implicit_return_value(checker: &mut Checker, stack: &Stack) { +fn implicit_return_value(checker: &Checker, stack: &Stack) { for stmt in &stack.returns { if stmt.value.is_some() { continue; @@ -404,7 +404,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) { "return None".to_string(), stmt.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -453,7 +453,7 @@ fn is_noreturn_func(func: &Expr, semantic: &SemanticModel) -> bool { || semantic.match_typing_qualified_name(&qualified_name, "Never") } -fn add_return_none(checker: &mut Checker, stmt: &Stmt, range: TextRange) { +fn add_return_none(checker: &Checker, stmt: &Stmt, range: TextRange) { let mut diagnostic = Diagnostic::new(ImplicitReturn, range); if let Some(indent) = indentation(checker.source(), stmt) { let mut content = String::new(); @@ -465,7 +465,7 @@ fn add_return_none(checker: &mut Checker, stmt: &Stmt, range: TextRange) { end_of_last_statement(stmt, checker.locator()), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns a list of all implicit returns in the given statement. @@ -545,7 +545,7 @@ fn implicit_returns<'a>(checker: &Checker, stmt: &'a Stmt) -> Vec<&'a Stmt> { } /// RET503 -fn implicit_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef, stmt: &Stmt) { +fn implicit_return(checker: &Checker, function_def: &ast::StmtFunctionDef, stmt: &Stmt) { let implicit_stmts = implicit_returns(checker, stmt); if implicit_stmts.is_empty() { @@ -562,7 +562,7 @@ fn implicit_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef, s } /// RET504 -fn unnecessary_assign(checker: &mut Checker, stack: &Stack) { +fn unnecessary_assign(checker: &Checker, stack: &Stack) { for (assign, return_, stmt) in &stack.assignment_return { // Identify, e.g., `return x`. let Some(value) = return_.value.as_ref() else { @@ -651,13 +651,13 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack) { Ok(Fix::unsafe_edits(replace_assign, [delete_return])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// RET505, RET506, RET507, RET508 fn superfluous_else_node( - checker: &mut Checker, + checker: &Checker, if_elif_body: &[Stmt], elif_else: &ElifElseClause, ) -> bool { @@ -682,7 +682,7 @@ fn superfluous_else_node( checker.stylist(), ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } return true; } else if child.is_break_stmt() { @@ -701,7 +701,7 @@ fn superfluous_else_node( ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } return true; } else if child.is_raise_stmt() { @@ -720,7 +720,7 @@ fn superfluous_else_node( ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } return true; } else if child.is_continue_stmt() { @@ -739,7 +739,7 @@ fn superfluous_else_node( ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } return true; } @@ -748,14 +748,14 @@ fn superfluous_else_node( } /// RET505, RET506, RET507, RET508 -fn superfluous_elif_else(checker: &mut Checker, stack: &Stack) { +fn superfluous_elif_else(checker: &Checker, stack: &Stack) { for (if_elif_body, elif_else) in &stack.elifs_elses { superfluous_else_node(checker, if_elif_body, elif_else); } } /// Run all checks from the `flake8-return` plugin. -pub(crate) fn function(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn function(checker: &Checker, function_def: &ast::StmtFunctionDef) { let ast::StmtFunctionDef { decorator_list, returns, diff --git a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs index a6548cbd30584..7437fde65762e 100644 --- a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs +++ b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs @@ -64,7 +64,7 @@ impl Violation for PrivateMemberAccess { } /// SLF001 -pub(crate) fn private_member_access(checker: &mut Checker, expr: &Expr) { +pub(crate) fn private_member_access(checker: &Checker, expr: &Expr) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = expr else { return; }; @@ -206,7 +206,7 @@ pub(crate) fn private_member_access(checker: &mut Checker, expr: &Expr) { } } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PrivateMemberAccess { access: attr.to_string(), }, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index d5cce6f530d65..bc63d55994120 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -325,7 +325,7 @@ fn isinstance_target<'a>(call: &'a Expr, semantic: &'a SemanticModel) -> Option< } /// SIM101 -pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { +pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { let Expr::BoolOp(ast::ExprBoolOp { op: BoolOp::Or, values, @@ -462,7 +462,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -493,7 +493,7 @@ fn match_eq_target(expr: &Expr) -> Option<(&Name, &Expr)> { } /// SIM109 -pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { +pub(crate) fn compare_with_tuple(checker: &Checker, expr: &Expr) { let Expr::BoolOp(ast::ExprBoolOp { op: BoolOp::Or, values, @@ -584,12 +584,12 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { checker.generator().expr(&in_expr), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// SIM220 -pub(crate) fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) { +pub(crate) fn expr_and_not_expr(checker: &Checker, expr: &Expr) { let Expr::BoolOp(ast::ExprBoolOp { op: BoolOp::And, values, @@ -639,14 +639,14 @@ pub(crate) fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) { "False".to_string(), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } } /// SIM221 -pub(crate) fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) { +pub(crate) fn expr_or_not_expr(checker: &Checker, expr: &Expr) { let Expr::BoolOp(ast::ExprBoolOp { op: BoolOp::Or, values, @@ -696,7 +696,7 @@ pub(crate) fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) { "True".to_string(), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -832,7 +832,7 @@ fn is_short_circuit( } /// SIM222 -pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) { +pub(crate) fn expr_or_true(checker: &Checker, expr: &Expr) { if checker.semantic().in_string_type_definition() { return; } @@ -846,12 +846,12 @@ pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) { edit.range(), ); diagnostic.set_fix(Fix::unsafe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// SIM223 -pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) { +pub(crate) fn expr_and_false(checker: &Checker, expr: &Expr) { if checker.semantic().in_string_type_definition() { return; } @@ -865,6 +865,6 @@ pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) { edit.range(), ); diagnostic.set_fix(Fix::unsafe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index f47c97a87b6b6..5131b6ad0fd55 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -121,7 +121,7 @@ fn is_lowercase_allowed(env_var: &str) -> bool { } /// SIM112 -pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Expr) { +pub(crate) fn use_capital_environment_variables(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::OS) { return; } @@ -169,7 +169,7 @@ pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Ex return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UncapitalizedEnvironmentVariables { expected: SourceCodeSnippet::new(capital_env_var), actual: SourceCodeSnippet::new(env_var.to_string()), @@ -178,7 +178,7 @@ pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Ex )); } -fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) { +fn check_os_environ_subscript(checker: &Checker, expr: &Expr) { let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = expr else { return; }; @@ -232,11 +232,11 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) { checker.generator().expr(&new_env_var), slice.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM910 -pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) { +pub(crate) fn dict_get_with_none_default(checker: &Checker, expr: &Expr) { let Expr::Call(ast::ExprCall { func, arguments: Arguments { args, keywords, .. }, @@ -303,5 +303,5 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) { expected, expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index 313e37ebd509d..568238894b65d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -140,7 +140,7 @@ impl AlwaysFixableViolation for IfExprWithTwistedArms { /// SIM210 pub(crate) fn if_expr_with_true_false( - checker: &mut Checker, + checker: &Checker, expr: &Expr, test: &Expr, body: &Expr, @@ -196,12 +196,12 @@ pub(crate) fn if_expr_with_true_false( expr.range(), ))); }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM211 pub(crate) fn if_expr_with_false_true( - checker: &mut Checker, + checker: &Checker, expr: &Expr, test: &Expr, body: &Expr, @@ -223,12 +223,12 @@ pub(crate) fn if_expr_with_false_true( ), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM212 pub(crate) fn twisted_arms_in_ifexpr( - checker: &mut Checker, + checker: &Checker, expr: &Expr, test: &Expr, body: &Expr, @@ -277,5 +277,5 @@ pub(crate) fn twisted_arms_in_ifexpr( checker.generator().expr(&node3.into()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index 2d8dc052c5f67..94c851f58a0b1 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -144,12 +144,7 @@ fn is_exception_check(stmt: &Stmt) -> bool { } /// SIM201 -pub(crate) fn negation_with_equal_op( - checker: &mut Checker, - expr: &Expr, - op: UnaryOp, - operand: &Expr, -) { +pub(crate) fn negation_with_equal_op(checker: &Checker, expr: &Expr, op: UnaryOp, operand: &Expr) { if !matches!(op, UnaryOp::Not) { return; } @@ -195,12 +190,12 @@ pub(crate) fn negation_with_equal_op( checker.generator().expr(&node.into()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM202 pub(crate) fn negation_with_not_equal_op( - checker: &mut Checker, + checker: &Checker, expr: &Expr, op: UnaryOp, operand: &Expr, @@ -250,11 +245,11 @@ pub(crate) fn negation_with_not_equal_op( checker.generator().expr(&node.into()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM208 -pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, operand: &Expr) { +pub(crate) fn double_negation(checker: &Checker, expr: &Expr, op: UnaryOp, operand: &Expr) { if !matches!(op, UnaryOp::Not) { return; } @@ -301,5 +296,5 @@ pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, o expr.range(), ))); }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs index 906aff0c25a53..fff6dace5be09 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs @@ -89,7 +89,7 @@ fn next_with(body: &[Stmt]) -> Option<(bool, &[WithItem], &[Stmt])> { /// with resource1(), resource2(): /// ... /// ``` -fn explicit_with_items(checker: &mut Checker, with_items: &[WithItem]) -> bool { +fn explicit_with_items(checker: &Checker, with_items: &[WithItem]) -> bool { let [with_item] = with_items else { return false; }; @@ -114,7 +114,7 @@ fn explicit_with_items(checker: &mut Checker, with_items: &[WithItem]) -> bool { /// SIM117 pub(crate) fn multiple_with_statements( - checker: &mut Checker, + checker: &Checker, with_stmt: &ast::StmtWith, with_parent: Option<&Stmt>, ) { @@ -195,6 +195,6 @@ pub(crate) fn multiple_with_statements( } }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs index 6ede86a536585..76aa2fe5e65c2 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs @@ -63,7 +63,7 @@ impl Violation for CollapsibleIf { /// SIM102 pub(crate) fn nested_if_statements( - checker: &mut Checker, + checker: &Checker, stmt_if: &ast::StmtIf, parent: Option<&Stmt>, ) { @@ -138,7 +138,7 @@ pub(crate) fn nested_if_statements( } }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy)] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs index bcace9ac01e0e..b056845bfe9f3 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs @@ -48,7 +48,7 @@ impl Violation for EnumerateForLoop { } /// SIM113 -pub(crate) fn enumerate_for_loop(checker: &mut Checker, for_stmt: &ast::StmtFor) { +pub(crate) fn enumerate_for_loop(checker: &Checker, for_stmt: &ast::StmtFor) { // If the loop is async, abort. if for_stmt.is_async { return; @@ -145,7 +145,7 @@ pub(crate) fn enumerate_for_loop(checker: &mut Checker, for_stmt: &ast::StmtFor) }, stmt.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs index d090638e0999b..d7a43a37ba9cf 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs @@ -71,7 +71,7 @@ impl Violation for IfElseBlockInsteadOfDictGet { } /// SIM401 -pub(crate) fn if_else_block_instead_of_dict_get(checker: &mut Checker, stmt_if: &ast::StmtIf) { +pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast::StmtIf) { let ast::StmtIf { test, body, @@ -229,12 +229,12 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &mut Checker, stmt_if: stmt_if.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM401 pub(crate) fn if_exp_instead_of_dict_get( - checker: &mut Checker, + checker: &Checker, expr: &Expr, test: &Expr, body: &Expr, @@ -318,5 +318,5 @@ pub(crate) fn if_exp_instead_of_dict_get( expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs index 2c4aa4ce2f3d4..9775e441482db 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs @@ -40,7 +40,7 @@ impl Violation for IfElseBlockInsteadOfDictLookup { } } /// SIM116 -pub(crate) fn if_else_block_instead_of_dict_lookup(checker: &mut Checker, stmt_if: &ast::StmtIf) { +pub(crate) fn if_else_block_instead_of_dict_lookup(checker: &Checker, stmt_if: &ast::StmtIf) { // Throughout this rule: // * Each if or elif statement's test must consist of a constant equality check with the same variable. // * Each if or elif statement's body must consist of a single `return`. @@ -156,7 +156,7 @@ pub(crate) fn if_else_block_instead_of_dict_lookup(checker: &mut Checker, stmt_i return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( IfElseBlockInsteadOfDictLookup, stmt_if.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs index 8e2b40a966d8f..d96d11df9da8d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs @@ -89,7 +89,7 @@ impl Violation for IfElseBlockInsteadOfIfExp { } /// SIM108 -pub(crate) fn if_else_block_instead_of_if_exp(checker: &mut Checker, stmt_if: &ast::StmtIf) { +pub(crate) fn if_else_block_instead_of_if_exp(checker: &Checker, stmt_if: &ast::StmtIf) { let ast::StmtIf { test, body, @@ -241,7 +241,7 @@ pub(crate) fn if_else_block_instead_of_if_exp(checker: &mut Checker, stmt_if: &a stmt_if.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs index 829826d982e96..df402fc2cd74d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs @@ -52,7 +52,7 @@ impl Violation for IfWithSameArms { } /// SIM114 -pub(crate) fn if_with_same_arms(checker: &mut Checker, stmt_if: &ast::StmtIf) { +pub(crate) fn if_with_same_arms(checker: &Checker, stmt_if: &ast::StmtIf) { let mut branches_iter = if_elif_branches(stmt_if).peekable(); while let Some(current_branch) = branches_iter.next() { let Some(following_branch) = branches_iter.peek() else { @@ -102,7 +102,7 @@ pub(crate) fn if_with_same_arms(checker: &mut Checker, stmt_if: &ast::StmtIf) { ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs index f73c91bde5b5f..e1e1e069b3a9e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -55,13 +55,7 @@ impl AlwaysFixableViolation for InDictKeys { } /// SIM118 -fn key_in_dict( - checker: &mut Checker, - left: &Expr, - right: &Expr, - operator: CmpOp, - parent: AnyNodeRef, -) { +fn key_in_dict(checker: &Checker, left: &Expr, right: &Expr, operator: CmpOp, parent: AnyNodeRef) { let Expr::Call(ast::ExprCall { func, arguments: Arguments { args, keywords, .. }, @@ -164,11 +158,11 @@ fn key_in_dict( )); } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// SIM118 in a `for` loop. -pub(crate) fn key_in_dict_for(checker: &mut Checker, for_stmt: &ast::StmtFor) { +pub(crate) fn key_in_dict_for(checker: &Checker, for_stmt: &ast::StmtFor) { key_in_dict( checker, &for_stmt.target, @@ -179,7 +173,7 @@ pub(crate) fn key_in_dict_for(checker: &mut Checker, for_stmt: &ast::StmtFor) { } /// SIM118 in a comprehension. -pub(crate) fn key_in_dict_comprehension(checker: &mut Checker, comprehension: &Comprehension) { +pub(crate) fn key_in_dict_comprehension(checker: &Checker, comprehension: &Comprehension) { key_in_dict( checker, &comprehension.target, @@ -190,7 +184,7 @@ pub(crate) fn key_in_dict_comprehension(checker: &mut Checker, comprehension: &C } /// SIM118 in a comparison. -pub(crate) fn key_in_dict_compare(checker: &mut Checker, compare: &ast::ExprCompare) { +pub(crate) fn key_in_dict_compare(checker: &Checker, compare: &ast::ExprCompare) { let [op] = &*compare.ops else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs index 320fdb21a4384..091a4bcc098bd 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs @@ -82,7 +82,7 @@ impl Violation for NeedlessBool { } /// SIM103 -pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { let Stmt::If(stmt_if) = stmt else { return }; let ast::StmtIf { test: if_test, @@ -306,7 +306,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) { range, ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs index 9d1c72d709674..e17aeb59de4bd 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs @@ -197,7 +197,7 @@ fn is_immediately_closed(semantic: &SemanticModel) -> bool { } /// SIM115 -pub(crate) fn open_file_with_context_handler(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn open_file_with_context_handler(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); if !is_open_call(semantic, call) { @@ -238,7 +238,7 @@ pub(crate) fn open_file_with_context_handler(checker: &mut Checker, call: &ast:: } } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( OpenFileWithContextHandler, call.func.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 4109a0e3febb1..f2da4443ff69c 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -58,7 +58,7 @@ impl Violation for ReimplementedBuiltin { } /// SIM110, SIM111 -pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { if !checker.semantic().current_scope().kind.is_function() { return; } @@ -120,7 +120,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) { terminal.stmt.end(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } // Replace with `all`. (false, true) => { @@ -212,7 +212,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) { terminal.stmt.end(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } _ => {} } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs index 5682dd6c4252e..de8cce737483e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs @@ -56,7 +56,7 @@ fn find_return(stmts: &[Stmt]) -> Option<&Stmt> { /// SIM107 pub(crate) fn return_in_try_except_finally( - checker: &mut Checker, + checker: &Checker, body: &[Stmt], handlers: &[ExceptHandler], finalbody: &[Stmt], @@ -69,7 +69,7 @@ pub(crate) fn return_in_try_except_finally( if try_has_return || except_has_return { if let Some(finally_return) = find_return(finalbody) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ReturnInTryExceptFinally, finally_return.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs index f58ed95342fde..c475d7a9c3ac2 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs @@ -59,7 +59,7 @@ impl Violation for SplitStaticString { /// SIM905 pub(crate) fn split_static_string( - checker: &mut Checker, + checker: &Checker, attr: &str, call: &ExprCall, str_value: &StringLiteralValue, @@ -112,7 +112,7 @@ pub(crate) fn split_static_string( }, )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn construct_replacement(elts: &[&str], flags: StringLiteralFlags) -> Expr { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs index d5659bb839275..49cfabae59521 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -72,7 +72,7 @@ fn is_empty(body: &[Stmt]) -> bool { /// SIM105 pub(crate) fn suppressible_exception( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, try_body: &[Stmt], handlers: &[ExceptHandler], @@ -147,5 +147,5 @@ pub(crate) fn suppressible_exception( )) }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs index df0be0a8f978f..9afd4812dfa98 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -203,7 +203,7 @@ fn reverse_comparison(expr: &Expr, locator: &Locator, stylist: &Stylist) -> Resu /// SIM300 pub(crate) fn yoda_conditions( - checker: &mut Checker, + checker: &Checker, expr: &Expr, left: &Expr, ops: &[CmpOp], @@ -235,9 +235,9 @@ pub(crate) fn yoda_conditions( pad(suggestion, expr.range(), checker.locator()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( YodaConditions { suggestion: None }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs index 1bd0f485eb1d9..f1dc612919c22 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for ZipDictKeysAndValues { } /// SIM911 -pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ast::ExprCall) { +pub(crate) fn zip_dict_keys_and_values(checker: &Checker, expr: &ast::ExprCall) { let ast::ExprCall { func, arguments: Arguments { args, keywords, .. }, @@ -113,7 +113,7 @@ pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ast::ExprCa expected, expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn get_var_attr(expr: &Expr) -> Option<(&ExprName, &Identifier)> { diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs index 4e8b53f2730db..f02e9e5b84b6c 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs @@ -74,7 +74,7 @@ impl fmt::Display for NamedTupleKind { /// SLOT002 pub(crate) fn no_slots_in_namedtuple_subclass( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, class: &StmtClassDef, ) { @@ -88,7 +88,7 @@ pub(crate) fn no_slots_in_namedtuple_subclass( if let Some(namedtuple_kind) = namedtuple_base(bases, checker.semantic()) { if !has_slots(&class.body) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NoSlotsInNamedtupleSubclass(namedtuple_kind), stmt.identifier(), )); diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs index c86cc9affa31b..7df55a4b009c1 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs @@ -49,7 +49,7 @@ impl Violation for NoSlotsInStrSubclass { } /// SLOT000 -pub(crate) fn no_slots_in_str_subclass(checker: &mut Checker, stmt: &Stmt, class: &StmtClassDef) { +pub(crate) fn no_slots_in_str_subclass(checker: &Checker, stmt: &Stmt, class: &StmtClassDef) { // https://github.com/astral-sh/ruff/issues/14535 if checker.source_type.is_stub() { return; @@ -73,9 +73,7 @@ pub(crate) fn no_slots_in_str_subclass(checker: &mut Checker, stmt: &Stmt, class return; } - checker - .diagnostics - .push(Diagnostic::new(NoSlotsInStrSubclass, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new(NoSlotsInStrSubclass, stmt.identifier())); } /// Return `true` if the class is a subclass of `str`. diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs index be2724efc9fd9..639cdc128961f 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs @@ -50,7 +50,7 @@ impl Violation for NoSlotsInTupleSubclass { } /// SLOT001 -pub(crate) fn no_slots_in_tuple_subclass(checker: &mut Checker, stmt: &Stmt, class: &StmtClassDef) { +pub(crate) fn no_slots_in_tuple_subclass(checker: &Checker, stmt: &Stmt, class: &StmtClassDef) { // https://github.com/astral-sh/ruff/issues/14535 if checker.source_type.is_stub() { return; @@ -66,9 +66,7 @@ pub(crate) fn no_slots_in_tuple_subclass(checker: &mut Checker, stmt: &Stmt, cla semantic.match_builtin_expr(base, "tuple") || semantic.match_typing_expr(base, "Tuple") }) { if !has_slots(&class.body) { - checker - .diagnostics - .push(Diagnostic::new(NoSlotsInTupleSubclass, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new(NoSlotsInTupleSubclass, stmt.identifier())); } } } diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs index 867463b95dfc1..f92c0c684f971 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs @@ -39,11 +39,11 @@ impl Violation for BannedApi { } /// TID251 -pub(crate) fn banned_api(checker: &mut Checker, policy: &NameMatchPolicy, node: &T) { +pub(crate) fn banned_api(checker: &Checker, policy: &NameMatchPolicy, node: &T) { let banned_api = &checker.settings.flake8_tidy_imports.banned_api; if let Some(banned_module) = policy.find(banned_api.keys().map(AsRef::as_ref)) { if let Some(reason) = banned_api.get(&banned_module) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BannedApi { name: banned_module, message: reason.msg.to_string(), @@ -55,7 +55,7 @@ pub(crate) fn banned_api(checker: &mut Checker, policy: &NameMatchPol } /// TID251 -pub(crate) fn banned_attribute_access(checker: &mut Checker, expr: &Expr) { +pub(crate) fn banned_attribute_access(checker: &Checker, expr: &Expr) { let banned_api = &checker.settings.flake8_tidy_imports.banned_api; if banned_api.is_empty() { return; @@ -71,7 +71,7 @@ pub(crate) fn banned_attribute_access(checker: &mut Checker, expr: &Expr) { }) }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BannedApi { name: banned_path.to_string(), message: ban.msg.to_string(), diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs index 9ad6fe2eaaa08..3b27c63e9c85f 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs @@ -56,7 +56,7 @@ impl Violation for BannedModuleLevelImports { } /// TID253 -pub(crate) fn banned_module_level_imports(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn banned_module_level_imports(checker: &Checker, stmt: &Stmt) { if !checker.semantic().at_top_level() { return; } @@ -68,7 +68,7 @@ pub(crate) fn banned_module_level_imports(checker: &mut Checker, stmt: &Stmt) { .flake8_tidy_imports .banned_module_level_imports(), ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BannedModuleLevelImports { name: banned_module, }, diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs index 52eee84523f08..303114a9a3435 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs @@ -47,7 +47,7 @@ impl AlwaysFixableViolation for EmptyTypeCheckingBlock { } /// TC005 -pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtIf) { +pub(crate) fn empty_type_checking_block(checker: &Checker, stmt: &ast::StmtIf) { if !typing::is_type_checking_block(stmt, checker.semantic()) { return; } @@ -71,5 +71,5 @@ pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtI diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_parent_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs index d627829e665cf..b3b94e6e88270 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs @@ -57,7 +57,7 @@ impl AlwaysFixableViolation for RuntimeCastValue { } /// TC006 -pub(crate) fn runtime_cast_value(checker: &mut Checker, type_expr: &Expr) { +pub(crate) fn runtime_cast_value(checker: &Checker, type_expr: &Expr) { if type_expr.is_string_literal_expr() { return; } @@ -75,5 +75,5 @@ pub(crate) fn runtime_cast_value(checker: &mut Checker, type_expr: &Expr) { } else { diagnostic.set_fix(Fix::safe_edit(edit)); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs index a61c7bcec1db2..3fe243cdc09c4 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs @@ -97,11 +97,7 @@ enum Action { } /// TC004 -pub(crate) fn runtime_import_in_type_checking_block( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn runtime_import_in_type_checking_block(checker: &Checker, scope: &Scope) { // Collect all runtime imports by statement. let mut actions: FxHashMap<(NodeId, Action), Vec> = FxHashMap::default(); @@ -206,7 +202,7 @@ pub(crate) fn runtime_import_in_type_checking_block( if let Some(fix) = fix.as_ref() { diagnostic.set_fix(fix.clone()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -233,7 +229,7 @@ pub(crate) fn runtime_import_in_type_checking_block( diagnostic.set_parent(range.start()); } diagnostic.set_fix(fix.clone()); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -257,7 +253,7 @@ pub(crate) fn runtime_import_in_type_checking_block( if let Some(range) = parent_range { diagnostic.set_parent(range.start()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs index ab849880897ca..b9379e9c16e1e 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs @@ -52,7 +52,7 @@ impl Violation for RuntimeStringUnion { } /// TC010 -pub(crate) fn runtime_string_union(checker: &mut Checker, expr: &Expr) { +pub(crate) fn runtime_string_union(checker: &Checker, expr: &Expr) { if !checker.semantic().in_type_definition() { return; } @@ -66,9 +66,7 @@ pub(crate) fn runtime_string_union(checker: &mut Checker, expr: &Expr) { traverse_op(expr, &mut strings); for string in strings { - checker - .diagnostics - .push(Diagnostic::new(RuntimeStringUnion, string.range())); + checker.report_diagnostic(Diagnostic::new(RuntimeStringUnion, string.range())); } } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs index ae94a2b9a9792..2a43e9724a183 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs @@ -267,7 +267,7 @@ fn collect_typing_references<'a>( /// TC008 pub(crate) fn quoted_type_alias( - checker: &mut Checker, + checker: &Checker, expr: &Expr, annotation_expr: &ast::ExprStringLiteral, ) { @@ -297,7 +297,7 @@ pub(crate) fn quoted_type_alias( } else { diagnostic.set_fix(Fix::safe_edit(edit)); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Traverses the type expression and checks if the expression can safely diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs index d49c465c7bd6d..ad873a8534d46 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs @@ -248,7 +248,6 @@ pub(crate) fn typing_only_runtime_import( checker: &Checker, scope: &Scope, runtime_imports: &[&Binding], - diagnostics: &mut Vec, ) { // Collect all typing-only imports by statement and import type. let mut errors_by_statement: FxHashMap<(NodeId, ImportType), Vec> = @@ -381,7 +380,7 @@ pub(crate) fn typing_only_runtime_import( if let Some(fix) = fix.as_ref() { diagnostic.set_fix(fix.clone()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -402,7 +401,7 @@ pub(crate) fn typing_only_runtime_import( if let Some(range) = parent_range { diagnostic.set_parent(range.start()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs index 5aacd3985dd03..8af376968312d 100644 --- a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs +++ b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs @@ -1,4 +1,3 @@ -use regex::Regex; use ruff_python_ast as ast; use ruff_python_ast::{Parameter, Parameters, Stmt, StmtExpr, StmtFunctionDef, StmtRaise}; @@ -246,15 +245,11 @@ impl Argumentable { } /// Check a plain function for unused arguments. -fn function( - argumentable: Argumentable, - parameters: &Parameters, - scope: &Scope, - semantic: &SemanticModel, - dummy_variable_rgx: &Regex, - ignore_variadic_names: bool, - diagnostics: &mut Vec, -) { +fn function(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) { + let ignore_variadic_names = checker + .settings + .flake8_unused_arguments + .ignore_variadic_names; let args = parameters .iter_non_variadic_params() .map(|parameter_with_default| ¶meter_with_default.parameter) @@ -272,26 +267,15 @@ fn function( .into_iter() .skip(usize::from(ignore_variadic_names)), ); - call( - argumentable, - args, - scope, - semantic, - dummy_variable_rgx, - diagnostics, - ); + call(argumentable, args, scope, checker); } /// Check a method for unused arguments. -fn method( - argumentable: Argumentable, - parameters: &Parameters, - scope: &Scope, - semantic: &SemanticModel, - dummy_variable_rgx: &Regex, - ignore_variadic_names: bool, - diagnostics: &mut Vec, -) { +fn method(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) { + let ignore_variadic_names = checker + .settings + .flake8_unused_arguments + .ignore_variadic_names; let args = parameters .iter_non_variadic_params() .skip(1) @@ -310,25 +294,18 @@ fn method( .into_iter() .skip(usize::from(ignore_variadic_names)), ); - call( - argumentable, - args, - scope, - semantic, - dummy_variable_rgx, - diagnostics, - ); + call(argumentable, args, scope, checker); } fn call<'a>( argumentable: Argumentable, parameters: impl Iterator, scope: &Scope, - semantic: &SemanticModel, - dummy_variable_rgx: &Regex, - diagnostics: &mut Vec, + checker: &Checker, ) { - diagnostics.extend(parameters.filter_map(|arg| { + let semantic = checker.semantic(); + let dummy_variable_rgx = &checker.settings.dummy_variable_rgx; + checker.report_diagnostics(parameters.filter_map(|arg| { let binding = scope .get(arg.name()) .map(|binding_id| semantic.binding(binding_id))?; @@ -404,11 +381,7 @@ pub(crate) fn is_not_implemented_stub_with_variable( } /// ARG001, ARG002, ARG003, ARG004, ARG005 -pub(crate) fn unused_arguments( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_arguments(checker: &Checker, scope: &Scope) { if scope.uses_locals() { return; } @@ -440,18 +413,7 @@ pub(crate) fn unused_arguments( && !is_not_implemented_stub_with_variable(function_def, checker.semantic()) && !visibility::is_overload(decorator_list, checker.semantic()) { - function( - Argumentable::Function, - parameters, - scope, - checker.semantic(), - &checker.settings.dummy_variable_rgx, - checker - .settings - .flake8_unused_arguments - .ignore_variadic_names, - diagnostics, - ); + function(Argumentable::Function, parameters, scope, checker); } } function_type::FunctionType::Method => { @@ -466,18 +428,7 @@ pub(crate) fn unused_arguments( && !visibility::is_override(decorator_list, checker.semantic()) && !visibility::is_overload(decorator_list, checker.semantic()) { - method( - Argumentable::Method, - parameters, - scope, - checker.semantic(), - &checker.settings.dummy_variable_rgx, - checker - .settings - .flake8_unused_arguments - .ignore_variadic_names, - diagnostics, - ); + method(Argumentable::Method, parameters, scope, checker); } } function_type::FunctionType::ClassMethod => { @@ -492,18 +443,7 @@ pub(crate) fn unused_arguments( && !visibility::is_override(decorator_list, checker.semantic()) && !visibility::is_overload(decorator_list, checker.semantic()) { - method( - Argumentable::ClassMethod, - parameters, - scope, - checker.semantic(), - &checker.settings.dummy_variable_rgx, - checker - .settings - .flake8_unused_arguments - .ignore_variadic_names, - diagnostics, - ); + method(Argumentable::ClassMethod, parameters, scope, checker); } } function_type::FunctionType::StaticMethod => { @@ -518,18 +458,7 @@ pub(crate) fn unused_arguments( && !visibility::is_override(decorator_list, checker.semantic()) && !visibility::is_overload(decorator_list, checker.semantic()) { - function( - Argumentable::StaticMethod, - parameters, - scope, - checker.semantic(), - &checker.settings.dummy_variable_rgx, - checker - .settings - .flake8_unused_arguments - .ignore_variadic_names, - diagnostics, - ); + function(Argumentable::StaticMethod, parameters, scope, checker); } } } @@ -537,18 +466,7 @@ pub(crate) fn unused_arguments( ScopeKind::Lambda(ast::ExprLambda { parameters, .. }) => { if let Some(parameters) = parameters { if checker.enabled(Argumentable::Lambda.rule_code()) { - function( - Argumentable::Lambda, - parameters, - scope, - checker.semantic(), - &checker.settings.dummy_variable_rgx, - checker - .settings - .flake8_unused_arguments - .ignore_variadic_names, - diagnostics, - ); + function(Argumentable::Lambda, parameters, scope, checker); } } } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/invalid_pathlib_with_suffix.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/invalid_pathlib_with_suffix.rs index 60790c16f820e..142650ed6a395 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/invalid_pathlib_with_suffix.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/invalid_pathlib_with_suffix.rs @@ -78,7 +78,7 @@ impl Violation for InvalidPathlibWithSuffix { } /// PTH210 -pub(crate) fn invalid_pathlib_with_suffix(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn invalid_pathlib_with_suffix(checker: &Checker, call: &ast::ExprCall) { let (func, arguments) = (&call.func, &call.arguments); if !is_path_with_suffix_call(checker.semantic(), func) { @@ -117,7 +117,7 @@ pub(crate) fn invalid_pathlib_with_suffix(checker: &mut Checker, call: &ast::Exp ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn is_path_with_suffix_call(semantic: &SemanticModel, func: &ast::Expr) -> bool { diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs index e075a5c8dfdcc..49244ba24065d 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs @@ -63,7 +63,7 @@ impl Violation for OsSepSplit { } /// PTH206 -pub(crate) fn os_sep_split(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn os_sep_split(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::OS) { return; } @@ -94,7 +94,5 @@ pub(crate) fn os_sep_split(checker: &mut Checker, call: &ast::ExprCall) { return; } - checker - .diagnostics - .push(Diagnostic::new(OsSepSplit, attr.range())); + checker.report_diagnostic(Diagnostic::new(OsSepSplit, attr.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index 7eb043e1a2212..9efa42132b9b4 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for PathConstructorCurrentDirectory { } /// PTH201 -pub(crate) fn path_constructor_current_directory(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn path_constructor_current_directory(checker: &Checker, call: &ExprCall) { let applicability = |range| { if checker.comment_ranges().intersects(range) { Applicability::Unsafe @@ -112,7 +112,7 @@ pub(crate) fn path_constructor_current_directory(checker: &mut Checker, call: &E }), }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn parent_and_next_path_fragment_range( diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index aee3bd32dcae5..41582bbf78f85 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -17,7 +17,7 @@ use crate::rules::flake8_use_pathlib::violations::{ }; use crate::settings::types::PythonVersion; -pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) { if let Some(diagnostic_kind) = checker .semantic() .resolve_qualified_name(&call.func) @@ -163,7 +163,7 @@ pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, call: &ExprCall) { let diagnostic = Diagnostic::new::(diagnostic_kind, call.func.range()); if checker.enabled(diagnostic.kind.rule()) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs index eec40c57a08d5..eccba401f506d 100644 --- a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs @@ -111,7 +111,7 @@ fn build_fstring(joiner: &str, joinees: &[Expr], flags: FStringFlags) -> Option< } /// FLY002 -pub(crate) fn static_join_to_fstring(checker: &mut Checker, expr: &Expr, joiner: &str) { +pub(crate) fn static_join_to_fstring(checker: &Checker, expr: &Expr, joiner: &str) { let Expr::Call(ast::ExprCall { arguments: Arguments { args, keywords, .. }, .. @@ -154,5 +154,5 @@ pub(crate) fn static_join_to_fstring(checker: &mut Checker, expr: &Expr, joiner: pad(contents, expr.range(), checker.locator()), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs index 054108afafeb5..06a61d9373bd7 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs @@ -55,7 +55,7 @@ impl Violation for NumpyDeprecatedFunction { } /// NPY003 -pub(crate) fn deprecated_function(checker: &mut Checker, expr: &Expr) { +pub(crate) fn deprecated_function(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::NUMPY) { return; } @@ -89,6 +89,6 @@ pub(crate) fn deprecated_function(checker: &mut Checker, expr: &Expr) { let replacement_edit = Edit::range_replacement(binding, expr.range()); Ok(Fix::safe_edits(import_edit, [replacement_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs index 096e43c92c698..675a6692688cd 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs @@ -51,7 +51,7 @@ impl Violation for NumpyDeprecatedTypeAlias { } /// NPY001 -pub(crate) fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) { +pub(crate) fn deprecated_type_alias(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::NUMPY) { return; } @@ -93,6 +93,6 @@ pub(crate) fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) { let binding_edit = Edit::range_replacement(binding, expr.range()); Ok(Fix::safe_edits(binding_edit, import_edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs b/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs index b175d24fe85f8..4174d8e6e3bd8 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs @@ -59,7 +59,7 @@ impl Violation for NumpyLegacyRandom { } /// NPY002 -pub(crate) fn legacy_random(checker: &mut Checker, expr: &Expr) { +pub(crate) fn legacy_random(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::NUMPY) { return; } @@ -137,7 +137,7 @@ pub(crate) fn legacy_random(checker: &mut Checker, expr: &Expr) { } }) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NumpyLegacyRandom { method_name: method_name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs index f31b506adec53..e5f7be5479331 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs @@ -156,7 +156,7 @@ enum Compatibility { } /// NPY201 -pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) { +pub(crate) fn numpy_2_0_deprecation(checker: &Checker, expr: &Expr) { let semantic = checker.semantic(); if !semantic.seen_module(Modules::NUMPY) { @@ -706,7 +706,7 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) { )), Details::Manual { guideline: _ } => {} }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Ignore attempts to access a `numpy` member via its deprecated name diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs index facd3aac07736..7fec3e4decff4 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs @@ -44,7 +44,7 @@ impl Violation for PandasUseOfDotValues { } /// PD011 -pub(crate) fn attr(checker: &mut Checker, attribute: &ast::ExprAttribute) { +pub(crate) fn attr(checker: &Checker, attribute: &ast::ExprAttribute) { if !checker.semantic().seen_module(Modules::PANDAS) { return; } @@ -77,7 +77,5 @@ pub(crate) fn attr(checker: &mut Checker, attribute: &ast::ExprAttribute) { return; } - checker - .diagnostics - .push(Diagnostic::new(PandasUseOfDotValues, attribute.range())); + checker.report_diagnostic(Diagnostic::new(PandasUseOfDotValues, attribute.range())); } diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs index acef895fe318b..ce69acc79067c 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs @@ -163,7 +163,7 @@ impl Violation for PandasUseOfDotStack { } } -pub(crate) fn call(checker: &mut Checker, func: &Expr) { +pub(crate) fn call(checker: &Checker, func: &Expr) { if !checker.semantic().seen_module(Modules::PANDAS) { return; } @@ -200,7 +200,5 @@ pub(crate) fn call(checker: &mut Checker, func: &Expr) { return; } - checker - .diagnostics - .push(Diagnostic::new(violation, func.range())); + checker.report_diagnostic(Diagnostic::new(violation, func.range())); } diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs index cb56049e983d9..487a23e4a700a 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs @@ -51,7 +51,7 @@ impl Violation for PandasUseOfInplaceArgument { } /// PD002 -pub(crate) fn inplace_argument(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn inplace_argument(checker: &Checker, call: &ast::ExprCall) { // If the function was imported from another module, and it's _not_ Pandas, abort. if checker .semantic() @@ -100,7 +100,7 @@ pub(crate) fn inplace_argument(checker: &mut Checker, call: &ast::ExprCall) { } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } // Duplicate keywords is a syntax error, so we can stop here. diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs index 8d7e981882d08..8daed47a7c780 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs @@ -63,7 +63,7 @@ impl Violation for PandasNuniqueConstantSeriesCheck { /// PD101 pub(crate) fn nunique_constant_series_check( - checker: &mut Checker, + checker: &Checker, expr: &Expr, left: &Expr, ops: &[CmpOp], @@ -114,7 +114,7 @@ pub(crate) fn nunique_constant_series_check( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PandasNuniqueConstantSeriesCheck, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs index 1b13d9c74bee3..224ba9dbf9ae6 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs @@ -55,7 +55,7 @@ impl Violation for PandasUseOfPdMerge { } /// PD015 -pub(crate) fn use_of_pd_merge(checker: &mut Checker, func: &Expr) { +pub(crate) fn use_of_pd_merge(checker: &Checker, func: &Expr) { if !checker.semantic().seen_module(Modules::PANDAS) { return; } @@ -63,9 +63,7 @@ pub(crate) fn use_of_pd_merge(checker: &mut Checker, func: &Expr) { if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func { if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() { if id == "pd" && attr == "merge" { - checker - .diagnostics - .push(Diagnostic::new(PandasUseOfPdMerge, func.range())); + checker.report_diagnostic(Diagnostic::new(PandasUseOfPdMerge, func.range())); } } } diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs index 0b52c24737adc..3a41259c4960e 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs @@ -46,7 +46,7 @@ impl Violation for PandasUseOfDotReadTable { } /// PD012 -pub(crate) fn use_of_read_table(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn use_of_read_table(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::PANDAS) { return; } @@ -63,8 +63,7 @@ pub(crate) fn use_of_read_table(checker: &mut Checker, call: &ast::ExprCall) { { if value == "," { checker - .diagnostics - .push(Diagnostic::new(PandasUseOfDotReadTable, call.func.range())); + .report_diagnostic(Diagnostic::new(PandasUseOfDotReadTable, call.func.range())); } } } diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs index 5e43c1cd5234e..4831569b1f172 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs @@ -143,7 +143,7 @@ impl Violation for PandasUseOfDotIat { } } -pub(crate) fn subscript(checker: &mut Checker, value: &Expr, expr: &Expr) { +pub(crate) fn subscript(checker: &Checker, value: &Expr, expr: &Expr) { if !checker.semantic().seen_module(Modules::PANDAS) { return; } @@ -170,7 +170,5 @@ pub(crate) fn subscript(checker: &mut Checker, value: &Expr, expr: &Expr) { return; } - checker - .diagnostics - .push(Diagnostic::new(violation, expr.range())); + checker.report_diagnostic(Diagnostic::new(violation, expr.range())); } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs index 6c8c5d69f3535..358180802c89d 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs @@ -53,10 +53,7 @@ impl Violation for InvalidArgumentName { } /// N803 -pub(crate) fn invalid_argument_name_function( - checker: &mut Checker, - function_def: &StmtFunctionDef, -) { +pub(crate) fn invalid_argument_name_function(checker: &Checker, function_def: &StmtFunctionDef) { let semantic = checker.semantic(); let scope = semantic.current_scope(); @@ -71,7 +68,7 @@ pub(crate) fn invalid_argument_name_function( } /// N803 -pub(crate) fn invalid_argument_name_lambda(checker: &mut Checker, lambda: &ExprLambda) { +pub(crate) fn invalid_argument_name_lambda(checker: &Checker, lambda: &ExprLambda) { let Some(parameters) = &lambda.parameters else { return; }; @@ -80,7 +77,7 @@ pub(crate) fn invalid_argument_name_lambda(checker: &mut Checker, lambda: &ExprL } /// N803 -fn invalid_argument_name(checker: &mut Checker, parameters: &Parameters) { +fn invalid_argument_name(checker: &Checker, parameters: &Parameters) { let ignore_names = &checker.settings.pep8_naming.ignore_names; for parameter in parameters { @@ -101,6 +98,6 @@ fn invalid_argument_name(checker: &mut Checker, parameters: &Parameters) { parameter.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs index 731ba2ef5c3ce..c61a5a7e4d73f 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs @@ -176,11 +176,7 @@ impl FunctionType { } /// N804, N805 -pub(crate) fn invalid_first_argument_name( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn invalid_first_argument_name(checker: &Checker, scope: &Scope) { let ScopeKind::Function(ast::StmtFunctionDef { name, parameters, @@ -258,7 +254,7 @@ pub(crate) fn invalid_first_argument_name( checker.stylist(), ) }); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Rename the first parameter to `self` or `cls`, if no other parameter has the target name. diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs index 86856052f833d..f7a7614a85c60 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs @@ -51,7 +51,7 @@ impl Violation for MixedCaseVariableInClassScope { /// N815 pub(crate) fn mixed_case_variable_in_class_scope( - checker: &mut Checker, + checker: &Checker, expr: &Expr, name: &str, class_def: &ast::StmtClassDef, @@ -72,7 +72,7 @@ pub(crate) fn mixed_case_variable_in_class_scope( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( MixedCaseVariableInClassScope { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs index 8ddadbd95b62a..3463617afd193 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs @@ -61,7 +61,7 @@ impl Violation for MixedCaseVariableInGlobalScope { } /// N816 -pub(crate) fn mixed_case_variable_in_global_scope(checker: &mut Checker, expr: &Expr, name: &str) { +pub(crate) fn mixed_case_variable_in_global_scope(checker: &Checker, expr: &Expr, name: &str) { if !helpers::is_mixed_case(name) { return; } @@ -75,7 +75,7 @@ pub(crate) fn mixed_case_variable_in_global_scope(checker: &mut Checker, expr: & return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( MixedCaseVariableInGlobalScope { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs index 99e28b43eda66..c580d2149cb6f 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs @@ -52,7 +52,7 @@ impl Violation for NonLowercaseVariableInFunction { } /// N806 -pub(crate) fn non_lowercase_variable_in_function(checker: &mut Checker, expr: &Expr, name: &str) { +pub(crate) fn non_lowercase_variable_in_function(checker: &Checker, expr: &Expr, name: &str) { if str::is_lowercase(name) { return; } @@ -81,7 +81,7 @@ pub(crate) fn non_lowercase_variable_in_function(checker: &mut Checker, expr: &E return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonLowercaseVariableInFunction { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs index f262d65c17dbc..c6f4a4d4230e8 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs @@ -62,7 +62,7 @@ impl AlwaysFixableViolation for IncorrectDictIterator { } /// PERF102 -pub(crate) fn incorrect_dict_iterator(checker: &mut Checker, stmt_for: &ast::StmtFor) { +pub(crate) fn incorrect_dict_iterator(checker: &Checker, stmt_for: &ast::StmtFor) { let Expr::Tuple(ast::ExprTuple { elts, .. }) = stmt_for.target.as_ref() else { return; }; @@ -115,7 +115,7 @@ pub(crate) fn incorrect_dict_iterator(checker: &mut Checker, stmt_for: &ast::Stm stmt_for.target.range(), ); diagnostic.set_fix(Fix::unsafe_edits(replace_attribute, [replace_target])); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } (false, true) => { // The value is unused, so replace with `dict.keys()`. @@ -135,7 +135,7 @@ pub(crate) fn incorrect_dict_iterator(checker: &mut Checker, stmt_for: &ast::Stm stmt_for.target.range(), ); diagnostic.set_fix(Fix::unsafe_edits(replace_attribute, [replace_target])); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs index 413a3b4d90e02..97f53cb55ce7a 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs @@ -52,7 +52,7 @@ impl Violation for ManualDictComprehension { } /// PERF403 -pub(crate) fn manual_dict_comprehension(checker: &mut Checker, target: &Expr, body: &[Stmt]) { +pub(crate) fn manual_dict_comprehension(checker: &Checker, target: &Expr, body: &[Stmt]) { let (stmt, if_test) = match body { // ```python // for idx, name in enumerate(names): @@ -164,7 +164,5 @@ pub(crate) fn manual_dict_comprehension(checker: &mut Checker, target: &Expr, bo return; } - checker - .diagnostics - .push(Diagnostic::new(ManualDictComprehension, *range)); + checker.report_diagnostic(Diagnostic::new(ManualDictComprehension, *range)); } diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs index e38e8efae64ae..752678546b4d6 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs @@ -96,7 +96,7 @@ impl Violation for ManualListComprehension { } /// PERF401 -pub(crate) fn manual_list_comprehension(checker: &mut Checker, for_stmt: &ast::StmtFor) { +pub(crate) fn manual_list_comprehension(checker: &Checker, for_stmt: &ast::StmtFor) { let Expr::Name(ast::ExprName { id: for_stmt_target_id, .. @@ -338,7 +338,7 @@ pub(crate) fn manual_list_comprehension(checker: &mut Checker, for_stmt: &ast::S }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn convert_to_list_extend( diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs index 6b42bcbfa4fe9..798647080881c 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs @@ -45,7 +45,7 @@ impl Violation for ManualListCopy { } /// PERF402 -pub(crate) fn manual_list_copy(checker: &mut Checker, for_stmt: &ast::StmtFor) { +pub(crate) fn manual_list_copy(checker: &Checker, for_stmt: &ast::StmtFor) { if for_stmt.is_async { return; } @@ -119,7 +119,5 @@ pub(crate) fn manual_list_copy(checker: &mut Checker, for_stmt: &ast::StmtFor) { return; } - checker - .diagnostics - .push(Diagnostic::new(ManualListCopy, *range)); + checker.report_diagnostic(Diagnostic::new(ManualListCopy, *range)); } diff --git a/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs b/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs index 64136aab35634..d611c5f28dd87 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs @@ -88,7 +88,7 @@ impl Violation for TryExceptInLoop { } /// PERF203 -pub(crate) fn try_except_in_loop(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn try_except_in_loop(checker: &Checker, body: &[Stmt]) { if checker.settings.target_version >= PythonVersion::Py311 { return; } @@ -107,9 +107,7 @@ pub(crate) fn try_except_in_loop(checker: &mut Checker, body: &[Stmt]) { return; } - checker - .diagnostics - .push(Diagnostic::new(TryExceptInLoop, handler.range())); + checker.report_diagnostic(Diagnostic::new(TryExceptInLoop, handler.range())); } /// Returns `true` if a `break` or `continue` statement is present in `body`. diff --git a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs index ed60d3e276d1b..2662e44e87e6e 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for UnnecessaryListCast { } /// PERF101 -pub(crate) fn unnecessary_list_cast(checker: &mut Checker, iter: &Expr, body: &[Stmt]) { +pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt]) { let Expr::Call(ast::ExprCall { func, arguments: @@ -88,7 +88,7 @@ pub(crate) fn unnecessary_list_cast(checker: &mut Checker, iter: &Expr, body: &[ }) => { let mut diagnostic = Diagnostic::new(UnnecessaryListCast, *list_range); diagnostic.set_fix(remove_cast(*list_range, *iterable_range)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Expr::Name(ast::ExprName { id, @@ -116,7 +116,7 @@ pub(crate) fn unnecessary_list_cast(checker: &mut Checker, iter: &Expr, body: &[ let mut diagnostic = Diagnostic::new(UnnecessaryListCast, *list_range); diagnostic.set_fix(remove_cast(*list_range, *iterable_range)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } _ => {} diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs index 1924f9804b451..bf306bf390f5e 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs @@ -45,12 +45,12 @@ impl Violation for AmbiguousVariableName { } /// E741 -pub(crate) fn ambiguous_variable_name(checker: &mut Checker, name: &str, range: TextRange) { +pub(crate) fn ambiguous_variable_name(checker: &Checker, name: &str, range: TextRange) { if checker.source_type.is_stub() { return; } if is_ambiguous_name(name) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AmbiguousVariableName(name.to_string()), range, )); diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs index 928f7ff1ebe2f..9844aa6ad934b 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for InvalidEscapeSequence { } /// W605 -pub(crate) fn invalid_escape_sequence(checker: &mut Checker, string_like: StringLike) { +pub(crate) fn invalid_escape_sequence(checker: &Checker, string_like: StringLike) { let locator = checker.locator(); for part in string_like.parts() { @@ -104,13 +104,7 @@ pub(crate) fn invalid_escape_sequence(checker: &mut Checker, string_like: String escape_chars_state } }; - check( - &mut checker.diagnostics, - locator, - part.start(), - part.flags(), - state, - ); + check(checker, locator, part.start(), part.flags(), state); } } @@ -242,7 +236,7 @@ fn analyze_escape_chars( /// a raw string. If we have seen valid escape characters, /// we manually add backslashes to each invalid escape character found. fn check( - diagnostics: &mut Vec, + checker: &Checker, locator: &Locator, // Start position of the expression that contains the source range. This is used to generate // the fix when the source range is part of the expression like in f-string which contains @@ -269,7 +263,7 @@ fn check( r"\".to_string(), invalid_escape_char.start() + TextSize::from(1), ))); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else { // Turn into raw string. @@ -302,7 +296,7 @@ fn check( ); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index b30ca36d2cb03..3bf860dd5a8d9 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -56,7 +56,7 @@ impl Violation for LambdaAssignment { /// E731 pub(crate) fn lambda_assignment( - checker: &mut Checker, + checker: &Checker, target: &Expr, value: &Expr, annotation: Option<&Expr>, @@ -130,7 +130,7 @@ pub(crate) fn lambda_assignment( } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Extract the argument types and return type from a `Callable` annotation. diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs index 018cc4f0ae4ec..265d0c7046a6c 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -171,7 +171,7 @@ impl AlwaysFixableViolation for TrueFalseComparison { } /// E711, E712 -pub(crate) fn literal_comparisons(checker: &mut Checker, compare: &ast::ExprCompare) { +pub(crate) fn literal_comparisons(checker: &Checker, compare: &ast::ExprCompare) { // Mapping from (bad operator index) to (replacement operator). As we iterate // through the list of operators, we apply "dummy" fixes for each error, // then replace the entire expression at the end with one "real" fix, to @@ -347,5 +347,5 @@ pub(crate) fn literal_comparisons(checker: &mut Checker, compare: &ast::ExprComp } } - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs index a8381ed6b3b4d..d8b752cef356c 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs @@ -56,9 +56,9 @@ impl Violation for ModuleImportNotAtTopOfFile { } /// E402 -pub(crate) fn module_import_not_at_top_of_file(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn module_import_not_at_top_of_file(checker: &Checker, stmt: &Stmt) { if checker.semantic().seen_import_boundary() && checker.semantic().at_top_level() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ModuleImportNotAtTopOfFile { source_type: checker.source_type, }, diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs index 73d429d9719b6..deadfbbc0c974 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs @@ -47,7 +47,7 @@ impl Violation for MultipleImportsOnOneLine { } /// E401 -pub(crate) fn multiple_imports_on_one_line(checker: &mut Checker, stmt: &Stmt, names: &[Alias]) { +pub(crate) fn multiple_imports_on_one_line(checker: &Checker, stmt: &Stmt, names: &[Alias]) { if names.len() > 1 { let mut diagnostic = Diagnostic::new(MultipleImportsOnOneLine, stmt.range()); diagnostic.set_fix(split_imports( @@ -57,7 +57,7 @@ pub(crate) fn multiple_imports_on_one_line(checker: &mut Checker, stmt: &Stmt, n checker.indexer(), checker.stylist(), )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs index 8846160a719e2..efe474a2d31af 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs @@ -78,7 +78,7 @@ impl AlwaysFixableViolation for NotIsTest { } /// E713, E714 -pub(crate) fn not_tests(checker: &mut Checker, unary_op: &ast::ExprUnaryOp) { +pub(crate) fn not_tests(checker: &Checker, unary_op: &ast::ExprUnaryOp) { if !unary_op.op.is_not() { return; } @@ -112,7 +112,7 @@ pub(crate) fn not_tests(checker: &mut Checker, unary_op: &ast::ExprUnaryOp) { ), unary_op.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } [CmpOp::Is] => { @@ -133,7 +133,7 @@ pub(crate) fn not_tests(checker: &mut Checker, unary_op: &ast::ExprUnaryOp) { ), unary_op.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } _ => {} diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs index 386d29f8518ac..2b596320a11de 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -60,7 +60,7 @@ impl Violation for TypeComparison { } /// E721 -pub(crate) fn type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) { +pub(crate) fn type_comparison(checker: &Checker, compare: &ast::ExprCompare) { for (left, right) in std::iter::once(&*compare.left) .chain(&compare.comparators) .tuple_windows() @@ -76,9 +76,7 @@ pub(crate) fn type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) } // Disallow the comparison. - checker - .diagnostics - .push(Diagnostic::new(TypeComparison, compare.range())); + checker.report_diagnostic(Diagnostic::new(TypeComparison, compare.range())); } } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs index 64eb36ee17865..d3126e32ea8b8 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for WhitespaceAfterDecorator { } /// E204 -pub(crate) fn whitespace_after_decorator(checker: &mut Checker, decorator_list: &[Decorator]) { +pub(crate) fn whitespace_after_decorator(checker: &Checker, decorator_list: &[Decorator]) { for decorator in decorator_list { let decorator_text = checker.locator().slice(decorator); @@ -64,7 +64,7 @@ pub(crate) fn whitespace_after_decorator(checker: &mut Checker, decorator_list: let mut diagnostic = Diagnostic::new(WhitespaceAfterDecorator, range); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(range))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs index 78cf46f4a6f35..95fb57feedf2b 100644 --- a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs +++ b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs @@ -859,7 +859,7 @@ fn is_one_line(docstring: &Docstring) -> bool { /// DOC201, DOC202, DOC402, DOC403, DOC501, DOC502 pub(crate) fn check_docstring( - checker: &mut Checker, + checker: &Checker, definition: &Definition, docstring: &Docstring, section_contexts: &SectionContexts, @@ -1045,5 +1045,5 @@ pub(crate) fn check_docstring( } } - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs index c2bcc593e9344..ec2bcc6e94e0c 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs @@ -58,7 +58,7 @@ impl Violation for EscapeSequenceInDocstring { } /// D301 -pub(crate) fn backslashes(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn backslashes(checker: &Checker, docstring: &Docstring) { // Docstring is already raw. if docstring.leading_quote().contains(['r', 'R']) { return; @@ -106,7 +106,7 @@ pub(crate) fn backslashes(checker: &mut Checker, docstring: &Docstring) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); break; } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs index 5fc4936780935..0bf28ea7bf8f8 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -66,7 +66,7 @@ impl Violation for MissingBlankLineAfterSummary { } /// D205 -pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn blank_after_summary(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); if !docstring.triple_quoted() { @@ -118,6 +118,6 @@ pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) blank_end, ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs index c640183ef70c7..c970c2408d1c1 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -156,7 +156,7 @@ impl AlwaysFixableViolation for BlankLineBeforeClass { } /// D203, D204, D211 -pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn blank_before_after_class(checker: &Checker, docstring: &Docstring) { let Some(class) = docstring.definition.as_class_def() else { return; }; @@ -199,7 +199,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr blank_lines_start, docstring.start() - docstring.indentation.text_len(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if checker.enabled(Rule::IncorrectBlankLineBeforeClass) { @@ -212,7 +212,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr blank_lines_start, docstring.start() - docstring.indentation.text_len(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -259,7 +259,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr replacement_start, first_line.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); return; } else if trailing.starts_with('#') { // Keep the end-of-line comment, start counting empty lines after it @@ -287,7 +287,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr replacement_start, blank_lines_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs index b7ff84031bb09..edc732bd96eb9 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -102,7 +102,7 @@ static INNER_FUNCTION_OR_CLASS_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^\s+(?:(?:class|def|async def)\s|@)").unwrap()); /// D201, D202 -pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn blank_before_after_function(checker: &Checker, docstring: &Docstring) { let Some(function) = docstring.definition.as_function_def() else { return; }; @@ -137,7 +137,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc blank_lines_start, docstring.start() - docstring.indentation.text_len(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -191,7 +191,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc first_line_end, blank_lines_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs index 3bec13ba98b40..577e9c2f2dd88 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs @@ -53,7 +53,7 @@ impl AlwaysFixableViolation for FirstWordUncapitalized { } /// D403 -pub(crate) fn capitalized(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn capitalized(checker: &Checker, docstring: &Docstring) { if docstring.definition.as_function_def().is_none() { return; } @@ -103,5 +103,5 @@ pub(crate) fn capitalized(checker: &mut Checker, docstring: &Docstring) { TextRange::at(body.start() + leading_whitespace_len, first_word.text_len()), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs index 2b89579e1bc4d..e58c8bea68e06 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs @@ -63,7 +63,7 @@ impl Violation for MissingTrailingPeriod { } /// D400 -pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn ends_with_period(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); if let Some(first_line) = body.trim().universal_newlines().next() { @@ -114,7 +114,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) { line.start() + trimmed.text_len(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); }; } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs index 17fdf9dfce069..de70eb4bf5b96 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -62,7 +62,7 @@ impl Violation for MissingTerminalPunctuation { } /// D415 -pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn ends_with_punctuation(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); if let Some(first_line) = body.trim().universal_newlines().next() { @@ -113,7 +113,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring line.start() + trimmed.text_len(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); }; } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs index d7ab3230fbafa..d739d28283acb 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs @@ -77,12 +77,12 @@ impl Violation for OverloadWithDocstring { } /// D418 -pub(crate) fn if_needed(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn if_needed(checker: &Checker, docstring: &Docstring) { let Some(function) = docstring.definition.as_function_def() else { return; }; if is_overload(&function.decorator_list, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( OverloadWithDocstring, function.identifier(), )); diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs index ae59026687db5..0508dda0de5a7 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs @@ -166,7 +166,7 @@ impl AlwaysFixableViolation for OverIndentation { } /// D206, D207, D208 -pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn indent(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); // Split the docstring into lines. @@ -229,7 +229,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { clean_space(docstring.indentation), TextRange::at(line.start(), line_indent.text_len()), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -266,9 +266,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { if checker.enabled(Rule::DocstringTabIndentation) { if has_seen_tab { - checker - .diagnostics - .push(Diagnostic::new(DocstringTabIndentation, docstring.range())); + checker.report_diagnostic(Diagnostic::new(DocstringTabIndentation, docstring.range())); } } @@ -312,7 +310,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { Edit::range_replacement(indent, range) }; diagnostic.set_fix(Fix::safe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -334,7 +332,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { Edit::range_replacement(indent, range) }; diagnostic.set_fix(Fix::safe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs index 3351dd67b57a0..b21e7bafc3c53 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -136,7 +136,7 @@ impl AlwaysFixableViolation for MultiLineSummarySecondLine { } /// D212, D213 -pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn multi_line_summary_start(checker: &Checker, docstring: &Docstring) { let contents = docstring.contents; let body = docstring.body(); @@ -165,7 +165,7 @@ pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstr break; } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else if first_line.as_str().ends_with('\\') { // Ignore the edge case whether a single quoted string is multiple lines through an @@ -218,7 +218,7 @@ pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstr first_line.end(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs index d3fade6023b9c..1930e543425e1 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs @@ -58,7 +58,7 @@ impl AlwaysFixableViolation for NewLineAfterLastParagraph { } /// D209 -pub(crate) fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn newline_after_last_paragraph(checker: &Checker, docstring: &Docstring) { let contents = docstring.contents; let body = docstring.body(); @@ -99,7 +99,7 @@ pub(crate) fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Do docstring.end() - num_trailing_quotes - num_trailing_spaces, docstring.end() - num_trailing_quotes, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } return; diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs index 2ae17806c5586..d63f698f2ffef 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs @@ -51,7 +51,7 @@ impl Violation for SignatureInDocstring { } /// D402 -pub(crate) fn no_signature(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn no_signature(checker: &Checker, docstring: &Docstring) { let Some(function) = docstring.definition.as_function_def() else { return; }; @@ -86,8 +86,6 @@ pub(crate) fn no_signature(checker: &mut Checker, docstring: &Docstring) { true }) { - checker - .diagnostics - .push(Diagnostic::new(SignatureInDocstring, docstring.range())); + checker.report_diagnostic(Diagnostic::new(SignatureInDocstring, docstring.range())); } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs index 23f802cc3869b..69fd6d877fa46 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -48,7 +48,7 @@ impl Violation for SurroundingWhitespace { } /// D210 -pub(crate) fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn no_surrounding_whitespace(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); let mut lines = NewlineWithTrailingNewline::from(body.as_str()); @@ -72,5 +72,5 @@ pub(crate) fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docst TextRange::at(body.start(), line.text_len()), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs index a66f4bb03ab48..22b552bf32936 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs @@ -64,11 +64,7 @@ impl Violation for NonImperativeMood { } /// D401 -pub(crate) fn non_imperative_mood( - checker: &mut Checker, - docstring: &Docstring, - settings: &Settings, -) { +pub(crate) fn non_imperative_mood(checker: &Checker, docstring: &Docstring, settings: &Settings) { let Some(function) = docstring.definition.as_function_def() else { return; }; @@ -103,7 +99,7 @@ pub(crate) fn non_imperative_mood( } if matches!(MOOD.is_imperative(&first_word_norm), Some(false)) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonImperativeMood { first_line: first_line.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs index dd13f99b86946..b00392a246c42 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs @@ -40,15 +40,13 @@ impl Violation for EmptyDocstring { } /// D419 -pub(crate) fn not_empty(checker: &mut Checker, docstring: &Docstring) -> bool { +pub(crate) fn not_empty(checker: &Checker, docstring: &Docstring) -> bool { if !docstring.body().trim().is_empty() { return true; } if checker.enabled(Rule::EmptyDocstring) { - checker - .diagnostics - .push(Diagnostic::new(EmptyDocstring, docstring.range())); + checker.report_diagnostic(Diagnostic::new(EmptyDocstring, docstring.range())); } false } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs index b5b90b5530b97..6e1e208a02bae 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs @@ -531,7 +531,7 @@ impl Violation for UndocumentedPublicInit { /// D100, D101, D102, D103, D104, D105, D106, D107 pub(crate) fn not_missing( - checker: &mut Checker, + checker: &Checker, definition: &Definition, visibility: Visibility, ) -> bool { @@ -552,7 +552,7 @@ pub(crate) fn not_missing( return true; } if checker.enabled(Rule::UndocumentedPublicModule) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicModule, TextRange::default(), )); @@ -564,7 +564,7 @@ pub(crate) fn not_missing( .. }) => { if checker.enabled(Rule::UndocumentedPublicPackage) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicPackage, TextRange::default(), )); @@ -576,9 +576,10 @@ pub(crate) fn not_missing( .. }) => { if checker.enabled(Rule::UndocumentedPublicClass) { - checker - .diagnostics - .push(Diagnostic::new(UndocumentedPublicClass, class.identifier())); + checker.report_diagnostic(Diagnostic::new( + UndocumentedPublicClass, + class.identifier(), + )); } false } @@ -587,7 +588,7 @@ pub(crate) fn not_missing( .. }) => { if checker.enabled(Rule::UndocumentedPublicNestedClass) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicNestedClass, function.identifier(), )); @@ -602,7 +603,7 @@ pub(crate) fn not_missing( true } else { if checker.enabled(Rule::UndocumentedPublicFunction) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicFunction, function.identifier(), )); @@ -620,7 +621,7 @@ pub(crate) fn not_missing( true } else if is_init(&function.name) { if checker.enabled(Rule::UndocumentedPublicInit) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicInit, function.identifier(), )); @@ -628,7 +629,7 @@ pub(crate) fn not_missing( true } else if is_new(&function.name) || is_call(&function.name) { if checker.enabled(Rule::UndocumentedPublicMethod) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicMethod, function.identifier(), )); @@ -636,7 +637,7 @@ pub(crate) fn not_missing( true } else if is_magic(&function.name) { if checker.enabled(Rule::UndocumentedMagicMethod) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedMagicMethod, function.identifier(), )); @@ -644,7 +645,7 @@ pub(crate) fn not_missing( true } else { if checker.enabled(Rule::UndocumentedPublicMethod) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedPublicMethod, function.identifier(), )); diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs index bcfc4b9dea935..bf12f66565078 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs @@ -49,7 +49,7 @@ impl Violation for UnnecessaryMultilineDocstring { } /// D200 -pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn one_liner(checker: &Checker, docstring: &Docstring) { let mut line_count = 0; let mut non_empty_line_count = 0; for line in NewlineWithTrailingNewline::from(docstring.body().as_str()) { @@ -82,6 +82,6 @@ pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) { ))); } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index cb2bb953316f0..4ed42c66184bd 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -1322,7 +1322,7 @@ impl AlwaysFixableViolation for BlankLinesBetweenHeaderAndContent { /// D212, D214, D215, D405, D406, D407, D408, D409, D410, D411, D412, D413, /// D414, D416, D417 pub(crate) fn sections( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, section_contexts: &SectionContexts, convention: Option, @@ -1338,7 +1338,7 @@ pub(crate) fn sections( } fn blanks_and_section_underline( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, context: &SectionContext, style: SectionStyle, @@ -1374,7 +1374,7 @@ fn blanks_and_section_underline( blank_lines_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1393,7 +1393,7 @@ fn blanks_and_section_underline( dashed_line, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1419,7 +1419,7 @@ fn blanks_and_section_underline( Edit::range_replacement(contents, range) })); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1439,7 +1439,7 @@ fn blanks_and_section_underline( if following_lines.peek().is_none() { if checker.enabled(Rule::EmptyDocstringSection) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( EmptyDocstringSection { name: context.section_name().to_string(), }, @@ -1482,7 +1482,7 @@ fn blanks_and_section_underline( line_after_dashes.start(), blank_lines_after_dashes_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else { let mut diagnostic = Diagnostic::new( @@ -1496,13 +1496,13 @@ fn blanks_and_section_underline( line_after_dashes.start(), blank_lines_after_dashes_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } } else { if checker.enabled(Rule::EmptyDocstringSection) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( EmptyDocstringSection { name: context.section_name().to_string(), }, @@ -1527,7 +1527,7 @@ fn blanks_and_section_underline( equal_line, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else { let mut diagnostic = Diagnostic::new( MissingDashedUnderlineAfterSection { @@ -1548,7 +1548,7 @@ fn blanks_and_section_underline( context.summary_range().end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } if num_blank_lines_after_header > 0 { @@ -1588,7 +1588,7 @@ fn blanks_and_section_underline( context.following_range().start(), blank_lines_end, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else { let mut diagnostic = Diagnostic::new( @@ -1602,7 +1602,7 @@ fn blanks_and_section_underline( TextRange::new(context.following_range().start(), blank_lines_end); // Delete any blank lines between the header and content. diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(range))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -1629,10 +1629,10 @@ fn blanks_and_section_underline( context.summary_range().end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } if checker.enabled(Rule::EmptyDocstringSection) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( EmptyDocstringSection { name: context.section_name().to_string(), }, @@ -1643,7 +1643,7 @@ fn blanks_and_section_underline( } fn common_section( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, context: &SectionContext, next: Option<&SectionContext>, @@ -1665,7 +1665,7 @@ fn common_section( capitalized_section_name.to_string(), section_range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1688,7 +1688,7 @@ fn common_section( } else { Edit::range_replacement(content, fix_range) })); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1714,7 +1714,7 @@ fn common_section( line_end.to_string(), next.start(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } else { @@ -1752,7 +1752,7 @@ fn common_section( section_range, ); diagnostic.set_fix(Fix::safe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -1774,14 +1774,14 @@ fn common_section( line_end.to_string(), context.start(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } blanks_and_section_underline(checker, docstring, context, style); } -fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: &FxHashSet) { +fn missing_args(checker: &Checker, docstring: &Docstring, docstrings_args: &FxHashSet) { let Some(function) = docstring.definition.as_function_def() else { return; }; @@ -1832,7 +1832,7 @@ fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: & if !missing_arg_names.is_empty() { if let Some(definition) = docstring.definition.name() { let names = missing_arg_names.into_iter().sorted().collect(); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndocumentedParam { definition: definition.to_string(), names, @@ -1899,7 +1899,7 @@ fn args_section(context: &SectionContext) -> FxHashSet { .collect::>() } -fn parameters_section(checker: &mut Checker, docstring: &Docstring, context: &SectionContext) { +fn parameters_section(checker: &Checker, docstring: &Docstring, context: &SectionContext) { // Collect the list of arguments documented in the docstring. let mut docstring_args: FxHashSet = FxHashSet::default(); let section_level_indent = leading_space(context.summary_line()); @@ -1941,7 +1941,7 @@ fn parameters_section(checker: &mut Checker, docstring: &Docstring, context: &Se } fn numpy_section( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, context: &SectionContext, next: Option<&SectionContext>, @@ -1964,7 +1964,7 @@ fn numpy_section( suffix.text_len(), )))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -1976,7 +1976,7 @@ fn numpy_section( } fn google_section( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, context: &SectionContext, next: Option<&SectionContext>, @@ -1998,13 +1998,13 @@ fn google_section( ":".to_string(), TextRange::at(section_name_range.end(), suffix.text_len()), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } fn parse_numpy_sections( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, section_contexts: &SectionContexts, ) { @@ -2015,7 +2015,7 @@ fn parse_numpy_sections( } fn parse_google_sections( - checker: &mut Checker, + checker: &Checker, docstring: &Docstring, section_contexts: &SectionContexts, ) { diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs index 127886918314e..e0c37ed291c8b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs @@ -50,7 +50,7 @@ impl Violation for DocstringStartsWithThis { } /// D404 -pub(crate) fn starts_with_this(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn starts_with_this(checker: &Checker, docstring: &Docstring) { let body = docstring.body(); let trimmed = body.trim(); @@ -64,7 +64,5 @@ pub(crate) fn starts_with_this(checker: &mut Checker, docstring: &Docstring) { if normalize_word(first_word) != "this" { return; } - checker - .diagnostics - .push(Diagnostic::new(DocstringStartsWithThis, docstring.range())); + checker.report_diagnostic(Diagnostic::new(DocstringStartsWithThis, docstring.range())); } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs index a863c3fc7682b..c704f95577d45 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs @@ -63,7 +63,7 @@ impl Violation for TripleSingleQuotes { } /// D300 -pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) { +pub(crate) fn triple_quotes(checker: &Checker, docstring: &Docstring) { let leading_quote = docstring.leading_quote(); let prefixes = leading_quote.trim_end_matches(['\'', '"']).to_owned(); @@ -91,7 +91,7 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } Quote::Double => { @@ -107,7 +107,7 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs b/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs index 2b7d5c066dea9..90ea3250e32ad 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs @@ -38,12 +38,10 @@ impl Violation for AssertTuple { } /// F631 -pub(crate) fn assert_tuple(checker: &mut Checker, stmt: &Stmt, test: &Expr) { +pub(crate) fn assert_tuple(checker: &Checker, stmt: &Stmt, test: &Expr) { if let Expr::Tuple(tuple) = &test { if !tuple.is_empty() { - checker - .diagnostics - .push(Diagnostic::new(AssertTuple, stmt.range())); + checker.report_diagnostic(Diagnostic::new(AssertTuple, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index 6dfdee0cda1f8..b9fd68f673814 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -68,7 +68,7 @@ impl AlwaysFixableViolation for FStringMissingPlaceholders { } /// F541 -pub(crate) fn f_string_missing_placeholders(checker: &mut Checker, expr: &ast::ExprFString) { +pub(crate) fn f_string_missing_placeholders(checker: &Checker, expr: &ast::ExprFString) { if expr.value.f_strings().any(|f_string| { f_string .elements @@ -97,7 +97,7 @@ pub(crate) fn f_string_missing_placeholders(checker: &mut Checker, expr: &ast::E f_string.range(), checker.locator(), )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs b/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs index 78e10000ef51b..3f66ca3bf554f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs @@ -30,12 +30,12 @@ impl Violation for FutureFeatureNotDefined { } } -pub(crate) fn future_feature_not_defined(checker: &mut Checker, alias: &Alias) { +pub(crate) fn future_feature_not_defined(checker: &Checker, alias: &Alias) { if is_feature_name(&alias.name) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( FutureFeatureNotDefined { name: alias.name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs b/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs index 9dba0a2ab0e5c..8ff228b3e543f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs @@ -39,7 +39,7 @@ impl Violation for IfTuple { } /// F634 -pub(crate) fn if_tuple(checker: &mut Checker, stmt_if: &StmtIf) { +pub(crate) fn if_tuple(checker: &Checker, stmt_if: &StmtIf) { for branch in if_elif_branches(stmt_if) { let Expr::Tuple(tuple) = &branch.test else { continue; @@ -47,8 +47,6 @@ pub(crate) fn if_tuple(checker: &mut Checker, stmt_if: &StmtIf) { if tuple.is_empty() { continue; } - checker - .diagnostics - .push(Diagnostic::new(IfTuple, branch.test.range())); + checker.report_diagnostic(Diagnostic::new(IfTuple, branch.test.range())); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs index 71c10a8adf76d..7fae459a4cc21 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -75,7 +75,7 @@ impl AlwaysFixableViolation for IsLiteral { /// F632 pub(crate) fn invalid_literal_comparison( - checker: &mut Checker, + checker: &Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr], @@ -117,7 +117,7 @@ pub(crate) fn invalid_literal_comparison( bail!("Failed to fix invalid comparison due to missing op") } }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } left = right; } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs index d13691c69da32..2ffe38b801fcc 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs @@ -57,10 +57,8 @@ impl Violation for InvalidPrintSyntax { } /// F633 -pub(crate) fn invalid_print_syntax(checker: &mut Checker, left: &Expr) { +pub(crate) fn invalid_print_syntax(checker: &Checker, left: &Expr) { if checker.semantic().match_builtin_expr(left, "print") { - checker - .diagnostics - .push(Diagnostic::new(InvalidPrintSyntax, left.range())); + checker.report_diagnostic(Diagnostic::new(InvalidPrintSyntax, left.range())); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs index 81b2a14be52e2..8db8537b63597 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -70,7 +70,7 @@ fn match_not_implemented(expr: &Expr) -> Option<&Expr> { } /// F901 -pub(crate) fn raise_not_implemented(checker: &mut Checker, expr: &Expr) { +pub(crate) fn raise_not_implemented(checker: &Checker, expr: &Expr) { let Some(expr) = match_not_implemented(expr) else { return; }; @@ -86,5 +86,5 @@ pub(crate) fn raise_not_implemented(checker: &mut Checker, expr: &Expr) { import_edit, )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs index 72ded4db1528d..f29d1dd3399cb 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs @@ -135,7 +135,7 @@ impl Violation for MultiValueRepeatedKeyVariable { } /// F601, F602 -pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { +pub(crate) fn repeated_keys(checker: &Checker, dict: &ast::ExprDict) { // Generate a map from key to (index, value). let mut seen: FxHashMap)> = FxHashMap::with_capacity_and_hasher(dict.len(), FxBuildHasher); @@ -194,7 +194,7 @@ pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { .end(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } Expr::Name(_) => { @@ -226,7 +226,7 @@ pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { .end(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } _ => {} diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs b/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs index 658c41c20ea05..548452b3cf76f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs @@ -32,13 +32,11 @@ impl Violation for ReturnOutsideFunction { } } -pub(crate) fn return_outside_function(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn return_outside_function(checker: &Checker, stmt: &Stmt) { if matches!( checker.semantic().current_scope().kind, ScopeKind::Class(_) | ScopeKind::Module ) { - checker - .diagnostics - .push(Diagnostic::new(ReturnOutsideFunction, stmt.range())); + checker.report_diagnostic(Diagnostic::new(ReturnOutsideFunction, stmt.range())); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index 80fe9f307789f..827a8596ea86f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -525,7 +525,7 @@ fn has_star_args(args: &[Expr]) -> bool { /// F502 pub(crate) fn percent_format_expected_mapping( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, @@ -538,9 +538,9 @@ pub(crate) fn percent_format_expected_mapping( | Expr::Set(_) | Expr::ListComp(_) | Expr::SetComp(_) - | Expr::Generator(_) => checker - .diagnostics - .push(Diagnostic::new(PercentFormatExpectedMapping, location)), + | Expr::Generator(_) => { + checker.report_diagnostic(Diagnostic::new(PercentFormatExpectedMapping, location)); + } _ => {} } } @@ -548,21 +548,19 @@ pub(crate) fn percent_format_expected_mapping( /// F503 pub(crate) fn percent_format_expected_sequence( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, ) { if summary.num_positional > 1 && matches!(right, Expr::Dict(_) | Expr::DictComp(_)) { - checker - .diagnostics - .push(Diagnostic::new(PercentFormatExpectedSequence, location)); + checker.report_diagnostic(Diagnostic::new(PercentFormatExpectedSequence, location)); } } /// F504 pub(crate) fn percent_format_extra_named_arguments( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, @@ -615,12 +613,12 @@ pub(crate) fn percent_format_extra_named_arguments( )?; Ok(Fix::safe_edit(edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// F505 pub(crate) fn percent_format_missing_arguments( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, @@ -656,7 +654,7 @@ pub(crate) fn percent_format_missing_arguments( .collect(); if !missing.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PercentFormatMissingArgument { missing: missing.iter().map(|&s| s.clone()).collect(), }, @@ -667,12 +665,12 @@ pub(crate) fn percent_format_missing_arguments( /// F506 pub(crate) fn percent_format_mixed_positional_and_named( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, location: TextRange, ) { if !(summary.num_positional == 0 || summary.keywords.is_empty()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PercentFormatMixedPositionalAndNamed, location, )); @@ -681,7 +679,7 @@ pub(crate) fn percent_format_mixed_positional_and_named( /// F507 pub(crate) fn percent_format_positional_count_mismatch( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, @@ -700,7 +698,7 @@ pub(crate) fn percent_format_positional_count_mismatch( } if found != summary.num_positional { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( PercentFormatPositionalCountMismatch { wanted: summary.num_positional, got: found, @@ -713,7 +711,7 @@ pub(crate) fn percent_format_positional_count_mismatch( /// F508 pub(crate) fn percent_format_star_requires_sequence( - checker: &mut Checker, + checker: &Checker, summary: &CFormatSummary, right: &Expr, location: TextRange, @@ -721,8 +719,7 @@ pub(crate) fn percent_format_star_requires_sequence( if summary.starred { match right { Expr::Dict(_) | Expr::DictComp(_) => checker - .diagnostics - .push(Diagnostic::new(PercentFormatStarRequiresSequence, location)), + .report_diagnostic(Diagnostic::new(PercentFormatStarRequiresSequence, location)), _ => {} } } @@ -730,7 +727,7 @@ pub(crate) fn percent_format_star_requires_sequence( /// F522 pub(crate) fn string_dot_format_extra_named_arguments( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, keywords: &[Keyword], @@ -774,12 +771,12 @@ pub(crate) fn string_dot_format_extra_named_arguments( )?; Ok(Fix::safe_edit(edit)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// F523 pub(crate) fn string_dot_format_extra_positional_arguments( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, args: &[Expr], @@ -844,12 +841,12 @@ pub(crate) fn string_dot_format_extra_positional_arguments( }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// F524 pub(crate) fn string_dot_format_missing_argument( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, args: &[Expr], @@ -883,7 +880,7 @@ pub(crate) fn string_dot_format_missing_argument( .collect(); if !missing.is_empty() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StringDotFormatMissingArguments { missing }, call.range(), )); @@ -892,12 +889,12 @@ pub(crate) fn string_dot_format_missing_argument( /// F525 pub(crate) fn string_dot_format_mixing_automatic( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary, ) { if !(summary.autos.is_empty() || summary.indices.is_empty()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( StringDotFormatMixingAutomatic, call.range(), )); diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs index d13aa29107864..3fef265e5d7ce 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs @@ -46,12 +46,7 @@ impl Violation for UndefinedLocal { } /// F823 -pub(crate) fn undefined_local( - checker: &Checker, - scope_id: ScopeId, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn undefined_local(checker: &Checker, scope_id: ScopeId, scope: &Scope) { if scope.kind.is_function() { for (name, binding_id) in scope.bindings() { // If the variable shadows a binding in a parent scope... @@ -67,7 +62,7 @@ pub(crate) fn undefined_local( } }) { // Then it's probably an error. - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UndefinedLocal { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs index 40684d1d10491..7ba0a158759dd 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs @@ -34,11 +34,7 @@ impl Violation for UnusedAnnotation { } /// F842 -pub(crate) fn unused_annotation( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn unused_annotation(checker: &Checker, scope: &Scope) { for (name, range) in scope.bindings().filter_map(|(name, binding_id)| { let binding = checker.semantic().binding(binding_id); if binding.kind.is_annotation() @@ -50,6 +46,6 @@ pub(crate) fn unused_annotation( None } }) { - diagnostics.push(Diagnostic::new(UnusedAnnotation { name }, range)); + checker.report_diagnostic(Diagnostic::new(UnusedAnnotation { name }, range)); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs index 487b190f0ad49..13b3bb333a621 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -273,7 +273,7 @@ fn find_dunder_all_exprs<'a>(semantic: &'a SemanticModel) -> Vec<&'a ast::Expr> /// ¬__init__.py ∧ stdlib → safe, remove /// ¬__init__.py ∧ 3rdpty → safe, remove /// -pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut Vec) { +pub(crate) fn unused_import(checker: &Checker, scope: &Scope) { // Collect all unused imports by statement. let mut unused: BTreeMap<(NodeId, Exceptions), Vec> = BTreeMap::default(); let mut ignored: BTreeMap<(NodeId, Exceptions), Vec> = BTreeMap::default(); @@ -429,7 +429,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut diagnostic.set_fix(fix.clone()); } } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -450,7 +450,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut if let Some(range) = binding.parent_range { diagnostic.set_parent(range.start()); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs index eca9622a16b2f..b175d7c360d98 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs @@ -249,7 +249,7 @@ fn remove_unused_variable(binding: &Binding, checker: &Checker) -> Option { } /// F841 -pub(crate) fn unused_variable(checker: &Checker, scope: &Scope, diagnostics: &mut Vec) { +pub(crate) fn unused_variable(checker: &Checker, scope: &Scope) { if scope.uses_locals() && scope.kind.is_function() { return; } @@ -290,6 +290,6 @@ pub(crate) fn unused_variable(checker: &Checker, scope: &Scope, diagnostics: &mu if let Some(fix) = remove_unused_variable(binding, checker) { diagnostic.set_fix(fix); } - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs b/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs index c7f8d852a2a68..a63bbde5030c4 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs @@ -59,7 +59,7 @@ impl Violation for YieldOutsideFunction { } /// F704 -pub(crate) fn yield_outside_function(checker: &mut Checker, expr: &Expr) { +pub(crate) fn yield_outside_function(checker: &Checker, expr: &Expr) { let scope = checker.semantic().current_scope(); if scope.kind.is_module() || scope.kind.is_class() { let keyword = match expr { @@ -78,7 +78,7 @@ pub(crate) fn yield_outside_function(checker: &mut Checker, expr: &Expr) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( YieldOutsideFunction { keyword }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs index 86c65f5cf98ac..102c9666bc921 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs @@ -49,7 +49,7 @@ impl Violation for InvalidMockAccess { } /// PGH005 -pub(crate) fn uncalled_mock_method(checker: &mut Checker, expr: &Expr) { +pub(crate) fn uncalled_mock_method(checker: &Checker, expr: &Expr) { if let Expr::Attribute(ast::ExprAttribute { attr, .. }) = expr { if matches!( attr.as_str(), @@ -61,7 +61,7 @@ pub(crate) fn uncalled_mock_method(checker: &mut Checker, expr: &Expr) { | "assert_has_calls" | "assert_not_called" ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidMockAccess { reason: Reason::UncalledMethod(attr.to_string()), }, @@ -72,7 +72,7 @@ pub(crate) fn uncalled_mock_method(checker: &mut Checker, expr: &Expr) { } /// PGH005 -pub(crate) fn non_existent_mock_method(checker: &mut Checker, test: &Expr) { +pub(crate) fn non_existent_mock_method(checker: &Checker, test: &Expr) { let attr = match test { Expr::Attribute(ast::ExprAttribute { attr, .. }) => attr, Expr::Call(ast::ExprCall { func, .. }) => match func.as_ref() { @@ -90,7 +90,7 @@ pub(crate) fn non_existent_mock_method(checker: &mut Checker, test: &Expr) { | "has_calls" | "not_called" ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidMockAccess { reason: Reason::NonExistentMethod(attr.to_string()), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs b/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs index f81f5b9ec9ee0..fea14ffb4af14 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs @@ -46,10 +46,10 @@ impl Violation for AssertOnStringLiteral { } /// PLW0129 -pub(crate) fn assert_on_string_literal(checker: &mut Checker, test: &Expr) { +pub(crate) fn assert_on_string_literal(checker: &Checker, test: &Expr) { match test { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AssertOnStringLiteral { kind: if value.is_empty() { Kind::Empty @@ -61,7 +61,7 @@ pub(crate) fn assert_on_string_literal(checker: &mut Checker, test: &Expr) { )); } Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AssertOnStringLiteral { kind: if value.is_empty() { Kind::Empty @@ -100,7 +100,7 @@ pub(crate) fn assert_on_string_literal(checker: &mut Checker, test: &Expr) { } else { Kind::Unknown }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( AssertOnStringLiteral { kind }, test.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs b/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs index 39b9e1935212e..98a4c26160cea 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs @@ -49,7 +49,7 @@ impl Violation for AwaitOutsideAsync { } /// PLE1142 -pub(crate) fn await_outside_async(checker: &mut Checker, node: T) { +pub(crate) fn await_outside_async(checker: &Checker, node: T) { // If we're in an `async` function, we're good. if checker.semantic().in_async_context() { return; @@ -78,7 +78,5 @@ pub(crate) fn await_outside_async(checker: &mut Checker, node: T) { return; } - checker - .diagnostics - .push(Diagnostic::new(AwaitOutsideAsync, node.range())); + checker.report_diagnostic(Diagnostic::new(AwaitOutsideAsync, node.range())); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs index 3ef1236a20750..468d0afd4bd62 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs @@ -56,7 +56,7 @@ impl Violation for BadDunderMethodName { } /// PLW3201 -pub(crate) fn bad_dunder_method_name(checker: &mut Checker, method: &ast::StmtFunctionDef) { +pub(crate) fn bad_dunder_method_name(checker: &Checker, method: &ast::StmtFunctionDef) { // https://github.com/astral-sh/ruff/issues/14535 if checker.source_type.is_stub() { return; @@ -82,7 +82,7 @@ pub(crate) fn bad_dunder_method_name(checker: &mut Checker, method: &ast::StmtFu return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadDunderMethodName { name: method.name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs index 3b32895afdb6b..3d0aa801ba01a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs @@ -49,7 +49,7 @@ impl Violation for BadOpenMode { } /// PLW1501 -pub(crate) fn bad_open_mode(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn bad_open_mode(checker: &Checker, call: &ast::ExprCall) { let Some(kind) = is_open(call.func.as_ref(), checker.semantic()) else { return; }; @@ -66,7 +66,7 @@ pub(crate) fn bad_open_mode(checker: &mut Checker, call: &ast::ExprCall) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadOpenMode { mode: value.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs index b0166b16ba244..21d49f35229ff 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs @@ -48,11 +48,7 @@ impl Violation for BadStaticmethodArgument { } /// PLW0211 -pub(crate) fn bad_staticmethod_argument( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn bad_staticmethod_argument(checker: &Checker, scope: &Scope) { let Some(func) = scope.kind.as_function() else { return; }; @@ -99,7 +95,7 @@ pub(crate) fn bad_staticmethod_argument( _ => return, } - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadStaticmethodArgument { argument_name: self_or_cls.name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs index 0f396ed7cab40..656b74bff48d2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs @@ -142,7 +142,7 @@ fn has_duplicates(s: &ast::StringLiteralValue) -> bool { } /// PLE1310 -pub(crate) fn bad_str_strip_call(checker: &mut Checker, func: &Expr, args: &[Expr]) { +pub(crate) fn bad_str_strip_call(checker: &Checker, func: &Expr, args: &[Expr]) { if let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func { if matches!( value.as_ref(), @@ -158,7 +158,7 @@ pub(crate) fn bad_str_strip_call(checker: &mut Checker, func: &Expr, args: &[Exp } else { None }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadStrStripCall { strip, removal }, arg.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs index 8cac142199311..614aac6a126fe 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs @@ -41,7 +41,7 @@ impl Violation for BadStringFormatCharacter { /// PLE1300 /// Ex) `"{:z}".format("1")` -pub(crate) fn call(checker: &mut Checker, string: &str, range: TextRange) { +pub(crate) fn call(checker: &Checker, string: &str, range: TextRange) { if let Ok(format_string) = FormatString::from_str(string) { for part in &format_string.format_parts { let FormatPart::Field { format_spec, .. } = part else { @@ -50,7 +50,7 @@ pub(crate) fn call(checker: &mut Checker, string: &str, range: TextRange) { match FormatSpec::parse(format_spec) { Err(FormatSpecError::InvalidFormatType) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadStringFormatCharacter { // The format type character is always the last one. // More info in the official spec: @@ -70,7 +70,7 @@ pub(crate) fn call(checker: &mut Checker, string: &str, range: TextRange) { if let Err(FormatSpecError::InvalidFormatType) = FormatSpec::parse(&format_spec) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadStringFormatCharacter { // The format type character is always the last one. // More info in the official spec: @@ -89,7 +89,7 @@ pub(crate) fn call(checker: &mut Checker, string: &str, range: TextRange) { /// PLE1300 /// Ex) `"%z" % "1"` -pub(crate) fn percent(checker: &mut Checker, expr: &Expr, format_string: &ExprStringLiteral) { +pub(crate) fn percent(checker: &Checker, expr: &Expr, format_string: &ExprStringLiteral) { for StringLiteral { value: _, range, @@ -103,7 +103,7 @@ pub(crate) fn percent(checker: &mut Checker, expr: &Expr, format_string: &ExprSt // Parse the format string (e.g. `"%s"`) into a list of `PercentFormat`. if let Err(format_error) = CFormatString::from_str(string) { if let CFormatErrorType::UnsupportedFormatChar(format_char) = format_error.typ { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BadStringFormatCharacter { format_char }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs index 8fb1cf28b8879..f7bea6d481c5b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs @@ -211,7 +211,7 @@ fn is_valid_dict(formats: &[CFormatStrOrBytes], items: &[ast::DictItem]) /// PLE1307 pub(crate) fn bad_string_format_type( - checker: &mut Checker, + checker: &Checker, bin_op: &ast::ExprBinOp, format_string: &ast::ExprStringLiteral, ) { @@ -240,8 +240,6 @@ pub(crate) fn bad_string_format_type( _ => is_valid_constant(&format_strings, &bin_op.right), }; if !is_valid { - checker - .diagnostics - .push(Diagnostic::new(BadStringFormatType, bin_op.range())); + checker.report_diagnostic(Diagnostic::new(BadStringFormatType, bin_op.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs b/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs index 8458c48f2008a..f7de7044f307a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs @@ -64,7 +64,7 @@ impl Violation for BinaryOpException { } /// PLW0711 -pub(crate) fn binary_op_exception(checker: &mut Checker, except_handler: &ExceptHandler) { +pub(crate) fn binary_op_exception(checker: &Checker, except_handler: &ExceptHandler) { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) = except_handler; @@ -76,7 +76,7 @@ pub(crate) fn binary_op_exception(checker: &mut Checker, except_handler: &Except return; }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( BinaryOpException { op: op.into() }, type_.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs index f354fe611f69b..545c62fe4ac8f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs @@ -49,7 +49,7 @@ impl AlwaysFixableViolation for BooleanChainedComparison { } /// PLR1716 -pub(crate) fn boolean_chained_comparison(checker: &mut Checker, expr_bool_op: &ExprBoolOp) { +pub(crate) fn boolean_chained_comparison(checker: &Checker, expr_bool_op: &ExprBoolOp) { // early exit for non `and` boolean operations if expr_bool_op.op != BoolOp::And { return; @@ -158,7 +158,7 @@ pub(crate) fn boolean_chained_comparison(checker: &mut Checker, expr_bool_op: &E Some(diagnostic) }); - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } /// Checks whether two compare expressions are simplifiable diff --git a/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs b/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs index a7855cfd44994..8fba531329778 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs @@ -62,7 +62,7 @@ impl Violation for CollapsibleElseIf { } /// PLR5501 -pub(crate) fn collapsible_else_if(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn collapsible_else_if(checker: &Checker, stmt: &Stmt) { let Stmt::If(ast::StmtIf { elif_else_clauses, .. }) = stmt @@ -95,7 +95,7 @@ pub(crate) fn collapsible_else_if(checker: &mut Checker, stmt: &Stmt) { checker.stylist(), ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Generate [`Fix`] to convert an `else` block to an `elif` block. diff --git a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs index 7f7685d9bf664..51a74aa06144e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs @@ -59,7 +59,7 @@ impl Violation for CompareToEmptyString { /// PLC1901 pub(crate) fn compare_to_empty_string( - checker: &mut Checker, + checker: &Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr], @@ -89,7 +89,7 @@ pub(crate) fn compare_to_empty_string( let expr = checker.generator().expr(rhs); let existing = format!("{literal} {op} {expr}"); let replacement = format!("{}{expr}", op.into_unary()); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CompareToEmptyString { existing, replacement, @@ -107,7 +107,7 @@ pub(crate) fn compare_to_empty_string( let literal = checker.generator().expr(rhs); let existing = format!("{expr} {op} {literal}"); let replacement = format!("{}{expr}", op.into_unary()); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( CompareToEmptyString { existing, replacement, diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs index 5958979019a76..63bc90ac70e8b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs @@ -51,7 +51,7 @@ impl Violation for ComparisonOfConstant { /// PLR0133 pub(crate) fn comparison_of_constant( - checker: &mut Checker, + checker: &Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr], @@ -71,7 +71,7 @@ pub(crate) fn comparison_of_constant( left.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); }; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index c15e85b928fdf..dbc2f76868c76 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -48,7 +48,7 @@ impl Violation for ComparisonWithItself { /// PLR0124 pub(crate) fn comparison_with_itself( - checker: &mut Checker, + checker: &Checker, left: &Expr, ops: &[CmpOp], comparators: &[Expr], @@ -67,7 +67,7 @@ pub(crate) fn comparison_with_itself( op, checker.locator().slice(right) ); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ComparisonWithItself { actual: SourceCodeSnippet::new(actual), }, @@ -115,7 +115,7 @@ pub(crate) fn comparison_with_itself( op, checker.locator().slice(right) ); - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ComparisonWithItself { actual: SourceCodeSnippet::new(actual), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs b/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs index ad3615b9cd2d7..ea2ed3a14a128 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs @@ -46,12 +46,10 @@ impl Violation for ContinueInFinally { } } -fn traverse_body(checker: &mut Checker, body: &[Stmt]) { +fn traverse_body(checker: &Checker, body: &[Stmt]) { for stmt in body { if stmt.is_continue_stmt() { - checker - .diagnostics - .push(Diagnostic::new(ContinueInFinally, stmt.range())); + checker.report_diagnostic(Diagnostic::new(ContinueInFinally, stmt.range())); } match stmt { @@ -86,6 +84,6 @@ fn traverse_body(checker: &mut Checker, body: &[Stmt]) { } /// PLE0116 -pub(crate) fn continue_in_finally(checker: &mut Checker, body: &[Stmt]) { +pub(crate) fn continue_in_finally(checker: &Checker, body: &[Stmt]) { traverse_body(checker, body); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs index a4b1932a129b0..61430227e64df 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs @@ -58,7 +58,7 @@ impl Violation for DictIndexMissingItems { } /// PLC0206 -pub(crate) fn dict_index_missing_items(checker: &mut Checker, stmt_for: &ast::StmtFor) { +pub(crate) fn dict_index_missing_items(checker: &Checker, stmt_for: &ast::StmtFor) { let ast::StmtFor { target, iter, body, .. } = stmt_for; @@ -88,7 +88,7 @@ pub(crate) fn dict_index_missing_items(checker: &mut Checker, stmt_for: &ast::St if has_violation { let diagnostic = Diagnostic::new(DictIndexMissingItems, stmt_for.range()); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs index fd925ff683db1..d7c1af53b913f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs @@ -65,7 +65,7 @@ impl AlwaysFixableViolation for DictIterMissingItems { } /// PLE1141 -pub(crate) fn dict_iter_missing_items(checker: &mut Checker, target: &Expr, iter: &Expr) { +pub(crate) fn dict_iter_missing_items(checker: &Checker, target: &Expr, iter: &Expr) { let Expr::Tuple(tuple) = target else { return; }; @@ -99,7 +99,7 @@ pub(crate) fn dict_iter_missing_items(checker: &mut Checker, target: &Expr, iter format!("{}.items()", name.id), iter.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns true if the binding is a dictionary where each key is a tuple with two elements. diff --git a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs index 83fa4a5f4549a..dcefe934508e7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs @@ -57,7 +57,7 @@ impl Violation for DuplicateBases { } /// PLE0241 -pub(crate) fn duplicate_bases(checker: &mut Checker, name: &str, arguments: Option<&Arguments>) { +pub(crate) fn duplicate_bases(checker: &Checker, name: &str, arguments: Option<&Arguments>) { let Some(arguments) = arguments else { return; }; @@ -83,7 +83,7 @@ pub(crate) fn duplicate_bases(checker: &mut Checker, name: &str, arguments: Opti ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs index b0a03cda3e769..695429683de6d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs @@ -110,7 +110,7 @@ impl Violation for EqWithoutHash { } /// W1641 -pub(crate) fn object_without_hash_method(checker: &mut Checker, class: &StmtClassDef) { +pub(crate) fn object_without_hash_method(checker: &Checker, class: &StmtClassDef) { if checker.source_type.is_stub() { return; } @@ -123,7 +123,7 @@ pub(crate) fn object_without_hash_method(checker: &mut Checker, class: &StmtClas } ) { let diagnostic = Diagnostic::new(EqWithoutHash, class.name.range()); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs b/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs index ab9cf87e0f7aa..5237f47c01541 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs @@ -25,10 +25,8 @@ impl Violation for GlobalAtModuleLevel { } /// PLW0604 -pub(crate) fn global_at_module_level(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn global_at_module_level(checker: &Checker, stmt: &Stmt) { if checker.semantic().current_scope().kind.is_module() { - checker - .diagnostics - .push(Diagnostic::new(GlobalAtModuleLevel, stmt.range())); + checker.report_diagnostic(Diagnostic::new(GlobalAtModuleLevel, stmt.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs b/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs index b19faabf0f159..6fe46484ddeea 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs @@ -52,9 +52,9 @@ impl Violation for GlobalStatement { } /// PLW0603 -pub(crate) fn global_statement(checker: &mut Checker, name: &str) { +pub(crate) fn global_statement(checker: &Checker, name: &str) { if let Some(range) = checker.semantic().global(name) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( GlobalStatement { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs index 49492b1950ec7..2fdfc45495829 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs @@ -68,7 +68,7 @@ impl Violation for IfStmtMinMax { } /// R1730, R1731 -pub(crate) fn if_stmt_min_max(checker: &mut Checker, stmt_if: &ast::StmtIf) { +pub(crate) fn if_stmt_min_max(checker: &Checker, stmt_if: &ast::StmtIf) { let ast::StmtIf { test, body, @@ -179,7 +179,7 @@ pub(crate) fn if_stmt_min_max(checker: &mut Checker, stmt_if: &ast::StmtIf) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs b/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs index 0d27c5c0aca1a..1ebe84b6e5c63 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs @@ -56,7 +56,7 @@ impl Violation for ImportOutsideTopLevel { } /// C0415 -pub(crate) fn import_outside_top_level(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn import_outside_top_level(checker: &Checker, stmt: &Stmt) { if checker.semantic().current_scope().kind.is_module() { // "Top-level" imports are allowed return; @@ -84,9 +84,7 @@ pub(crate) fn import_outside_top_level(checker: &mut Checker, stmt: &Stmt) { } // Emit the diagnostic - checker - .diagnostics - .push(Diagnostic::new(ImportOutsideTopLevel, stmt.range())); + checker.report_diagnostic(Diagnostic::new(ImportOutsideTopLevel, stmt.range())); } fn is_banned_module_level_import(policy: &NameMatchPolicy, checker: &Checker) -> bool { diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs index 65f3d04a19a00..78beec5e92c96 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs @@ -69,11 +69,7 @@ impl Violation for ImportPrivateName { } /// PLC2701 -pub(crate) fn import_private_name( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn import_private_name(checker: &Checker, scope: &Scope) { for binding_id in scope.binding_ids() { let binding = checker.semantic().binding(binding_id); let Some(import) = binding.as_any_import() else { @@ -140,7 +136,7 @@ pub(crate) fn import_private_name( } else { None }; - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( ImportPrivateName { name, module }, binding.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs index fd4f48f0d6e56..7f36077b9af9c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs @@ -45,7 +45,7 @@ impl Violation for InvalidBoolReturnType { } /// PLE0304 -pub(crate) fn invalid_bool_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_bool_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__bool__" { return; } @@ -68,7 +68,7 @@ pub(crate) fn invalid_bool_return(checker: &mut Checker, function_def: &ast::Stm // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidBoolReturnType, function_def.identifier(), )); @@ -88,15 +88,11 @@ pub(crate) fn invalid_bool_return(checker: &mut Checker, function_def: &ast::Stm ResolvedPythonType::Unknown | ResolvedPythonType::Atom(PythonType::Number(NumberLike::Bool)) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidBoolReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidBoolReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidBoolReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidBoolReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs index 93330d5472bad..86f41eff893c9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs @@ -45,7 +45,7 @@ impl Violation for InvalidBytesReturnType { } /// PLE0308 -pub(crate) fn invalid_bytes_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_bytes_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__bytes__" { return; } @@ -68,7 +68,7 @@ pub(crate) fn invalid_bytes_return(checker: &mut Checker, function_def: &ast::St // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidBytesReturnType, function_def.identifier(), )); @@ -87,15 +87,11 @@ pub(crate) fn invalid_bytes_return(checker: &mut Checker, function_def: &ast::St ResolvedPythonType::from(value), ResolvedPythonType::Unknown | ResolvedPythonType::Atom(PythonType::Bytes) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidBytesReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidBytesReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidBytesReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidBytesReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs index 735e24cc29185..51cf79b7ca6ad 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs @@ -43,7 +43,7 @@ impl Violation for InvalidEnvvarDefault { } /// PLW1508 -pub(crate) fn invalid_envvar_default(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn invalid_envvar_default(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::OS) { return; } @@ -74,8 +74,6 @@ pub(crate) fn invalid_envvar_default(checker: &mut Checker, call: &ast::ExprCall ) { return; } - checker - .diagnostics - .push(Diagnostic::new(InvalidEnvvarDefault, expr.range())); + checker.report_diagnostic(Diagnostic::new(InvalidEnvvarDefault, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs index 8c735d95f7559..bee484546f8c8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs @@ -36,7 +36,7 @@ impl Violation for InvalidEnvvarValue { } /// PLE1507 -pub(crate) fn invalid_envvar_value(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn invalid_envvar_value(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::OS) { return; } @@ -58,8 +58,6 @@ pub(crate) fn invalid_envvar_value(checker: &mut Checker, call: &ast::ExprCall) return; } - checker - .diagnostics - .push(Diagnostic::new(InvalidEnvvarValue, expr.range())); + checker.report_diagnostic(Diagnostic::new(InvalidEnvvarValue, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs index 59e68ad547790..5fe3b0ca56949 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs @@ -49,7 +49,7 @@ impl Violation for InvalidHashReturnType { } /// E0309 -pub(crate) fn invalid_hash_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_hash_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__hash__" { return; } @@ -72,7 +72,7 @@ pub(crate) fn invalid_hash_return(checker: &mut Checker, function_def: &ast::Stm // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidHashReturnType, function_def.identifier(), )); @@ -92,15 +92,11 @@ pub(crate) fn invalid_hash_return(checker: &mut Checker, function_def: &ast::Stm ResolvedPythonType::Unknown | ResolvedPythonType::Atom(PythonType::Number(NumberLike::Integer)) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidHashReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidHashReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidHashReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidHashReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs index d71d7d60be6e6..1ecc5de3c5f29 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs @@ -51,7 +51,7 @@ impl Violation for InvalidIndexReturnType { } /// E0305 -pub(crate) fn invalid_index_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_index_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__index__" { return; } @@ -74,7 +74,7 @@ pub(crate) fn invalid_index_return(checker: &mut Checker, function_def: &ast::St // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidIndexReturnType, function_def.identifier(), )); @@ -94,15 +94,11 @@ pub(crate) fn invalid_index_return(checker: &mut Checker, function_def: &ast::St ResolvedPythonType::Unknown | ResolvedPythonType::Atom(PythonType::Number(NumberLike::Integer)) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidIndexReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidIndexReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidIndexReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidIndexReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs index 72814967880ee..30918afb568bf 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs @@ -50,7 +50,7 @@ impl Violation for InvalidLengthReturnType { } /// E0303 -pub(crate) fn invalid_length_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_length_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__len__" { return; } @@ -73,7 +73,7 @@ pub(crate) fn invalid_length_return(checker: &mut Checker, function_def: &ast::S // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidLengthReturnType, function_def.identifier(), )); @@ -95,15 +95,11 @@ pub(crate) fn invalid_length_return(checker: &mut Checker, function_def: &ast::S | ResolvedPythonType::Atom(PythonType::Number(NumberLike::Integer)) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidLengthReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidLengthReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidLengthReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidLengthReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs index ae4cbb0f905a7..47c103ed3480a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs @@ -45,7 +45,7 @@ impl Violation for InvalidStrReturnType { } /// E0307 -pub(crate) fn invalid_str_return(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn invalid_str_return(checker: &Checker, function_def: &ast::StmtFunctionDef) { if function_def.name.as_str() != "__str__" { return; } @@ -68,7 +68,7 @@ pub(crate) fn invalid_str_return(checker: &mut Checker, function_def: &ast::Stmt // If there are no return statements, add a diagnostic. if terminal == Terminal::Implicit { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidStrReturnType, function_def.identifier(), )); @@ -87,15 +87,11 @@ pub(crate) fn invalid_str_return(checker: &mut Checker, function_def: &ast::Stmt ResolvedPythonType::from(value), ResolvedPythonType::Unknown | ResolvedPythonType::Atom(PythonType::String) ) { - checker - .diagnostics - .push(Diagnostic::new(InvalidStrReturnType, value.range())); + checker.report_diagnostic(Diagnostic::new(InvalidStrReturnType, value.range())); } } else { // Disallow implicit `None`. - checker - .diagnostics - .push(Diagnostic::new(InvalidStrReturnType, stmt.range())); + checker.report_diagnostic(Diagnostic::new(InvalidStrReturnType, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs b/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs index 03e0d31bfd0ce..b38acef7f0262 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for IterationOverSet { } /// PLC0208 -pub(crate) fn iteration_over_set(checker: &mut Checker, expr: &Expr) { +pub(crate) fn iteration_over_set(checker: &Checker, expr: &Expr) { let Expr::Set(set) = expr else { return; }; @@ -74,5 +74,5 @@ pub(crate) fn iteration_over_set(checker: &mut Checker, expr: &Expr) { }; diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(tuple, expr.range()))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs index 003bdc85b1b96..7ff9e48043568 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs @@ -63,7 +63,7 @@ impl AlwaysFixableViolation for LenTest { } /// PLC1802 -pub(crate) fn len_test(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn len_test(checker: &Checker, call: &ExprCall) { let ExprCall { func, arguments, .. } = call; @@ -90,7 +90,7 @@ pub(crate) fn len_test(checker: &mut Checker, call: &ExprCall) { let replacement = checker.locator().slice(argument.range()).to_string(); - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new( LenTest { expression: SourceCodeSnippet::new(replacement.clone()), diff --git a/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs b/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs index 0bf8b94e78bf7..9c1a6984c19a8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs @@ -46,7 +46,7 @@ impl AlwaysFixableViolation for LiteralMembership { } /// PLR6201 -pub(crate) fn literal_membership(checker: &mut Checker, compare: &ast::ExprCompare) { +pub(crate) fn literal_membership(checker: &Checker, compare: &ast::ExprCompare) { let [op] = &*compare.ops else { return; }; @@ -110,5 +110,5 @@ pub(crate) fn literal_membership(checker: &mut Checker, compare: &ast::ExprCompa right.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs b/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs index f3d6e1d64743c..5e37ea09b4f30 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs @@ -55,10 +55,10 @@ impl Violation for LoadBeforeGlobalDeclaration { } /// PLE0118 -pub(crate) fn load_before_global_declaration(checker: &mut Checker, name: &str, expr: &Expr) { +pub(crate) fn load_before_global_declaration(checker: &Checker, name: &str, expr: &Expr) { if let Some(stmt) = checker.semantic().global(name) { if expr.start() < stmt.start() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( LoadBeforeGlobalDeclaration { name: name.to_string(), row: checker.compute_source_row(stmt.start()), diff --git a/crates/ruff_linter/src/rules/pylint/rules/logging.rs b/crates/ruff_linter/src/rules/pylint/rules/logging.rs index 99f22ae6caf9a..ad731e93f2cd6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/logging.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/logging.rs @@ -85,7 +85,7 @@ impl Violation for LoggingTooManyArgs { /// PLE1205 /// PLE1206 -pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { // If there are any starred arguments, abort. if call.arguments.args.iter().any(Expr::is_starred_expr) { return; @@ -154,17 +154,13 @@ pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) { if checker.enabled(Rule::LoggingTooManyArgs) { if summary.num_positional < num_message_args { - checker - .diagnostics - .push(Diagnostic::new(LoggingTooManyArgs, call.func.range())); + checker.report_diagnostic(Diagnostic::new(LoggingTooManyArgs, call.func.range())); } } if checker.enabled(Rule::LoggingTooFewArgs) { if num_message_args > 0 && num_keywords == 0 && summary.num_positional > num_message_args { - checker - .diagnostics - .push(Diagnostic::new(LoggingTooFewArgs, call.func.range())); + checker.report_diagnostic(Diagnostic::new(LoggingTooFewArgs, call.func.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs index 4ba10f132c69a..ff34e25dfcbcf 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs @@ -99,7 +99,7 @@ fn is_magic_value(literal_expr: LiteralExpressionRef, allowed_types: &[ConstantT } /// PLR2004 -pub(crate) fn magic_value_comparison(checker: &mut Checker, left: &Expr, comparators: &[Expr]) { +pub(crate) fn magic_value_comparison(checker: &Checker, left: &Expr, comparators: &[Expr]) { for (left, right) in std::iter::once(left).chain(comparators).tuple_windows() { // If both of the comparators are literals, skip rule for the whole expression. // R0133: comparison-of-constants @@ -111,7 +111,7 @@ pub(crate) fn magic_value_comparison(checker: &mut Checker, left: &Expr, compara for comparison_expr in std::iter::once(left).chain(comparators) { if let Some(value) = as_literal(comparison_expr) { if is_magic_value(value, &checker.settings.pylint.allow_magic_value_types) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( MagicValueComparison { value: checker.locator().slice(comparison_expr).to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs index b2a58b64ab551..e1237e4b1e934 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs @@ -47,12 +47,7 @@ impl Violation for ManualFromImport { } /// PLR0402 -pub(crate) fn manual_from_import( - checker: &mut Checker, - stmt: &Stmt, - alias: &Alias, - names: &[Alias], -) { +pub(crate) fn manual_from_import(checker: &Checker, stmt: &Stmt, alias: &Alias, names: &[Alias]) { let Some(asname) = &alias.asname else { return; }; @@ -86,5 +81,5 @@ pub(crate) fn manual_from_import( stmt.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs b/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs index 22007bac8973a..88f29b9769adc 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs @@ -51,7 +51,7 @@ impl Violation for MisplacedBareRaise { } /// PLE0704 -pub(crate) fn misplaced_bare_raise(checker: &mut Checker, raise: &ast::StmtRaise) { +pub(crate) fn misplaced_bare_raise(checker: &Checker, raise: &ast::StmtRaise) { if raise.exc.is_some() { return; } @@ -64,7 +64,5 @@ pub(crate) fn misplaced_bare_raise(checker: &mut Checker, raise: &ast::StmtRaise return; } - checker - .diagnostics - .push(Diagnostic::new(MisplacedBareRaise, raise.range())); + checker.report_diagnostic(Diagnostic::new(MisplacedBareRaise, raise.range())); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs b/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs index f918f65f25309..84bb50f0734a1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for ModifiedIteratingSet { } /// PLE4703 -pub(crate) fn modified_iterating_set(checker: &mut Checker, for_stmt: &StmtFor) { +pub(crate) fn modified_iterating_set(checker: &Checker, for_stmt: &StmtFor) { let Some(name) = for_stmt.iter.as_name_expr() else { return; }; @@ -102,7 +102,7 @@ pub(crate) fn modified_iterating_set(checker: &mut Checker, for_stmt: &StmtFor) format!("{}.copy()", checker.locator().slice(name)), name.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs b/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs index f062e21a3e09c..87a46a20b0b43 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs @@ -35,10 +35,8 @@ impl Violation for NamedExprWithoutContext { } /// PLW0131 -pub(crate) fn named_expr_without_context(checker: &mut Checker, value: &Expr) { +pub(crate) fn named_expr_without_context(checker: &Checker, value: &Expr) { if let Expr::Named(ast::ExprNamed { range, .. }) = value { - checker - .diagnostics - .push(Diagnostic::new(NamedExprWithoutContext, *range)); + checker.report_diagnostic(Diagnostic::new(NamedExprWithoutContext, *range)); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs index 6ee5f6b25ba5e..5eee0a1ee5222 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs @@ -47,18 +47,18 @@ impl Violation for NanComparison { } /// PLW0177 -pub(crate) fn nan_comparison(checker: &mut Checker, left: &Expr, comparators: &[Expr]) { +pub(crate) fn nan_comparison(checker: &Checker, left: &Expr, comparators: &[Expr]) { for expr in std::iter::once(left).chain(comparators) { if let Some(qualified_name) = checker.semantic().resolve_qualified_name(expr) { match qualified_name.segments() { ["numpy", "nan" | "NAN" | "NaN"] => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NanComparison { nan: Nan::NumPy }, expr.range(), )); } ["math", "nan"] => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NanComparison { nan: Nan::Math }, expr.range(), )); @@ -68,7 +68,7 @@ pub(crate) fn nan_comparison(checker: &mut Checker, left: &Expr, comparators: &[ } if is_nan_float(expr, checker.semantic()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NanComparison { nan: Nan::Math }, expr.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index 6c7cfcf2a4d09..5c7290b932159 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -128,7 +128,7 @@ fn collect_nested_args(min_max: MinMax, args: &[Expr], semantic: &SemanticModel) /// PLW3301 pub(crate) fn nested_min_max( - checker: &mut Checker, + checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr], @@ -173,6 +173,6 @@ pub(crate) fn nested_min_max( expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs index d9047f858c5c9..a3b91e07cdaf1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs @@ -88,16 +88,16 @@ enum MethodType { } /// PLR0202 -pub(crate) fn no_classmethod_decorator(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn no_classmethod_decorator(checker: &Checker, stmt: &Stmt) { get_undecorated_methods(checker, stmt, &MethodType::Classmethod); } /// PLR0203 -pub(crate) fn no_staticmethod_decorator(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn no_staticmethod_decorator(checker: &Checker, stmt: &Stmt) { get_undecorated_methods(checker, stmt, &MethodType::Staticmethod); } -fn get_undecorated_methods(checker: &mut Checker, class_stmt: &Stmt, method_type: &MethodType) { +fn get_undecorated_methods(checker: &Checker, class_stmt: &Stmt, method_type: &MethodType) { let Stmt::ClassDef(class_def) = class_stmt else { return; }; @@ -191,7 +191,7 @@ fn get_undecorated_methods(checker: &mut Checker, class_stmt: &Stmt, method_type checker.indexer(), )], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } None => { continue; diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs index 6599e9ed20042..53327e050da2e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs @@ -52,12 +52,7 @@ impl Violation for NoSelfUse { } /// PLR6301 -pub(crate) fn no_self_use( - checker: &Checker, - scope_id: ScopeId, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn no_self_use(checker: &Checker, scope_id: ScopeId, scope: &Scope) { let semantic = checker.semantic(); let Some(parent) = semantic.first_non_type_parent_scope(scope) else { @@ -131,7 +126,7 @@ pub(crate) fn no_self_use( .map(|binding_id| semantic.binding(binding_id)) .is_some_and(|binding| binding.kind.is_argument() && binding.is_unused()) { - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NoSelfUse { method_name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs index 8ac75c6f6e190..148825e3870e7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs @@ -63,13 +63,13 @@ enum Kind { } /// PLC2403 -pub(crate) fn non_ascii_module_import(checker: &mut Checker, alias: &Alias) { +pub(crate) fn non_ascii_module_import(checker: &Checker, alias: &Alias) { if let Some(asname) = &alias.asname { if asname.as_str().is_ascii() { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonAsciiImportName { name: asname.to_string(), kind: Kind::Aliased, @@ -81,7 +81,7 @@ pub(crate) fn non_ascii_module_import(checker: &mut Checker, alias: &Alias) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonAsciiImportName { name: alias.name.to_string(), kind: Kind::Unaliased, diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs index 5e7d953853442..6bc86a582da7f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs @@ -86,7 +86,7 @@ impl AlwaysFixableViolation for NonAugmentedAssignment { } /// PLR6104 -pub(crate) fn non_augmented_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { +pub(crate) fn non_augmented_assignment(checker: &Checker, assign: &ast::StmtAssign) { // Ignore multiple assignment targets. let [target] = assign.targets.as_slice() else { return; @@ -110,7 +110,7 @@ pub(crate) fn non_augmented_assignment(checker: &mut Checker, assign: &ast::Stmt value, assign.range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); return; } @@ -129,7 +129,7 @@ pub(crate) fn non_augmented_assignment(checker: &mut Checker, assign: &ast::Stmt value, assign.range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index 029876b1ae7a5..af2a211cda64f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -60,7 +60,7 @@ impl Violation for NonSlotAssignment { } /// PLE0237 -pub(crate) fn non_slot_assignment(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn non_slot_assignment(checker: &Checker, class_def: &ast::StmtClassDef) { let semantic = checker.semantic(); // If the class inherits from another class (aside from `object`), then it's possible that @@ -74,7 +74,7 @@ pub(crate) fn non_slot_assignment(checker: &mut Checker, class_def: &ast::StmtCl } for attribute in is_attributes_not_in_slots(&class_def.body) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonSlotAssignment { name: attribute.name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs index d1193264b9854..a45d9770fbbda 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs @@ -54,12 +54,12 @@ impl Violation for NonlocalAndGlobal { } /// E115 -pub(crate) fn nonlocal_and_global(checker: &mut Checker, nonlocal: &ast::StmtNonlocal) { +pub(crate) fn nonlocal_and_global(checker: &Checker, nonlocal: &ast::StmtNonlocal) { // Determine whether any of the newly declared `nonlocal` variables are already declared as // `global`. for name in &nonlocal.names { if let Some(global) = checker.semantic().global(name) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( NonlocalAndGlobal { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs index 59e2446979652..95cb2705bc0f3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs @@ -29,7 +29,7 @@ impl Violation for PotentialIndexError { } /// PLE0643 -pub(crate) fn potential_index_error(checker: &mut Checker, value: &Expr, slice: &Expr) { +pub(crate) fn potential_index_error(checker: &Checker, value: &Expr, slice: &Expr) { // Determine the length of the sequence. let length = match value { Expr::Tuple(ast::ExprTuple { elts, .. }) | Expr::List(ast::ExprList { elts, .. }) => { @@ -66,8 +66,6 @@ pub(crate) fn potential_index_error(checker: &mut Checker, value: &Expr, slice: // Emit a diagnostic if the index is out of bounds. If the index can't be represented as an // `i64`, but the length _can_, then the index is definitely out of bounds. if index.map_or(true, |index| index >= length || index < -length) { - checker - .diagnostics - .push(Diagnostic::new(PotentialIndexError, slice.range())); + checker.report_diagnostic(Diagnostic::new(PotentialIndexError, slice.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs index 681406e742335..1061849c1848f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs @@ -46,7 +46,7 @@ impl Violation for PropertyWithParameters { /// PLR0206 pub(crate) fn property_with_parameters( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, decorator_list: &[Decorator], parameters: &Parameters, @@ -57,8 +57,6 @@ pub(crate) fn property_with_parameters( let semantic = checker.semantic(); let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); if is_property(decorator_list, extra_property_decorators, semantic) { - checker - .diagnostics - .push(Diagnostic::new(PropertyWithParameters, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new(PropertyWithParameters, stmt.identifier())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs index cb0e361bf8a29..e4f5774ebdef4 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs @@ -42,7 +42,7 @@ impl Violation for RedeclaredAssignedName { } /// PLW0128 -pub(crate) fn redeclared_assigned_name(checker: &mut Checker, targets: &Vec) { +pub(crate) fn redeclared_assigned_name(checker: &Checker, targets: &Vec) { let mut names: Vec = Vec::new(); for target in targets { @@ -50,7 +50,7 @@ pub(crate) fn redeclared_assigned_name(checker: &mut Checker, targets: &Vec) { +fn check_expr(checker: &Checker, expr: &Expr, names: &mut Vec) { match expr { Expr::Tuple(tuple) => { for target in tuple { @@ -63,7 +63,7 @@ fn check_expr(checker: &mut Checker, expr: &Expr, names: &mut Vec) { return; } if names.contains(id) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RedeclaredAssignedName { name: id.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs index 145845c498058..39111a10dc6c8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs @@ -338,7 +338,7 @@ fn assignment_targets_from_assign_targets<'a>( } /// PLW2901 -pub(crate) fn redefined_loop_name(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn redefined_loop_name(checker: &Checker, stmt: &Stmt) { let (outer_assignment_targets, inner_assignment_targets) = match stmt { Stmt::With(ast::StmtWith { items, body, .. }) => { let outer_assignment_targets: Vec = @@ -399,5 +399,5 @@ pub(crate) fn redefined_loop_name(checker: &mut Checker, stmt: &Stmt) { } } - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs index 3817e8e888391..bdeec02ce85c7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_slots_in_subclass.rs @@ -52,7 +52,7 @@ impl Violation for RedefinedSlotsInSubclass { } // PLW0244 -pub(crate) fn redefined_slots_in_subclass(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn redefined_slots_in_subclass(checker: &Checker, class_def: &ast::StmtClassDef) { // Early return if this is not a subclass if class_def.bases().is_empty() { return; @@ -67,11 +67,10 @@ pub(crate) fn redefined_slots_in_subclass(checker: &mut Checker, class_def: &ast } let semantic = checker.semantic(); - let mut diagnostics: Vec<_> = class_slots + let diagnostics = class_slots .iter() - .filter_map(|slot| check_super_slots(class_def, semantic, slot)) - .collect(); - checker.diagnostics.append(&mut diagnostics); + .filter_map(|slot| check_super_slots(class_def, semantic, slot)); + checker.report_diagnostics(diagnostics); } #[derive(Clone, Debug)] diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index 942cc71bb9f17..783fc5f8bc809 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -78,7 +78,7 @@ impl AlwaysFixableViolation for RepeatedEqualityComparison { } /// PLR1714 -pub(crate) fn repeated_equality_comparison(checker: &mut Checker, bool_op: &ast::ExprBoolOp) { +pub(crate) fn repeated_equality_comparison(checker: &Checker, bool_op: &ast::ExprBoolOp) { // Map from expression hash to (starting offset, number of comparisons, list let mut value_to_comparators: FxHashMap, Vec)> = FxHashMap::with_capacity_and_hasher(bool_op.values.len() * 2, FxBuildHasher); @@ -195,7 +195,7 @@ pub(crate) fn repeated_equality_comparison(checker: &mut Checker, bool_op: &ast: bool_op.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs index 9e6a95cbe9cdd..18054602f1178 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs @@ -35,7 +35,7 @@ impl Violation for RepeatedKeywordArgument { } } -pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn repeated_keyword_argument(checker: &Checker, call: &ExprCall) { let ExprCall { arguments, .. } = call; let mut seen = FxHashSet::with_capacity_and_hasher(arguments.keywords.len(), FxBuildHasher); @@ -44,7 +44,7 @@ pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) if let Some(id) = &keyword.arg { // Ex) `func(a=1, a=2)` if !seen.insert(id.as_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RepeatedKeywordArgument { duplicate_keyword: id.to_string(), }, @@ -56,7 +56,7 @@ pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) for key in dict.iter_keys().flatten() { if let Expr::StringLiteral(ExprStringLiteral { value, .. }) = key { if !seen.insert(value.to_str()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( RepeatedKeywordArgument { duplicate_keyword: value.to_string(), }, diff --git a/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs b/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs index 46dcf30c1746f..e311673226e9a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs @@ -45,7 +45,7 @@ impl Violation for ReturnInInit { } /// PLE0101 -pub(crate) fn return_in_init(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn return_in_init(checker: &Checker, stmt: &Stmt) { if let Stmt::Return(ast::StmtReturn { value, range: _ }) = stmt { if let Some(expr) = value { if expr.is_none_literal_expr() { @@ -59,8 +59,6 @@ pub(crate) fn return_in_init(checker: &mut Checker, stmt: &Stmt) { } if in_dunder_method("__init__", checker.semantic(), checker.settings) { - checker - .diagnostics - .push(Diagnostic::new(ReturnInInit, stmt.range())); + checker.report_diagnostic(Diagnostic::new(ReturnInInit, stmt.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs b/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs index 60ff30a9d3bb0..11c2d04852efa 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs @@ -37,12 +37,13 @@ impl Violation for SelfAssigningVariable { } /// PLW0127 -pub(crate) fn self_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { +pub(crate) fn self_assignment(checker: &Checker, assign: &ast::StmtAssign) { // Assignments in class bodies are attributes (e.g., `x = x` assigns `x` to `self.x`, and thus // is not a self-assignment). if checker.semantic().current_scope().kind.is_class() { return; } + let mut diagnostics = Vec::new(); for (left, right) in assign .targets @@ -50,12 +51,13 @@ pub(crate) fn self_assignment(checker: &mut Checker, assign: &ast::StmtAssign) { .chain(std::iter::once(assign.value.as_ref())) .tuple_combinations() { - visit_assignments(left, right, &mut checker.diagnostics); + visit_assignments(left, right, &mut diagnostics); } + checker.report_diagnostics(diagnostics); } /// PLW0127 -pub(crate) fn self_annotated_assignment(checker: &mut Checker, assign: &ast::StmtAnnAssign) { +pub(crate) fn self_annotated_assignment(checker: &Checker, assign: &ast::StmtAnnAssign) { let Some(value) = assign.value.as_ref() else { return; }; @@ -65,8 +67,10 @@ pub(crate) fn self_annotated_assignment(checker: &mut Checker, assign: &ast::Stm if checker.semantic().current_scope().kind.is_class() { return; } + let mut diagnostics = Vec::new(); - visit_assignments(&assign.target, value, &mut checker.diagnostics); + visit_assignments(&assign.target, value, &mut diagnostics); + checker.report_diagnostics(diagnostics); } fn visit_assignments(left: &Expr, right: &Expr, diagnostics: &mut Vec) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs index 2b27a8bfeed42..4ec58b6a83ba6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs @@ -64,7 +64,7 @@ impl Violation for SelfOrClsAssignment { } /// PLW0127 -pub(crate) fn self_or_cls_assignment(checker: &mut Checker, target: &Expr) { +pub(crate) fn self_or_cls_assignment(checker: &Checker, target: &Expr) { let ScopeKind::Function(ast::StmtFunctionDef { name, decorator_list, @@ -108,12 +108,12 @@ pub(crate) fn self_or_cls_assignment(checker: &mut Checker, target: &Expr) { check_expr(checker, target, method_type); } -fn check_expr(checker: &mut Checker, target: &Expr, method_type: MethodType) { +fn check_expr(checker: &Checker, target: &Expr, method_type: MethodType) { match target { Expr::Name(_) => { if let Expr::Name(ast::ExprName { id, .. }) = target { if id.as_str() == method_type.arg_name() { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( SelfOrClsAssignment { method_type }, target.range(), )); diff --git a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs index 4b715bd4bb0dc..7837c10478c0f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for ShallowCopyEnviron { } /// PLW1507 -pub(crate) fn shallow_copy_environ(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn shallow_copy_environ(checker: &Checker, call: &ast::ExprCall) { if !(checker.semantic().seen_module(Modules::OS) && checker.semantic().seen_module(Modules::COPY)) { @@ -86,5 +86,5 @@ pub(crate) fn shallow_copy_environ(checker: &mut Checker, call: &ast::ExprCall) format!("{}.copy()", checker.locator().slice(arg)), call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs index 1b3f528905a37..75699aa9bfc72 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs @@ -58,7 +58,7 @@ impl Violation for SingleStringSlots { } /// PLC0205 -pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) { +pub(crate) fn single_string_slots(checker: &Checker, class: &StmtClassDef) { for stmt in &class.body { match stmt { Stmt::Assign(ast::StmtAssign { targets, value, .. }) => { @@ -66,9 +66,10 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) { if let Expr::Name(ast::ExprName { id, .. }) = target { if id.as_str() == "__slots__" { if matches!(value.as_ref(), Expr::StringLiteral(_) | Expr::FString(_)) { - checker - .diagnostics - .push(Diagnostic::new(SingleStringSlots, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new( + SingleStringSlots, + stmt.identifier(), + )); } } } @@ -82,9 +83,10 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) { if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { if id.as_str() == "__slots__" { if matches!(value.as_ref(), Expr::StringLiteral(_) | Expr::FString(_)) { - checker - .diagnostics - .push(Diagnostic::new(SingleStringSlots, stmt.identifier())); + checker.report_diagnostic(Diagnostic::new( + SingleStringSlots, + stmt.identifier(), + )); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs b/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs index b5048bee1f94b..7b1588abe57d8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs @@ -59,11 +59,7 @@ impl Violation for SingledispatchMethod { } /// E1519 -pub(crate) fn singledispatch_method( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn singledispatch_method(checker: &Checker, scope: &Scope) { let Some(func) = scope.kind.as_function() else { return; }; @@ -115,7 +111,7 @@ pub(crate) fn singledispatch_method( [import_edit], )) }); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs b/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs index 9aaa9cff5b389..554b4d461b5e2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs @@ -57,11 +57,7 @@ impl Violation for SingledispatchmethodFunction { } /// E1520 -pub(crate) fn singledispatchmethod_function( - checker: &Checker, - scope: &Scope, - diagnostics: &mut Vec, -) { +pub(crate) fn singledispatchmethod_function(checker: &Checker, scope: &Scope) { let Some(func) = scope.kind.as_function() else { return; }; @@ -111,7 +107,7 @@ pub(crate) fn singledispatchmethod_function( [import_edit], )) }); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs b/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs index 09db5f8083ea2..5420981619c44 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs @@ -50,7 +50,7 @@ impl Violation for SubprocessPopenPreexecFn { } /// PLW1509 -pub(crate) fn subprocess_popen_preexec_fn(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn subprocess_popen_preexec_fn(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::SUBPROCESS) { return; } @@ -65,9 +65,7 @@ pub(crate) fn subprocess_popen_preexec_fn(checker: &mut Checker, call: &ast::Exp .find_keyword("preexec_fn") .filter(|keyword| !keyword.value.is_none_literal_expr()) { - checker - .diagnostics - .push(Diagnostic::new(SubprocessPopenPreexecFn, keyword.range())); + checker.report_diagnostic(Diagnostic::new(SubprocessPopenPreexecFn, keyword.range())); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs b/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs index 4644226152ff8..150056b7e49ef 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs @@ -60,7 +60,7 @@ impl AlwaysFixableViolation for SubprocessRunWithoutCheck { } /// PLW1510 -pub(crate) fn subprocess_run_without_check(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn subprocess_run_without_check(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::SUBPROCESS) { return; } @@ -91,7 +91,7 @@ pub(crate) fn subprocess_run_without_check(checker: &mut Checker, call: &ast::Ex Applicability::Safe }, )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs index 43d68e5d783a0..1e33a383f93b4 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs @@ -61,7 +61,7 @@ impl AlwaysFixableViolation for SuperWithoutBrackets { } /// PLW0245 -pub(crate) fn super_without_brackets(checker: &mut Checker, func: &Expr) { +pub(crate) fn super_without_brackets(checker: &Checker, func: &Expr) { // The call must be to `super` (without parentheses). let Expr::Attribute(ast::ExprAttribute { value, .. }) = func else { return; @@ -115,5 +115,5 @@ pub(crate) fn super_without_brackets(checker: &mut Checker, func: &Expr) { value.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index 7e498cb471c67..818904daef5c0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -56,7 +56,7 @@ impl Violation for SysExitAlias { } /// PLR1722 -pub(crate) fn sys_exit_alias(checker: &mut Checker, func: &Expr) { +pub(crate) fn sys_exit_alias(checker: &Checker, func: &Expr) { let Some(builtin) = checker.semantic().resolve_builtin_symbol(func) else { return; }; @@ -78,5 +78,5 @@ pub(crate) fn sys_exit_alias(checker: &mut Checker, func: &Expr) { let reference_edit = Edit::range_replacement(binding, func.range()); Ok(Fix::unsafe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs index e7c6bef1ca95d..2e20e80cce463 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs @@ -58,7 +58,7 @@ impl Violation for TooManyArguments { } /// PLR0913 -pub(crate) fn too_many_arguments(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn too_many_arguments(checker: &Checker, function_def: &ast::StmtFunctionDef) { // https://github.com/astral-sh/ruff/issues/14535 if checker.source_type.is_stub() { return; @@ -106,7 +106,7 @@ pub(crate) fn too_many_arguments(checker: &mut Checker, function_def: &ast::Stmt return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyArguments { c_args: num_arguments, max_args: checker.settings.pylint.max_args, diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs index 96047fa979738..ddb86458d5e69 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs @@ -43,11 +43,11 @@ impl Violation for TooManyBooleanExpressions { } /// PLR0916 -pub(crate) fn too_many_boolean_expressions(checker: &mut Checker, stmt: &StmtIf) { +pub(crate) fn too_many_boolean_expressions(checker: &Checker, stmt: &StmtIf) { if let Some(bool_op) = stmt.test.as_bool_op_expr() { let expressions = count_bools(bool_op); if expressions > checker.settings.pylint.max_bool_expr { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyBooleanExpressions { expressions, max_expressions: checker.settings.pylint.max_bool_expr, @@ -61,7 +61,7 @@ pub(crate) fn too_many_boolean_expressions(checker: &mut Checker, stmt: &StmtIf) if let Some(bool_op) = elif.test.as_ref().and_then(Expr::as_bool_op_expr) { let expressions = count_bools(bool_op); if expressions > checker.settings.pylint.max_bool_expr { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyBooleanExpressions { expressions, max_expressions: checker.settings.pylint.max_bool_expr, diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs index 3293a9a586443..a144b81098908 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs @@ -37,7 +37,7 @@ impl Violation for TooManyLocals { } /// PLR0914 -pub(crate) fn too_many_locals(checker: &Checker, scope: &Scope, diagnostics: &mut Vec) { +pub(crate) fn too_many_locals(checker: &Checker, scope: &Scope) { let num_locals = scope .binding_ids() .filter(|id| { @@ -47,7 +47,7 @@ pub(crate) fn too_many_locals(checker: &Checker, scope: &Scope, diagnostics: &mu .count(); if num_locals > checker.settings.pylint.max_locals { if let ScopeKind::Function(func) = scope.kind { - diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyLocals { current_amount: num_locals, max_amount: checker.settings.pylint.max_locals, diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs index c796402adb080..63ea268e8462a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs @@ -36,7 +36,7 @@ impl Violation for TooManyNestedBlocks { } /// PLR1702 -pub(crate) fn too_many_nested_blocks(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn too_many_nested_blocks(checker: &Checker, stmt: &Stmt) { // Only enforce nesting within functions or methods. if !checker.semantic().current_scope().kind.is_function() { return; @@ -74,7 +74,7 @@ pub(crate) fn too_many_nested_blocks(checker: &mut Checker, stmt: &Stmt) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyNestedBlocks { nested_blocks: count, max_nested_blocks, diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs index ddd2a5d36357a..28300a5cb9c46 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs @@ -57,7 +57,7 @@ impl Violation for TooManyPositionalArguments { /// PLR0917 pub(crate) fn too_many_positional_arguments( - checker: &mut Checker, + checker: &Checker, function_def: &ast::StmtFunctionDef, ) { // https://github.com/astral-sh/ruff/issues/14535 @@ -110,7 +110,7 @@ pub(crate) fn too_many_positional_arguments( return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyPositionalArguments { c_pos: num_positional_args, max_pos: checker.settings.pylint.max_positional_args, diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs index 1ca87aad44104..a5e7d9883f33e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs @@ -101,7 +101,7 @@ impl Violation for TooManyPublicMethods { /// R0904 pub(crate) fn too_many_public_methods( - checker: &mut Checker, + checker: &Checker, class_def: &ast::StmtClassDef, max_methods: usize, ) { @@ -121,7 +121,7 @@ pub(crate) fn too_many_public_methods( .count(); if methods > max_methods { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TooManyPublicMethods { methods, max_methods, diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs index c639e33840118..0180c3cda5587 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs @@ -73,7 +73,7 @@ impl Violation for TypeBivariance { } /// PLC0131 -pub(crate) fn type_bivariance(checker: &mut Checker, value: &Expr) { +pub(crate) fn type_bivariance(checker: &Checker, value: &Expr) { // If the typing modules were never imported, we'll never match below. if !checker.semantic().seen_typing() { return; @@ -124,7 +124,7 @@ pub(crate) fn type_bivariance(checker: &mut Checker, value: &Expr) { return; }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TypeBivariance { kind, param_name: type_param_name(arguments).map(ToString::to_string), diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs index 37dd7f544cb74..b6981f259f7ee 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs @@ -64,7 +64,7 @@ impl Violation for TypeNameIncorrectVariance { } /// PLC0105 -pub(crate) fn type_name_incorrect_variance(checker: &mut Checker, value: &Expr) { +pub(crate) fn type_name_incorrect_variance(checker: &Checker, value: &Expr) { // If the typing modules were never imported, we'll never match below. if !checker.semantic().seen_typing() { return; @@ -126,7 +126,7 @@ pub(crate) fn type_name_incorrect_variance(checker: &mut Checker, value: &Expr) VarVariance::Invariance => name_root.to_string(), }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TypeNameIncorrectVariance { kind, param_name: param_name.to_string(), diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs index 04dfb50b6736f..ca08d84e79813 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs @@ -58,7 +58,7 @@ impl Violation for TypeParamNameMismatch { } /// PLC0132 -pub(crate) fn type_param_name_mismatch(checker: &mut Checker, value: &Expr, targets: &[Expr]) { +pub(crate) fn type_param_name_mismatch(checker: &Checker, value: &Expr, targets: &[Expr]) { // If the typing modules were never imported, we'll never match below. if !checker.semantic().seen_typing() { return; @@ -119,7 +119,7 @@ pub(crate) fn type_param_name_mismatch(checker: &mut Checker, value: &Expr, targ return; }; - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( TypeParamNameMismatch { kind, var_name: var_name.to_string(), diff --git a/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs b/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs index dac7bc9655d31..b921dbf318be1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs @@ -137,7 +137,7 @@ impl Violation for UnexpectedSpecialMethodSignature { /// PLE0302 pub(crate) fn unexpected_special_method_signature( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, name: &str, decorator_list: &[Decorator], @@ -189,7 +189,7 @@ pub(crate) fn unexpected_special_method_signature( }; if !valid_signature { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnexpectedSpecialMethodSignature { method_name: name.to_owned(), expected_params, diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs index 26003fa609b98..2173f718ee234 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for UnnecessaryDictIndexLookup { } /// PLR1733 -pub(crate) fn unnecessary_dict_index_lookup(checker: &mut Checker, stmt_for: &StmtFor) { +pub(crate) fn unnecessary_dict_index_lookup(checker: &Checker, stmt_for: &StmtFor) { let Some((dict_name, index_name, value_name)) = dict_items(&stmt_for.iter, &stmt_for.target) else { return; @@ -64,12 +64,12 @@ pub(crate) fn unnecessary_dict_index_lookup(checker: &mut Checker, stmt_for: &St Edit::range_replacement(value_name.id.to_string(), range), [noop(index_name), noop(value_name)], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// PLR1733 -pub(crate) fn unnecessary_dict_index_lookup_comprehension(checker: &mut Checker, expr: &Expr) { +pub(crate) fn unnecessary_dict_index_lookup_comprehension(checker: &Checker, expr: &Expr) { let (Expr::Generator(ast::ExprGenerator { elt, generators, .. }) @@ -109,7 +109,7 @@ pub(crate) fn unnecessary_dict_index_lookup_comprehension(checker: &mut Checker, Edit::range_replacement(value_name.id.to_string(), range), [noop(index_name), noop(value_name)], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs index ddb77bcbe3b17..1b8775fd3ad91 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs @@ -36,10 +36,8 @@ impl Violation for UnnecessaryDirectLambdaCall { } /// PLC3002 -pub(crate) fn unnecessary_direct_lambda_call(checker: &mut Checker, expr: &Expr, func: &Expr) { +pub(crate) fn unnecessary_direct_lambda_call(checker: &Checker, expr: &Expr, func: &Expr) { if let Expr::Lambda(_) = func { - checker - .diagnostics - .push(Diagnostic::new(UnnecessaryDirectLambdaCall, expr.range())); + checker.report_diagnostic(Diagnostic::new(UnnecessaryDirectLambdaCall, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs index 2f910875789a9..a9a43177075f8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs @@ -65,7 +65,7 @@ impl Violation for UnnecessaryDunderCall { } /// PLC2801 -pub(crate) fn unnecessary_dunder_call(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = call.func.as_ref() else { return; }; @@ -210,7 +210,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &mut Checker, call: &ast::ExprCal ))); }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Return `true` if this is a dunder method that is allowed to be called explicitly. diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs index 73e373fb89ee9..9b6483b31b02c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs @@ -58,7 +58,7 @@ impl AlwaysFixableViolation for UnnecessaryLambda { } /// PLW0108 -pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { +pub(crate) fn unnecessary_lambda(checker: &Checker, lambda: &ExprLambda) { let ExprLambda { parameters, body, @@ -215,7 +215,7 @@ pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { ), Applicability::Unsafe, )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Identify all `Expr::Name` nodes in an AST. diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs index 952ea2faac671..e4c2b594d948a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs @@ -46,7 +46,7 @@ impl AlwaysFixableViolation for UnnecessaryListIndexLookup { } /// PLR1736 -pub(crate) fn unnecessary_list_index_lookup(checker: &mut Checker, stmt_for: &StmtFor) { +pub(crate) fn unnecessary_list_index_lookup(checker: &Checker, stmt_for: &StmtFor) { let Some((sequence, index_name, value_name)) = enumerate_items(&stmt_for.iter, &stmt_for.target, checker.semantic()) else { @@ -66,12 +66,12 @@ pub(crate) fn unnecessary_list_index_lookup(checker: &mut Checker, stmt_for: &St Edit::range_replacement(value_name.id.to_string(), range), [noop(index_name), noop(value_name)], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// PLR1736 -pub(crate) fn unnecessary_list_index_lookup_comprehension(checker: &mut Checker, expr: &Expr) { +pub(crate) fn unnecessary_list_index_lookup_comprehension(checker: &Checker, expr: &Expr) { let (Expr::Generator(ast::ExprGenerator { elt, generators, .. }) @@ -110,7 +110,7 @@ pub(crate) fn unnecessary_list_index_lookup_comprehension(checker: &mut Checker, Edit::range_replacement(value_name.id.to_string(), range), [noop(index_name), noop(value_name)], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs index a87793a92423f..0ebee95e794e3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs @@ -72,7 +72,7 @@ impl AlwaysFixableViolation for UnspecifiedEncoding { } /// PLW1514 -pub(crate) fn unspecified_encoding(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unspecified_encoding(checker: &Checker, call: &ast::ExprCall) { let Some((function_name, mode)) = Callee::try_from_call_expression(call, checker.semantic()) .filter(|segments| is_violation(call, segments)) .map(|segments| (segments.to_string(), segments.mode_argument())) @@ -88,7 +88,7 @@ pub(crate) fn unspecified_encoding(checker: &mut Checker, call: &ast::ExprCall) call.func.range(), ); diagnostic.set_fix(generate_keyword_fix(checker, call)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Represents the path of the function or method being called. diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs index 19ebcf1dfebf6..0161b2e4f0087 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs @@ -63,12 +63,7 @@ impl Violation for UselessElseOnLoop { } /// PLW0120 -pub(crate) fn useless_else_on_loop( - checker: &mut Checker, - stmt: &Stmt, - body: &[Stmt], - orelse: &[Stmt], -) { +pub(crate) fn useless_else_on_loop(checker: &Checker, stmt: &Stmt, body: &[Stmt], orelse: &[Stmt]) { if orelse.is_empty() || loop_exits_early(body) { return; } @@ -86,7 +81,7 @@ pub(crate) fn useless_else_on_loop( checker.stylist(), ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns `true` if the given body contains a `break` statement. diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs index 633be017357e2..2e2d7db477f0d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs @@ -50,7 +50,7 @@ impl Violation for UselessExceptionStatement { } /// PLW0133 -pub(crate) fn useless_exception_statement(checker: &mut Checker, expr: &ast::StmtExpr) { +pub(crate) fn useless_exception_statement(checker: &Checker, expr: &ast::StmtExpr) { let Expr::Call(ast::ExprCall { func, .. }) = expr.value.as_ref() else { return; }; @@ -61,7 +61,7 @@ pub(crate) fn useless_exception_statement(checker: &mut Checker, expr: &ast::Stm "raise ".to_string(), expr.start(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs index 25ea96e35c60f..292f26f8f6ba3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs @@ -55,7 +55,7 @@ impl Violation for UselessImportAlias { } /// PLC0414 -pub(crate) fn useless_import_alias(checker: &mut Checker, alias: &Alias) { +pub(crate) fn useless_import_alias(checker: &Checker, alias: &Alias) { let Some(asname) = &alias.asname else { return; }; @@ -81,12 +81,12 @@ pub(crate) fn useless_import_alias(checker: &mut Checker, alias: &Alias) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// PLC0414 pub(crate) fn useless_import_from_alias( - checker: &mut Checker, + checker: &Checker, alias: &Alias, module: Option<&str>, level: u32, @@ -119,5 +119,5 @@ pub(crate) fn useless_import_from_alias( ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs index 83bb4a838c8f0..b06064d842600 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UselessReturn { /// PLR1711 pub(crate) fn useless_return( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, body: &[Stmt], returns: Option<&Expr>, @@ -99,5 +99,5 @@ pub(crate) fn useless_return( diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs index 378013cde8c23..02d0b1df4ab9a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs @@ -58,7 +58,7 @@ impl Violation for UselessWithLock { } /// PLW2101 -pub(crate) fn useless_with_lock(checker: &mut Checker, with: &ast::StmtWith) { +pub(crate) fn useless_with_lock(checker: &Checker, with: &ast::StmtWith) { for item in &with.items { let Some(call) = item.context_expr.as_call_expr() else { continue; @@ -80,8 +80,6 @@ pub(crate) fn useless_with_lock(checker: &mut Checker, with: &ast::StmtWith) { return; } - checker - .diagnostics - .push(Diagnostic::new(UselessWithLock, call.range())); + checker.report_diagnostic(Diagnostic::new(UselessWithLock, call.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs b/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs index 7ea7771f4fd91..7a8c31e744cf7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs @@ -38,13 +38,11 @@ impl Violation for YieldFromInAsyncFunction { } /// PLE1700 -pub(crate) fn yield_from_in_async_function(checker: &mut Checker, expr: &ast::ExprYieldFrom) { +pub(crate) fn yield_from_in_async_function(checker: &Checker, expr: &ast::ExprYieldFrom) { if matches!( checker.semantic().current_scope().kind, ScopeKind::Function(ast::StmtFunctionDef { is_async: true, .. }) ) { - checker - .diagnostics - .push(Diagnostic::new(YieldFromInAsyncFunction, expr.range())); + checker.report_diagnostic(Diagnostic::new(YieldFromInAsyncFunction, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs b/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs index 5ce1903803af4..60a0c349b16d3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs @@ -39,10 +39,8 @@ impl Violation for YieldInInit { } /// PLE0100 -pub(crate) fn yield_in_init(checker: &mut Checker, expr: &Expr) { +pub(crate) fn yield_in_init(checker: &Checker, expr: &Expr) { if in_dunder_method("__init__", checker.semantic(), checker.settings) { - checker - .diagnostics - .push(Diagnostic::new(YieldInInit, expr.range())); + checker.report_diagnostic(Diagnostic::new(YieldInInit, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 514f288865e3d..0c4299ba3b3cd 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -72,7 +72,7 @@ impl Violation for ConvertNamedTupleFunctionalToClass { /// UP014 pub(crate) fn convert_named_tuple_functional_to_class( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, targets: &[Expr], value: &Expr, @@ -130,7 +130,7 @@ pub(crate) fn convert_named_tuple_functional_to_class( checker.comment_ranges(), )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Return the typename, args, keywords, and base class. diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index ef3e3768e4913..3891ae3ac7cbf 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -67,7 +67,7 @@ impl Violation for ConvertTypedDictFunctionalToClass { /// UP013 pub(crate) fn convert_typed_dict_functional_to_class( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, targets: &[Expr], value: &Expr, @@ -100,7 +100,7 @@ pub(crate) fn convert_typed_dict_functional_to_class( checker.comment_ranges(), )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Return the class name, arguments, keywords and base class for a `TypedDict` diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs index a7adefa18dcfa..77c899c752f7b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -50,7 +50,7 @@ impl Violation for DatetimeTimezoneUTC { } /// UP017 -pub(crate) fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) { +pub(crate) fn datetime_utc_alias(checker: &Checker, expr: &Expr) { if checker .semantic() .resolve_qualified_name(expr) @@ -68,6 +68,6 @@ pub(crate) fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) { let reference_edit = Edit::range_replacement(binding, expr.range()); Ok(Fix::safe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index 0511d3c631813..177bb99d9a89d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -38,7 +38,7 @@ impl AlwaysFixableViolation for DeprecatedCElementTree { } } -fn add_check_for_node(checker: &mut Checker, node: &T) +fn add_check_for_node(checker: &Checker, node: &T) where T: Ranged, { @@ -48,11 +48,11 @@ where contents.replacen("cElementTree", "ElementTree", 1), node.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// UP023 -pub(crate) fn deprecated_c_element_tree(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn deprecated_c_element_tree(checker: &Checker, stmt: &Stmt) { match stmt { Stmt::Import(ast::StmtImport { names, range: _ }) => { // Ex) `import xml.etree.cElementTree as ET` diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs index 6312a69a90942..a11eb3a19e3da 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs @@ -696,7 +696,7 @@ impl<'a> ImportReplacer<'a> { } /// UP035 -pub(crate) fn deprecated_import(checker: &mut Checker, import_from_stmt: &StmtImportFrom) { +pub(crate) fn deprecated_import(checker: &Checker, import_from_stmt: &StmtImportFrom) { // Avoid relative and star imports. if import_from_stmt.level > 0 { return; @@ -738,7 +738,7 @@ pub(crate) fn deprecated_import(checker: &mut Checker, import_from_stmt: &StmtIm import_from_stmt.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } for operation in fixer.with_renames() { @@ -748,6 +748,6 @@ pub(crate) fn deprecated_import(checker: &mut Checker, import_from_stmt: &StmtIm }, import_from_stmt.range(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs index 92268c8ee7702..f0edbc51a4a65 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -250,7 +250,7 @@ fn format_import_from( } /// UP026 -pub(crate) fn deprecated_mock_attribute(checker: &mut Checker, attribute: &ast::ExprAttribute) { +pub(crate) fn deprecated_mock_attribute(checker: &Checker, attribute: &ast::ExprAttribute) { if !checker.semantic().seen_module(Modules::MOCK) { return; } @@ -268,12 +268,12 @@ pub(crate) fn deprecated_mock_attribute(checker: &mut Checker, attribute: &ast:: "mock".to_string(), attribute.value.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } /// UP026 -pub(crate) fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn deprecated_mock_import(checker: &Checker, stmt: &Stmt) { match stmt { Stmt::Import(ast::StmtImport { names, range: _ }) => { // Find all `mock` imports. @@ -309,7 +309,7 @@ pub(crate) fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) { stmt.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -337,7 +337,7 @@ pub(crate) fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) { .map(Fix::safe_edit) }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } _ => (), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index 97a81149dfd99..77087ce14bf53 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -78,7 +78,7 @@ static DEPRECATED_ALIASES: LazyLock> = Laz }); /// UP005 -pub(crate) fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { +pub(crate) fn deprecated_unittest_alias(checker: &Checker, expr: &Expr) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = expr else { return; }; @@ -102,5 +102,5 @@ pub(crate) fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { format!("self.{target}"), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index 81500d4be9515..e032bb6516814 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -391,7 +391,7 @@ impl FStringConversion { } /// UP032 -pub(crate) fn f_strings(checker: &mut Checker, call: &ast::ExprCall, summary: &FormatSummary) { +pub(crate) fn f_strings(checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary) { if summary.has_nested_parts { return; } @@ -528,5 +528,5 @@ pub(crate) fn f_strings(checker: &mut Checker, call: &ast::ExprCall, summary: &F ))); } }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs index 372320060eaf8..b14f9ad181ceb 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs @@ -59,11 +59,7 @@ impl Violation for FormatLiterals { } /// UP030 -pub(crate) fn format_literals( - checker: &mut Checker, - call: &ast::ExprCall, - summary: &FormatSummary, -) { +pub(crate) fn format_literals(checker: &Checker, call: &ast::ExprCall, summary: &FormatSummary) { // The format we expect is, e.g.: `"{0} {1}".format(...)` if summary.has_nested_parts { return; @@ -117,7 +113,7 @@ pub(crate) fn format_literals( generate_call(call, arguments, checker.locator(), checker.stylist()) .map(|suggestion| Fix::unsafe_edit(Edit::range_replacement(suggestion, call.range()))) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns true if the indices are sequential. diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index 5051ad8b5a12c..aa4e142a5a094 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -55,7 +55,7 @@ impl AlwaysFixableViolation for LRUCacheWithMaxsizeNone { } /// UP033 -pub(crate) fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list: &[Decorator]) { +pub(crate) fn lru_cache_with_maxsize_none(checker: &Checker, decorator_list: &[Decorator]) { for decorator in decorator_list { let Expr::Call(ast::ExprCall { func, @@ -101,7 +101,7 @@ pub(crate) fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list: Edit::range_replacement(binding, decorator.expression.range()); Ok(Fix::safe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index da04f10073b13..80c404813c454 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -53,7 +53,7 @@ impl AlwaysFixableViolation for LRUCacheWithoutParameters { } /// UP011 -pub(crate) fn lru_cache_without_parameters(checker: &mut Checker, decorator_list: &[Decorator]) { +pub(crate) fn lru_cache_without_parameters(checker: &Checker, decorator_list: &[Decorator]) { for decorator in decorator_list { let Expr::Call(ast::ExprCall { func, @@ -79,7 +79,7 @@ pub(crate) fn lru_cache_without_parameters(checker: &mut Checker, decorator_list TextRange::new(func.end(), decorator.end()), ); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(arguments.range()))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index 42ffe9cc9331a..c2fe9c782c2f8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -145,7 +145,7 @@ impl AlwaysFixableViolation for NativeLiterals { /// UP018 pub(crate) fn native_literals( - checker: &mut Checker, + checker: &Checker, call: &ast::ExprCall, parent_expr: Option<&ast::Expr>, ) { @@ -202,7 +202,7 @@ pub(crate) fn native_literals( content, call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Some(arg) => { let literal_expr = if let Some(literal_expr) = arg.as_literal_expr() { @@ -254,7 +254,7 @@ pub(crate) fn native_literals( content, call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs index ad9903850994d..1c3a62c8ed18e 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs @@ -46,7 +46,7 @@ impl Violation for OpenAlias { } /// UP020 -pub(crate) fn open_alias(checker: &mut Checker, expr: &Expr, func: &Expr) { +pub(crate) fn open_alias(checker: &Checker, expr: &Expr, func: &Expr) { if checker .semantic() .resolve_qualified_name(func) @@ -64,6 +64,6 @@ pub(crate) fn open_alias(checker: &mut Checker, expr: &Expr, func: &Expr) { import_edit, )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index 72b34ecb42760..a9c65a92a06f6 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -70,7 +70,7 @@ fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool { } /// Create a [`Diagnostic`] for a single target, like an [`Expr::Name`]. -fn atom_diagnostic(checker: &mut Checker, target: &Expr) { +fn atom_diagnostic(checker: &Checker, target: &Expr) { let mut diagnostic = Diagnostic::new( OSErrorAlias { name: UnqualifiedName::from_expr(target).map(|name| name.to_string()), @@ -88,11 +88,11 @@ fn atom_diagnostic(checker: &mut Checker, target: &Expr) { import_edit, )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Create a [`Diagnostic`] for a tuple of expressions. -fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&Expr]) { +fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr]) { let mut diagnostic = Diagnostic::new(OSErrorAlias { name: None }, tuple.range()); let semantic = checker.semantic(); if semantic.has_builtin_binding("OSError") { @@ -138,11 +138,11 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E tuple.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// UP024 -pub(crate) fn os_error_alias_handlers(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn os_error_alias_handlers(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) = handler; let Some(expr) = type_.as_ref() else { @@ -172,14 +172,14 @@ pub(crate) fn os_error_alias_handlers(checker: &mut Checker, handlers: &[ExceptH } /// UP024 -pub(crate) fn os_error_alias_call(checker: &mut Checker, func: &Expr) { +pub(crate) fn os_error_alias_call(checker: &Checker, func: &Expr) { if is_alias(func, checker.semantic()) { atom_diagnostic(checker, func); } } /// UP024 -pub(crate) fn os_error_alias_raise(checker: &mut Checker, expr: &Expr) { +pub(crate) fn os_error_alias_raise(checker: &Checker, expr: &Expr) { if matches!(expr, Expr::Name(_) | Expr::Attribute(_)) { if is_alias(expr, checker.semantic()) { atom_diagnostic(checker, expr); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs index 4bf05db158ae0..37b1c7a859f7f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -82,7 +82,7 @@ enum Reason { } /// UP036 -pub(crate) fn outdated_version_block(checker: &mut Checker, stmt_if: &StmtIf) { +pub(crate) fn outdated_version_block(checker: &Checker, stmt_if: &StmtIf) { for branch in if_elif_branches(stmt_if) { let Expr::Compare(ast::ExprCompare { left, @@ -142,10 +142,10 @@ pub(crate) fn outdated_version_block(checker: &mut Checker, stmt_if: &StmtIf) { } { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Err(_) => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( OutdatedVersionBlock { reason: Reason::Invalid, }, @@ -183,7 +183,7 @@ pub(crate) fn outdated_version_block(checker: &mut Checker, stmt_if: &StmtIf) { if let Some(fix) = fix_always_true_branch(checker, stmt_if, &branch) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Reason::AlwaysFalse => { let mut diagnostic = @@ -191,10 +191,10 @@ pub(crate) fn outdated_version_block(checker: &mut Checker, stmt_if: &StmtIf) { if let Some(fix) = fix_always_false_branch(checker, stmt_if, &branch) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Reason::Invalid => { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( OutdatedVersionBlock { reason: Reason::Invalid, }, @@ -366,7 +366,7 @@ fn fix_always_false_branch( /// if sys.version_info >= (3, 8): ... /// ``` fn fix_always_true_branch( - checker: &mut Checker, + checker: &Checker, stmt_if: &StmtIf, branch: &IfElifBranch, ) -> Option { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs index fbf95f7a931cc..3ed1f805b6755 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_class.rs @@ -104,7 +104,7 @@ impl Violation for NonPEP695GenericClass { } /// UP046 -pub(crate) fn non_pep695_generic_class(checker: &mut Checker, class_def: &StmtClassDef) { +pub(crate) fn non_pep695_generic_class(checker: &Checker, class_def: &StmtClassDef) { // PEP-695 syntax is only available on Python 3.12+ if checker.settings.target_version < PythonVersion::Py312 { return; @@ -154,7 +154,7 @@ pub(crate) fn non_pep695_generic_class(checker: &mut Checker, class_def: &StmtCl // because `find_generic` also finds the *first* Generic argument, this has the additional // benefit of bailing out with a diagnostic if multiple Generic arguments are present if generic_idx != arguments.len() - 1 { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); return; } @@ -210,5 +210,5 @@ pub(crate) fn non_pep695_generic_class(checker: &mut Checker, class_def: &StmtCl }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_function.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_function.rs index ea6a8a40b4d7f..1a5ed053e8d78 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_function.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_function.rs @@ -96,7 +96,7 @@ impl Violation for NonPEP695GenericFunction { } /// UP047 -pub(crate) fn non_pep695_generic_function(checker: &mut Checker, function_def: &StmtFunctionDef) { +pub(crate) fn non_pep695_generic_function(checker: &Checker, function_def: &StmtFunctionDef) { // PEP-695 syntax is only available on Python 3.12+ if checker.settings.target_version < PythonVersion::Py312 { return; @@ -163,7 +163,7 @@ pub(crate) fn non_pep695_generic_function(checker: &mut Checker, function_def: & source: checker.source(), }; - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new( NonPEP695GenericFunction { name: name.to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs index 0762580d073f7..7a5e12352354c 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs @@ -110,7 +110,7 @@ impl Violation for NonPEP695TypeAlias { } /// UP040 -pub(crate) fn non_pep695_type_alias_type(checker: &mut Checker, stmt: &StmtAssign) { +pub(crate) fn non_pep695_type_alias_type(checker: &Checker, stmt: &StmtAssign) { if checker.settings.target_version < PythonVersion::Py312 { return; } @@ -182,7 +182,7 @@ pub(crate) fn non_pep695_type_alias_type(checker: &mut Checker, stmt: &StmtAssig Applicability::Safe }; - checker.diagnostics.push(create_diagnostic( + checker.report_diagnostic(create_diagnostic( checker.source(), stmt.range, &target_name.id, @@ -194,7 +194,7 @@ pub(crate) fn non_pep695_type_alias_type(checker: &mut Checker, stmt: &StmtAssig } /// UP040 -pub(crate) fn non_pep695_type_alias(checker: &mut Checker, stmt: &StmtAnnAssign) { +pub(crate) fn non_pep695_type_alias(checker: &Checker, stmt: &StmtAnnAssign) { if checker.settings.target_version < PythonVersion::Py312 { return; } @@ -242,7 +242,7 @@ pub(crate) fn non_pep695_type_alias(checker: &mut Checker, stmt: &StmtAnnAssign) return; } - checker.diagnostics.push(create_diagnostic( + checker.report_diagnostic(create_diagnostic( checker.source(), stmt.range(), name, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index 3917f8bf6b4cb..205b0219ca26f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -361,7 +361,7 @@ fn convertible(format_string: &CFormatString, params: &Expr) -> bool { /// UP031 pub(crate) fn printf_string_formatting( - checker: &mut Checker, + checker: &Checker, bin_op: &ast::ExprBinOp, string_expr: &ast::ExprStringLiteral, ) { @@ -384,9 +384,7 @@ pub(crate) fn printf_string_formatting( return; }; if !convertible(&format_string, right) { - checker - .diagnostics - .push(Diagnostic::new(PrintfStringFormatting, string_expr.range())); + checker.report_diagnostic(Diagnostic::new(PrintfStringFormatting, string_expr.range())); return; } @@ -447,9 +445,10 @@ pub(crate) fn printf_string_formatting( let Some(params_string) = clean_params_dictionary(right, checker.locator(), checker.stylist()) else { - checker - .diagnostics - .push(Diagnostic::new(PrintfStringFormatting, string_expr.range())); + checker.report_diagnostic(Diagnostic::new( + PrintfStringFormatting, + string_expr.range(), + )); return; }; Cow::Owned(params_string) @@ -509,7 +508,7 @@ pub(crate) fn printf_string_formatting( contents, bin_op.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[cfg(test)] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs index c1a4022716977..9afaa5104f8df 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs @@ -84,7 +84,7 @@ impl AlwaysFixableViolation for QuotedAnnotation { } /// UP037 -pub(crate) fn quoted_annotation(checker: &mut Checker, annotation: &str, range: TextRange) { +pub(crate) fn quoted_annotation(checker: &Checker, annotation: &str, range: TextRange) { let diagnostic = Diagnostic::new(QuotedAnnotation, range); let placeholder_range = TextRange::up_to(annotation.text_len()); @@ -108,7 +108,7 @@ pub(crate) fn quoted_annotation(checker: &mut Checker, annotation: &str, range: let edit = Edit::range_replacement(new_content, range); let fix = Fix::safe_edit(edit); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } fn in_parameter_annotation(offset: TextSize, semantic: &SemanticModel) -> bool { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs index b6fcfbaf7fd40..1451301913f9a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -56,7 +56,7 @@ impl AlwaysFixableViolation for RedundantOpenModes { } /// UP015 -pub(crate) fn redundant_open_modes(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn redundant_open_modes(checker: &Checker, call: &ast::ExprCall) { if !checker .semantic() .resolve_qualified_name(&call.func) @@ -81,9 +81,7 @@ pub(crate) fn redundant_open_modes(checker: &mut Checker, call: &ast::ExprCall) }; let reduced = mode.reduce(); if reduced != mode { - checker - .diagnostics - .push(create_diagnostic(call, mode_arg, reduced, checker)); + checker.report_diagnostic(create_diagnostic(call, mode_arg, reduced, checker)); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs index b6088e65f12dc..9a752241d0000 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -53,7 +53,7 @@ impl Violation for ReplaceStdoutStderr { } /// UP022 -pub(crate) fn replace_stdout_stderr(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn replace_stdout_stderr(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::SUBPROCESS) { return; } @@ -93,7 +93,7 @@ pub(crate) fn replace_stdout_stderr(checker: &mut Checker, call: &ast::ExprCall) diagnostic .try_set_fix(|| generate_fix(stdout, stderr, call, checker.locator().contents())); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs index 75a7adf0c57f4..3d7db1bdbd480 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs @@ -97,7 +97,7 @@ impl Violation for ReplaceStrEnum { } /// UP042 -pub(crate) fn replace_str_enum(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn replace_str_enum(checker: &Checker, class_def: &ast::StmtClassDef) { let Some(arguments) = class_def.arguments.as_deref() else { // class does not inherit anything, exit early return; @@ -154,5 +154,5 @@ pub(crate) fn replace_str_enum(checker: &mut Checker, class_def: &ast::StmtClass }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs index b951f05d04c7f..3f31a36d9ae80 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -49,7 +49,7 @@ impl AlwaysFixableViolation for ReplaceUniversalNewlines { } /// UP021 -pub(crate) fn replace_universal_newlines(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn replace_universal_newlines(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().seen_module(Modules::SUBPROCESS) { return; } @@ -85,6 +85,6 @@ pub(crate) fn replace_universal_newlines(checker: &mut Checker, call: &ast::Expr arg.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index 2a6d7ee81a7f0..ba11eb64c5505 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -58,7 +58,7 @@ impl AlwaysFixableViolation for SuperCallWithParameters { } /// UP008 -pub(crate) fn super_call_with_parameters(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall) { // Only bother going through the super check at all if we're in a `super` call. // (We check this in `super_args` too, so this is just an optimization.) if !is_super_call_with_arguments(call) { @@ -157,7 +157,7 @@ pub(crate) fn super_call_with_parameters(checker: &mut Checker, call: &ast::Expr call.arguments.start() + TextSize::new(1), call.arguments.end() - TextSize::new(1), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns `true` if a call is an argumented `super` invocation. diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs index 3591c9940b478..a1387cb7c545a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs @@ -82,7 +82,7 @@ fn is_alias(expr: &Expr, semantic: &SemanticModel, target_version: PythonVersion } /// Create a [`Diagnostic`] for a single target, like an [`Expr::Name`]. -fn atom_diagnostic(checker: &mut Checker, target: &Expr) { +fn atom_diagnostic(checker: &Checker, target: &Expr) { let mut diagnostic = Diagnostic::new( TimeoutErrorAlias { name: UnqualifiedName::from_expr(target).map(|name| name.to_string()), @@ -100,11 +100,11 @@ fn atom_diagnostic(checker: &mut Checker, target: &Expr) { import_edit, )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Create a [`Diagnostic`] for a tuple of expressions. -fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&Expr]) { +fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr]) { let mut diagnostic = Diagnostic::new(TimeoutErrorAlias { name: None }, tuple.range()); let semantic = checker.semantic(); if semantic.has_builtin_binding("TimeoutError") { @@ -150,11 +150,11 @@ fn tuple_diagnostic(checker: &mut Checker, tuple: &ast::ExprTuple, aliases: &[&E tuple.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// UP041 -pub(crate) fn timeout_error_alias_handlers(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn timeout_error_alias_handlers(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) = handler; let Some(expr) = type_.as_ref() else { @@ -184,14 +184,14 @@ pub(crate) fn timeout_error_alias_handlers(checker: &mut Checker, handlers: &[Ex } /// UP041 -pub(crate) fn timeout_error_alias_call(checker: &mut Checker, func: &Expr) { +pub(crate) fn timeout_error_alias_call(checker: &Checker, func: &Expr) { if is_alias(func, checker.semantic(), checker.settings.target_version) { atom_diagnostic(checker, func); } } /// UP041 -pub(crate) fn timeout_error_alias_raise(checker: &mut Checker, expr: &Expr) { +pub(crate) fn timeout_error_alias_raise(checker: &Checker, expr: &Expr) { if matches!(expr, Expr::Name(_) | Expr::Attribute(_)) { if is_alias(expr, checker.semantic(), checker.settings.target_version) { atom_diagnostic(checker, expr); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs index 2dffa3c81d8af..3308350af4506 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -54,7 +54,7 @@ impl Violation for TypeOfPrimitive { } /// UP003 -pub(crate) fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { +pub(crate) fn type_of_primitive(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { let [arg] = args else { return; }; @@ -73,5 +73,5 @@ pub(crate) fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs index 51d1516a40225..4a4165b878b4e 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -46,7 +46,7 @@ impl Violation for TypingTextStrAlias { } /// UP019 -pub(crate) fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { +pub(crate) fn typing_text_str_alias(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::TYPING) { return; } @@ -68,6 +68,6 @@ pub(crate) fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { import_edit, )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 33d68c9281ab5..1447896ab50cc 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -39,13 +39,13 @@ impl AlwaysFixableViolation for UnicodeKindPrefix { } /// UP025 -pub(crate) fn unicode_kind_prefix(checker: &mut Checker, string: &StringLiteral) { +pub(crate) fn unicode_kind_prefix(checker: &Checker, string: &StringLiteral) { if string.flags.prefix().is_unicode() { let mut diagnostic = Diagnostic::new(UnicodeKindPrefix, string.range); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(TextRange::at( string.start(), TextSize::from(1), )))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs index 167cfd1406c1f..f89671027777a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -54,7 +54,7 @@ impl AlwaysFixableViolation for UnnecessaryBuiltinImport { /// UP029 pub(crate) fn unnecessary_builtin_import( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, module: &str, names: &[Alias], @@ -138,5 +138,5 @@ pub(crate) fn unnecessary_builtin_import( checker.semantic().current_statement_parent_id(), ))) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs index 5e9703b0f71d5..d671e0c33751b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs @@ -39,7 +39,7 @@ impl AlwaysFixableViolation for UnnecessaryClassParentheses { } /// UP039 -pub(crate) fn unnecessary_class_parentheses(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn unnecessary_class_parentheses(checker: &Checker, class_def: &ast::StmtClassDef) { let Some(arguments) = class_def.arguments.as_deref() else { return; }; @@ -53,5 +53,5 @@ pub(crate) fn unnecessary_class_parentheses(checker: &mut Checker, class_def: &a arguments.start(), arguments.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs index d7783c98de926..4a994f7b6b8c2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs @@ -74,7 +74,7 @@ impl AlwaysFixableViolation for UnnecessaryDefaultTypeArgs { } /// UP043 -pub(crate) fn unnecessary_default_type_args(checker: &mut Checker, expr: &Expr) { +pub(crate) fn unnecessary_default_type_args(checker: &Checker, expr: &Expr) { let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = expr else { return; }; @@ -136,7 +136,7 @@ pub(crate) fn unnecessary_default_type_args(checker: &mut Checker, expr: &Expr) ), applicability, )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Trim trailing `None` literals from the given elements. diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 89f53b46c17a4..505ed8ffa522d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -148,7 +148,7 @@ fn replace_with_bytes_literal(locator: &Locator, call: &ast::ExprCall, tokens: & } /// UP012 -pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn unnecessary_encode_utf8(checker: &Checker, call: &ast::ExprCall) { let Some(variable) = match_encoded_variable(&call.func) else { return; }; @@ -169,7 +169,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal call, checker.tokens(), )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else if let EncodingArg::Keyword(kwarg) = encoding_arg { // Ex) Convert `"unicode text©".encode(encoding="utf-8")` to // `"unicode text©".encode()`. @@ -188,7 +188,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else if let EncodingArg::Positional(arg) = encoding_arg { // Ex) Convert `"unicode text©".encode("utf-8")` to `"unicode text©".encode()`. let mut diagnostic = Diagnostic::new( @@ -206,7 +206,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } @@ -231,7 +231,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } else if let EncodingArg::Positional(arg) = encoding_arg { // Ex) Convert `f"unicode text©".encode("utf-8")` to `f"unicode text©".encode()`. let mut diagnostic = Diagnostic::new( @@ -249,7 +249,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 6fb174e7fbd84..d04d11580adc8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -82,7 +82,7 @@ const PY37_PLUS_REMOVE_FUTURES: &[&str] = &[ ]; /// UP010 -pub(crate) fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, names: &[Alias]) { +pub(crate) fn unnecessary_future_import(checker: &Checker, stmt: &Stmt, names: &[Alias]) { let mut unused_imports: Vec<&Alias> = vec![]; for alias in names { if alias.asname.is_some() { @@ -127,5 +127,5 @@ pub(crate) fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, name checker.semantic().current_statement_parent_id(), ))) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs index 1e08b7e9aa176..cc4c89bfe9f4d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -76,11 +76,7 @@ impl Violation for NonPEP585Annotation { } /// UP006 -pub(crate) fn use_pep585_annotation( - checker: &mut Checker, - expr: &Expr, - replacement: &ModuleMember, -) { +pub(crate) fn use_pep585_annotation(checker: &Checker, expr: &Expr, replacement: &ModuleMember) { let Some(from) = UnqualifiedName::from_expr(expr) else { return; }; @@ -136,5 +132,5 @@ pub(crate) fn use_pep585_annotation( } } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs index cd389116f8dbb..5a370cce3fecc 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -130,7 +130,7 @@ impl Violation for NonPEP604AnnotationOptional { /// UP007, UP045 pub(crate) fn non_pep604_annotation( - checker: &mut Checker, + checker: &Checker, expr: &Expr, slice: &Expr, operator: Pep604Operator, @@ -186,7 +186,7 @@ pub(crate) fn non_pep604_annotation( } } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } Pep604Operator::Union => { if !checker.enabled(Rule::NonPEP604AnnotationUnion) { @@ -228,7 +228,7 @@ pub(crate) fn non_pep604_annotation( } } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index d1d9c5cf78722..067ee2acbd491 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -81,12 +81,7 @@ impl AlwaysFixableViolation for NonPEP604Isinstance { } /// UP038 -pub(crate) fn use_pep604_isinstance( - checker: &mut Checker, - expr: &Expr, - func: &Expr, - args: &[Expr], -) { +pub(crate) fn use_pep604_isinstance(checker: &Checker, expr: &Expr, func: &Expr, args: &[Expr]) { let Some(types) = args.get(1) else { return; }; @@ -107,7 +102,7 @@ pub(crate) fn use_pep604_isinstance( let Some(kind) = CallKind::from_name(builtin_function_name) else { return; }; - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new(NonPEP604Isinstance { kind }, expr.range()).with_fix(Fix::unsafe_edit( Edit::range_replacement( checker.generator().expr(&pep_604_union(&tuple.elts)), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs index 8d802dd3ac2dc..d9d14e9d292d7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs @@ -52,7 +52,7 @@ impl Violation for NonPEP646Unpack { } /// UP044 -pub(crate) fn use_pep646_unpack(checker: &mut Checker, expr: &ExprSubscript) { +pub(crate) fn use_pep646_unpack(checker: &Checker, expr: &ExprSubscript) { if checker.settings.target_version < PythonVersion::Py311 { return; } @@ -93,7 +93,7 @@ pub(crate) fn use_pep646_unpack(checker: &mut Checker, expr: &ExprSubscript) { format!("*{}", checker.locator().slice(slice.as_ref())), *range, ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Determine whether the [`ExprSubscript`] is in a subscript index (e.g., `Generic[Unpack[int]]`). diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs index 47d6ba5e92aa2..1ca18d6fa06c6 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -44,7 +44,7 @@ impl AlwaysFixableViolation for UselessMetaclassType { /// UP001 pub(crate) fn useless_metaclass_type( - checker: &mut Checker, + checker: &Checker, stmt: &Stmt, value: &Expr, targets: &[Expr], @@ -69,5 +69,5 @@ pub(crate) fn useless_metaclass_type( diagnostic.set_fix(Fix::safe_edit(edit).isolate(Checker::isolation( checker.semantic().current_statement_parent_id(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs index 243ce6e86f6d1..53b7e0f7dbc41 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for UselessObjectInheritance { } /// UP004 -pub(crate) fn useless_object_inheritance(checker: &mut Checker, class_def: &ast::StmtClassDef) { +pub(crate) fn useless_object_inheritance(checker: &Checker, class_def: &ast::StmtClassDef) { let Some(arguments) = class_def.arguments.as_deref() else { return; }; @@ -70,6 +70,6 @@ pub(crate) fn useless_object_inheritance(checker: &mut Checker, class_def: &ast: ) .map(Fix::safe_edit) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs index 922122d481b4b..cfbbec09d57a5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for YieldInForLoop { } /// UP028 -pub(crate) fn yield_in_for_loop(checker: &mut Checker, stmt_for: &ast::StmtFor) { +pub(crate) fn yield_in_for_loop(checker: &Checker, stmt_for: &ast::StmtFor) { // Intentionally omit async contexts. if checker.semantic().in_async_context() { return; @@ -134,7 +134,7 @@ pub(crate) fn yield_in_for_loop(checker: &mut Checker, stmt_for: &ast::StmtFor) contents, stmt_for.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Return `true` if the two expressions are equivalent, and both consistent solely diff --git a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs index 713d5844603d5..c855081c5b424 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs @@ -56,7 +56,7 @@ impl AlwaysFixableViolation for BitCount { } /// FURB161 -pub(crate) fn bit_count(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn bit_count(checker: &Checker, call: &ExprCall) { // `int.bit_count()` was added in Python 3.10 if checker.settings.target_version < PythonVersion::Py310 { return; @@ -177,5 +177,5 @@ pub(crate) fn bit_count(checker: &mut Checker, call: &ExprCall) { call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index 5290d98c37cab..55c1c3e93eb7c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -67,7 +67,7 @@ impl AlwaysFixableViolation for CheckAndRemoveFromSet { } /// FURB132 -pub(crate) fn check_and_remove_from_set(checker: &mut Checker, if_stmt: &ast::StmtIf) { +pub(crate) fn check_and_remove_from_set(checker: &Checker, if_stmt: &ast::StmtIf) { // In order to fit the profile, we need if without else clauses and with only one statement in its body. if if_stmt.body.len() != 1 || !if_stmt.elif_else_clauses.is_empty() { return; @@ -116,7 +116,7 @@ pub(crate) fn check_and_remove_from_set(checker: &mut Checker, if_stmt: &ast::St if_stmt.start(), if_stmt.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn compare(lhs: &ComparableExpr, rhs: &ComparableExpr) -> bool { diff --git a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs index 99df2e9cae1ca..e07864fbf95b2 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs @@ -60,7 +60,7 @@ impl Violation for DeleteFullSlice { } /// FURB131 -pub(crate) fn delete_full_slice(checker: &mut Checker, delete: &ast::StmtDelete) { +pub(crate) fn delete_full_slice(checker: &Checker, delete: &ast::StmtDelete) { for target in &delete.targets { let Some(name) = match_full_slice(target, checker.semantic()) else { continue; @@ -78,7 +78,7 @@ pub(crate) fn delete_full_slice(checker: &mut Checker, delete: &ast::StmtDelete) ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs index 7751f668aaf92..ceb0fab87bd8c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs @@ -60,7 +60,7 @@ impl AlwaysFixableViolation for ForLoopSetMutations { } /// FURB142 -pub(crate) fn for_loop_set_mutations(checker: &mut Checker, for_stmt: &StmtFor) { +pub(crate) fn for_loop_set_mutations(checker: &Checker, for_stmt: &StmtFor) { if !for_stmt.orelse.is_empty() { return; } @@ -136,5 +136,5 @@ pub(crate) fn for_loop_set_mutations(checker: &mut Checker, for_stmt: &StmtFor) for_stmt.range, ); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs b/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs index 55bba05d2a16a..e3b5765593df2 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs @@ -78,7 +78,7 @@ pub(crate) fn for_loop_writes_binding(checker: &Checker, binding: &Binding) -> O } /// FURB122 -pub(crate) fn for_loop_writes_stmt(checker: &mut Checker, for_stmt: &StmtFor) { +pub(crate) fn for_loop_writes_stmt(checker: &Checker, for_stmt: &StmtFor) { // Loops with bindings are handled later. if !binding_names(&for_stmt.target).is_empty() { return; @@ -87,7 +87,7 @@ pub(crate) fn for_loop_writes_stmt(checker: &mut Checker, for_stmt: &StmtFor) { let scope_id = checker.semantic().scope_id; if let Some(diagnostic) = for_loop_writes(checker, for_stmt, scope_id, &[]) { - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs index 34fc9b84d7fb8..d71772e6ded69 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs @@ -62,7 +62,7 @@ impl Violation for FStringNumberFormat { } /// FURB116 -pub(crate) fn fstring_number_format(checker: &mut Checker, subscript: &ast::ExprSubscript) { +pub(crate) fn fstring_number_format(checker: &Checker, subscript: &ast::ExprSubscript) { // The slice must be exactly `[2:]`. let Expr::Slice(ast::ExprSlice { lower: Some(lower), @@ -140,7 +140,7 @@ pub(crate) fn fstring_number_format(checker: &mut Checker, subscript: &ast::Expr ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs index a9d3921fa8a57..c9583cdbddabe 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for HardcodedStringCharset { } /// FURB156 -pub(crate) fn hardcoded_string_charset_literal(checker: &mut Checker, expr: &ExprStringLiteral) { +pub(crate) fn hardcoded_string_charset_literal(checker: &Checker, expr: &ExprStringLiteral) { if let Some(charset) = check_charset_exact(expr.value.to_str().as_bytes()) { push_diagnostic(checker, expr.range, charset); } @@ -122,7 +122,7 @@ fn check_charset_exact(bytes: &[u8]) -> Option<&NamedCharset> { .find(|&charset| charset.bytes == bytes) } -fn push_diagnostic(checker: &mut Checker, range: TextRange, charset: &NamedCharset) { +fn push_diagnostic(checker: &Checker, range: TextRange, charset: &NamedCharset) { let name = charset.name; let mut diagnostic = Diagnostic::new(HardcodedStringCharset { name }, range); diagnostic.try_set_fix(|| { @@ -136,5 +136,5 @@ fn push_diagnostic(checker: &mut Checker, range: TextRange, charset: &NamedChars [edit], )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs b/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs index aa16786f737de..617173613773a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs @@ -47,7 +47,7 @@ impl Violation for HashlibDigestHex { } /// FURB181 -pub(crate) fn hashlib_digest_hex(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn hashlib_digest_hex(checker: &Checker, call: &ExprCall) { if !checker.semantic().seen_module(Modules::HASHLIB) { return; } @@ -116,6 +116,6 @@ pub(crate) fn hashlib_digest_hex(checker: &mut Checker, call: &ExprCall) { TextRange::new(value.end(), call.func.end()), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs index 1331c9eb22eb2..53265e57f5765 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs @@ -55,7 +55,7 @@ impl Violation for IfExpInsteadOfOrOperator { } /// FURB110 -pub(crate) fn if_exp_instead_of_or_operator(checker: &mut Checker, if_expr: &ast::ExprIf) { +pub(crate) fn if_exp_instead_of_or_operator(checker: &Checker, if_expr: &ast::ExprIf) { let ast::ExprIf { test, body, @@ -86,7 +86,7 @@ pub(crate) fn if_exp_instead_of_or_operator(checker: &mut Checker, if_expr: &ast }, )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Parenthesize an expression for use in an `or` operator (e.g., parenthesize `x` in `x or y`), diff --git a/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs index 5e9423e46f613..3036feef1add1 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs @@ -76,7 +76,7 @@ impl Violation for IfExprMinMax { } /// FURB136 -pub(crate) fn if_expr_min_max(checker: &mut Checker, if_exp: &ast::ExprIf) { +pub(crate) fn if_expr_min_max(checker: &Checker, if_exp: &ast::ExprIf) { let Expr::Compare(ast::ExprCompare { left, ops, @@ -146,7 +146,7 @@ pub(crate) fn if_expr_min_max(checker: &mut Checker, if_exp: &ast::ExprIf) { ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs index d60b9850cac4d..a3da7c6513c21 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs @@ -42,7 +42,7 @@ impl Violation for ImplicitCwd { } /// FURB177 -pub(crate) fn no_implicit_cwd(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn no_implicit_cwd(checker: &Checker, call: &ExprCall) { if !call.arguments.is_empty() { return; } @@ -102,5 +102,5 @@ pub(crate) fn no_implicit_cwd(checker: &mut Checker, call: &ExprCall) { )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs index 28a52cad8b137..252cf0ec46e49 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs @@ -64,7 +64,7 @@ impl AlwaysFixableViolation for IntOnSlicedStr { } } -pub(crate) fn int_on_sliced_str(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn int_on_sliced_str(checker: &Checker, call: &ExprCall) { // Verify that the function is `int`. if !checker.semantic().match_builtin_expr(&call.func, "int") { return; @@ -124,5 +124,5 @@ pub(crate) fn int_on_sliced_str(checker: &mut Checker, call: &ExprCall) { ), [Edit::range_replacement("0".to_string(), base.range())], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs index 92f624039c1ac..d051a8704d119 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs @@ -48,7 +48,7 @@ impl Violation for IsinstanceTypeNone { } /// FURB168 -pub(crate) fn isinstance_type_none(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn isinstance_type_none(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let (func, arguments) = (&call.func, &call.arguments); @@ -71,7 +71,7 @@ pub(crate) fn isinstance_type_none(checker: &mut Checker, call: &ast::ExprCall) let fix = replace_with_identity_check(expr, call.range, false, checker); let diagnostic = Diagnostic::new(IsinstanceTypeNone, call.range); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } /// Returns `true` if the given expression is equivalent to checking if the diff --git a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs index 714a43110d43a..24ba55f860b34 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs @@ -65,7 +65,7 @@ impl AlwaysFixableViolation for ListReverseCopy { } /// FURB187 -pub(crate) fn list_assign_reversed(checker: &mut Checker, assign: &StmtAssign) { +pub(crate) fn list_assign_reversed(checker: &Checker, assign: &StmtAssign) { let [Expr::Name(target_expr)] = assign.targets.as_slice() else { return; }; @@ -89,7 +89,7 @@ pub(crate) fn list_assign_reversed(checker: &mut Checker, assign: &StmtAssign) { return; } - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new( ListReverseCopy { name: target_expr.id.to_string(), diff --git a/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs b/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs index e2085cf879bdb..af468f75368ba 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs @@ -49,7 +49,7 @@ impl Violation for MathConstant { } /// FURB152 -pub(crate) fn math_constant(checker: &mut Checker, literal: &ast::ExprNumberLiteral) { +pub(crate) fn math_constant(checker: &Checker, literal: &ast::ExprNumberLiteral) { let Number::Float(value) = literal.value else { return; }; @@ -63,7 +63,7 @@ pub(crate) fn math_constant(checker: &mut Checker, literal: &ast::ExprNumberLite literal.range(), ); diagnostic.try_set_fix(|| convert_to_constant(literal, constant.name(), checker)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs index 72c371684470a..9fff62560c938 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs @@ -49,7 +49,7 @@ impl AlwaysFixableViolation for MetaClassABCMeta { } /// FURB180 -pub(crate) fn metaclass_abcmeta(checker: &mut Checker, class_def: &StmtClassDef) { +pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) { // Identify the `metaclass` keyword. let Some((position, keyword)) = class_def.keywords().iter().find_position(|&keyword| { keyword @@ -100,5 +100,5 @@ pub(crate) fn metaclass_abcmeta(checker: &mut Checker, class_def: &StmtClassDef) }) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index 3ca8a0644b9f1..31ec1632ec7b9 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -70,7 +70,7 @@ impl Violation for PrintEmptyString { } /// FURB105 -pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn print_empty_string(checker: &Checker, call: &ast::ExprCall) { if !checker.semantic().match_builtin_expr(&call.func, "print") { return; } @@ -96,7 +96,7 @@ pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { .into_fix(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } [arg] if arg.is_starred_expr() => { @@ -124,7 +124,7 @@ pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { .into_fix(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -186,7 +186,7 @@ pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { .into_fix(), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs index 2a9db8f2283de..046640394720d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs @@ -51,7 +51,7 @@ impl Violation for ReadWholeFile { } /// FURB101 -pub(crate) fn read_whole_file(checker: &mut Checker, with: &ast::StmtWith) { +pub(crate) fn read_whole_file(checker: &Checker, with: &ast::StmtWith) { // `async` check here is more of a precaution. if with.is_async { return; @@ -88,7 +88,7 @@ pub(crate) fn read_whole_file(checker: &mut Checker, with: &ast::StmtWith) { ) }) .collect(); - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } /// AST visitor that matches `open` operations with the corresponding `read` calls. diff --git a/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs b/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs index 120dfa88dd0c7..e06626da9c438 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs @@ -46,16 +46,16 @@ impl AlwaysFixableViolation for ReadlinesInFor { } /// FURB129 -pub(crate) fn readlines_in_for(checker: &mut Checker, for_stmt: &StmtFor) { +pub(crate) fn readlines_in_for(checker: &Checker, for_stmt: &StmtFor) { readlines_in_iter(checker, for_stmt.iter.as_ref()); } /// FURB129 -pub(crate) fn readlines_in_comprehension(checker: &mut Checker, comprehension: &Comprehension) { +pub(crate) fn readlines_in_comprehension(checker: &Checker, comprehension: &Comprehension) { readlines_in_iter(checker, &comprehension.iter); } -fn readlines_in_iter(checker: &mut Checker, iter_expr: &Expr) { +fn readlines_in_iter(checker: &Checker, iter_expr: &Expr) { let Expr::Call(expr_call) = iter_expr else { return; }; @@ -88,5 +88,5 @@ fn readlines_in_iter(checker: &mut Checker, iter_expr: &Expr) { diagnostic.set_fix(Fix::unsafe_edit(Edit::range_deletion( expr_call.range().add_start(expr_attr.value.range().len()), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs index e072b428d17ce..a506aa17b834c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs @@ -65,7 +65,7 @@ impl Violation for RedundantLogBase { } /// FURB163 -pub(crate) fn redundant_log_base(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn redundant_log_base(checker: &Checker, call: &ast::ExprCall) { if !call.arguments.keywords.is_empty() { return; } @@ -104,7 +104,7 @@ pub(crate) fn redundant_log_base(checker: &mut Checker, call: &ast::ExprCall) { call.range(), ); diagnostic.try_set_fix(|| generate_fix(checker, call, base, arg)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs b/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs index 5798c21501dab..d7e0fee51e8cf 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for RegexFlagAlias { } /// FURB167 -pub(crate) fn regex_flag_alias(checker: &mut Checker, expr: &Expr) { +pub(crate) fn regex_flag_alias(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::RE) { return; } @@ -86,7 +86,7 @@ pub(crate) fn regex_flag_alias(checker: &mut Checker, expr: &Expr) { [edit], )) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index 23c6e7b3d7d83..ba771643a50a1 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -90,7 +90,7 @@ impl Violation for ReimplementedOperator { } /// FURB118 -pub(crate) fn reimplemented_operator(checker: &mut Checker, target: &FunctionLike) { +pub(crate) fn reimplemented_operator(checker: &Checker, target: &FunctionLike) { // Ignore methods. // Methods can be defined via a `def` statement in a class scope, // or via a lambda appearing on the right-hand side of an assignment in a class scope. @@ -120,7 +120,7 @@ pub(crate) fn reimplemented_operator(checker: &mut Checker, target: &FunctionLik target.range(), ); diagnostic.try_set_optional_fix(|| fix); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Candidate for lambda expression or function definition consisting of a return statement. diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index 49f37a00bac7f..1d4cee5154c92 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -62,7 +62,7 @@ impl Violation for ReimplementedStarmap { } /// FURB140 -pub(crate) fn reimplemented_starmap(checker: &mut Checker, target: &StarmapCandidate) { +pub(crate) fn reimplemented_starmap(checker: &Checker, target: &StarmapCandidate) { // Generator should have exactly one comprehension. let [comprehension] = target.generators() else { return; @@ -156,7 +156,7 @@ pub(crate) fn reimplemented_starmap(checker: &mut Checker, target: &StarmapCandi ); Ok(Fix::safe_edits(import_edit, [main_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// An enum for a node that can be considered a candidate for replacement with `starmap`. diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index f650ebb26f965..6c82f94e5b34a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -76,7 +76,7 @@ impl Violation for RepeatedAppend { } /// FURB113 -pub(crate) fn repeated_append(checker: &mut Checker, stmt: &Stmt) { +pub(crate) fn repeated_append(checker: &Checker, stmt: &Stmt) { let Some(appends) = match_consecutive_appends(stmt, checker.semantic()) else { return; }; @@ -127,7 +127,7 @@ pub(crate) fn repeated_append(checker: &mut Checker, stmt: &Stmt) { }) .collect(); - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } #[derive(Debug, Clone)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs index 913318a300ad0..7fa845806a4b5 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs @@ -53,7 +53,7 @@ impl AlwaysFixableViolation for RepeatedGlobal { } /// FURB154 -pub(crate) fn repeated_global(checker: &mut Checker, mut suite: &[Stmt]) { +pub(crate) fn repeated_global(checker: &Checker, mut suite: &[Stmt]) { while let Some(idx) = suite .iter() .position(|stmt| GlobalKind::from_stmt(stmt).is_some()) @@ -74,7 +74,7 @@ pub(crate) fn repeated_global(checker: &mut Checker, mut suite: &[Stmt]) { // diagnostic. if let [first, .., last] = globals_sequence { let range = first.range().cover(last.range()); - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new(RepeatedGlobal { global_kind }, range).with_fix(Fix::safe_edit( Edit::range_replacement( format!( diff --git a/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs b/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs index 40a0c116ea335..d77e2b4f81e64 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs @@ -61,7 +61,7 @@ impl Violation for SingleItemMembershipTest { /// FURB171 pub(crate) fn single_item_membership_test( - checker: &mut Checker, + checker: &Checker, expr: &Expr, left: &Expr, ops: &[CmpOp], @@ -110,7 +110,7 @@ pub(crate) fn single_item_membership_test( let fix = Fix::applicable_edit(edit, applicability); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } /// Return the single item wrapped in `Some` if the expression contains a single diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs index 8e79e976dc99a..b35e58ed84aed 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs @@ -53,7 +53,7 @@ impl Violation for SliceCopy { } /// FURB145 -pub(crate) fn slice_copy(checker: &mut Checker, subscript: &ast::ExprSubscript) { +pub(crate) fn slice_copy(checker: &Checker, subscript: &ast::ExprSubscript) { if subscript.ctx.is_store() || subscript.ctx.is_del() { return; } @@ -68,7 +68,7 @@ pub(crate) fn slice_copy(checker: &mut Checker, subscript: &ast::ExprSubscript) subscript.start(), subscript.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Matches `obj[:]` where `obj` is a list. diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs index a01d02f09d264..31eff56c4c763 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs @@ -68,7 +68,7 @@ impl AlwaysFixableViolation for SliceToRemovePrefixOrSuffix { } /// FURB188 -pub(crate) fn slice_to_remove_affix_expr(checker: &mut Checker, if_expr: &ast::ExprIf) { +pub(crate) fn slice_to_remove_affix_expr(checker: &Checker, if_expr: &ast::ExprIf) { if checker.settings.target_version < PythonVersion::Py39 { return; } @@ -93,13 +93,13 @@ pub(crate) fn slice_to_remove_affix_expr(checker: &mut Checker, if_expr: &ast::E if_expr.start(), if_expr.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } /// FURB188 -pub(crate) fn slice_to_remove_affix_stmt(checker: &mut Checker, if_stmt: &ast::StmtIf) { +pub(crate) fn slice_to_remove_affix_stmt(checker: &Checker, if_stmt: &ast::StmtIf) { if checker.settings.target_version < PythonVersion::Py39 { return; } @@ -127,7 +127,7 @@ pub(crate) fn slice_to_remove_affix_stmt(checker: &mut Checker, if_stmt: &ast::S if_stmt.start(), if_stmt.end(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs index 3f41823596b07..85df541faa684 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs @@ -79,7 +79,7 @@ impl Violation for SortedMinMax { } /// FURB192 -pub(crate) fn sorted_min_max(checker: &mut Checker, subscript: &ast::ExprSubscript) { +pub(crate) fn sorted_min_max(checker: &Checker, subscript: &ast::ExprSubscript) { if subscript.ctx.is_store() || subscript.ctx.is_del() { return; } @@ -201,7 +201,7 @@ pub(crate) fn sorted_min_max(checker: &mut Checker, subscript: &ast::ExprSubscri }); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs index 8fed10b623038..234003ee73b8a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs @@ -65,7 +65,7 @@ impl AlwaysFixableViolation for SubclassBuiltin { } /// FURB189 -pub(crate) fn subclass_builtin(checker: &mut Checker, class: &StmtClassDef) { +pub(crate) fn subclass_builtin(checker: &Checker, class: &StmtClassDef) { let Some(Arguments { args: bases, .. }) = class.arguments.as_deref() else { return; }; @@ -100,7 +100,7 @@ pub(crate) fn subclass_builtin(checker: &mut Checker, class: &StmtClassDef) { let other_edit = Edit::range_replacement(binding, base.range()); Ok(Fix::unsafe_edits(import_edit, [other_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs index 7df7f14de914b..80ff6cc17bed7 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs @@ -56,7 +56,7 @@ impl AlwaysFixableViolation for TypeNoneComparison { } /// FURB169 -pub(crate) fn type_none_comparison(checker: &mut Checker, compare: &ast::ExprCompare) { +pub(crate) fn type_none_comparison(checker: &Checker, compare: &ast::ExprCompare) { let ([op], [right]) = (&*compare.ops, &*compare.comparators) else { return; }; @@ -91,7 +91,7 @@ pub(crate) fn type_none_comparison(checker: &mut Checker, compare: &ast::ExprCom let negate = replacement == IdentityCheck::IsNot; let fix = replace_with_identity_check(other_arg, compare.range, negate, checker); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } /// Returns the object passed to the function, if the expression is a call to diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index d6a0ee4355e92..ae2e7c5241f59 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -87,7 +87,7 @@ impl Violation for UnnecessaryEnumerate { } /// FURB148 -pub(crate) fn unnecessary_enumerate(checker: &mut Checker, stmt_for: &ast::StmtFor) { +pub(crate) fn unnecessary_enumerate(checker: &Checker, stmt_for: &ast::StmtFor) { // Check the for statement is of the form `for x, y in func(...)`. let Expr::Tuple(ast::ExprTuple { elts, .. }) = stmt_for.target.as_ref() else { return; @@ -144,7 +144,7 @@ pub(crate) fn unnecessary_enumerate(checker: &mut Checker, stmt_for: &ast::StmtF ); diagnostic.set_fix(Fix::unsafe_edits(replace_iter, [replace_target])); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } (false, true) => { // Ensure the sequence object works with `len`. If it doesn't, the @@ -205,7 +205,7 @@ pub(crate) fn unnecessary_enumerate(checker: &mut Checker, stmt_for: &ast::StmtF diagnostic.set_fix(Fix::unsafe_edits(replace_iter, [replace_target])); } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs index cb074efa8df74..60cf8233b8562 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs @@ -59,7 +59,7 @@ impl Violation for UnnecessaryFromFloat { } /// FURB164 -pub(crate) fn unnecessary_from_float(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unnecessary_from_float(checker: &Checker, call: &ExprCall) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = &*call.func else { return; }; @@ -157,13 +157,13 @@ pub(crate) fn unnecessary_from_float(checker: &mut Checker, call: &ExprCall) { edit, [Edit::range_replacement(replacement, call.range())], )); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); return; } diagnostic.set_fix(Fix::safe_edit(edit)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs index e3d4833540ff2..12de439a77062 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs @@ -57,7 +57,7 @@ impl Violation for VerboseDecimalConstructor { } /// FURB157 -pub(crate) fn verbose_decimal_constructor(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn verbose_decimal_constructor(checker: &Checker, call: &ast::ExprCall) { if !checker .semantic() .resolve_qualified_name(&call.func) @@ -199,7 +199,7 @@ pub(crate) fn verbose_decimal_constructor(checker: &mut Checker, call: &ast::Exp } }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } // ```console diff --git a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs index 798020c78c9f5..e35320d7cc9db 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs @@ -52,7 +52,7 @@ impl Violation for WriteWholeFile { } /// FURB103 -pub(crate) fn write_whole_file(checker: &mut Checker, with: &ast::StmtWith) { +pub(crate) fn write_whole_file(checker: &Checker, with: &ast::StmtWith) { // `async` check here is more of a precaution. if with.is_async { return; @@ -90,7 +90,7 @@ pub(crate) fn write_whole_file(checker: &mut Checker, with: &ast::StmtWith) { ) }) .collect(); - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } /// AST visitor that matches `open` operations with the corresponding `write` calls. diff --git a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs index dd507ff551d36..128162070f179 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -185,7 +185,7 @@ pub(crate) fn ambiguous_unicode_character_comment( } /// RUF001, RUF002 -pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_like: StringLike) { +pub(crate) fn ambiguous_unicode_character_string(checker: &Checker, string_like: StringLike) { let context = if checker.semantic().in_pep_257_docstring() { Context::Docstring } else { @@ -196,25 +196,29 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_l match part { ast::StringLikePart::String(string_literal) => { let text = checker.locator().slice(string_literal); + let mut diagnostics = Vec::new(); ambiguous_unicode_character( - &mut checker.diagnostics, + &mut diagnostics, text, string_literal.range(), context, checker.settings, ); + checker.report_diagnostics(diagnostics); } ast::StringLikePart::Bytes(_) => {} ast::StringLikePart::FString(f_string) => { for literal in f_string.elements.literals() { let text = checker.locator().slice(literal); + let mut diagnostics = Vec::new(); ambiguous_unicode_character( - &mut checker.diagnostics, + &mut diagnostics, text, literal.range(), context, checker.settings, ); + checker.report_diagnostics(diagnostics); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs index b8b730e0ada32..cea4a135333fa 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs @@ -55,7 +55,7 @@ impl AlwaysFixableViolation for AssertWithPrintMessage { /// /// Checks if the `msg` argument to an `assert` statement is a `print` call, and if so, /// replace the message with the arguments to the `print` call. -pub(crate) fn assert_with_print_message(checker: &mut Checker, stmt: &ast::StmtAssert) { +pub(crate) fn assert_with_print_message(checker: &Checker, stmt: &ast::StmtAssert) { if let Some(Expr::Call(call)) = stmt.msg.as_deref() { // We have to check that the print call is a call to the built-in `print` function let semantic = checker.semantic(); @@ -74,7 +74,7 @@ pub(crate) fn assert_with_print_message(checker: &mut Checker, stmt: &ast::StmtA // will cease to exist. stmt.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs index 0c5a3ab5abe3c..ce96afc093c0b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs @@ -7,6 +7,8 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{analyze::typing, Scope, SemanticModel}; use ruff_text_size::Ranged; +use crate::checkers::ast::Checker; + /// ## What it does /// Checks for `asyncio.create_task` and `asyncio.ensure_future` calls /// that do not store a reference to the returned result. @@ -116,11 +118,8 @@ pub(crate) fn asyncio_dangling_task(expr: &Expr, semantic: &SemanticModel) -> Op } /// RUF006 -pub(crate) fn asyncio_dangling_binding( - scope: &Scope, - semantic: &SemanticModel, - diagnostics: &mut Vec, -) { +pub(crate) fn asyncio_dangling_binding(scope: &Scope, checker: &Checker) { + let semantic = checker.semantic(); for binding_id in scope.binding_ids() { // If the binding itself is used, or it's not an assignment, skip it. let binding = semantic.binding(binding_id); @@ -165,7 +164,7 @@ pub(crate) fn asyncio_dangling_binding( }; if let Some(diagnostic) = diagnostic { - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/class_with_mixed_type_vars.rs b/crates/ruff_linter/src/rules/ruff/rules/class_with_mixed_type_vars.rs index 6cd75352d7b58..306514e187279 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/class_with_mixed_type_vars.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/class_with_mixed_type_vars.rs @@ -78,7 +78,7 @@ impl Violation for ClassWithMixedTypeVars { } /// RUF053 -pub(crate) fn class_with_mixed_type_vars(checker: &mut Checker, class_def: &StmtClassDef) { +pub(crate) fn class_with_mixed_type_vars(checker: &Checker, class_def: &StmtClassDef) { if checker.settings.target_version < PythonVersion::Py312 { return; } @@ -115,7 +115,7 @@ pub(crate) fn class_with_mixed_type_vars(checker: &mut Checker, class_def: &Stmt ) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn typing_generic_base_and_arguments<'a>( diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index 94f900b44da19..f909767264e08 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -169,7 +169,7 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> { } /// RUF005 -pub(crate) fn collection_literal_concatenation(checker: &mut Checker, expr: &Expr) { +pub(crate) fn collection_literal_concatenation(checker: &Checker, expr: &Expr) { // If the expression is already a child of an addition, we'll have analyzed it already. if matches!( checker.semantic().current_expression_parent(), @@ -207,5 +207,5 @@ pub(crate) fn collection_literal_concatenation(checker: &mut Checker, expr: &Exp expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/dataclass_enum.rs b/crates/ruff_linter/src/rules/ruff/rules/dataclass_enum.rs index ec7c1a69dc807..0f4e6797d02c2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/dataclass_enum.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/dataclass_enum.rs @@ -59,7 +59,7 @@ impl Violation for DataclassEnum { } /// RUF049 -pub(crate) fn dataclass_enum(checker: &mut Checker, class_def: &StmtClassDef) { +pub(crate) fn dataclass_enum(checker: &Checker, class_def: &StmtClassDef) { let semantic = checker.semantic(); let Some((DataclassKind::Stdlib, decorator)) = dataclass_kind(class_def, semantic) else { @@ -72,5 +72,5 @@ pub(crate) fn dataclass_enum(checker: &mut Checker, class_def: &StmtClassDef) { let diagnostic = Diagnostic::new(DataclassEnum, decorator.range); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs index aed69b9cff9aa..a8d29a9741288 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs @@ -47,7 +47,7 @@ impl AlwaysFixableViolation for DecimalFromFloatLiteral { } /// RUF032: `Decimal()` called with float literal argument -pub(crate) fn decimal_from_float_literal_syntax(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn decimal_from_float_literal_syntax(checker: &Checker, call: &ast::ExprCall) { let Some(arg) = call.arguments.args.first() else { return; }; @@ -63,7 +63,7 @@ pub(crate) fn decimal_from_float_literal_syntax(checker: &mut Checker, call: &as let diagnostic = Diagnostic::new(DecimalFromFloatLiteral, arg.range()).with_fix( fix_float_literal(arg.range(), float, checker.locator(), checker.stylist()), ); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs index d305351588239..14613afe1253a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs @@ -73,7 +73,7 @@ impl Violation for DefaultFactoryKwarg { } /// RUF026 -pub(crate) fn default_factory_kwarg(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn default_factory_kwarg(checker: &Checker, call: &ast::ExprCall) { // If the call isn't a `defaultdict` constructor, return. if !checker .semantic() @@ -107,7 +107,7 @@ pub(crate) fn default_factory_kwarg(checker: &mut Checker, call: &ast::ExprCall) call.range(), ); diagnostic.try_set_fix(|| convert_to_positional(call, keyword, checker.locator())); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Returns `true` if a value is definitively not callable (e.g., `1` or `[]`). diff --git a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index 21a8f98effe30..00f7417aab974 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for ExplicitFStringTypeConversion { } /// RUF010 -pub(crate) fn explicit_f_string_type_conversion(checker: &mut Checker, f_string: &ast::FString) { +pub(crate) fn explicit_f_string_type_conversion(checker: &Checker, f_string: &ast::FString) { for (index, element) in f_string.elements.iter().enumerate() { let Some(ast::FStringExpressionElement { expression, @@ -112,7 +112,7 @@ pub(crate) fn explicit_f_string_type_conversion(checker: &mut Checker, f_string: diagnostic.try_set_fix(|| { convert_call_to_conversion_flag(f_string, index, checker.locator(), checker.stylist()) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs b/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs index 1f73cceb29d06..8dddb24d8c1bb 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for FalsyDictGetFallback { } } -pub(crate) fn falsy_dict_get_fallback(checker: &mut Checker, expr: &Expr) { +pub(crate) fn falsy_dict_get_fallback(checker: &Checker, expr: &Expr) { let semantic = checker.semantic(); // Check if we are in a boolean test @@ -107,5 +107,5 @@ pub(crate) fn falsy_dict_get_fallback(checker: &mut Checker, expr: &Expr) { .map(|edit| Fix::applicable_edit(edit, applicability)) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs index 79748cd0ef8e7..b5db8114f8b52 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs @@ -74,11 +74,7 @@ impl Violation for FunctionCallInDataclassDefaultArgument { } /// RUF009 -pub(crate) fn function_call_in_dataclass_default( - checker: &Checker, - class_def: &ast::StmtClassDef, - diagnostics: &mut Vec, -) { +pub(crate) fn function_call_in_dataclass_default(checker: &Checker, class_def: &ast::StmtClassDef) { let semantic = checker.semantic(); let Some((dataclass_kind, _)) = dataclass_kind(class_def, semantic) else { @@ -153,7 +149,7 @@ pub(crate) fn function_call_in_dataclass_default( }; let diagnostic = Diagnostic::new(kind, expr.range()); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/if_key_in_dict_del.rs b/crates/ruff_linter/src/rules/ruff/rules/if_key_in_dict_del.rs index 3b15438ac32dc..6243c11dad6a1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/if_key_in_dict_del.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/if_key_in_dict_del.rs @@ -43,7 +43,7 @@ impl AlwaysFixableViolation for IfKeyInDictDel { } /// RUF051 -pub(crate) fn if_key_in_dict_del(checker: &mut Checker, stmt: &StmtIf) { +pub(crate) fn if_key_in_dict_del(checker: &Checker, stmt: &StmtIf) { let [Stmt::Delete(delete)] = &stmt.body[..] else { return; }; @@ -67,7 +67,7 @@ pub(crate) fn if_key_in_dict_del(checker: &mut Checker, stmt: &StmtIf) { let diagnostic = Diagnostic::new(IfKeyInDictDel, delete.range); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } fn extract_dict_and_key_from_test(test: &Expr) -> Option<(&Dict, &Key)> { diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs index 744679a77a0ba..0a843ade1da61 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs @@ -162,7 +162,7 @@ fn generate_fix(checker: &Checker, conversion_type: ConversionType, expr: &Expr) } /// RUF013 -pub(crate) fn implicit_optional(checker: &mut Checker, parameters: &Parameters) { +pub(crate) fn implicit_optional(checker: &Checker, parameters: &Parameters) { for parameter in parameters.iter_non_variadic_params() { let Some(Expr::NoneLiteral(_)) = parameter.default() else { continue; @@ -188,7 +188,7 @@ pub(crate) fn implicit_optional(checker: &mut Checker, parameters: &Parameters) if parsed_annotation.kind().is_simple() { diagnostic.try_set_fix(|| generate_fix(checker, conversion_type, expr)); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } else { // Unquoted annotation. @@ -204,7 +204,7 @@ pub(crate) fn implicit_optional(checker: &mut Checker, parameters: &Parameters) let mut diagnostic = Diagnostic::new(ImplicitOptional { conversion_type }, expr.range()); diagnostic.try_set_fix(|| generate_fix(checker, conversion_type, expr)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs index dbe9ea55fd759..0242c1717f2b2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs @@ -62,7 +62,7 @@ impl AlwaysFixableViolation for IncorrectlyParenthesizedTupleInSubscript { } /// RUF031 -pub(crate) fn subscript_with_parenthesized_tuple(checker: &mut Checker, subscript: &ExprSubscript) { +pub(crate) fn subscript_with_parenthesized_tuple(checker: &Checker, subscript: &ExprSubscript) { let prefer_parentheses = checker.settings.ruff.parenthesize_tuple_in_subscript; let Expr::Tuple(tuple_subscript) = &*subscript.slice else { @@ -105,7 +105,7 @@ pub(crate) fn subscript_with_parenthesized_tuple(checker: &mut Checker, subscrip }; let edit = Edit::range_replacement(new_source, source_range); - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new( IncorrectlyParenthesizedTupleInSubscript { prefer_parentheses }, source_range, diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs index 1942bab772a8c..5ff849717a0e4 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs @@ -36,7 +36,7 @@ impl Violation for InvalidAssertMessageLiteralArgument { } /// RUF040 -pub(crate) fn invalid_assert_message_literal_argument(checker: &mut Checker, stmt: &StmtAssert) { +pub(crate) fn invalid_assert_message_literal_argument(checker: &Checker, stmt: &StmtAssert) { let Some(message) = stmt.msg.as_deref() else { return; }; @@ -52,7 +52,7 @@ pub(crate) fn invalid_assert_message_literal_argument(checker: &mut Checker, stm return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidAssertMessageLiteralArgument, message.range(), )); diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs index 3fb3254041b59..887e05df05848 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs @@ -69,7 +69,7 @@ impl AlwaysFixableViolation for InvalidFormatterSuppressionComment { } /// RUF028 -pub(crate) fn ignored_formatter_suppression_comment(checker: &mut Checker, suite: &ast::Suite) { +pub(crate) fn ignored_formatter_suppression_comment(checker: &Checker, suite: &ast::Suite) { let locator = checker.locator(); let comment_ranges: SmallVec<[SuppressionComment; 8]> = checker .comment_ranges() @@ -99,7 +99,7 @@ pub(crate) fn ignored_formatter_suppression_comment(checker: &mut Checker, suite comments.sort(); for (range, reason) in comments.ignored_comments() { - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new(InvalidFormatterSuppressionComment { reason }, range) .with_fix(Fix::unsafe_edit(delete_comment(range, checker.locator()))), ); diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs index c2bcab6ed4e1c..bd7fd69ccc17c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs @@ -51,7 +51,7 @@ impl Violation for InvalidIndexType { } /// RUF016 -pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) { +pub(crate) fn invalid_index_type(checker: &Checker, expr: &ExprSubscript) { let ExprSubscript { value, slice: index, @@ -88,7 +88,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) { if index_type.is_literal() { // If the index is a literal, require an integer if index_type != CheckableExprType::IntLiteral { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidIndexType { value_type: value_type.to_string(), index_type: index_type.to_string(), @@ -111,7 +111,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) { is_slice_type, CheckableExprType::IntLiteral | CheckableExprType::NoneLiteral ) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidIndexType { value_type: value_type.to_string(), index_type: is_slice_type.to_string(), @@ -121,7 +121,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) { )); } } else if let Some(is_slice_type) = CheckableExprType::try_from(is_slice.as_ref()) { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidIndexType { value_type: value_type.to_string(), index_type: is_slice_type.to_string(), @@ -133,7 +133,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) { } } else { // If it's some other checkable data type, it's a violation - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( InvalidIndexType { value_type: value_type.to_string(), index_type: index_type.to_string(), diff --git a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs index 4d787d78730c3..d4223508b41ff 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs @@ -45,7 +45,7 @@ impl Violation for MapIntVersionParsing { } /// RUF048 -pub(crate) fn map_int_version_parsing(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn map_int_version_parsing(checker: &Checker, call: &ast::ExprCall) { let semantic = checker.semantic(); let Some((first, second)) = map_call_with_two_arguments(semantic, call) else { @@ -53,9 +53,7 @@ pub(crate) fn map_int_version_parsing(checker: &mut Checker, call: &ast::ExprCal }; if is_dunder_version_split_dot(second) && semantic.match_builtin_expr(first, "int") { - checker - .diagnostics - .push(Diagnostic::new(MapIntVersionParsing, call.range())); + checker.report_diagnostic(Diagnostic::new(MapIntVersionParsing, call.range())); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs index 186b9636e38a0..05c7cb54f4bc8 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs @@ -70,7 +70,7 @@ impl AlwaysFixableViolation for MissingFStringSyntax { } /// RUF027 -pub(crate) fn missing_fstring_syntax(checker: &mut Checker, literal: &ast::StringLiteral) { +pub(crate) fn missing_fstring_syntax(checker: &Checker, literal: &ast::StringLiteral) { let semantic = checker.semantic(); // we want to avoid statement expressions that are just a string literal. @@ -107,7 +107,7 @@ pub(crate) fn missing_fstring_syntax(checker: &mut Checker, literal: &ast::Strin if should_be_fstring(literal, checker.locator(), semantic) { let diagnostic = Diagnostic::new(MissingFStringSyntax, literal.range()) .with_fix(fix_fstring_syntax(literal.range())); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs index 28ecb6b51411d..2b86c5cda5a7b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs @@ -94,11 +94,7 @@ impl Violation for MutableClassDefault { } /// RUF012 -pub(crate) fn mutable_class_default( - checker: &Checker, - class_def: &ast::StmtClassDef, - diagnostics: &mut Vec, -) { +pub(crate) fn mutable_class_default(checker: &Checker, class_def: &ast::StmtClassDef) { for statement in &class_def.body { match statement { Stmt::AnnAssign(ast::StmtAnnAssign { @@ -122,7 +118,7 @@ pub(crate) fn mutable_class_default( return; } - diagnostics.push(Diagnostic::new(MutableClassDefault, value.range())); + checker.report_diagnostic(Diagnostic::new(MutableClassDefault, value.range())); } } Stmt::Assign(ast::StmtAssign { value, targets, .. }) => { @@ -134,7 +130,7 @@ pub(crate) fn mutable_class_default( return; } - diagnostics.push(Diagnostic::new(MutableClassDefault, value.range())); + checker.report_diagnostic(Diagnostic::new(MutableClassDefault, value.range())); } } _ => (), diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs index 911a85cacc966..9cec4913dd591 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs @@ -65,11 +65,7 @@ impl Violation for MutableDataclassDefault { } /// RUF008 -pub(crate) fn mutable_dataclass_default( - checker: &Checker, - class_def: &ast::StmtClassDef, - diagnostics: &mut Vec, -) { +pub(crate) fn mutable_dataclass_default(checker: &Checker, class_def: &ast::StmtClassDef) { let semantic = checker.semantic(); if dataclass_kind(class_def, semantic).is_none() { @@ -92,7 +88,7 @@ pub(crate) fn mutable_dataclass_default( { let diagnostic = Diagnostic::new(MutableDataclassDefault, value.range()); - diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs index 66068c7a02ed6..88e2bb5803ad0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs @@ -65,7 +65,7 @@ impl Violation for MutableFromkeysValue { } /// RUF024 -pub(crate) fn mutable_fromkeys_value(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn mutable_fromkeys_value(checker: &Checker, call: &ast::ExprCall) { let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = call.func.as_ref() else { return; }; @@ -92,7 +92,7 @@ pub(crate) fn mutable_fromkeys_value(checker: &mut Checker, call: &ast::ExprCall generate_dict_comprehension(keys, value, checker.generator()), call.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Format a code snippet to expression `{key: value for key in keys}`, where diff --git a/crates/ruff_linter/src/rules/ruff/rules/needless_else.rs b/crates/ruff_linter/src/rules/ruff/rules/needless_else.rs index b9db80f3bfe0f..61cc964fddd9e 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/needless_else.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/needless_else.rs @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for NeedlessElse { } /// RUF047 -pub(crate) fn needless_else(checker: &mut Checker, stmt: AnyNodeWithOrElse) { +pub(crate) fn needless_else(checker: &Checker, stmt: AnyNodeWithOrElse) { let source = checker.source(); let tokens = checker.tokens(); @@ -72,7 +72,7 @@ pub(crate) fn needless_else(checker: &mut Checker, stmt: AnyNodeWithOrElse) { let diagnostic = Diagnostic::new(NeedlessElse, else_range); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } /// Whether `body` contains only one `pass` or `...` statement. diff --git a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs index 19d97d6ebe0dd..fdfcd56e260b3 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs @@ -66,7 +66,7 @@ impl Violation for NeverUnion { } /// RUF020 -pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { +pub(crate) fn never_union(checker: &Checker, expr: &Expr) { match expr { // Ex) `typing.NoReturn | int` Expr::BinOp(ast::ExprBinOp { @@ -95,7 +95,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } // Analyze the right-hand side of the `|` operator. @@ -113,7 +113,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { expr.range(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } @@ -172,7 +172,7 @@ pub(crate) fn never_union(checker: &mut Checker, expr: &Expr) { }, expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs b/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs index cd8fd93f669d9..07a72cd30c8fd 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs @@ -40,7 +40,7 @@ impl Violation for NoneNotAtEndOfUnion { } /// RUF036 -pub(crate) fn none_not_at_end_of_union<'a>(checker: &mut Checker, union: &'a Expr) { +pub(crate) fn none_not_at_end_of_union<'a>(checker: &Checker, union: &'a Expr) { let semantic = checker.semantic(); let mut none_exprs: SmallVec<[&Expr; 1]> = SmallVec::new(); @@ -70,8 +70,6 @@ pub(crate) fn none_not_at_end_of_union<'a>(checker: &mut Checker, union: &'a Exp } for none_expr in none_exprs { - checker - .diagnostics - .push(Diagnostic::new(NoneNotAtEndOfUnion, none_expr.range())); + checker.report_diagnostic(Diagnostic::new(NoneNotAtEndOfUnion, none_expr.range())); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs index 4e637b4d7023f..76c58dec4797e 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs @@ -48,10 +48,7 @@ impl AlwaysFixableViolation for ParenthesizeChainedOperators { } /// RUF021 -pub(crate) fn parenthesize_chained_logical_operators( - checker: &mut Checker, - expr: &ast::ExprBoolOp, -) { +pub(crate) fn parenthesize_chained_logical_operators(checker: &Checker, expr: &ast::ExprBoolOp) { // We're only interested in `and` expressions inside `or` expressions: // - `a or b or c` => `BoolOp(values=[Name("a"), Name("b"), Name("c")], op=Or)` // - `a and b and c` => `BoolOp(values=[Name("a"), Name("b"), Name("c")], op=And)` @@ -89,7 +86,7 @@ pub(crate) fn parenthesize_chained_logical_operators( { let new_source = format!("({})", locator.slice(source_range)); let edit = Edit::range_replacement(new_source, source_range); - checker.diagnostics.push( + checker.report_diagnostic( Diagnostic::new(ParenthesizeChainedOperators, source_range) .with_fix(Fix::safe_edit(edit)), ); diff --git a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs index 937d1ae2ac3ee..c587a0f7a2e0a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs @@ -83,7 +83,7 @@ impl Violation for PostInitDefault { } /// RUF033 -pub(crate) fn post_init_default(checker: &mut Checker, function_def: &ast::StmtFunctionDef) { +pub(crate) fn post_init_default(checker: &Checker, function_def: &ast::StmtFunctionDef) { if &function_def.name != "__post_init__" { return; } @@ -129,7 +129,7 @@ pub(crate) fn post_init_default(checker: &mut Checker, function_def: &ast::StmtF diagnostics.push(diagnostic); } - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } /// Generate a [`Fix`] to transform a `__post_init__` default argument into a diff --git a/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs b/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs index de90a1b1e675a..067ed63c22649 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs @@ -77,7 +77,7 @@ impl Violation for PytestRaisesAmbiguousPattern { } /// RUF043 -pub(crate) fn pytest_raises_ambiguous_pattern(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn pytest_raises_ambiguous_pattern(checker: &Checker, call: &ast::ExprCall) { if !is_pytest_raises(&call.func, checker.semantic()) { return; } @@ -100,7 +100,7 @@ pub(crate) fn pytest_raises_ambiguous_pattern(checker: &mut Checker, call: &ast: let diagnostic = Diagnostic::new(PytestRaisesAmbiguousPattern, string.range); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn string_has_unescaped_metacharacters(value: &ast::StringLiteralValue) -> bool { diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index 42e05baeed84d..105da2ac7fe95 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -66,7 +66,7 @@ impl AlwaysFixableViolation for QuadraticListSummation { } /// RUF017 -pub(crate) fn quadratic_list_summation(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn quadratic_list_summation(checker: &Checker, call: &ast::ExprCall) { let ast::ExprCall { func, arguments, @@ -89,7 +89,7 @@ pub(crate) fn quadratic_list_summation(checker: &mut Checker, call: &ast::ExprCa let mut diagnostic = Diagnostic::new(QuadraticListSummation, *range); diagnostic.try_set_fix(|| convert_to_reduce(iterable, call, checker)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Generate a [`Fix`] to convert a `sum()` call to a `functools.reduce()` call. diff --git a/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs index 67800ef64cd27..7adb5e26c0897 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs @@ -81,7 +81,7 @@ impl Violation for RedundantBoolLiteral { } /// RUF038 -pub(crate) fn redundant_bool_literal<'a>(checker: &mut Checker, literal_expr: &'a Expr) { +pub(crate) fn redundant_bool_literal<'a>(checker: &Checker, literal_expr: &'a Expr) { if !checker.semantic().seen_typing() { return; } @@ -124,7 +124,7 @@ pub(crate) fn redundant_bool_literal<'a>(checker: &mut Checker, literal_expr: &' } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } bitflags! { diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs index 3c44653f71ac5..d1d2b479588e8 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs @@ -109,7 +109,7 @@ const SORTING_STYLE: SortingStyle = SortingStyle::Isort; /// Sort an `__all__` definition represented by a `StmtAssign` AST node. /// For example: `__all__ = ["b", "c", "a"]`. pub(crate) fn sort_dunder_all_assign( - checker: &mut Checker, + checker: &Checker, ast::StmtAssign { value, targets, .. }: &ast::StmtAssign, ) { if let [expr] = targets.as_slice() { @@ -119,7 +119,7 @@ pub(crate) fn sort_dunder_all_assign( /// Sort an `__all__` mutation represented by a `StmtAugAssign` AST node. /// For example: `__all__ += ["b", "c", "a"]`. -pub(crate) fn sort_dunder_all_aug_assign(checker: &mut Checker, node: &ast::StmtAugAssign) { +pub(crate) fn sort_dunder_all_aug_assign(checker: &Checker, node: &ast::StmtAugAssign) { if node.op.is_add() { sort_dunder_all(checker, &node.target, &node.value); } @@ -127,7 +127,7 @@ pub(crate) fn sort_dunder_all_aug_assign(checker: &mut Checker, node: &ast::Stmt /// Sort a tuple or list passed to `__all__.extend()`. pub(crate) fn sort_dunder_all_extend_call( - checker: &mut Checker, + checker: &Checker, ast::ExprCall { func, arguments: ast::Arguments { args, keywords, .. }, @@ -152,7 +152,7 @@ pub(crate) fn sort_dunder_all_extend_call( /// Sort an `__all__` definition represented by a `StmtAnnAssign` AST node. /// For example: `__all__: list[str] = ["b", "c", "a"]`. -pub(crate) fn sort_dunder_all_ann_assign(checker: &mut Checker, node: &ast::StmtAnnAssign) { +pub(crate) fn sort_dunder_all_ann_assign(checker: &Checker, node: &ast::StmtAnnAssign) { if let Some(value) = &node.value { sort_dunder_all(checker, &node.target, value); } @@ -163,7 +163,7 @@ pub(crate) fn sort_dunder_all_ann_assign(checker: &mut Checker, node: &ast::Stmt /// This routine checks whether the tuple or list is sorted, and emits a /// violation if it is not sorted. If the tuple/list was not sorted, /// it attempts to set a `Fix` on the violation. -fn sort_dunder_all(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr) { +fn sort_dunder_all(checker: &Checker, target: &ast::Expr, node: &ast::Expr) { let ast::Expr::Name(ast::ExprName { id, .. }) = target else { return; }; @@ -207,7 +207,7 @@ fn sort_dunder_all(checker: &mut Checker, target: &ast::Expr, node: &ast::Expr) } } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Attempt to return `Some(fix)`, where `fix` is a `Fix` diff --git a/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs b/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs index 89b114b0966aa..d47d5dad00d0f 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/starmap_zip.rs @@ -55,7 +55,7 @@ impl Violation for StarmapZip { } /// RUF058 -pub(crate) fn starmap_zip(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn starmap_zip(checker: &Checker, call: &ExprCall) { let semantic = checker.semantic(); if !call.arguments.keywords.is_empty() { @@ -95,7 +95,7 @@ pub(crate) fn starmap_zip(checker: &mut Checker, call: &ExprCall) { diagnostic.set_fix(fix); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Replace the `starmap` call with a call to the `map` builtin, if `map` has not been shadowed. diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs index 4c67155629e94..6a2d318a08c78 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_cast_to_int.rs @@ -59,7 +59,7 @@ impl AlwaysFixableViolation for UnnecessaryCastToInt { } /// RUF046 -pub(crate) fn unnecessary_cast_to_int(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unnecessary_cast_to_int(checker: &Checker, call: &ExprCall) { let Some(argument) = single_argument_to_int_call(call, checker.semantic()) else { return; }; @@ -90,7 +90,7 @@ pub(crate) fn unnecessary_cast_to_int(checker: &mut Checker, call: &ExprCall) { ); let diagnostic = Diagnostic::new(UnnecessaryCastToInt, call.range()); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } /// Creates a fix that replaces `int(expression)` with `expression`. @@ -150,7 +150,7 @@ fn unwrap_int_expression( /// Returns `Some` if `call` in `int(call(...))` is a method that returns an `int` /// and `None` otherwise. -fn call_applicability(checker: &mut Checker, inner_call: &ExprCall) -> Option { +fn call_applicability(checker: &Checker, inner_call: &ExprCall) -> Option { let (func, arguments) = (&inner_call.func, &inner_call.arguments); let qualified_name = checker.semantic().resolve_qualified_name(func)?; diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index 55b07d14c5233..8f0069b7cd5cf 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -72,10 +72,7 @@ impl AlwaysFixableViolation for UnnecessaryIterableAllocationForFirstElement { } /// RUF015 -pub(crate) fn unnecessary_iterable_allocation_for_first_element( - checker: &mut Checker, - expr: &Expr, -) { +pub(crate) fn unnecessary_iterable_allocation_for_first_element(checker: &Checker, expr: &Expr) { let value = match expr { // Ex) `list(x)[0]` Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { @@ -130,7 +127,7 @@ pub(crate) fn unnecessary_iterable_allocation_for_first_element( expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// Check that the slice [`Expr`] is a slice of the first element (e.g., `x[0]`). diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs index 5a8a86fe026f5..6957d191d2da9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs @@ -43,7 +43,7 @@ impl AlwaysFixableViolation for UnnecessaryKeyCheck { } /// RUF019 -pub(crate) fn unnecessary_key_check(checker: &mut Checker, expr: &Expr) { +pub(crate) fn unnecessary_key_check(checker: &Checker, expr: &Expr) { if !checker.semantic().in_boolean_test() { return; } @@ -127,5 +127,5 @@ pub(crate) fn unnecessary_key_check(checker: &mut Checker, expr: &Expr) { ), expr.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs index c28ca3c8360bb..b9b51cfec38fa 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs @@ -52,7 +52,7 @@ impl AlwaysFixableViolation for UnnecessaryEmptyIterableWithinDequeCall { } /// RUF037 -pub(crate) fn unnecessary_literal_within_deque_call(checker: &mut Checker, deque: &ast::ExprCall) { +pub(crate) fn unnecessary_literal_within_deque_call(checker: &Checker, deque: &ast::ExprCall) { let ast::ExprCall { func, arguments, .. } = deque; @@ -100,7 +100,7 @@ pub(crate) fn unnecessary_literal_within_deque_call(checker: &mut Checker, deque diagnostic.set_fix(fix_unnecessary_literal_in_deque(checker, deque, maxlen)); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } fn fix_unnecessary_literal_in_deque( diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs index 122579474f181..4b89da7bc28a5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs @@ -75,7 +75,7 @@ impl Violation for UnnecessaryNestedLiteral { } /// RUF039 -pub(crate) fn unnecessary_nested_literal<'a>(checker: &mut Checker, literal_expr: &'a Expr) { +pub(crate) fn unnecessary_nested_literal<'a>(checker: &Checker, literal_expr: &'a Expr) { let mut is_nested = false; // Traverse the type expressions in the `Literal`. @@ -135,5 +135,5 @@ pub(crate) fn unnecessary_nested_literal<'a>(checker: &mut Checker, literal_expr diagnostic.set_fix(fix); }; - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs index f52466e6d9568..343c3cdec05a8 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs @@ -73,7 +73,7 @@ impl Violation for UnnecessaryRegularExpression { } /// RUF055 -pub(crate) fn unnecessary_regular_expression(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unnecessary_regular_expression(checker: &Checker, call: &ExprCall) { // adapted from unraw_re_pattern let semantic = checker.semantic(); @@ -134,7 +134,7 @@ pub(crate) fn unnecessary_regular_expression(checker: &mut Checker, call: &ExprC )); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } /// The `re` functions supported by this rule. diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs index fbd1066499136..89b08df619386 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for UnnecessaryRound { } /// RUF057 -pub(crate) fn unnecessary_round(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unnecessary_round(checker: &Checker, call: &ExprCall) { if !checker.semantic().match_builtin_expr(&call.func, "round") { return; } @@ -96,7 +96,7 @@ pub(crate) fn unnecessary_round(checker: &mut Checker, call: &ExprCall) { let diagnostic = Diagnostic::new(UnnecessaryRound, call.range()); - checker.diagnostics.push(diagnostic.with_fix(fix)); + checker.report_diagnostic(diagnostic.with_fix(fix)); } #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs index 0267ba00f8693..3b1fedbae2722 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs @@ -108,7 +108,7 @@ enum PatternKind { } /// RUF039 -pub(crate) fn unraw_re_pattern(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unraw_re_pattern(checker: &Checker, call: &ExprCall) { let semantic = checker.semantic(); if !semantic.seen_module(Modules::RE) && !semantic.seen_module(Modules::REGEX) { @@ -153,7 +153,7 @@ fn regex_module_and_func<'model>( None } -fn check_string(checker: &mut Checker, literal: &StringLiteral, module: RegexModule, func: &str) { +fn check_string(checker: &Checker, literal: &StringLiteral, module: RegexModule, func: &str) { if literal.flags.prefix().is_raw() { return; } @@ -177,10 +177,10 @@ fn check_string(checker: &mut Checker, literal: &StringLiteral, module: RegexMod literal.range().start(), ))); } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } -fn check_bytes(checker: &mut Checker, literal: &BytesLiteral, module: RegexModule, func: &str) { +fn check_bytes(checker: &Checker, literal: &BytesLiteral, module: RegexModule, func: &str) { if literal.flags.prefix().is_raw() { return; } @@ -190,5 +190,5 @@ fn check_bytes(checker: &mut Checker, literal: &BytesLiteral, module: RegexModul let range = literal.range; let diagnostic = Diagnostic::new(UnrawRePattern { module, func, kind }, range); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs b/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs index cb12e40b16480..77e5e85fa7061 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs @@ -90,7 +90,7 @@ impl Violation for UnsafeMarkupUse { /// Checks for unsafe calls to `[markupsafe.Markup]`. /// /// [markupsafe.Markup]: https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup -pub(crate) fn unsafe_markup_call(checker: &mut Checker, call: &ExprCall) { +pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) { if checker.settings.ruff.extend_markup_names.is_empty() && !(checker.semantic().seen_module(Modules::MARKUPSAFE) || checker.semantic().seen_module(Modules::FLASK)) @@ -110,7 +110,7 @@ pub(crate) fn unsafe_markup_call(checker: &mut Checker, call: &ExprCall) { return; } - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnsafeMarkupUse { name: qualified_name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs index ca0aa2d6cdefc..6ef9495c60e4d 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs @@ -154,7 +154,7 @@ where /// RUF029 pub(crate) fn unused_async( - checker: &mut Checker, + checker: &Checker, function_def @ ast::StmtFunctionDef { is_async, name, @@ -188,7 +188,7 @@ pub(crate) fn unused_async( }; if !found_await_or_async { - checker.diagnostics.push(Diagnostic::new( + checker.report_diagnostic(Diagnostic::new( UnusedAsync { name: name.to_string(), }, diff --git a/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs b/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs index 57ebbd18bca2e..9543d9762283a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs @@ -31,7 +31,7 @@ impl Violation for UselessIfElse { } /// RUF034 -pub(crate) fn useless_if_else(checker: &mut Checker, if_expr: &ast::ExprIf) { +pub(crate) fn useless_if_else(checker: &Checker, if_expr: &ast::ExprIf) { let ast::ExprIf { body, orelse, @@ -44,7 +44,5 @@ pub(crate) fn useless_if_else(checker: &mut Checker, if_expr: &ast::ExprIf) { return; } - checker - .diagnostics - .push(Diagnostic::new(UselessIfElse, *range)); + checker.report_diagnostic(Diagnostic::new(UselessIfElse, *range)); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs index 5ad2c78517bd3..9a473eb32b7c6 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs @@ -102,7 +102,7 @@ fn match_slice_info(expr: &Expr) -> Option { } /// RUF007 -pub(crate) fn zip_instead_of_pairwise(checker: &mut Checker, call: &ast::ExprCall) { +pub(crate) fn zip_instead_of_pairwise(checker: &Checker, call: &ast::ExprCall) { let ast::ExprCall { func, arguments: Arguments { args, .. }, @@ -165,5 +165,5 @@ pub(crate) fn zip_instead_of_pairwise(checker: &mut Checker, call: &ast::ExprCal Ok(Fix::unsafe_edits(import_edit, [reference_edit])) }); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs b/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs index 0f5fe6a30b63d..4093e4ea3d7eb 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs @@ -68,7 +68,7 @@ impl Violation for ErrorInsteadOfException { } /// TRY400 -pub(crate) fn error_instead_of_exception(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn error_instead_of_exception(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { body, .. }) = handler; let calls = { @@ -135,7 +135,7 @@ pub(crate) fn error_instead_of_exception(checker: &mut Checker, handlers: &[Exce _ => {} } - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs index 2c1349fe4d342..8351e52350105 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs @@ -54,7 +54,7 @@ impl Violation for RaiseVanillaArgs { } /// TRY003 -pub(crate) fn raise_vanilla_args(checker: &mut Checker, expr: &Expr) { +pub(crate) fn raise_vanilla_args(checker: &Checker, expr: &Expr) { let Expr::Call(ast::ExprCall { func, arguments: Arguments { args, .. }, @@ -78,9 +78,7 @@ pub(crate) fn raise_vanilla_args(checker: &mut Checker, expr: &Expr) { } if contains_message(arg) { - checker - .diagnostics - .push(Diagnostic::new(RaiseVanillaArgs, expr.range())); + checker.report_diagnostic(Diagnostic::new(RaiseVanillaArgs, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs index 744c1e9d40d97..f06029be2add7 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs @@ -63,7 +63,7 @@ impl Violation for RaiseVanillaClass { } /// TRY002 -pub(crate) fn raise_vanilla_class(checker: &mut Checker, expr: &Expr) { +pub(crate) fn raise_vanilla_class(checker: &Checker, expr: &Expr) { if checker .semantic() .resolve_qualified_name(map_callable(expr)) @@ -74,8 +74,6 @@ pub(crate) fn raise_vanilla_class(checker: &mut Checker, expr: &Expr) { ) }) { - checker - .diagnostics - .push(Diagnostic::new(RaiseVanillaClass, expr.range())); + checker.report_diagnostic(Diagnostic::new(RaiseVanillaClass, expr.range())); } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs index d7ae13fffd5b0..59d28065e5ff0 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs @@ -75,7 +75,7 @@ impl<'a> StatementVisitor<'a> for RaiseStatementVisitor<'a> { } /// TRY301 -pub(crate) fn raise_within_try(checker: &mut Checker, body: &[Stmt], handlers: &[ExceptHandler]) { +pub(crate) fn raise_within_try(checker: &Checker, body: &[Stmt], handlers: &[ExceptHandler]) { if handlers.is_empty() { return; } @@ -115,9 +115,7 @@ pub(crate) fn raise_within_try(checker: &mut Checker, body: &[Stmt], handlers: & .is_some_and(|builtin| matches!(builtin, "Exception" | "BaseException")) }) { - checker - .diagnostics - .push(Diagnostic::new(RaiseWithinTry, stmt.range())); + checker.report_diagnostic(Diagnostic::new(RaiseWithinTry, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs b/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs index 7b211b3f72b16..a8aeb115df550 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs @@ -60,7 +60,7 @@ impl Violation for TryConsiderElse { /// TRY300 pub(crate) fn try_consider_else( - checker: &mut Checker, + checker: &Checker, body: &[Stmt], orelse: &[Stmt], handler: &[ExceptHandler], @@ -73,9 +73,7 @@ pub(crate) fn try_consider_else( return; } } - checker - .diagnostics - .push(Diagnostic::new(TryConsiderElse, stmt.range())); + checker.report_diagnostic(Diagnostic::new(TryConsiderElse, stmt.range())); } } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs b/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs index 1ddd4b01163ef..a4c238bf57f51 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs @@ -92,16 +92,14 @@ fn check_type_check_test(semantic: &SemanticModel, test: &Expr) -> bool { } } -fn check_raise(checker: &mut Checker, exc: &Expr, item: &Stmt) { +fn check_raise(checker: &Checker, exc: &Expr, item: &Stmt) { if is_builtin_exception(exc, checker.semantic()) { - checker - .diagnostics - .push(Diagnostic::new(TypeCheckWithoutTypeError, item.range())); + checker.report_diagnostic(Diagnostic::new(TypeCheckWithoutTypeError, item.range())); } } /// Search the body of an if-condition for raises. -fn check_body(checker: &mut Checker, body: &[Stmt]) { +fn check_body(checker: &Checker, body: &[Stmt]) { for item in body { if has_control_flow(item) { return; @@ -145,7 +143,7 @@ fn is_builtin_exception(expr: &Expr, semantic: &SemanticModel) -> bool { /// TRY004 pub(crate) fn type_check_without_type_error( - checker: &mut Checker, + checker: &Checker, stmt_if: &StmtIf, parent: Option<&Stmt>, ) { diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs index c4cdb13053c64..3dcb96d1c87f9 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs @@ -39,7 +39,7 @@ impl Violation for UselessTryExcept { } /// TRY203 (previously TRY302) -pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn useless_try_except(checker: &Checker, handlers: &[ExceptHandler]) { if let Some(diagnostics) = handlers .iter() .map(|handler| { @@ -67,6 +67,6 @@ pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandle .collect::>>() { // Require that all handlers are useless, but create one diagnostic per handler. - checker.diagnostics.extend(diagnostics); + checker.report_diagnostics(diagnostics); } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs index 1a2ccbae749bf..8d46cbb4493b6 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs @@ -44,7 +44,7 @@ impl Violation for VerboseLogMessage { } /// TRY401 -pub(crate) fn verbose_log_message(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn verbose_log_message(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { body, .. }) = handler; @@ -78,9 +78,7 @@ pub(crate) fn verbose_log_message(checker: &mut Checker, handlers: &[ExceptHandl }; let binding = checker.semantic().binding(id); if binding.kind.is_bound_exception() { - checker - .diagnostics - .push(Diagnostic::new(VerboseLogMessage, expr.range())); + checker.report_diagnostic(Diagnostic::new(VerboseLogMessage, expr.range())); } } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs index 7e27aa71a5c4c..4f41f7a5d8c5e 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs @@ -50,7 +50,7 @@ impl AlwaysFixableViolation for VerboseRaise { } /// TRY201 -pub(crate) fn verbose_raise(checker: &mut Checker, handlers: &[ExceptHandler]) { +pub(crate) fn verbose_raise(checker: &Checker, handlers: &[ExceptHandler]) { for handler in handlers { // If the handler assigned a name to the exception... if let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { @@ -77,7 +77,7 @@ pub(crate) fn verbose_raise(checker: &mut Checker, handlers: &[ExceptHandler]) { "raise".to_string(), raise.range(), ))); - checker.diagnostics.push(diagnostic); + checker.report_diagnostic(diagnostic); } } }