mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add checks for from module_utils import * (#21800)
This commit is contained in:
parent
8c521655e1
commit
4b320ce0e4
2 changed files with 17 additions and 0 deletions
|
@ -76,6 +76,8 @@ Errors
|
|||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 207 | ``REPLACER_WINDOWS`` not found in module |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 208 | ``module_utils`` imports should import specific components, not ``*`` |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| **3xx** | **Documentation** |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
@ -140,6 +142,8 @@ Warnings
|
|||
+=========+============================================================================================================================================+
|
||||
| **2xx** | **Imports** |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 208 | ``module_utils`` imports should import specific components for legacy module, not ``*`` |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 291 | Try/Except ``HAS_`` expression missing |
|
||||
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 292 | Did not find ``ansible.module_utils.basic`` import |
|
||||
|
|
|
@ -364,6 +364,19 @@ class ModuleValidator(Validator):
|
|||
linenos.append(child.lineno)
|
||||
|
||||
for name in child.names:
|
||||
if ('module_utils' in getattr(child, 'module', '') and
|
||||
isinstance(name, ast.alias) and
|
||||
name.name == '*'):
|
||||
msg = (
|
||||
208,
|
||||
('module_utils imports should import specific '
|
||||
'components, not "*". line %d' % child.lineno)
|
||||
)
|
||||
if self._is_new_module():
|
||||
self.errors.append(msg)
|
||||
else:
|
||||
self.warnings.append(msg)
|
||||
|
||||
if (isinstance(name, ast.alias) and
|
||||
name.name == 'basic'):
|
||||
found_basic = True
|
||||
|
|
Loading…
Reference in a new issue