mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[flake8-builtins
] Make strict module name comparison optional (A005
) (#15951)
## Summary This PR adds the configuration option `lint.flake8-builtins.builtins-strict-checking`, which is used in A005 to determine whether the fully-qualified module name (relative to the project root or source directories) should be checked instead of just the final component as is currently the case. As discussed in https://github.com/astral-sh/ruff/issues/15399#issuecomment-2587017147, the default value of the new option is `false` on preview, so modules like `utils.logging` from the initial report are no longer flagged by default. For non-preview the default is still strict checking. ## Test Plan New A005 test module with the structure reported in #15399. Fixes #15399
This commit is contained in:
parent
f367aa8367
commit
88b543d73a
9 changed files with 175 additions and 76 deletions
|
@ -234,6 +234,13 @@ 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
|
||||
|
@ -335,10 +342,7 @@ impl Configuration {
|
|||
.flake8_bugbear
|
||||
.map(Flake8BugbearOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_builtins: lint
|
||||
.flake8_builtins
|
||||
.map(Flake8BuiltinsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_builtins,
|
||||
flake8_comprehensions: lint
|
||||
.flake8_comprehensions
|
||||
.map(Flake8ComprehensionsOptions::into_settings)
|
||||
|
|
|
@ -28,7 +28,7 @@ use ruff_linter::rules::{
|
|||
pycodestyle, pydoclint, pydocstyle, pyflakes, pylint, pyupgrade, ruff,
|
||||
};
|
||||
use ruff_linter::settings::types::{
|
||||
IdentifierPattern, OutputFormat, PythonVersion, RequiredVersion,
|
||||
IdentifierPattern, OutputFormat, PreviewMode, PythonVersion, RequiredVersion,
|
||||
};
|
||||
use ruff_linter::{warn_user_once, RuleSelector};
|
||||
use ruff_macros::{CombineOptions, OptionsMetadata};
|
||||
|
@ -1143,13 +1143,27 @@ pub struct Flake8BuiltinsOptions {
|
|||
)]
|
||||
/// List of builtin module names to allow.
|
||||
pub builtins_allowed_modules: Option<Vec<String>>,
|
||||
#[option(
|
||||
default = r#"true"#,
|
||||
value_type = "bool",
|
||||
example = "builtins-strict-checking = false"
|
||||
)]
|
||||
/// Compare module names instead of full module paths.
|
||||
pub builtins_strict_checking: Option<bool>,
|
||||
}
|
||||
|
||||
impl Flake8BuiltinsOptions {
|
||||
pub fn into_settings(self) -> ruff_linter::rules::flake8_builtins::settings::Settings {
|
||||
pub fn into_settings(
|
||||
self,
|
||||
preview: PreviewMode,
|
||||
) -> ruff_linter::rules::flake8_builtins::settings::Settings {
|
||||
ruff_linter::rules::flake8_builtins::settings::Settings {
|
||||
builtins_ignorelist: self.builtins_ignorelist.unwrap_or_default(),
|
||||
builtins_allowed_modules: self.builtins_allowed_modules.unwrap_or_default(),
|
||||
builtins_strict_checking: self
|
||||
.builtins_strict_checking
|
||||
// use the old default of true on non-preview
|
||||
.unwrap_or(preview.is_disabled()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue