Skip to content

Commit

Permalink
Stabilize A004 (#14480)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Nov 20, 2024
1 parent 4ccacc8 commit 942d6ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 69 deletions.
26 changes: 1 addition & 25 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 942d6ee

Please sign in to comment.