diff --git a/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs b/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs index 52cdfc12d0..6ba0eab32d 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/bindings.rs @@ -34,7 +34,7 @@ pub(crate) fn bindings(checker: &Checker) { if binding.kind.is_bound_exception() && binding.is_unused() && !checker - .settings + .settings() .dummy_variable_rgx .is_match(binding.name(checker.source())) { @@ -67,7 +67,7 @@ pub(crate) fn bindings(checker: &Checker) { flake8_import_conventions::rules::unconventional_import_alias( checker, binding, - &checker.settings.flake8_import_conventions.aliases, + &checker.settings().flake8_import_conventions.aliases, ); } if checker.is_rule_enabled(Rule::UnaliasedCollectionsAbcSetImport) { 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 69bc5866ab..def136a437 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -76,7 +76,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) { flake8_type_checking::helpers::is_valid_runtime_import( binding, &checker.semantic, - &checker.settings.flake8_type_checking, + &checker.settings().flake8_type_checking, ) }) .collect() @@ -139,7 +139,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) { if !shadowed.kind.is_argument() { continue; } - if checker.settings.dummy_variable_rgx.is_match(name) { + if checker.settings().dummy_variable_rgx.is_match(name) { continue; } let scope = &checker.semantic.scopes[binding.scope]; @@ -231,7 +231,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) { | BindingKind::FromImport(..) | BindingKind::SubmoduleImport(..) | BindingKind::FutureImport - ) && checker.settings.dummy_variable_rgx.is_match(name) + ) && checker.settings().dummy_variable_rgx.is_match(name) { continue; } @@ -402,7 +402,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) { && binding.is_unused() && !binding.is_nonlocal() && !binding.is_global() - && !checker.settings.dummy_variable_rgx.is_match(name) + && !checker.settings().dummy_variable_rgx.is_match(name) && !matches!( name, "__tracebackhide__" diff --git a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs index 3044223468..9938ba4b33 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs @@ -167,7 +167,7 @@ pub(crate) fn definitions(checker: &mut Checker) { if enforce_docstrings || enforce_pydoclint { if pydocstyle::helpers::should_ignore_definition( definition, - &checker.settings.pydocstyle, + &checker.settings().pydocstyle, &checker.semantic, ) { continue; @@ -253,7 +253,7 @@ pub(crate) fn definitions(checker: &mut Checker) { pydocstyle::rules::non_imperative_mood( checker, &docstring, - &checker.settings.pydocstyle, + &checker.settings().pydocstyle, ); } if checker.is_rule_enabled(Rule::SignatureInDocstring) { @@ -292,7 +292,7 @@ pub(crate) fn definitions(checker: &mut Checker) { if enforce_sections || enforce_pydoclint { let section_contexts = pydocstyle::helpers::get_section_contexts( &docstring, - checker.settings.pydocstyle.convention(), + checker.settings().pydocstyle.convention(), ); if enforce_sections { @@ -300,7 +300,7 @@ pub(crate) fn definitions(checker: &mut Checker) { checker, &docstring, §ion_contexts, - checker.settings.pydocstyle.convention(), + checker.settings().pydocstyle.convention(), ); } @@ -310,7 +310,7 @@ pub(crate) fn definitions(checker: &mut Checker) { definition, &docstring, §ion_contexts, - checker.settings.pydocstyle.convention(), + checker.settings().pydocstyle.convention(), ); } } 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 4d7b03a37a..fd8bed0e29 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs @@ -41,7 +41,7 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &Checker) except_handler, type_.as_deref(), body, - checker.settings.flake8_bandit.check_typed_exception, + checker.settings().flake8_bandit.check_typed_exception, ); } if checker.is_rule_enabled(Rule::TryExceptContinue) { @@ -50,7 +50,7 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &Checker) except_handler, type_.as_deref(), body, - checker.settings.flake8_bandit.check_typed_exception, + checker.settings().flake8_bandit.check_typed_exception, ); } if checker.is_rule_enabled(Rule::ExceptWithEmptyTuple) { diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 51c88aea87..fdc5f37028 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -35,7 +35,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { && checker.target_version() < PythonVersion::PY310 && checker.target_version() >= PythonVersion::PY37 && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing + && !checker.settings().pyupgrade.keep_runtime_typing { flake8_future_annotations::rules::future_rewritable_type_annotation( checker, value, @@ -51,7 +51,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { || (checker.target_version() >= PythonVersion::PY37 && checker.semantic.future_annotations_or_stub() && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing) + && !checker.settings().pyupgrade.keep_runtime_typing) { pyupgrade::rules::non_pep604_annotation(checker, expr, slice, operator); } @@ -288,7 +288,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { && checker.target_version() < PythonVersion::PY39 && checker.target_version() >= PythonVersion::PY37 && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing + && !checker.settings().pyupgrade.keep_runtime_typing { flake8_future_annotations::rules::future_rewritable_type_annotation(checker, expr); } @@ -299,7 +299,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { || (checker.target_version() >= PythonVersion::PY37 && checker.semantic.future_annotations_or_stub() && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing) + && !checker.settings().pyupgrade.keep_runtime_typing) { pyupgrade::rules::use_pep585_annotation( checker, @@ -395,7 +395,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { && checker.target_version() < PythonVersion::PY39 && checker.target_version() >= PythonVersion::PY37 && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing + && !checker.settings().pyupgrade.keep_runtime_typing { flake8_future_annotations::rules::future_rewritable_type_annotation( checker, expr, @@ -408,7 +408,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { || (checker.target_version() >= PythonVersion::PY37 && checker.semantic.future_annotations_or_stub() && checker.semantic.in_annotation() - && !checker.settings.pyupgrade.keep_runtime_typing) + && !checker.settings().pyupgrade.keep_runtime_typing) { pyupgrade::rules::use_pep585_annotation(checker, expr, &replacement); } @@ -841,7 +841,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { flake8_comprehensions::rules::unnecessary_collection_call( checker, call, - &checker.settings.flake8_comprehensions, + &checker.settings().flake8_comprehensions, ); } if checker.is_rule_enabled(Rule::UnnecessaryLiteralWithinTupleCall) { @@ -1006,7 +1006,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { Rule::PrintfInGetTextFuncCall, ]) && flake8_gettext::is_gettext_func_call( func, - &checker.settings.flake8_gettext.functions_names, + &checker.settings().flake8_gettext.functions_names, ) { if checker.is_rule_enabled(Rule::FStringInGetTextFuncCall) { flake8_gettext::rules::f_string_in_gettext_func_call(checker, args); diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index 4e00591aff..704a8d65df 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -132,7 +132,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, name, decorator_list, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, &checker.semantic, ); } @@ -189,7 +189,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker.semantic.current_scope(), stmt, name, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::GlobalStatement) { @@ -240,7 +240,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, name, body, - checker.settings.mccabe.max_complexity, + checker.settings().mccabe.max_complexity, ); } if checker.is_rule_enabled(Rule::HardcodedPasswordDefault) { @@ -265,7 +265,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker, stmt, body, - checker.settings.pylint.max_returns, + checker.settings().pylint.max_returns, ); } if checker.is_rule_enabled(Rule::TooManyBranches) { @@ -273,7 +273,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker, stmt, body, - checker.settings.pylint.max_branches, + checker.settings().pylint.max_branches, ); } if checker.is_rule_enabled(Rule::TooManyStatements) { @@ -281,7 +281,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker, stmt, body, - checker.settings.pylint.max_statements, + checker.settings().pylint.max_statements, ); } if checker.any_rule_enabled(&[ @@ -431,7 +431,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { pylint::rules::too_many_public_methods( checker, class_def, - checker.settings.pylint.max_public_methods, + checker.settings().pylint.max_public_methods, ); } if checker.is_rule_enabled(Rule::GlobalStatement) { @@ -459,7 +459,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker, stmt, name, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::ErrorSuffixOnExceptionName) { @@ -468,7 +468,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, arguments.as_deref(), name, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if !checker.source_type.is_stub() { @@ -646,7 +646,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::LowercaseImportedAsNonLowercase) { @@ -656,7 +656,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsLowercase) { @@ -666,7 +666,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsConstant) { @@ -676,7 +676,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsAcronym) { @@ -692,7 +692,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &alias.name, asname, - &checker.settings.flake8_import_conventions.banned_aliases, + &checker.settings().flake8_import_conventions.banned_aliases, ); } } @@ -854,7 +854,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { level, module, checker.module.qualified_name(), - checker.settings.flake8_tidy_imports.ban_relative_imports, + checker.settings().flake8_tidy_imports.ban_relative_imports, ); } if checker.is_rule_enabled(Rule::Debugger) { @@ -869,7 +869,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { stmt, &qualified_name, asname, - &checker.settings.flake8_import_conventions.banned_aliases, + &checker.settings().flake8_import_conventions.banned_aliases, ); } } @@ -881,7 +881,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::LowercaseImportedAsNonLowercase) { @@ -891,7 +891,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsLowercase) { @@ -901,7 +901,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsConstant) { @@ -911,7 +911,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { asname, alias, stmt, - &checker.settings.pep8_naming.ignore_names, + &checker.settings().pep8_naming.ignore_names, ); } if checker.is_rule_enabled(Rule::CamelcaseImportedAsAcronym) { @@ -947,7 +947,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { checker, stmt, &helpers::format_import_from(level, module), - &checker.settings.flake8_import_conventions.banned_from, + &checker.settings().flake8_import_conventions.banned_from, ); } if checker.is_rule_enabled(Rule::ByteStringUsage) { 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 25c37bcd01..f28e60d928 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/string_like.rs @@ -34,7 +34,7 @@ pub(crate) fn string_like(string_like: StringLike, checker: &Checker) { flake8_quotes::rules::unnecessary_escaped_quote(checker, string_like); } if checker.is_rule_enabled(Rule::AvoidableEscapedQuote) - && checker.settings.flake8_quotes.avoid_escape + && checker.settings().flake8_quotes.avoid_escape { flake8_quotes::rules::avoidable_escaped_quote(checker, string_like); } diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index e1e86c40e3..aee72035eb 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -207,8 +207,6 @@ pub(crate) struct Checker<'a> { /// The [`NoqaMapping`] for the current analysis (i.e., the mapping from line number to /// suppression commented line number). noqa_line_for: &'a NoqaMapping, - /// The [`LinterSettings`] for the current analysis, including the enabled rules. - pub(crate) settings: &'a LinterSettings, /// The [`Locator`] for the current file, which enables extraction of source code from byte /// offsets. locator: &'a Locator<'a>, @@ -260,13 +258,12 @@ impl<'a> Checker<'a> { notebook_index: Option<&'a NotebookIndex>, target_version: TargetVersion, context: &'a LintContext<'a>, - ) -> Checker<'a> { + ) -> Self { let semantic = SemanticModel::new(&settings.typing_modules, path, module); Self { parsed, parsed_type_annotation: None, parsed_annotations_cache: ParsedAnnotationsCache::new(parsed_annotations_arena), - settings, noqa_line_for, noqa, path, @@ -464,6 +461,11 @@ impl<'a> Checker<'a> { &self.semantic } + /// The [`LinterSettings`] for the current analysis, including the enabled rules. + pub(crate) const fn settings(&self) -> &'a LinterSettings { + self.context.settings + } + /// The [`Path`] to the file under analysis. pub(crate) const fn path(&self) -> &'a Path { self.path @@ -576,7 +578,7 @@ impl<'a> Checker<'a> { ) -> Option> { let source_module = if self.target_version() >= version_added_to_typing { "typing" - } else if !self.settings.typing_extensions { + } else if !self.settings().typing_extensions { return None; } else { "typing_extensions" @@ -1054,7 +1056,7 @@ impl<'a> Visitor<'a> for Checker<'a> { let annotation = AnnotationContext::from_function( function_def, &self.semantic, - self.settings, + self.settings(), self.target_version(), ); @@ -1256,7 +1258,7 @@ impl<'a> Visitor<'a> for Checker<'a> { }) => { match AnnotationContext::from_model( &self.semantic, - self.settings, + self.settings(), self.target_version(), ) { AnnotationContext::RuntimeRequired => { @@ -1868,8 +1870,8 @@ impl<'a> Visitor<'a> for Checker<'a> { match typing::match_annotated_subscript( value, &self.semantic, - self.settings.typing_modules.iter().map(String::as_str), - &self.settings.pyflakes.extend_generics, + self.settings().typing_modules.iter().map(String::as_str), + &self.settings().pyflakes.extend_generics, ) { // Ex) Literal["Class"] Some(typing::SubscriptKind::Literal) => { @@ -2476,6 +2478,7 @@ impl<'a> Checker<'a> { fn bind_builtins(&mut self) { let target_version = self.target_version(); + let settings = self.settings(); let mut bind_builtin = |builtin| { // Add the builtin to the scope. let binding_id = self.semantic.push_builtin(); @@ -2489,7 +2492,7 @@ impl<'a> Checker<'a> { for builtin in MAGIC_GLOBALS { bind_builtin(builtin); } - for builtin in &self.settings.builtins { + for builtin in &settings.builtins { bind_builtin(builtin); } } @@ -2963,7 +2966,7 @@ impl<'a> Checker<'a> { } } else { if self.is_rule_enabled(Rule::UndefinedExport) { - if is_undefined_export_in_dunder_init_enabled(self.settings) + if is_undefined_export_in_dunder_init_enabled(self.settings()) || !self.path.ends_with("__init__.py") { self.report_diagnostic( @@ -3115,7 +3118,6 @@ pub(crate) struct LintContext<'a> { diagnostics: RefCell>, source_file: SourceFile, rules: RuleTable, - #[expect(unused, reason = "TODO(brent) use this instead of Checker::settings")] settings: &'a LinterSettings, } diff --git a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs index 72d95137e0..5b0f24d56f 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs @@ -648,9 +648,9 @@ pub(crate) fn definition( ); } } else { - if !(checker.settings.flake8_annotations.suppress_dummy_args + if !(checker.settings().flake8_annotations.suppress_dummy_args && checker - .settings + .settings() .dummy_variable_rgx .is_match(parameter.name())) { @@ -670,15 +670,15 @@ pub(crate) fn definition( if let Some(arg) = ¶meters.vararg { if let Some(expr) = &arg.annotation { has_any_typed_arg = true; - if !checker.settings.flake8_annotations.allow_star_arg_any { + if !checker.settings().flake8_annotations.allow_star_arg_any { if checker.is_rule_enabled(Rule::AnyType) && !is_overridden { let name = &arg.name; check_dynamically_typed(checker, expr, || format!("*{name}"), &mut diagnostics); } } } else { - if !(checker.settings.flake8_annotations.suppress_dummy_args - && checker.settings.dummy_variable_rgx.is_match(&arg.name)) + if !(checker.settings().flake8_annotations.suppress_dummy_args + && checker.settings().dummy_variable_rgx.is_match(&arg.name)) { if checker.is_rule_enabled(Rule::MissingTypeArgs) { diagnostics.push(checker.report_diagnostic( @@ -696,7 +696,7 @@ pub(crate) fn definition( if let Some(arg) = ¶meters.kwarg { if let Some(expr) = &arg.annotation { has_any_typed_arg = true; - if !checker.settings.flake8_annotations.allow_star_arg_any { + if !checker.settings().flake8_annotations.allow_star_arg_any { if checker.is_rule_enabled(Rule::AnyType) && !is_overridden { let name = &arg.name; check_dynamically_typed( @@ -708,8 +708,8 @@ pub(crate) fn definition( } } } else { - if !(checker.settings.flake8_annotations.suppress_dummy_args - && checker.settings.dummy_variable_rgx.is_match(&arg.name)) + if !(checker.settings().flake8_annotations.suppress_dummy_args + && checker.settings().dummy_variable_rgx.is_match(&arg.name)) { if checker.is_rule_enabled(Rule::MissingTypeKwargs) { diagnostics.push(checker.report_diagnostic( @@ -732,7 +732,11 @@ pub(crate) fn definition( } else if !( // Allow omission of return annotation if the function only returns `None` // (explicitly or implicitly). - checker.settings.flake8_annotations.suppress_none_returning && is_none_returning(body) + checker + .settings() + .flake8_annotations + .suppress_none_returning + && is_none_returning(body) ) { if is_method && visibility::is_classmethod(decorator_list, checker.semantic()) { if checker.is_rule_enabled(Rule::MissingReturnTypeClassMethod) { @@ -790,7 +794,7 @@ pub(crate) fn definition( // Allow omission of return annotation in `__init__` functions, as long as at // least one argument is typed. if checker.is_rule_enabled(Rule::MissingReturnTypeSpecialMethod) { - if !(checker.settings.flake8_annotations.mypy_init_return && has_any_typed_arg) { + if !(checker.settings().flake8_annotations.mypy_init_return && has_any_typed_arg) { let mut diagnostic = checker.report_diagnostic( MissingReturnTypeSpecialMethod { name: name.to_string(), @@ -901,7 +905,7 @@ pub(crate) fn definition( // If settings say so, don't report any of the // diagnostics gathered here if there were no type annotations at all. - let diagnostics_enabled = !checker.settings.flake8_annotations.ignore_fully_untyped + let diagnostics_enabled = !checker.settings().flake8_annotations.ignore_fully_untyped || has_any_typed_arg || has_typed_return || (is_method 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 03df078819..77893289e3 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 @@ -84,7 +84,7 @@ pub(crate) fn hardcoded_tmp_directory(checker: &Checker, string: StringLike) { fn check(checker: &Checker, value: &str, range: TextRange) { if !checker - .settings + .settings() .flake8_bandit .hardcoded_tmp_directory .iter() 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 5fcc3e6ed5..4e2a1dc35c 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 @@ -936,7 +936,7 @@ pub(crate) fn suspicious_function_call(checker: &Checker, call: &ExprCall) { } pub(crate) fn suspicious_function_reference(checker: &Checker, func: &Expr) { - if !is_suspicious_function_reference_enabled(checker.settings) { + if !is_suspicious_function_reference_enabled(checker.settings()) { return; } @@ -1270,7 +1270,7 @@ fn suspicious_function( /// S308 pub(crate) fn suspicious_function_decorator(checker: &Checker, decorator: &Decorator) { // In preview mode, references are handled collectively by `suspicious_function_reference` - if !is_suspicious_function_reference_enabled(checker.settings) { + if !is_suspicious_function_reference_enabled(checker.settings()) { suspicious_function(checker, &decorator.expression, None, decorator.range); } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs index c5fc91a1f6..25cd68d58b 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_markup_use.rs @@ -90,7 +90,7 @@ impl Violation for UnsafeMarkupUse { /// S704 pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) { if checker - .settings + .settings() .flake8_bandit .extend_markup_names .is_empty() @@ -100,7 +100,7 @@ pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) { return; } - if !is_unsafe_call(call, checker.semantic(), checker.settings) { + if !is_unsafe_call(call, checker.semantic(), checker.settings()) { return; } @@ -108,7 +108,7 @@ pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) { return; }; - if !is_markup_call(&qualified_name, checker.settings) { + if !is_markup_call(&qualified_name, checker.settings()) { return; } 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 569ce05254..53a69d33e6 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 @@ -101,7 +101,7 @@ pub(crate) fn blind_except( } // If the exception is logged, don't flag an error. - let mut visitor = LogExceptionVisitor::new(semantic, &checker.settings.logger_objects); + let mut visitor = LogExceptionVisitor::new(semantic, &checker.settings().logger_objects); visitor.visit_body(body); if visitor.seen() { return; diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs index f11b2b12fa..b91bdad4a2 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs @@ -185,7 +185,7 @@ pub(super) fn allow_boolean_trap(call: &ast::ExprCall, checker: &Checker) -> boo } // If the call is explicitly allowed by the user, then the boolean trap is allowed. - if is_user_allowed_func_call(call, checker.semantic(), checker.settings) { + if is_user_allowed_func_call(call, checker.semantic(), checker.settings()) { return true; } 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 d724833cf7..9849cdf816 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 @@ -88,8 +88,8 @@ pub(crate) fn cached_instance_method(checker: &Checker, function_def: &ast::Stmt &function_def.decorator_list, scope, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); if !matches!(type_, function_type::FunctionType::Method) { return; 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 9243209f7f..54faca1174 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 @@ -132,7 +132,7 @@ impl Visitor<'_> for ArgumentDefaultVisitor<'_, '_> { 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 + .settings() .flake8_bugbear .extend_immutable_calls .iter() 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 c5e1b38969..960ddbfdfb 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 @@ -105,7 +105,7 @@ pub(crate) fn mutable_argument_default(checker: &Checker, function_def: &ast::St }; let extend_immutable_calls: Vec = checker - .settings + .settings() .flake8_bugbear .extend_immutable_calls .iter() 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 1b7b699691..a6d3879d42 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 @@ -82,7 +82,7 @@ pub(crate) fn mutable_contextvar_default(checker: &Checker, call: &ast::ExprCall }; let extend_immutable_calls: Vec = checker - .settings + .settings() .flake8_bugbear .extend_immutable_calls .iter() 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 00038ea515..4b0a48ac16 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 @@ -93,7 +93,7 @@ pub(crate) fn unused_loop_control_variable(checker: &Checker, stmt_for: &ast::St for (name, expr) in control_names { // Ignore names that are already underscore-prefixed. - if checker.settings.dummy_variable_rgx.is_match(name) { + if checker.settings().dummy_variable_rgx.is_match(name) { continue; } @@ -116,7 +116,7 @@ pub(crate) fn unused_loop_control_variable(checker: &Checker, stmt_for: &ast::St // violation in the next pass. let rename = format!("_{name}"); let rename = checker - .settings + .settings() .dummy_variable_rgx .is_match(rename.as_str()) .then_some(rename); 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 27173cc9f0..c600059c11 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 @@ -66,7 +66,7 @@ pub(crate) fn builtin_argument_shadowing(checker: &Checker, parameter: &Paramete if shadows_builtin( parameter.name(), checker.source_type, - &checker.settings.flake8_builtins.ignorelist, + &checker.settings().flake8_builtins.ignorelist, checker.target_version(), ) { // Ignore parameters in lambda expressions. 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 3ec4fb5d5c..b0e5c4979c 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 @@ -97,7 +97,7 @@ pub(crate) fn builtin_attribute_shadowing( if shadows_builtin( name, checker.source_type, - &checker.settings.flake8_builtins.ignorelist, + &checker.settings().flake8_builtins.ignorelist, checker.target_version(), ) { // Ignore explicit overrides. 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 781d6df893..6dae6ea8bd 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 @@ -59,7 +59,7 @@ pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) { if shadows_builtin( name.as_str(), checker.source_type, - &checker.settings.flake8_builtins.ignorelist, + &checker.settings().flake8_builtins.ignorelist, checker.target_version(), ) { checker.report_diagnostic( 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 73dddd9a4f..ef9ef4a5d0 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 @@ -43,7 +43,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &Expr if shadows_builtin( name, checker.source_type, - &checker.settings.flake8_builtins.ignorelist, + &checker.settings().flake8_builtins.ignorelist, checker.target_version(), ) { checker.report_diagnostic( 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 7d69a7fc3c..31708157dd 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 @@ -70,7 +70,7 @@ pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: T if shadows_builtin( name, checker.source_type, - &checker.settings.flake8_builtins.ignorelist, + &checker.settings().flake8_builtins.ignorelist, checker.target_version(), ) { checker.report_diagnostic( 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 dc3cc820c8..6565131796 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 @@ -126,7 +126,7 @@ pub(crate) fn unnecessary_comprehension_in_call( if !(matches!( builtin_function, SupportedBuiltins::Any | SupportedBuiltins::All - ) || (is_comprehension_with_min_max_sum_enabled(checker.settings) + ) || (is_comprehension_with_min_max_sum_enabled(checker.settings()) && matches!( builtin_function, SupportedBuiltins::Sum | SupportedBuiltins::Min | SupportedBuiltins::Max 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 9803e4dae4..b2d3af263f 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 @@ -101,7 +101,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call( let argument_kind = match argument { Expr::Tuple(_) => TupleLiteralKind::Tuple, Expr::List(_) => TupleLiteralKind::List, - Expr::ListComp(_) if is_check_comprehensions_in_tuple_call_enabled(checker.settings) => { + Expr::ListComp(_) if is_check_comprehensions_in_tuple_call_enabled(checker.settings()) => { TupleLiteralKind::ListComp } _ => return, 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 9e4b5b9e91..649206bee8 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 @@ -186,7 +186,7 @@ pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) { // Check for string literals. Expr::StringLiteral(ast::ExprStringLiteral { value: string, .. }) => { if checker.is_rule_enabled(Rule::RawStringInException) { - if string.len() >= checker.settings.flake8_errmsg.max_string_length { + if string.len() >= checker.settings().flake8_errmsg.max_string_length { let mut diagnostic = checker.report_diagnostic(RawStringInException, first.range()); if let Some(indentation) = diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs index 04aa996322..ba2a9f61a0 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs @@ -52,7 +52,11 @@ pub(crate) fn explicit(checker: &Checker, expr: &Expr) { // strings that span multiple lines even if this rule is enabled. Otherwise, there's no way // for the user to write multiline strings, and that setting is "more explicit" than this rule // being enabled. - if !checker.settings.flake8_implicit_str_concat.allow_multiline { + if !checker + .settings() + .flake8_implicit_str_concat + .allow_multiline + { return; } 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 4715710d96..0cd766ec6e 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 @@ -68,7 +68,7 @@ pub(crate) fn exc_info_outside_except_handler(checker: &Checker, call: &ExprCall match &*call.func { func @ Expr::Attribute(ExprAttribute { attr, .. }) => { - if !is_logger_candidate(func, semantic, &checker.settings.logger_objects) { + if !is_logger_candidate(func, semantic, &checker.settings().logger_objects) { return; } 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 0925322e32..4724239d56 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 @@ -54,7 +54,7 @@ pub(crate) fn exception_without_exc_info(checker: &Checker, call: &ExprCall) { if !logging::is_logger_candidate( &call.func, checker.semantic(), - &checker.settings.logger_objects, + &checker.settings().logger_objects, ) { return; } 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 c043ef4780..00c099014e 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 @@ -69,7 +69,7 @@ pub(crate) fn log_exception_outside_except_handler(checker: &Checker, call: &Exp let fix = match &*call.func { func @ Expr::Attribute(ExprAttribute { attr, .. }) => { - let logger_objects = &checker.settings.logger_objects; + let logger_objects = &checker.settings().logger_objects; if !logging::is_logger_candidate(func, semantic, logger_objects) { return; 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 05a70d9fc8..8df841b4b0 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 @@ -147,7 +147,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { if !logging::is_logger_candidate( &call.func, checker.semantic(), - &checker.settings.logger_objects, + &checker.settings().logger_objects, ) { return; } 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 deaaa7af4b..d5bd0095f6 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 @@ -141,7 +141,7 @@ pub(crate) fn bad_version_info_comparison(checker: &Checker, test: &Expr, has_el if matches!(op, CmpOp::Lt) { if checker.is_rule_enabled(Rule::BadVersionInfoOrder) // See https://github.com/astral-sh/ruff/issues/15347 - && (checker.source_type.is_stub() || is_bad_version_info_in_non_stub_enabled(checker.settings)) + && (checker.source_type.is_stub() || is_bad_version_info_in_non_stub_enabled(checker.settings())) { if has_else_clause { checker.report_diagnostic(BadVersionInfoOrder, test.range()); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_for_self.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_for_self.rs index 8e5e656ecf..aaa182b4e0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_for_self.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_for_self.rs @@ -173,8 +173,8 @@ pub(crate) fn custom_type_var_instead_of_self(checker: &Checker, binding: &Bindi decorator_list, current_scope, semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); let method = match function_kind { 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 2b83f7783d..ec5fd871bb 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 @@ -75,8 +75,8 @@ pub(crate) fn pep_484_positional_parameter(checker: &Checker, function_def: &ast &function_def.decorator_list, scope, semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); // If the method has a `self` or `cls` argument, skip it. 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 5d07b81c68..70a6b8f56a 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 @@ -714,7 +714,7 @@ fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decor node_index: _, }) => { if checker.is_rule_enabled(Rule::PytestFixtureIncorrectParenthesesStyle) { - if !checker.settings.flake8_pytest_style.fixture_parentheses + if !checker.settings().flake8_pytest_style.fixture_parentheses && arguments.args.is_empty() && arguments.keywords.is_empty() { @@ -771,7 +771,7 @@ fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decor } _ => { if checker.is_rule_enabled(Rule::PytestFixtureIncorrectParenthesesStyle) { - if checker.settings.flake8_pytest_style.fixture_parentheses { + if checker.settings().flake8_pytest_style.fixture_parentheses { let fix = Fix::safe_edit(Edit::insertion( Parentheses::Empty.to_string(), decorator.end(), 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 f48d33b6d5..02351b39d7 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 @@ -165,7 +165,7 @@ fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str range: _, node_index: _, }) => { - if !checker.settings.flake8_pytest_style.mark_parentheses + if !checker.settings().flake8_pytest_style.mark_parentheses && args.is_empty() && keywords.is_empty() { @@ -191,7 +191,7 @@ fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str } } _ => { - if checker.settings.flake8_pytest_style.mark_parentheses { + if checker.settings().flake8_pytest_style.mark_parentheses { let fix = Fix::safe_edit(Edit::insertion( Parentheses::Empty.to_string(), decorator.end(), 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 3d4d4601f8..bd3059e430 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 @@ -335,7 +335,10 @@ fn get_parametrize_name_range( /// PT006 fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr) { - let names_type = checker.settings.flake8_pytest_style.parametrize_names_type; + let names_type = checker + .settings() + .flake8_pytest_style + .parametrize_names_type; match expr { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => { @@ -516,10 +519,13 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr /// PT007 fn check_values(checker: &Checker, names: &Expr, values: &Expr) { - let values_type = checker.settings.flake8_pytest_style.parametrize_values_type; + let values_type = checker + .settings() + .flake8_pytest_style + .parametrize_values_type; let values_row_type = checker - .settings + .settings() .flake8_pytest_style .parametrize_values_row_type; 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 93ad1f8cc2..870ca5a2d7 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 @@ -244,13 +244,13 @@ fn exception_needs_match(checker: &Checker, exception: &Expr) { .and_then(|qualified_name| { let qualified_name = qualified_name.to_string(); checker - .settings + .settings() .flake8_pytest_style .raises_require_match_for .iter() .chain( &checker - .settings + .settings() .flake8_pytest_style .raises_extend_require_match_for, ) 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 3a1ef04b5a..413a93807d 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 @@ -233,13 +233,13 @@ fn warning_needs_match(checker: &Checker, warning: &Expr) { .and_then(|qualified_name| { let qualified_name = qualified_name.to_string(); checker - .settings + .settings() .flake8_pytest_style .warns_require_match_for .iter() .chain( &checker - .settings + .settings() .flake8_pytest_style .warns_extend_require_match_for, ) 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 47972e53af..80f1c03426 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 @@ -86,7 +86,7 @@ impl<'a, 'b> AvoidableEscapedQuoteChecker<'a, 'b> { fn new(checker: &'a Checker<'b>, target_version: PythonVersion) -> Self { Self { checker, - quotes_settings: &checker.settings.flake8_quotes, + quotes_settings: &checker.settings().flake8_quotes, supports_pep701: target_version.supports_pep_701(), } } 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 e7cb010a4c..aae3f18480 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 @@ -251,7 +251,7 @@ fn text_ends_at_quote(locator: &Locator, range: TextRange, quote: Quote) -> bool /// Q002 fn docstring(checker: &Checker, range: TextRange) { - let quotes_settings = &checker.settings.flake8_quotes; + let quotes_settings = &checker.settings().flake8_quotes; let locator = checker.locator(); let text = locator.slice(range); @@ -302,7 +302,7 @@ fn docstring(checker: &Checker, range: TextRange) { /// Q000, Q001 fn strings(checker: &Checker, sequence: &[TextRange]) { - let quotes_settings = &checker.settings.flake8_quotes; + let quotes_settings = &checker.settings().flake8_quotes; let locator = checker.locator(); let trivia = sequence 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 d6504968f8..a3c87512b4 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -379,7 +379,7 @@ fn unnecessary_return_none(checker: &Checker, decorator_list: &[Decorator], stac // Skip property functions if is_property( decorator_list, - checker.settings.pydocstyle.property_decorators(), + checker.settings().pydocstyle.property_decorators(), checker.semantic(), ) { return; 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 52b704d93a..2326e24ea3 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 @@ -85,7 +85,7 @@ pub(crate) fn private_member_access(checker: &Checker, expr: &Expr) { } if checker - .settings + .settings() .flake8_self .ignore_names .contains(attr.id()) 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 0c00f73a1a..248a7250e7 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 @@ -191,11 +191,11 @@ pub(crate) fn multiple_with_statements( content, with_stmt.into(), checker.locator(), - checker.settings.pycodestyle.max_line_length, - checker.settings.tab_size, + checker.settings().pycodestyle.max_line_length, + checker.settings().tab_size, ) }) { - if is_multiple_with_statements_fix_safe_enabled(checker.settings) { + if is_multiple_with_statements_fix_safe_enabled(checker.settings()) { Ok(Some(Fix::safe_edit(edit))) } else { Ok(Some(Fix::unsafe_edit(edit))) 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 04039a8f5f..da4721b875 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 @@ -125,8 +125,8 @@ pub(crate) fn nested_if_statements( content, (&nested_if).into(), checker.locator(), - checker.settings.pycodestyle.max_line_length, - checker.settings.tab_size, + checker.settings().pycodestyle.max_line_length, + checker.settings().tab_size, ) }) { Ok(Some(Fix::unsafe_edit(edit))) 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 a4ab3ff311..e93e829bb0 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 @@ -215,8 +215,8 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast &contents, stmt_if.into(), checker.locator(), - checker.settings.pycodestyle.max_line_length, - checker.settings.tab_size, + checker.settings().pycodestyle.max_line_length, + checker.settings().tab_size, ) { return; } 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 1166a272e3..97cbcb76ac 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 @@ -225,8 +225,8 @@ pub(crate) fn if_else_block_instead_of_if_exp(checker: &Checker, stmt_if: &ast:: &contents, stmt_if.into(), checker.locator(), - checker.settings.pycodestyle.max_line_length, - checker.settings.tab_size, + checker.settings().pycodestyle.max_line_length, + checker.settings().tab_size, ) { return; } 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 d3fef19779..67f70ecb35 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 @@ -105,8 +105,8 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { &contents, stmt.into(), checker.locator(), - checker.settings.pycodestyle.max_line_length, - checker.settings.tab_size, + checker.settings().pycodestyle.max_line_length, + checker.settings().tab_size, ) { return; } @@ -195,14 +195,14 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { // Don't flag if the resulting expression would exceed the maximum line length. let line_start = checker.locator().line_start(stmt.start()); - if LineWidthBuilder::new(checker.settings.tab_size) + if LineWidthBuilder::new(checker.settings().tab_size) .add_str( checker .locator() .slice(TextRange::new(line_start, stmt.start())), ) .add_str(&contents) - > checker.settings.pycodestyle.max_line_length + > checker.settings().pycodestyle.max_line_length { return; } 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 c51d016e6b..dc352e3e4e 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 @@ -40,7 +40,7 @@ impl Violation for BannedApi { /// TID251 pub(crate) fn banned_api(checker: &Checker, policy: &NameMatchPolicy, node: &T) { - let banned_api = &checker.settings.flake8_tidy_imports.banned_api; + 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.report_diagnostic( @@ -56,7 +56,7 @@ pub(crate) fn banned_api(checker: &Checker, policy: &NameMatchPolicy, /// TID251 pub(crate) fn banned_attribute_access(checker: &Checker, expr: &Expr) { - let banned_api = &checker.settings.flake8_tidy_imports.banned_api; + let banned_api = &checker.settings().flake8_tidy_imports.banned_api; if banned_api.is_empty() { return; } 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 11283e7202..6527d8d522 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 @@ -64,7 +64,7 @@ pub(crate) fn banned_module_level_imports(checker: &Checker, stmt: &Stmt) { for (policy, node) in &BannedModuleImportPolicies::new(stmt, checker) { if let Some(banned_module) = policy.find( checker - .settings + .settings() .flake8_tidy_imports .banned_module_level_imports(), ) { 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 8aecca5d57..10a1580388 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 @@ -164,7 +164,7 @@ pub(crate) fn runtime_import_in_type_checking_block(checker: &Checker, scope: &S // since some people will consistently use their // type aliases at runtimes, while others won't, so // the best solution is unclear. - if checker.settings.flake8_type_checking.quote_annotations + if checker.settings().flake8_type_checking.quote_annotations && binding.references().all(|reference_id| { let reference = checker.semantic().reference(reference_id); reference.in_typing_context() || reference.in_runtime_evaluated_annotation() 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 872a079f86..fafa086aa7 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 @@ -273,7 +273,7 @@ pub(crate) fn typing_only_runtime_import( // If we're in un-strict mode, don't flag typing-only imports that are // implicitly loaded by way of a valid runtime import. - if !checker.settings.flake8_type_checking.strict + if !checker.settings().flake8_type_checking.strict && runtime_imports .iter() .any(|import| is_implicit_import(binding, import)) @@ -294,7 +294,7 @@ pub(crate) fn typing_only_runtime_import( .references() .map(|reference_id| checker.semantic().reference(reference_id)) .all(|reference| { - is_typing_reference(reference, &checker.settings.flake8_type_checking) + is_typing_reference(reference, &checker.settings().flake8_type_checking) }) { let qualified_name = import.qualified_name(); @@ -302,7 +302,7 @@ pub(crate) fn typing_only_runtime_import( if is_exempt( &qualified_name.to_string(), &checker - .settings + .settings() .flake8_type_checking .exempt_modules .iter() @@ -316,7 +316,7 @@ pub(crate) fn typing_only_runtime_import( // Categorize the import, using coarse-grained categorization. let match_source_strategy = - if is_full_path_match_source_strategy_enabled(checker.settings) { + if is_full_path_match_source_strategy_enabled(checker.settings()) { MatchSourceStrategy::FullPath } else { MatchSourceStrategy::Root @@ -325,14 +325,14 @@ pub(crate) fn typing_only_runtime_import( let import_type = match categorize( &source_name, qualified_name.is_unresolved_import(), - &checker.settings.src, + &checker.settings().src, checker.package(), - checker.settings.isort.detect_same_package, - &checker.settings.isort.known_modules, + checker.settings().isort.detect_same_package, + &checker.settings().isort.known_modules, checker.target_version(), - checker.settings.isort.no_sections, - &checker.settings.isort.section_order, - &checker.settings.isort.default_section, + checker.settings().isort.no_sections, + &checker.settings().isort.section_order, + &checker.settings().isort.default_section, match_source_strategy, ) { ImportSection::Known(ImportType::LocalFolder | ImportType::FirstParty) => { 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 62d083d107..fb0ea5a004 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 @@ -250,7 +250,7 @@ impl Argumentable { /// Check a plain function for unused arguments. fn function(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) { let ignore_variadic_names = checker - .settings + .settings() .flake8_unused_arguments .ignore_variadic_names; let args = parameters @@ -276,7 +276,7 @@ fn function(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, /// Check a method for unused arguments. fn method(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) { let ignore_variadic_names = checker - .settings + .settings() .flake8_unused_arguments .ignore_variadic_names; let args = parameters @@ -307,7 +307,7 @@ fn call<'a>( checker: &Checker, ) { let semantic = checker.semantic(); - let dummy_variable_rgx = &checker.settings.dummy_variable_rgx; + let dummy_variable_rgx = &checker.settings().dummy_variable_rgx; for arg in parameters { let Some(binding) = scope .get(arg.name()) @@ -408,8 +408,8 @@ pub(crate) fn unused_arguments(checker: &Checker, scope: &Scope) { decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ) { function_type::FunctionType::Function => { if checker.is_rule_enabled(Argumentable::Function.rule_code()) diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs index 282e48591f..6c547ff5c8 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs @@ -68,7 +68,7 @@ pub(crate) fn camelcase_imported_as_acronym( && str::is_cased_uppercase(asname) && helpers::is_acronym(name, asname) { - let ignore_names = &checker.settings.pep8_naming.ignore_names; + let ignore_names = &checker.settings().pep8_naming.ignore_names; // Ignore any explicitly-allowed names. if ignore_names.matches(name) || ignore_names.matches(asname) { @@ -114,7 +114,7 @@ fn is_ignored_because_of_import_convention( // Ignore names that follow a community-agreed import convention. checker - .settings + .settings() .flake8_import_conventions .aliases .get(&*full_name) 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 855e987e8f..5bab2edfc7 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 @@ -81,7 +81,7 @@ pub(crate) fn invalid_argument_name_lambda(checker: &Checker, lambda: &ExprLambd /// N803 fn invalid_argument_name(checker: &Checker, parameters: &Parameters) { - let ignore_names = &checker.settings.pep8_naming.ignore_names; + let ignore_names = &checker.settings().pep8_naming.ignore_names; for parameter in parameters { let name = parameter.name().as_str(); 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 f326f16f2b..790f1a8b40 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 @@ -226,8 +226,8 @@ pub(crate) fn invalid_first_argument_name(checker: &Checker, scope: &Scope) { decorator_list, parent_scope, semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ) { function_type::FunctionType::Function | function_type::FunctionType::StaticMethod => { return; @@ -260,7 +260,7 @@ pub(crate) fn invalid_first_argument_name(checker: &Checker, scope: &Scope) { if &self_or_cls.name == function_type.valid_first_argument_name() || checker - .settings + .settings() .pep8_naming .ignore_names .matches(&self_or_cls.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 50fe2df5c5..1ad5f88381 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 @@ -72,7 +72,7 @@ pub(crate) fn mixed_case_variable_in_class_scope( return; } - if checker.settings.pep8_naming.ignore_names.matches(name) { + if checker.settings().pep8_naming.ignore_names.matches(name) { return; } 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 09ff4be6c4..84e955033e 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 @@ -75,7 +75,7 @@ pub(crate) fn mixed_case_variable_in_global_scope(checker: &Checker, expr: &Expr return; } - if checker.settings.pep8_naming.ignore_names.matches(name) { + if checker.settings().pep8_naming.ignore_names.matches(name) { return; } 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 85050984d5..d066363122 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 @@ -77,7 +77,7 @@ pub(crate) fn non_lowercase_variable_in_function(checker: &Checker, expr: &Expr, } // Ignore explicitly-allowed names. - if checker.settings.pep8_naming.ignore_names.matches(name) { + if checker.settings().pep8_naming.ignore_names.matches(name) { return; } 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 07423b3a67..5228ee6305 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 @@ -235,7 +235,7 @@ pub(crate) fn manual_dict_comprehension(checker: &Checker, for_stmt: &ast::StmtF return; } - if is_fix_manual_dict_comprehension_enabled(checker.settings) { + if is_fix_manual_dict_comprehension_enabled(checker.settings()) { let binding_stmt = binding.statement(checker.semantic()); let binding_value = binding_stmt.and_then(|binding_stmt| match binding_stmt { ast::Stmt::AnnAssign(assign) => assign.value.as_deref(), 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 d157842e0d..058de22939 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 @@ -337,7 +337,7 @@ pub(crate) fn manual_list_comprehension(checker: &Checker, for_stmt: &ast::StmtF ); // TODO: once this fix is stabilized, change the rule to always fixable - if is_fix_manual_list_comprehension_enabled(checker.settings) { + if is_fix_manual_list_comprehension_enabled(checker.settings()) { diagnostic.try_set_fix(|| { convert_to_list_extend( comprehension_type, 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 26305caf81..f815258da2 100644 --- a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs +++ b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs @@ -887,7 +887,7 @@ pub(crate) fn check_docstring( return; }; - if checker.settings.pydoclint.ignore_one_line_docstrings && is_one_line(docstring) { + if checker.settings().pydoclint.ignore_one_line_docstrings && is_one_line(docstring) { return; } @@ -919,7 +919,7 @@ pub(crate) fn check_docstring( if should_document_returns(function_def) && !returns_documented(docstring, &docstring_sections, convention) { - let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); + let extra_property_decorators = checker.settings().pydocstyle.property_decorators(); if !definition.is_property(extra_property_decorators, semantic) { if !body_entries.returns.is_empty() { match function_def.returns.as_deref() { diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index d09fb9a8cd..bd6f8b11fb 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -1789,7 +1789,7 @@ fn missing_args(checker: &Checker, docstring: &Docstring, docstrings_args: &FxHa // Check specifically for `vararg` and `kwarg`, which can be prefixed with a // single or double star, respectively. - if !checker.settings.pydocstyle.ignore_var_parameters() { + if !checker.settings().pydocstyle.ignore_var_parameters() { if let Some(arg) = function.parameters.vararg.as_ref() { let arg_name = arg.name.as_str(); let starred_arg_name = format!("*{arg_name}"); 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 8cd4e2bd39..041a5a0211 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs @@ -39,7 +39,7 @@ pub(crate) fn unused_annotation(checker: &Checker, scope: &Scope) { let binding = checker.semantic().binding(binding_id); if binding.kind.is_annotation() && binding.is_unused() - && !checker.settings.dummy_variable_rgx.is_match(name) + && !checker.settings().dummy_variable_rgx.is_match(name) { Some((name.to_string(), binding.range())) } else { 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 68d49ed7f5..56acb220fd 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -231,7 +231,7 @@ enum UnusedImportContext { fn is_first_party(import: &AnyImport, checker: &Checker) -> bool { let source_name = import.source_name().join("."); - let match_source_strategy = if is_full_path_match_source_strategy_enabled(checker.settings) { + let match_source_strategy = if is_full_path_match_source_strategy_enabled(checker.settings()) { MatchSourceStrategy::FullPath } else { MatchSourceStrategy::Root @@ -239,14 +239,14 @@ fn is_first_party(import: &AnyImport, checker: &Checker) -> bool { let category = isort::categorize( &source_name, import.qualified_name().is_unresolved_import(), - &checker.settings.src, + &checker.settings().src, checker.package(), - checker.settings.isort.detect_same_package, - &checker.settings.isort.known_modules, + checker.settings().isort.detect_same_package, + &checker.settings().isort.known_modules, checker.target_version(), - checker.settings.isort.no_sections, - &checker.settings.isort.section_order, - &checker.settings.isort.default_section, + checker.settings().isort.no_sections, + &checker.settings().isort.section_order, + &checker.settings().isort.default_section, match_source_strategy, ); matches! { @@ -317,7 +317,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) { // If an import is marked as required, avoid treating it as unused, regardless of whether // it was _actually_ used. if checker - .settings + .settings() .isort .required_imports .iter() @@ -328,7 +328,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) { // If an import was marked as allowed, avoid treating it as unused. if checker - .settings + .settings() .pyflakes .allowed_unused_imports .iter() @@ -366,8 +366,8 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) { } let in_init = checker.path().ends_with("__init__.py"); - let fix_init = !checker.settings.ignore_init_module_imports; - let preview_mode = is_dunder_init_fix_unused_import_enabled(checker.settings); + let fix_init = !checker.settings().ignore_init_module_imports; + let preview_mode = is_dunder_init_fix_unused_import_enabled(checker.settings()); let dunder_all_exprs = find_dunder_all_exprs(checker.semantic()); // Generate a diagnostic for every import, but share fixes across all imports within the same 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 5b6296301b..7dde1bd468 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs @@ -187,7 +187,7 @@ fn remove_unused_variable(binding: &Binding, checker: &Checker) -> Option { } else { let name = binding.name(checker.source()); let renamed = format!("_{name}"); - if checker.settings.dummy_variable_rgx.is_match(&renamed) { + if checker.settings().dummy_variable_rgx.is_match(&renamed) { let edit = Edit::range_replacement(renamed, binding.range()); return Some(Fix::unsafe_edit(edit).isolate(isolation)); 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 973d90bbad..b4ee0a4332 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 @@ -69,7 +69,7 @@ pub(crate) fn bad_dunder_method_name(checker: &Checker, method: &ast::StmtFuncti // If the name is explicitly allowed, skip it. if is_known_dunder_method(&method.name) || checker - .settings + .settings() .pylint .allow_dunder_method_names .contains(method.name.as_str()) 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 20d979ffb2..4108cd8c74 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 @@ -71,8 +71,8 @@ pub(crate) fn bad_staticmethod_argument(checker: &Checker, scope: &Scope) { decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); match type_ { 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 2bf244d273..ed3434460e 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 @@ -91,7 +91,7 @@ fn is_banned_module_level_import(policy: &NameMatchPolicy, checker: &Checker) -> policy .find( checker - .settings + .settings() .flake8_tidy_imports .banned_module_level_imports(), ) diff --git a/crates/ruff_linter/src/rules/pylint/rules/logging.rs b/crates/ruff_linter/src/rules/pylint/rules/logging.rs index f5a194d231..d8a13cfdf3 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/logging.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/logging.rs @@ -109,7 +109,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { if !logging::is_logger_candidate( &call.func, checker.semantic(), - &checker.settings.logger_objects, + &checker.settings().logger_objects, ) { return; } 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 f6728e5b38..a469e7b40c 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 @@ -110,7 +110,7 @@ pub(crate) fn magic_value_comparison(checker: &Checker, left: &Expr, comparators 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) { + if is_magic_value(value, &checker.settings().pylint.allow_magic_value_types) { checker.report_diagnostic( MagicValueComparison { value: checker.locator().slice(comparison_expr).to_string(), 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 16b8a14293..3856d2e649 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 @@ -60,7 +60,7 @@ pub(crate) fn misplaced_bare_raise(checker: &Checker, raise: &ast::StmtRaise) { return; } - if in_dunder_method("__exit__", checker.semantic(), checker.settings) { + if in_dunder_method("__exit__", checker.semantic(), checker.settings()) { return; } 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 78d59d0329..c46a268005 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 @@ -76,15 +76,15 @@ pub(crate) fn no_self_use(checker: &Checker, scope_id: ScopeId, scope: &Scope) { decorator_list, parent, semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ), function_type::FunctionType::Method ) { return; } - let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); + let extra_property_decorators = checker.settings().pydocstyle.property_decorators(); if function_type::is_stub(func, semantic) || visibility::is_magic(name) 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 43d5a6175b..a0c2c9db75 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 @@ -55,7 +55,7 @@ pub(crate) fn property_with_parameters( return; } let semantic = checker.semantic(); - let extra_property_decorators = checker.settings.pydocstyle.property_decorators(); + let extra_property_decorators = checker.settings().pydocstyle.property_decorators(); if is_property(decorator_list, extra_property_decorators, semantic) { checker.report_diagnostic(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 1a56bd6737..b85a58b1da 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 @@ -65,7 +65,7 @@ fn check_expr(checker: &Checker, expr: &Expr, names: &mut Vec) { check_expr(checker, &starred.value, names); } Expr::Name(ast::ExprName { id, .. }) => { - if checker.settings.dummy_variable_rgx.is_match(id) { + if checker.settings().dummy_variable_rgx.is_match(id) { // Ignore dummy variable assignments return; } 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 1be0f21c5b..bbdf17e8e7 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 @@ -346,7 +346,7 @@ 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 = - assignment_targets_from_with_items(items, &checker.settings.dummy_variable_rgx) + assignment_targets_from_with_items(items, &checker.settings().dummy_variable_rgx) .map(|expr| ExprWithOuterBindingKind { expr, binding_kind: OuterBindingKind::With, @@ -354,7 +354,7 @@ pub(crate) fn redefined_loop_name(checker: &Checker, stmt: &Stmt) { .collect(); let mut visitor = InnerForWithAssignTargetsVisitor { context: checker.semantic(), - dummy_variable_rgx: &checker.settings.dummy_variable_rgx, + dummy_variable_rgx: &checker.settings().dummy_variable_rgx, assignment_targets: vec![], }; for stmt in body { @@ -364,7 +364,7 @@ pub(crate) fn redefined_loop_name(checker: &Checker, stmt: &Stmt) { } Stmt::For(ast::StmtFor { target, body, .. }) => { let outer_assignment_targets: Vec = - assignment_targets_from_expr(target, &checker.settings.dummy_variable_rgx) + assignment_targets_from_expr(target, &checker.settings().dummy_variable_rgx) .map(|expr| ExprWithOuterBindingKind { expr, binding_kind: OuterBindingKind::For, @@ -372,7 +372,7 @@ pub(crate) fn redefined_loop_name(checker: &Checker, stmt: &Stmt) { .collect(); let mut visitor = InnerForWithAssignTargetsVisitor { context: checker.semantic(), - dummy_variable_rgx: &checker.settings.dummy_variable_rgx, + dummy_variable_rgx: &checker.settings().dummy_variable_rgx, assignment_targets: vec![], }; for stmt in body { 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 ec80640c1d..a80913635c 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 @@ -63,7 +63,7 @@ pub(crate) fn return_in_init(checker: &Checker, stmt: &Stmt) { } } - if in_dunder_method("__init__", checker.semantic(), checker.settings) { + if in_dunder_method("__init__", checker.semantic(), checker.settings()) { checker.report_diagnostic(ReturnInInit, stmt.range()); } } 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 c77203bfec..6799396b1a 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 @@ -98,8 +98,8 @@ pub(crate) fn self_or_cls_assignment(checker: &Checker, target: &Expr) { decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); let method_type = match (function_type, self_or_cls.name().as_str()) { 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 b0ac23c933..c9b83fd2e8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs @@ -79,8 +79,8 @@ pub(crate) fn singledispatch_method(checker: &Checker, scope: &Scope) { decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); if !matches!( type_, 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 9bb153bdea..ead9609e5d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs @@ -77,8 +77,8 @@ pub(crate) fn singledispatchmethod_function(checker: &Checker, scope: &Scope) { decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); if !matches!(type_, function_type::FunctionType::Function) { return; 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 e9eb23cc5a..510fc836c5 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 @@ -96,8 +96,8 @@ pub(crate) fn super_without_brackets(checker: &Checker, func: &Expr) { &function_def.decorator_list, parent, checker.semantic(), - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ); if !matches!( classification, 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 3e1156d4c5..7fb946ea83 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 @@ -68,10 +68,10 @@ pub(crate) fn too_many_arguments(checker: &Checker, function_def: &ast::StmtFunc let num_arguments = function_def .parameters .iter_non_variadic_params() - .filter(|param| !checker.settings.dummy_variable_rgx.is_match(param.name())) + .filter(|param| !checker.settings().dummy_variable_rgx.is_match(param.name())) .count(); - if num_arguments <= checker.settings.pylint.max_args { + if num_arguments <= checker.settings().pylint.max_args { return; } @@ -90,8 +90,8 @@ pub(crate) fn too_many_arguments(checker: &Checker, function_def: &ast::StmtFunc &function_def.decorator_list, semantic.current_scope(), semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ), function_type::FunctionType::Method | function_type::FunctionType::ClassMethod @@ -104,14 +104,14 @@ pub(crate) fn too_many_arguments(checker: &Checker, function_def: &ast::StmtFunc num_arguments }; - if num_arguments <= checker.settings.pylint.max_args { + if num_arguments <= checker.settings().pylint.max_args { return; } checker.report_diagnostic( TooManyArguments { c_args: num_arguments, - max_args: checker.settings.pylint.max_args, + max_args: checker.settings().pylint.max_args, }, function_def.identifier(), ); 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 690e3652ad..76bf947411 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 @@ -46,11 +46,11 @@ impl Violation for TooManyBooleanExpressions { 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 { + if expressions > checker.settings().pylint.max_bool_expr { checker.report_diagnostic( TooManyBooleanExpressions { expressions, - max_expressions: checker.settings.pylint.max_bool_expr, + max_expressions: checker.settings().pylint.max_bool_expr, }, bool_op.range(), ); @@ -60,11 +60,11 @@ pub(crate) fn too_many_boolean_expressions(checker: &Checker, stmt: &StmtIf) { for elif in &stmt.elif_else_clauses { 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 { + if expressions > checker.settings().pylint.max_bool_expr { checker.report_diagnostic( TooManyBooleanExpressions { expressions, - max_expressions: checker.settings.pylint.max_bool_expr, + max_expressions: checker.settings().pylint.max_bool_expr, }, bool_op.range(), ); 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 dfd3142c63..56ac5cf986 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 @@ -45,12 +45,12 @@ pub(crate) fn too_many_locals(checker: &Checker, scope: &Scope) { binding.kind.is_assignment() }) .count(); - if num_locals > checker.settings.pylint.max_locals { + if num_locals > checker.settings().pylint.max_locals { if let ScopeKind::Function(func) = scope.kind { checker.report_diagnostic( TooManyLocals { current_amount: num_locals, - max_amount: checker.settings.pylint.max_locals, + max_amount: checker.settings().pylint.max_locals, }, func.identifier(), ); 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 4d0b1d86d4..0e4ee0dea3 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 @@ -48,7 +48,7 @@ pub(crate) fn too_many_nested_blocks(checker: &Checker, stmt: &Stmt) { return; } - let max_nested_blocks = checker.settings.pylint.max_nested_blocks; + let max_nested_blocks = checker.settings().pylint.max_nested_blocks; // Traverse up the hierarchy, identifying the root node and counting the number of nested // blocks between the root and this leaf. 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 80abaa8071..2e0e02908c 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 @@ -72,10 +72,10 @@ pub(crate) fn too_many_positional_arguments( .posonlyargs .iter() .chain(&function_def.parameters.args) - .filter(|param| !checker.settings.dummy_variable_rgx.is_match(param.name())) + .filter(|param| !checker.settings().dummy_variable_rgx.is_match(param.name())) .count(); - if num_positional_args <= checker.settings.pylint.max_positional_args { + if num_positional_args <= checker.settings().pylint.max_positional_args { return; } @@ -94,8 +94,8 @@ pub(crate) fn too_many_positional_arguments( &function_def.decorator_list, semantic.current_scope(), semantic, - &checker.settings.pep8_naming.classmethod_decorators, - &checker.settings.pep8_naming.staticmethod_decorators, + &checker.settings().pep8_naming.classmethod_decorators, + &checker.settings().pep8_naming.staticmethod_decorators, ), function_type::FunctionType::Method | function_type::FunctionType::ClassMethod @@ -108,14 +108,14 @@ pub(crate) fn too_many_positional_arguments( num_positional_args }; - if num_positional_args <= checker.settings.pylint.max_positional_args { + if num_positional_args <= checker.settings().pylint.max_positional_args { return; } checker.report_diagnostic( TooManyPositionalArguments { c_pos: num_positional_args, - max_pos: checker.settings.pylint.max_positional_args, + max_pos: checker.settings().pylint.max_positional_args, }, function_def.identifier(), ); 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 31d01656d9..bc9101b646 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 @@ -75,7 +75,7 @@ pub(crate) fn useless_import_alias(checker: &Checker, alias: &Alias) { // A re-export in __init__.py is probably intentional. if checker.path().ends_with("__init__.py") - && is_ignore_init_files_in_useless_alias_enabled(checker.settings) + && is_ignore_init_files_in_useless_alias_enabled(checker.settings()) { return; } @@ -83,7 +83,7 @@ pub(crate) fn useless_import_alias(checker: &Checker, alias: &Alias) { // A required import with a useless alias causes an infinite loop. // See https://github.com/astral-sh/ruff/issues/14283 let required_import_conflict = checker - .settings + .settings() .isort .requires_module_import(alias.name.to_string(), Some(asname.to_string())); let mut diagnostic = checker.report_diagnostic( @@ -121,7 +121,7 @@ pub(crate) fn useless_import_from_alias( // A required import with a useless alias causes an infinite loop. // See https://github.com/astral-sh/ruff/issues/14283 - let required_import_conflict = checker.settings.isort.requires_member_import( + let required_import_conflict = checker.settings().isort.requires_member_import( module.map(str::to_string), alias.name.to_string(), Some(asname.to_string()), 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 1cee03fe04..67236eed6b 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 @@ -40,7 +40,7 @@ impl Violation for YieldInInit { /// PLE0100 pub(crate) fn yield_in_init(checker: &Checker, expr: &Expr) { - if in_dunder_method("__init__", checker.semantic(), checker.settings) { + if in_dunder_method("__init__", checker.semantic(), checker.settings()) { checker.report_diagnostic(YieldInInit, expr.range()); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs b/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs index f8961f82a4..f314d38c1a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/access_annotations_from_class_dict.rs @@ -97,7 +97,7 @@ impl Violation for AccessAnnotationsFromClassDict { /// RUF063 pub(crate) fn access_annotations_from_class_dict_with_get(checker: &Checker, call: &ExprCall) { let python_version = checker.target_version(); - let typing_extensions = checker.settings.typing_extensions; + let typing_extensions = checker.settings().typing_extensions; // Only apply this rule for Python 3.10 and newer unless `typing-extensions` is enabled. if python_version < PythonVersion::PY310 && !typing_extensions { @@ -152,7 +152,7 @@ pub(crate) fn access_annotations_from_class_dict_by_key( subscript: &ExprSubscript, ) { let python_version = checker.target_version(); - let typing_extensions = checker.settings.typing_extensions; + let typing_extensions = checker.settings().typing_extensions; // Only apply this rule for Python 3.10 and newer unless `typing-extensions` is enabled. if python_version < PythonVersion::PY310 && !typing_extensions { 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 9d69926176..1af8f6fcaa 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 @@ -205,7 +205,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &Checker, string_like: ast::StringLikePart::String(string_literal) => { let text = checker.locator().slice(string_literal); for candidate in - ambiguous_unicode_character(text, string_literal.range(), checker.settings) + ambiguous_unicode_character(text, string_literal.range(), checker.settings()) { candidate.report_diagnostic(checker, context); } @@ -216,7 +216,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &Checker, string_like: for literal in elements.literals() { let text = checker.locator().slice(literal); for candidate in - ambiguous_unicode_character(text, literal.range(), checker.settings) + ambiguous_unicode_character(text, literal.range(), checker.settings()) { candidate.report_diagnostic(checker, context); } @@ -378,7 +378,7 @@ impl Candidate { fn report_diagnostic(self, checker: &Checker, context: Context) { if !checker - .settings + .settings() .allowed_confusables .contains(&self.confusable) { 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 d960205161..bd21ae829a 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 @@ -107,7 +107,7 @@ pub(crate) fn function_call_in_dataclass_default(checker: &Checker, class_def: & }; let extend_immutable_calls: Vec = checker - .settings + .settings() .flake8_bugbear .extend_immutable_calls .iter() diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs index a07b262a95..47e3fc4d8e 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs @@ -87,7 +87,7 @@ pub(crate) fn implicit_class_var_in_dataclass(checker: &mut Checker, class_def: continue; }; - if checker.settings.dummy_variable_rgx.is_match(id.as_str()) { + if checker.settings().dummy_variable_rgx.is_match(id.as_str()) { continue; } 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 490cd20cf0..e0c537f0b0 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 @@ -63,7 +63,7 @@ impl AlwaysFixableViolation for IncorrectlyParenthesizedTupleInSubscript { /// RUF031 pub(crate) fn subscript_with_parenthesized_tuple(checker: &Checker, subscript: &ExprSubscript) { - let prefer_parentheses = checker.settings.ruff.parenthesize_tuple_in_subscript; + let prefer_parentheses = checker.settings().ruff.parenthesize_tuple_in_subscript; let Expr::Tuple(tuple_subscript) = &*subscript.slice else { return; 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 e13cb03dd5..9194d758da 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 @@ -93,7 +93,7 @@ pub(crate) fn missing_fstring_syntax(checker: &Checker, literal: &ast::StringLit } } - let logger_objects = &checker.settings.logger_objects; + let logger_objects = &checker.settings().logger_objects; let fastapi_seen = semantic.seen_module(Modules::FASTAPI); // We also want to avoid: diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_unpacked_variable.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_unpacked_variable.rs index 65cb79563c..16a893d1ea 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_unpacked_variable.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_unpacked_variable.rs @@ -69,7 +69,7 @@ fn remove_unused_variable(binding: &Binding, checker: &Checker) -> Option { return None; } - if checker.settings.dummy_variable_rgx.is_match(&renamed) { + if checker.settings().dummy_variable_rgx.is_match(&renamed) { let edit = Edit::range_replacement(renamed, binding.range()); return Some(Fix::unsafe_edit(edit).isolate(isolation)); diff --git a/crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rs b/crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rs index a3d3f3a986..a87fc40273 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rs @@ -157,7 +157,7 @@ pub(crate) fn used_dummy_variable(checker: &Checker, binding: &Binding, binding_ { return; } - if !checker.settings.dummy_variable_rgx.is_match(name) { + if !checker.settings().dummy_variable_rgx.is_match(name) { return; } @@ -211,7 +211,7 @@ fn get_possible_new_name( }; // Check if the fix name is again dummy identifier - if checker.settings.dummy_variable_rgx.is_match(&fix_name) { + if checker.settings().dummy_variable_rgx.is_match(&fix_name) { return None; } 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 5a59099cae..ebc2d40a75 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 @@ -73,7 +73,7 @@ pub(crate) fn error_instead_of_exception(checker: &Checker, handlers: &[ExceptHa let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { body, .. }) = handler; let calls = { let mut visitor = - LoggerCandidateVisitor::new(checker.semantic(), &checker.settings.logger_objects); + LoggerCandidateVisitor::new(checker.semantic(), &checker.settings().logger_objects); visitor.visit_body(body); visitor.calls }; 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 e95100cf81..9b8c6619c8 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 @@ -51,7 +51,7 @@ pub(crate) fn verbose_log_message(checker: &Checker, handlers: &[ExceptHandler]) // Find all calls to `logging.exception`. let calls = { let mut visitor = - LoggerCandidateVisitor::new(checker.semantic(), &checker.settings.logger_objects); + LoggerCandidateVisitor::new(checker.semantic(), &checker.settings().logger_objects); visitor.visit_body(body); visitor.calls };