From 83fe44728bbba114c1f032485314a19d5026f5e9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 25 Jun 2024 18:47:19 -0400 Subject: [PATCH] Match import name ignores against both name and alias (#12033) ## Summary Right now, it's inconsistent... We sometimes match against the name, and sometimes against the alias (`asname`). I could see a case for always matching against the name, but matching against both seems fine too, since the rule is really about the combination of the two? Closes https://github.com/astral-sh/ruff/issues/12031. --- .../rules/pep8_naming/rules/camelcase_imported_as_acronym.rs | 2 +- .../rules/pep8_naming/rules/camelcase_imported_as_constant.rs | 2 +- .../rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs | 2 +- .../pep8_naming/rules/constant_imported_as_non_constant.rs | 2 +- .../pep8_naming/rules/lowercase_imported_as_non_lowercase.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs index cdf0180510..f01d232ee4 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs @@ -62,7 +62,7 @@ pub(crate) fn camelcase_imported_as_acronym( && helpers::is_acronym(name, asname) { // Ignore any explicitly-allowed names. - if ignore_names.matches(name) { + if ignore_names.matches(name) || ignore_names.matches(asname) { return None; } let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs index f5763ab1ee..f805bd2915 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs @@ -59,7 +59,7 @@ pub(crate) fn camelcase_imported_as_constant( && !helpers::is_acronym(name, asname) { // Ignore any explicitly-allowed names. - if ignore_names.matches(asname) { + if ignore_names.matches(name) || ignore_names.matches(asname) { return None; } let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs index 5a3d9e0f6d..5a006d6260 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs @@ -54,7 +54,7 @@ pub(crate) fn camelcase_imported_as_lowercase( ) -> Option { if helpers::is_camelcase(name) && ruff_python_stdlib::str::is_cased_lowercase(asname) { // Ignore any explicitly-allowed names. - if ignore_names.matches(asname) { + if ignore_names.matches(name) || ignore_names.matches(asname) { return None; } let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs index d398a342a0..0f81043f60 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs @@ -54,7 +54,7 @@ pub(crate) fn constant_imported_as_non_constant( ) -> Option { if str::is_cased_uppercase(name) && !str::is_cased_uppercase(asname) { // Ignore any explicitly-allowed names. - if ignore_names.matches(asname) { + if ignore_names.matches(name) || ignore_names.matches(asname) { return None; } let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs index 1f5d9a7a2b..097e0f3948 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs @@ -54,7 +54,7 @@ pub(crate) fn lowercase_imported_as_non_lowercase( if !str::is_cased_uppercase(name) && str::is_cased_lowercase(name) && !str::is_lowercase(asname) { // Ignore any explicitly-allowed names. - if ignore_names.matches(asname) { + if ignore_names.matches(name) || ignore_names.matches(asname) { return None; } let mut diagnostic = Diagnostic::new(