Skip to content

Commit

Permalink
Refactor all rule identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 4, 2021
1 parent ad22de1 commit 3afdfe0
Show file tree
Hide file tree
Showing 36 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/ansiblelint/_internal/rules.py
Expand Up @@ -71,7 +71,7 @@ def __lt__(self, other: "BaseRule") -> bool:
class RuntimeErrorRule(BaseRule):
"""Used to identify errors."""

id = '999'
id = 'internal-error'
shortdesc = 'Unexpected internal error'
description = (
'This error can be caused by internal bugs but also by '
Expand All @@ -86,7 +86,7 @@ class RuntimeErrorRule(BaseRule):
class AnsibleParserErrorRule(BaseRule):
"""Used to mark errors received from Ansible."""

id = '998'
id = 'parser-error'
shortdesc = 'AnsibleParserError'
description = (
'Ansible parser fails, this usually indicate invalid file.')
Expand All @@ -98,7 +98,7 @@ class AnsibleParserErrorRule(BaseRule):
class LoadingFailureRule(BaseRule):
"""File loading failure."""

id = '901'
id = 'load-failure'
shortdesc = 'Failed to load or parse file'
description = 'Linter failed to process a YAML file, possible not an Ansible file.'
severity = 'VERY_HIGH'
Expand Down
24 changes: 12 additions & 12 deletions src/ansiblelint/generate_docs.py
Expand Up @@ -30,26 +30,26 @@ def rules_as_rst(rules: RulesCollection) -> str:
r = DOC_HEADER

for d in rules:
if not hasattr(d, 'id'):
_logger.warning(
"Rule %s skipped from being documented as it does not have an `id` attribute.",
d.__class__.__name__)
continue
# if not hasattr(d, 'id'):
# _logger.warning(
# "Rule %s skipped from being documented as it does not have an `id` attribute.",
# d.__class__.__name__)
# continue

if d.id.endswith('01'):
# if d.id.endswith('01'):

section = '{} Rules ({}xx)'.format(
d.tags[0].title(),
d.id[-3:-2])
r += f'\n\n{section}\n{ "-" * len(section) }'
# section = '{} Rules ({}xx)'.format(
# d.tags[0].title(),
# d.id[-3:-2])
# r += f'\n\n{section}\n{ "-" * len(section) }'

title = f"{d.id}: {d.shortdesc}"
title = f"{d.id}"

description = d.description
if d.link:
description += " `(more) <%s>`_" % d.link

r += f"\n\n.. _{d.id}:\n\n{title}\n{'*' * len(title)}\n\n{description}"
r += f"\n\n.. _{d.id}:\n\n{title}\n{'*' * len(title)}\n\n{d.shortdesc}\n\n{description}"

return r

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/AnsibleSyntaxCheckRule.py
Expand Up @@ -24,7 +24,7 @@
class AnsibleSyntaxCheckRule(AnsibleLintRule):
"""Ansible syntax check report failure."""

id = "911"
id = "syntax-check"
shortdesc = "Ansible syntax check failed"
description = "Running ansible-playbook --syntax-check ... reported an error."
severity = "VERY_HIGH"
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/BecomeUserWithoutBecomeRule.py
Expand Up @@ -74,11 +74,11 @@ def _become_user_without_become(becomeuserabove: bool, data: "odict[str, Any]")


class BecomeUserWithoutBecomeRule(AnsibleLintRule):
id = '501'
id = 'partial-become'
shortdesc = 'become_user requires become to work as expected'
description = '``become_user`` without ``become`` will not actually change user'
severity = 'VERY_HIGH'
tags = ['task', 'unpredictability']
tags = ['unpredictability']
version_added = 'historic'

def matchplay(self, file: "Lintable", data: "odict[str, Any]") -> List["MatchError"]:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/CommandHasChangesCheckRule.py
Expand Up @@ -24,7 +24,7 @@


class CommandHasChangesCheckRule(AnsibleLintRule):
id = '301'
id = 'no-changed-when'
shortdesc = 'Commands should not change things if nothing needs doing'
description = (
'Commands should either read information (and thus set '
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/CommandsInsteadOfArgumentsRule.py
Expand Up @@ -26,14 +26,14 @@


class CommandsInsteadOfArgumentsRule(AnsibleLintRule):
id = '302'
id = 'deprecated-command-syntax'
shortdesc = 'Using command rather than an argument to e.g. file'
description = (
'Executing a command when there are arguments to modules '
'is generally a bad idea'
)
severity = 'VERY_HIGH'
tags = ['command-shell', 'resources']
tags = ['command-shell', 'deprecations']
version_added = 'historic'

_commands = ['command', 'shell', 'raw']
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/CommandsInsteadOfModulesRule.py
Expand Up @@ -26,7 +26,7 @@


class CommandsInsteadOfModulesRule(AnsibleLintRule):
id = '303'
id = 'command-instead-of-module'
shortdesc = 'Using command rather than module'
description = (
'Executing a command when there is an Ansible module '
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/ComparisonToEmptyStringRule.py
Expand Up @@ -8,7 +8,7 @@


class ComparisonToEmptyStringRule(AnsibleLintRule):
id = '602'
id = 'empty-string-compare'
shortdesc = "Don't compare to empty string"
description = (
'Use ``when: var|length > 0`` rather than ``when: var != ""`` (or '
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/ComparisonToLiteralBoolRule.py
Expand Up @@ -7,7 +7,7 @@


class ComparisonToLiteralBoolRule(AnsibleLintRule):
id = '601'
id = 'literal-compare'
shortdesc = "Don't compare to literal True/False"
description = (
'Use ``when: var`` rather than ``when: var == True`` '
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/DeprecatedModuleRule.py
Expand Up @@ -6,7 +6,7 @@


class DeprecatedModuleRule(AnsibleLintRule):
id = '105'
id = 'deprecated-module'
shortdesc = 'Deprecated module'
description = (
'These are deprecated modules, some modules are kept '
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/EnvVarsInCommandRule.py
Expand Up @@ -25,14 +25,14 @@


class EnvVarsInCommandRule(AnsibleLintRule):
id = '304'
id = 'inline-env-var'
shortdesc = "Command module does not accept setting environment variables inline"
description = (
'Use ``environment:`` to set environment variables '
'or use ``shell`` module which accepts both'
)
severity = 'VERY_HIGH'
tags = ['command-shell', 'bug']
tags = ['command-shell', 'idiom']
version_added = 'historic'

expected_args = ['chdir', 'creates', 'executable', 'removes', 'stdin', 'warn',
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/GitHasVersionRule.py
Expand Up @@ -24,14 +24,14 @@


class GitHasVersionRule(AnsibleLintRule):
id = '401'
id = 'git-latest'
shortdesc = 'Git checkouts must contain explicit version'
description = (
'All version control checkouts must point to '
'an explicit commit or tag, not just ``latest``'
)
severity = 'MEDIUM'
tags = ['module', 'repeatability']
tags = ['idempotency']
version_added = 'historic'

def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]:
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/rules/IncludeMissingFileRule.py
Expand Up @@ -17,15 +17,15 @@


class IncludeMissingFileRule(AnsibleLintRule):
id = '505'
id = 'missing-import'
shortdesc = 'referenced files must exist'
description = (
'All files referenced by by include / import tasks '
'All files referenced by include / import tasks '
'must exist. The check excludes files with jinja2 '
'templates in the filename.'
)
severity = 'MEDIUM'
tags = ['task', 'bug']
tags = ['idiom']
version_added = 'v4.3.0'

def matchplay(self, file: "Lintable", data: "odict[str, Any]") -> List["MatchError"]:
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/MercurialHasRevisionRule.py
Expand Up @@ -24,14 +24,14 @@


class MercurialHasRevisionRule(AnsibleLintRule):
id = '402'
id = 'hg-latest'
shortdesc = 'Mercurial checkouts must contain explicit revision'
description = (
'All version control checkouts must point to '
'an explicit commit or tag, not just ``latest``'
)
severity = 'MEDIUM'
tags = ['module', 'repeatability']
tags = ['idempotency']
version_added = 'historic'

def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/MetaChangeFromDefaultRule.py
Expand Up @@ -13,7 +13,7 @@


class MetaChangeFromDefaultRule(AnsibleLintRule):
id = '703'
id = 'meta-incorrect'
shortdesc = 'meta/main.yml default values should be changed'
field_defaults = [
('author', 'your name'),
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/MetaMainHasInfoRule.py
Expand Up @@ -52,7 +52,7 @@ def _galaxy_info_errors_itr(


class MetaMainHasInfoRule(AnsibleLintRule):
id = '701'
id = 'meta-no-info'
shortdesc = 'meta/main.yml should contain relevant info'
str_info = META_STR_INFO
info = META_INFO
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/MetaTagValidRule.py
Expand Up @@ -15,7 +15,7 @@


class MetaTagValidRule(AnsibleLintRule):
id = '702'
id = 'meta-no-tags'
shortdesc = 'Tags must contain lowercase letters and digits only'
description = (
'Tags must contain lowercase letters and digits only, '
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/MetaVideoLinksRule.py
Expand Up @@ -14,7 +14,7 @@


class MetaVideoLinksRule(AnsibleLintRule):
id = '704'
id = 'meta-video-links'
shortdesc = "meta/main.yml video_links should be formatted correctly"
description = (
'Items in ``video_links`` in meta/main.yml should be '
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/MissingFilePermissionsRule.py
Expand Up @@ -29,7 +29,7 @@


class MissingFilePermissionsRule(AnsibleLintRule):
id = "208"
id = "risky-file-permisions"
shortdesc = 'File permissions unset or incorrect'
description = (
"Missing or unsupported mode parameter can cause unexpected file "
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/NestedJinjaRule.py
Expand Up @@ -28,7 +28,7 @@


class NestedJinjaRule(AnsibleLintRule):
id = '207'
id = 'no-jinja-nesting'
shortdesc = 'Nested jinja pattern'
description = (
"There should not be any nested jinja pattern. "
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/NoFormattingInWhenRule.py
Expand Up @@ -9,7 +9,7 @@


class NoFormattingInWhenRule(AnsibleLintRule):
id = '102'
id = 'no-jinja-when'
shortdesc = 'No Jinja2 in when'
description = '``when`` is a raw Jinja2 expression, remove redundant {{ }} from variable(s).'
severity = 'HIGH'
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/NoTabsRule.py
Expand Up @@ -7,7 +7,7 @@


class NoTabsRule(AnsibleLintRule):
id = '203'
id = 'no-tabs'
shortdesc = 'Most files should not contain tabs'
description = 'Tabs can cause unexpected display issues, use spaces'
severity = 'LOW'
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/OctalPermissionsRule.py
Expand Up @@ -24,7 +24,7 @@


class OctalPermissionsRule(AnsibleLintRule):
id = '202'
id = 'risky-octal'
shortdesc = 'Octal file permissions must contain leading zero or be a string'
description = (
'Numeric file permissions without leading zero can behave '
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/PackageIsNotLatestRule.py
Expand Up @@ -24,14 +24,14 @@


class PackageIsNotLatestRule(AnsibleLintRule):
id = '403'
id = 'package-latest'
shortdesc = 'Package installs should not use latest'
description = (
'Package installs should use ``state=present`` '
'with or without a version'
)
severity = 'VERY_LOW'
tags = ['module', 'repeatability']
tags = ['idempotency']
version_added = 'historic'

_package_managers = [
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/PlaybookExtension.py
Expand Up @@ -10,7 +10,7 @@


class PlaybookExtension(AnsibleLintRule):
id = '205'
id = 'playbook-extension'
shortdesc = 'Use ".yml" or ".yaml" playbook extension'
description = 'Playbooks should have the ".yml" or ".yaml" extension'
severity = 'MEDIUM'
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/RoleLoopVarPrefix.py
Expand Up @@ -25,7 +25,7 @@ class RoleLoopVarPrefix(AnsibleLintRule):
Looping inside roles has the risk of clashing with loops from user-playbooks.\
"""

tags = ['no-loop-var-prefix', 'safety']
tags = ['idiom']
prefix = ""
severity = 'MEDIUM'

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/RoleNames.py
Expand Up @@ -39,7 +39,7 @@ def _remove_prefix(text: str, prefix: str) -> str:


class RoleNames(AnsibleLintRule):
id = '106'
id = 'role-name'
shortdesc = (
"Role name {0} does not match ``%s`` pattern" % ROLE_NAME_REGEX
)
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/RoleRelativePath.py
Expand Up @@ -7,11 +7,11 @@


class RoleRelativePath(AnsibleLintRule):
id = '404'
id = 'no-relative-paths'
shortdesc = "Doesn't need a relative path in role"
description = '``copy`` and ``template`` do not need to use relative path for ``src``'
severity = 'HIGH'
tags = ['module']
tags = ['idiom']
version_added = 'v4.0.0'

_module_to_path_folder = {
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/ShellWithoutPipefail.py
Expand Up @@ -5,7 +5,7 @@


class ShellWithoutPipefail(AnsibleLintRule):
id = '306'
id = 'risky-shell-pipe'
shortdesc = 'Shells that use pipes should set the pipefail option'
description = (
'Without the pipefail option set, a shell command that '
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/TaskHasNameRule.py
Expand Up @@ -24,14 +24,14 @@


class TaskHasNameRule(AnsibleLintRule):
id = '502'
id = 'unamed-task'
shortdesc = 'All tasks should be named'
description = (
'All tasks should have a distinct name for readability '
'and for ``--start-at-task`` to work'
)
severity = 'MEDIUM'
tags = ['task', 'readability']
tags = ['idiom']
version_added = 'historic'

_nameless_tasks = ['meta', 'debug', 'include_role', 'import_role',
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/TaskNoLocalAction.py
Expand Up @@ -5,11 +5,11 @@


class TaskNoLocalAction(AnsibleLintRule):
id = '504'
id = 'deprecated-local-action'
shortdesc = "Do not use 'local_action', use 'delegate_to: localhost'"
description = 'Do not use ``local_action``, use ``delegate_to: localhost``'
severity = 'MEDIUM'
tags = ['task']
tags = ['deprecations']
version_added = 'v4.0.0'

def match(self, line: str) -> bool:
Expand Down

0 comments on commit 3afdfe0

Please sign in to comment.