diff --git a/crates/ruff/tests/lint.rs b/crates/ruff/tests/lint.rs index 2846fbc9d7909..702723d54b8f3 100644 --- a/crates/ruff/tests/lint.rs +++ b/crates/ruff/tests/lint.rs @@ -2556,11 +2556,7 @@ fn a005_module_shadowing_strict_default() -> Result<()> { ----- stdout ----- abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module - collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module - foobar/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module - foobar/collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module - foobar/collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module - Found 6 errors. + Found 2 errors. ----- stderr ----- "); diff --git a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap index 6fdb2e691c73d..7fe041a00d69b 100644 --- a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap +++ b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap @@ -231,7 +231,7 @@ linter.flake8_bandit.allowed_markup_calls = [] linter.flake8_bugbear.extend_immutable_calls = [] linter.flake8_builtins.allowed_modules = [] linter.flake8_builtins.ignorelist = [] -linter.flake8_builtins.strict_checking = true +linter.flake8_builtins.strict_checking = false linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})* linter.flake8_copyright.author = none diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs index ca75b0248ee82..b26369d0f3862 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs @@ -23,12 +23,12 @@ use crate::settings::LinterSettings; /// Standard-library modules can be marked as exceptions to this rule via the /// [`lint.flake8-builtins.allowed-modules`] configuration option. /// -/// By default, only the last component of the module name is considered, so `logging.py`, -/// `utils/logging.py`, and `utils/logging/__init__.py` would all clash with the builtin `logging` -/// module. With the [`lint.flake8-builtins.strict-checking`] option set to `false`, the module -/// path is considered, so only a top-level `logging.py` or `logging/__init__.py` will trigger the -/// rule and `utils/logging.py`, for example, would not. In preview mode, the default value of -/// [`lint.flake8-builtins.strict-checking`] is `false` rather than `true` in stable mode. +/// By default, the module path relative to the project root or [`src`] directories is considered, +/// so a top-level `logging.py` or `logging/__init__.py` will clash with the builtin `logging` +/// module, but `utils/logging.py`, for example, will not. With the +/// [`lint.flake8-builtins.builtins-strict-checking`] option set to `true`, only the last component +/// of the module name is considered, so `logging.py`, `utils/logging.py`, and +/// `utils/logging/__init__.py` will all trigger the rule. /// /// This rule is not applied to stub files, as the name of a stub module is out /// of the control of the author of the stub file. Instead, a stub should aim to diff --git a/crates/ruff_linter/src/rules/flake8_builtins/settings.rs b/crates/ruff_linter/src/rules/flake8_builtins/settings.rs index c086d6742323f..7be3222326cb8 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/settings.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/settings.rs @@ -1,6 +1,6 @@ //! Settings for the `flake8-builtins` plugin. -use crate::{display_settings, settings::types::PreviewMode}; +use crate::display_settings; use ruff_macros::CacheKey; use std::fmt::{Display, Formatter}; @@ -11,16 +11,6 @@ pub struct Settings { pub strict_checking: bool, } -impl Settings { - pub fn new(preview: PreviewMode) -> Self { - Self { - ignorelist: Vec::new(), - allowed_modules: Vec::new(), - strict_checking: preview.is_disabled(), - } - } -} - impl Display for Settings { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { display_settings! { diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 4cf3e9df1b33a..260f4edc68986 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -235,13 +235,6 @@ impl Configuration { let rules = lint.as_rule_table(lint_preview)?; - let flake8_builtins = lint - .flake8_builtins - .map(|builtins| builtins.into_settings(lint_preview)) - .unwrap_or_else(|| { - ruff_linter::rules::flake8_builtins::settings::Settings::new(lint_preview) - }); - // LinterSettings validation let isort = lint .isort @@ -344,7 +337,10 @@ impl Configuration { .flake8_bugbear .map(Flake8BugbearOptions::into_settings) .unwrap_or_default(), - flake8_builtins, + flake8_builtins: lint + .flake8_builtins + .map(Flake8BuiltinsOptions::into_settings) + .unwrap_or_default(), flake8_comprehensions: lint .flake8_comprehensions .map(Flake8ComprehensionsOptions::into_settings) diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 7fec4c70c7a21..1a9bb972b5abb 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -28,7 +28,7 @@ use ruff_linter::rules::{ pycodestyle, pydoclint, pydocstyle, pyflakes, pylint, pyupgrade, ruff, }; use ruff_linter::settings::types::{ - IdentifierPattern, OutputFormat, PreviewMode, PythonVersion, RequiredVersion, + IdentifierPattern, OutputFormat, PythonVersion, RequiredVersion, }; use ruff_linter::{warn_user_once, RuleSelector}; use ruff_macros::{CombineOptions, OptionsMetadata}; @@ -1267,9 +1267,9 @@ pub struct Flake8BuiltinsOptions { /// /// This option is ignored if both `strict-checking` and `builtins-strict-checking` are set. #[option( - default = r#"true"#, + default = r#"false"#, value_type = "bool", - example = "builtins-strict-checking = false" + example = "builtins-strict-checking = true" )] #[deprecated( since = "0.10.0", @@ -1280,21 +1280,16 @@ pub struct Flake8BuiltinsOptions { /// Compare module names instead of full module paths. /// /// Used by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/). - /// - /// In preview mode the default value is `false` rather than `true`. #[option( - default = r#"true"#, + default = r#"false"#, value_type = "bool", - example = "strict-checking = false" + example = "strict-checking = true" )] pub strict_checking: Option, } impl Flake8BuiltinsOptions { - pub fn into_settings( - self, - preview: PreviewMode, - ) -> ruff_linter::rules::flake8_builtins::settings::Settings { + pub fn into_settings(self) -> ruff_linter::rules::flake8_builtins::settings::Settings { #[allow(deprecated)] ruff_linter::rules::flake8_builtins::settings::Settings { ignorelist: self @@ -1309,7 +1304,7 @@ impl Flake8BuiltinsOptions { .strict_checking .or(self.builtins_strict_checking) // use the old default of true on non-preview - .unwrap_or(preview.is_disabled()), + .unwrap_or_default(), } } } diff --git a/crates/ruff_workspace/src/pyproject.rs b/crates/ruff_workspace/src/pyproject.rs index 30cf81716b85d..aa92b186bd484 100644 --- a/crates/ruff_workspace/src/pyproject.rs +++ b/crates/ruff_workspace/src/pyproject.rs @@ -210,7 +210,7 @@ mod tests { use ruff_linter::codes; use ruff_linter::line_width::LineLength; - use ruff_linter::settings::types::{PatternPrefixPair, PreviewMode}; + use ruff_linter::settings::types::PatternPrefixPair; use crate::options::{Flake8BuiltinsOptions, LintCommonOptions, LintOptions, Options}; use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools}; @@ -363,7 +363,7 @@ strict-checking = false }) ); - let settings = expected.into_settings(PreviewMode::Enabled); + let settings = expected.into_settings(); assert_eq!(settings.allowed_modules, vec!["sys".to_string()]); assert_eq!( diff --git a/ruff.schema.json b/ruff.schema.json index 5cd24026bf1ac..919189643efc3 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1086,7 +1086,7 @@ } }, "strict-checking": { - "description": "Compare module names instead of full module paths.\n\nUsed by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).\n\nIn preview mode the default value is `false` rather than `true`.", + "description": "Compare module names instead of full module paths.\n\nUsed by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).", "type": [ "boolean", "null"