[flake8-builtins] Default to non-strict checking (A005) (#16125)

## Summary

This PR changes the default value of
`lint.flake8-builtins.builtins-strict-checking` added in
https://github.com/astral-sh/ruff/pull/15951 from `true` to `false`.
This also allows simplifying the default option logic and removes the
dependence on preview mode.

https://github.com/astral-sh/ruff/issues/15399 was already closed by
#15951, but this change will finalize the behavior mentioned in
https://github.com/astral-sh/ruff/issues/15399#issuecomment-2587017147.

As an example, strict checking flags modules based on their last
component, so `utils/logging.py` triggers A005. Non-strict checking
checks the path to the module, so `utils/logging.py` is allowed (this is
the example and desired behavior from #15399 exactly) but a top-level
`logging.py` or `logging/__init__.py` is still disallowed.

## Test Plan

Existing tests from #15951 and #16006, with the snapshot updated in
`a005_module_shadowing_strict_default` to reflect the new default.
This commit is contained in:
Brent Westbrook 2025-03-11 14:10:01 -04:00 committed by Micha Reiser
parent 958e1177ce
commit a04347b7a3
8 changed files with 23 additions and 46 deletions

View file

@ -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<bool>,
}
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(),
}
}
}