mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[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:
parent
958e1177ce
commit
a04347b7a3
8 changed files with 23 additions and 46 deletions
|
@ -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
|
||||
|
|
|
@ -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! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue