mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Stabilize A004
(#14480)
This commit is contained in:
parent
4ccacc80f9
commit
942d6eeb9f
5 changed files with 25 additions and 69 deletions
|
@ -591,18 +591,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
|||
if checker.enabled(Rule::NonAsciiImportName) {
|
||||
pylint::rules::non_ascii_module_import(checker, alias);
|
||||
}
|
||||
// TODO(charlie): Remove when stabilizing A004.
|
||||
if let Some(asname) = &alias.asname {
|
||||
if checker.settings.preview.is_disabled()
|
||||
&& checker.enabled(Rule::BuiltinVariableShadowing)
|
||||
{
|
||||
flake8_builtins::rules::builtin_variable_shadowing(
|
||||
checker,
|
||||
asname,
|
||||
asname.range(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if checker.enabled(Rule::Debugger) {
|
||||
if let Some(diagnostic) =
|
||||
flake8_debugger::rules::debugger_import(stmt, None, &alias.name)
|
||||
|
@ -912,19 +901,6 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
|||
stmt.range(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// TODO(charlie): Remove when stabilizing A004.
|
||||
if let Some(asname) = &alias.asname {
|
||||
if checker.settings.preview.is_disabled()
|
||||
&& checker.enabled(Rule::BuiltinVariableShadowing)
|
||||
{
|
||||
flake8_builtins::rules::builtin_variable_shadowing(
|
||||
checker,
|
||||
asname,
|
||||
asname.range(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if checker.enabled(Rule::RelativeImports) {
|
||||
if let Some(diagnostic) = flake8_tidy_imports::rules::banned_relative_import(
|
||||
|
|
|
@ -313,8 +313,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Flake8Builtins, "001") => (RuleGroup::Stable, rules::flake8_builtins::rules::BuiltinVariableShadowing),
|
||||
(Flake8Builtins, "002") => (RuleGroup::Stable, rules::flake8_builtins::rules::BuiltinArgumentShadowing),
|
||||
(Flake8Builtins, "003") => (RuleGroup::Stable, rules::flake8_builtins::rules::BuiltinAttributeShadowing),
|
||||
// TODO(charlie): When stabilizing, remove preview gating for A001's treatment of imports.
|
||||
(Flake8Builtins, "004") => (RuleGroup::Preview, rules::flake8_builtins::rules::BuiltinImportShadowing),
|
||||
(Flake8Builtins, "004") => (RuleGroup::Stable, rules::flake8_builtins::rules::BuiltinImportShadowing),
|
||||
(Flake8Builtins, "005") => (RuleGroup::Preview, rules::flake8_builtins::rules::BuiltinModuleShadowing),
|
||||
(Flake8Builtins, "006") => (RuleGroup::Preview, rules::flake8_builtins::rules::BuiltinLambdaArgumentShadowing),
|
||||
|
||||
|
|
|
@ -16,8 +16,31 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
|
|||
/// Builtins can be marked as exceptions to this rule via the
|
||||
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// from rich import print
|
||||
///
|
||||
/// print("Some message")
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// from rich import print as rich_print
|
||||
///
|
||||
/// rich_print("Some message")
|
||||
/// ```
|
||||
///
|
||||
/// or:
|
||||
/// ```python
|
||||
/// import rich
|
||||
///
|
||||
/// rich.print("Some message")
|
||||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `lint.flake8-builtins.builtins-ignorelist`
|
||||
/// - `target-version`
|
||||
///
|
||||
#[violation]
|
||||
pub struct BuiltinImportShadowing {
|
||||
name: String,
|
||||
|
|
|
@ -2,32 +2,6 @@
|
|||
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
A001.py:1:16: A001 Variable `sum` is shadowing a Python builtin
|
||||
|
|
||||
1 | import some as sum
|
||||
| ^^^ A001
|
||||
2 | from some import other as int
|
||||
3 | from directory import new as dir
|
||||
|
|
||||
|
||||
A001.py:2:27: A001 Variable `int` is shadowing a Python builtin
|
||||
|
|
||||
1 | import some as sum
|
||||
2 | from some import other as int
|
||||
| ^^^ A001
|
||||
3 | from directory import new as dir
|
||||
|
|
||||
|
||||
A001.py:3:30: A001 Variable `dir` is shadowing a Python builtin
|
||||
|
|
||||
1 | import some as sum
|
||||
2 | from some import other as int
|
||||
3 | from directory import new as dir
|
||||
| ^^^ A001
|
||||
4 |
|
||||
5 | print = 1
|
||||
|
|
||||
|
||||
A001.py:5:1: A001 Variable `print` is shadowing a Python builtin
|
||||
|
|
||||
3 | from directory import new as dir
|
||||
|
|
|
@ -2,22 +2,6 @@
|
|||
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
A001.py:1:16: A001 Variable `sum` is shadowing a Python builtin
|
||||
|
|
||||
1 | import some as sum
|
||||
| ^^^ A001
|
||||
2 | from some import other as int
|
||||
3 | from directory import new as dir
|
||||
|
|
||||
|
||||
A001.py:2:27: A001 Variable `int` is shadowing a Python builtin
|
||||
|
|
||||
1 | import some as sum
|
||||
2 | from some import other as int
|
||||
| ^^^ A001
|
||||
3 | from directory import new as dir
|
||||
|
|
||||
|
||||
A001.py:5:1: A001 Variable `print` is shadowing a Python builtin
|
||||
|
|
||||
3 | from directory import new as dir
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue