1- use ruff_python_ast:: { Alias , Stmt } ;
2-
31use ruff_diagnostics:: { Diagnostic , Violation } ;
42use ruff_macros:: { derive_message_formats, violation} ;
3+ use ruff_python_ast:: { Alias , Stmt } ;
54use ruff_python_stdlib:: str:: { self } ;
65use ruff_text_size:: Ranged ;
76
7+ use crate :: checkers:: ast:: Checker ;
88use crate :: rules:: pep8_naming:: helpers;
9- use crate :: rules:: pep8_naming:: settings:: IgnoreNames ;
109
1110/// ## What it does
1211/// Checks for `CamelCase` imports that are aliased as acronyms.
@@ -23,6 +22,10 @@ use crate::rules::pep8_naming::settings::IgnoreNames;
2322/// Note that this rule is distinct from `camelcase-imported-as-constant`
2423/// to accommodate selective enforcement.
2524///
25+ /// Also note that import aliases following an import convention according to the
26+ /// [`lint.flake8-boolean-trap.extend-allowed-calls`] option are allowed.
27+ ///
28+ ///
2629/// ## Example
2730/// ```python
2831/// from example import MyClassName as MCN
@@ -34,6 +37,9 @@ use crate::rules::pep8_naming::settings::IgnoreNames;
3437/// ```
3538///
3639/// [PEP 8]: https://peps.python.org/pep-0008/
40+ ///
41+ /// ## Options
42+ /// - `lint.flake8-import-conventions.banned-aliases`
3743#[ violation]
3844pub struct CamelcaseImportedAsAcronym {
3945 name : String ,
@@ -54,17 +60,32 @@ pub(crate) fn camelcase_imported_as_acronym(
5460 asname : & str ,
5561 alias : & Alias ,
5662 stmt : & Stmt ,
57- ignore_names : & IgnoreNames ,
63+ checker : & Checker ,
5864) -> Option < Diagnostic > {
5965 if helpers:: is_camelcase ( name)
6066 && !str:: is_cased_lowercase ( asname)
6167 && str:: is_cased_uppercase ( asname)
6268 && helpers:: is_acronym ( name, asname)
6369 {
70+ let ignore_names = & checker. settings . pep8_naming . ignore_names ;
71+
6472 // Ignore any explicitly-allowed names.
6573 if ignore_names. matches ( name) || ignore_names. matches ( asname) {
6674 return None ;
6775 }
76+
77+ // Ignore names that follow a community-agreed import convention.
78+ if checker
79+ . settings
80+ . flake8_import_conventions
81+ . aliases
82+ . get ( & * alias. name )
83+ . map ( String :: as_str)
84+ == Some ( asname)
85+ {
86+ return None ;
87+ }
88+
6889 let mut diagnostic = Diagnostic :: new (
6990 CamelcaseImportedAsAcronym {
7091 name : name. to_string ( ) ,
0 commit comments