refactor: use lint-like rule identifier (#757)

This commit is contained in:
Robert Kaussow 2024-01-27 19:56:35 +01:00 committed by GitHub
parent 80ac8ec34d
commit 2f4e35d83c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
44 changed files with 104 additions and 104 deletions

View File

@ -18,8 +18,8 @@ HostVars
Rolesfile Rolesfile
Makefile Makefile
Jinja2 Jinja2
ANSIBLE([0-9]{4}) ANS([0-9]{3})
LINT([0-9]{4}) YML([0-9]{3})
SCM SCM
bools bools
Check[A-Z].+ Check[A-Z].+

View File

@ -41,10 +41,10 @@ class Candidate:
excludes = self.config["rules"]["exclude_filter"] excludes = self.config["rules"]["exclude_filter"]
if len(includes) == 0: if len(includes) == 0:
includes = [s.sid for s in self.rules] includes = [s.rid for s in self.rules]
for rule in self.rules: for rule in self.rules:
if rule.sid in includes and rule.sid not in excludes: if rule.rid in includes and rule.rid not in excludes:
target_rules.append(rule) target_rules.append(rule)
return target_rules return target_rules
@ -60,7 +60,7 @@ class Candidate:
result = rule.check(self, self.config) result = rule.check(self, self.config)
if not result: if not result:
LOG.error(f"rule '{rule.sid}' returns an empty result object. Check failed!") LOG.error(f"rule '{rule.rid}' returns an empty result object. Check failed!")
continue continue
labels = { labels = {
@ -70,23 +70,23 @@ class Candidate:
"passed": True, "passed": True,
} }
if rule.sid and rule.sid.strip(): if rule.rid and rule.rid.strip():
labels["sid"] = rule.sid labels["rid"] = rule.rid
for err in result.errors: for err in result.errors:
err_labels = copy.copy(labels) err_labels = copy.copy(labels)
err_labels["passed"] = False err_labels["passed"] = False
sid = self._format_id(rule.sid) rid = self._format_id(rule.rid)
path = self.path path = self.path
description = rule.description description = rule.description
if isinstance(err, RuleBase.Error): if isinstance(err, RuleBase.Error):
err_labels.update(err.to_dict()) err_labels.update(err.to_dict())
msg = f"{sid}rule '{description}' not met:\n{path}:{err}" msg = f"{rid}rule '{description}' not met:\n{path}:{err}"
if rule.sid not in self.config["rules"]["warning_filter"]: if rule.rid not in self.config["rules"]["warning_filter"]:
LOG.error(msg, extra=flag_extra(err_labels)) LOG.error(msg, extra=flag_extra(err_labels))
errors = errors + 1 errors = errors + 1
else: else:
@ -138,9 +138,9 @@ class Candidate:
return None return None
def _format_id(self, rule_id): def _format_id(self, rule_id):
sid = rule_id.strip() rid = rule_id.strip()
if sid: if rid:
rule_id = f"[{sid}] " rule_id = f"[{rid}] "
return rule_id return rule_id

View File

@ -30,7 +30,7 @@ from ansiblelater.utils.yamlhelper import (
class RuleMeta(type): class RuleMeta(type):
def __call__(cls, *args): def __call__(cls, *args):
mcls = type.__call__(cls, *args) mcls = type.__call__(cls, *args)
mcls.sid = cls.sid mcls.rid = cls.rid
mcls.description = getattr(cls, "description", "__unknown__") mcls.description = getattr(cls, "description", "__unknown__")
mcls.helptext = getattr(cls, "helptext", "") mcls.helptext = getattr(cls, "helptext", "")
mcls.types = getattr(cls, "types", []) mcls.types = getattr(cls, "types", [])
@ -46,7 +46,7 @@ class RuleBase(metaclass=RuleExtendedMeta):
@property @property
@abstractmethod @abstractmethod
def sid(self): def rid(self):
pass pass
@abstractmethod @abstractmethod
@ -334,10 +334,10 @@ class RulesLoader:
) )
def validate(self): def validate(self):
normalized_std = list(toolz.remove(lambda x: x.sid == "", self.rules)) normalize_rule = list(toolz.remove(lambda x: x.rid == "", self.rules))
unique_std = len(list(toolz.unique(normalized_std, key=lambda x: x.sid))) unique_rule = len(list(toolz.unique(normalize_rule, key=lambda x: x.rid)))
all_std = len(normalized_std) all_rules = len(normalize_rule)
if all_std != unique_std: if all_rules != unique_rule:
sysexit_with_message( sysexit_with_message(
"Found duplicate tags in rules definition. Please use unique tags only." "Found duplicate tags in rules definition. Please use unique tags only."
) )

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckBecomeUser(RuleBase): class CheckBecomeUser(RuleBase):
sid = "ANSIBLE0015" rid = "ANS115"
description = "Become should be combined with become_user" description = "Become should be combined with become_user"
helptext = "the task has `become` enabled but `become_user` is missing" helptext = "the task has `become` enabled but `become_user` is missing"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -5,7 +5,7 @@ from ansiblelater.utils import count_spaces
class CheckBracesSpaces(RuleBase): class CheckBracesSpaces(RuleBase):
sid = "ANSIBLE0004" rid = "ANS104"
description = "YAML should use consistent number of spaces around variables" description = "YAML should use consistent number of spaces around variables"
helptext = "no suitable numbers of spaces (min: {min} max: {max})" helptext = "no suitable numbers of spaces (min: {min} max: {max})"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase
class CheckChangedInWhen(RuleBase): class CheckChangedInWhen(RuleBase):
sid = "ANSIBLE0026" rid = "ANS126"
description = "Use handlers instead of `when: changed`" description = "Use handlers instead of `when: changed`"
helptext = "tasks using `when: result.changed` setting are effectively acting as a handler" helptext = "tasks using `when: result.changed` setting are effectively acting as a handler"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckCommandHasChanges(RuleBase): class CheckCommandHasChanges(RuleBase):
sid = "ANSIBLE0011" rid = "ANS111"
description = "Commands should be idempotent" description = "Commands should be idempotent"
helptext = ( helptext = (
"commands should only read while using `changed_when` or try to be " "commands should only read while using `changed_when` or try to be "

View File

@ -24,7 +24,7 @@ from ansiblelater.rule import RuleBase
class CheckCommandInsteadOfArgument(RuleBase): class CheckCommandInsteadOfArgument(RuleBase):
sid = "ANSIBLE0017" rid = "ANS117"
description = "Commands should not be used in place of module arguments" description = "Commands should not be used in place of module arguments"
helptext = "{exec} used in place of file modules argument {arg}" helptext = "{exec} used in place of file modules argument {arg}"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckCommandInsteadOfModule(RuleBase): class CheckCommandInsteadOfModule(RuleBase):
sid = "ANSIBLE0008" rid = "ANS108"
description = "Commands should not be used in place of modules" description = "Commands should not be used in place of modules"
helptext = "{exec} command used in place of {module} module" helptext = "{exec} command used in place of {module} module"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase
class CheckCompareToEmptyString(RuleBase): class CheckCompareToEmptyString(RuleBase):
sid = "ANSIBLE0012" rid = "ANS112"
description = 'Don\'t compare to empty string ""' description = 'Don\'t compare to empty string ""'
helptext = "use `when: var` rather than `when: var !=` (or conversely `when: not var`)" helptext = "use `when: var` rather than `when: var !=` (or conversely `when: not var`)"
types = ["playbook", "task", "handler", "template"] types = ["playbook", "task", "handler", "template"]

View File

@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase
class CheckCompareToLiteralBool(RuleBase): class CheckCompareToLiteralBool(RuleBase):
sid = "ANSIBLE0013" rid = "ANS113"
description = "Don't compare to True or False" description = "Don't compare to True or False"
helptext = "use `when: var` rather than `when: var == True` (or conversely `when: not var`)" helptext = "use `when: var` rather than `when: var == True` (or conversely `when: not var`)"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckDeprecated(RuleBase): class CheckDeprecated(RuleBase):
sid = "ANSIBLE9999" rid = "ANS999"
description = "Deprecated features should not be used" description = "Deprecated features should not be used"
helptext = "`{old}` is deprecated and should not be used anymore. Use `{new}` instead." helptext = "`{old}` is deprecated and should not be used anymore. Use `{new}` instead."
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -25,7 +25,7 @@ from ansiblelater.utils import has_glob, has_jinja
class CheckDeprecatedBareVars(RuleBase): class CheckDeprecatedBareVars(RuleBase):
sid = "ANSIBLE0027" rid = "ANS127"
description = "Deprecated bare variables in loops must not be used" description = "Deprecated bare variables in loops must not be used"
helptext = ( helptext = (
"bare var '{barevar}' in '{loop_type}' must use full var syntax '{{{{ {barevar} }}}}' " "bare var '{barevar}' in '{loop_type}' must use full var syntax '{{{{ {barevar} }}}}' "

View File

@ -23,7 +23,7 @@ from ansiblelater.rule import RuleBase
class CheckFilePermissionMissing(RuleBase): class CheckFilePermissionMissing(RuleBase):
sid = "ANSIBLE0018" rid = "ANS118"
description = "File permissions unset or incorrect" description = "File permissions unset or incorrect"
helptext = ( helptext = (
"`mode` parameter should set permissions explicitly (e.g. `mode: 0644`) " "`mode` parameter should set permissions explicitly (e.g. `mode: 0644`) "

View File

@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase
class CheckFilePermissionOctal(RuleBase): class CheckFilePermissionOctal(RuleBase):
sid = "ANSIBLE0019" rid = "ANS119"
description = "Octal file permissions must contain leading zero or be a string" description = "Octal file permissions must contain leading zero or be a string"
helptext = "numeric file permissions without leading zero can behave in unexpected ways" helptext = "numeric file permissions without leading zero can behave in unexpected ways"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckFilterSeparation(RuleBase): class CheckFilterSeparation(RuleBase):
sid = "ANSIBLE0016" rid = "ANS116"
description = "Jinja2 filters should be separated with spaces" description = "Jinja2 filters should be separated with spaces"
helptext = "no suitable numbers of spaces (required: 1)" helptext = "no suitable numbers of spaces (required: 1)"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]

View File

@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase
class CheckGitHasVersion(RuleBase): class CheckGitHasVersion(RuleBase):
sid = "ANSIBLE0020" rid = "ANS120"
description = "Git checkouts should use explicit version" description = "Git checkouts should use explicit version"
helptext = "git checkouts should point to an explicit commit or tag, not `latest`" helptext = "git checkouts should point to an explicit commit or tag, not `latest`"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckInstallUseLatest(RuleBase): class CheckInstallUseLatest(RuleBase):
sid = "ANSIBLE0009" rid = "ANS109"
description = "Package installs should use present, not latest" description = "Package installs should use present, not latest"
helptext = "package installs should use `state=present` with or without a version" helptext = "package installs should use `state=present` with or without a version"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckLiteralBoolFormat(RuleBase): class CheckLiteralBoolFormat(RuleBase):
sid = "ANSIBLE0014" rid = "ANS114"
description = "Literal bools should be consistent" description = "Literal bools should be consistent"
helptext = "literal bools should be written as `{bools}`" helptext = "literal bools should be written as `{bools}`"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckLocalAction(RuleBase): class CheckLocalAction(RuleBase):
sid = "ANSIBLE0024" rid = "ANS124"
description = "Don't use local_action" description = "Don't use local_action"
helptext = "`delegate_to: localhost` should be used instead of `local_action`" helptext = "`delegate_to: localhost` should be used instead of `local_action`"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase
class CheckMetaChangeFromDefault(RuleBase): class CheckMetaChangeFromDefault(RuleBase):
sid = "ANSIBLE0021" rid = "ANS121"
description = "Roles meta/main.yml default values should be changed" description = "Roles meta/main.yml default values should be changed"
helptext = "meta/main.yml default values should be changed for: `{field}`" helptext = "meta/main.yml default values should be changed for: `{field}`"
types = ["meta"] types = ["meta"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckMetaMain(RuleBase): class CheckMetaMain(RuleBase):
sid = "ANSIBLE0002" rid = "ANS102"
description = "Roles must contain suitable meta/main.yml" description = "Roles must contain suitable meta/main.yml"
helptext = "file should contain `{key}` key" helptext = "file should contain `{key}` key"
types = ["meta"] types = ["meta"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckNameFormat(RuleBase): class CheckNameFormat(RuleBase):
sid = "ANSIBLE0007" rid = "ANS107"
description = "Name of tasks and handlers must be formatted" description = "Name of tasks and handlers must be formatted"
helptext = "name `{name}` should start with uppercase" helptext = "name `{name}` should start with uppercase"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckNamedTask(RuleBase): class CheckNamedTask(RuleBase):
sid = "ANSIBLE0006" rid = "ANS106"
description = "Tasks and handlers must be named" description = "Tasks and handlers must be named"
helptext = "module `{module}` used without or empty `name` attribute" helptext = "module `{module}` used without or empty `name` attribute"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckNativeYaml(RuleBase): class CheckNativeYaml(RuleBase):
sid = "LINT0008" rid = "YML108"
description = "Use YAML format for tasks and handlers rather than key=value" description = "Use YAML format for tasks and handlers rather than key=value"
helptext = "task arguments appear to be in key value rather than YAML format" helptext = "task arguments appear to be in key value rather than YAML format"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -25,7 +25,7 @@ from ansiblelater.rule import RuleBase
class CheckNestedJinja(RuleBase): class CheckNestedJinja(RuleBase):
sid = "ANSIBLE0023" rid = "ANS123"
description = "Don't use nested Jinja2 pattern" description = "Don't use nested Jinja2 pattern"
helptext = ( helptext = (
"there should not be any nested jinja pattern " "there should not be any nested jinja pattern "

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckRelativeRolePaths(RuleBase): class CheckRelativeRolePaths(RuleBase):
sid = "ANSIBLE0025" rid = "ANS125"
description = "Don't use a relative path in a role" description = "Don't use a relative path in a role"
helptext = "`copy` and `template` modules don't need relative path for `src`" helptext = "`copy` and `template` modules don't need relative path for `src`"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckScmInSrc(RuleBase): class CheckScmInSrc(RuleBase):
sid = "ANSIBLE0005" rid = "ANS105"
description = "Use `scm:` key rather than `src: scm+url`" description = "Use `scm:` key rather than `src: scm+url`"
helptext = "usage of `src: scm+url` not recommended" helptext = "usage of `src: scm+url` not recommended"
types = ["rolesfile"] types = ["rolesfile"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckShellInsteadCommand(RuleBase): class CheckShellInsteadCommand(RuleBase):
sid = "ANSIBLE0010" rid = "ANS110"
description = "Shell should only be used when essential" description = "Shell should only be used when essential"
helptext = "shell should only be used when piping, redirecting or chaining commands" helptext = "shell should only be used when piping, redirecting or chaining commands"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase
class CheckTaskSeparation(RuleBase): class CheckTaskSeparation(RuleBase):
sid = "ANSIBLE0001" rid = "ANS101"
description = "Single tasks should be separated by empty line" description = "Single tasks should be separated by empty line"
helptext = "missing task separation (required: 1 empty line)" helptext = "missing task separation (required: 1 empty line)"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckUniqueNamedTask(RuleBase): class CheckUniqueNamedTask(RuleBase):
sid = "ANSIBLE0003" rid = "ANS103"
description = "Tasks and handlers must be uniquely named within a single file" description = "Tasks and handlers must be uniquely named within a single file"
helptext = "name `{name}` appears multiple times" helptext = "name `{name}` appears multiple times"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckWhenFormat(RuleBase): class CheckWhenFormat(RuleBase):
sid = "ANSIBLE0022" rid = "ANS122"
description = "Don't use Jinja2 in when" description = "Don't use Jinja2 in when"
helptext = ( helptext = (
"`when` is a raw Jinja2 expression, redundant {{ }} " "should be removed from variable(s)" "`when` is a raw Jinja2 expression, redundant {{ }} " "should be removed from variable(s)"

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlColons(RuleBase): class CheckYamlColons(RuleBase):
sid = "LINT0005" rid = "YML105"
description = "YAML should use consistent number of spaces around colons" description = "YAML should use consistent number of spaces around colons"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlDocumentEnd(RuleBase): class CheckYamlDocumentEnd(RuleBase):
sid = "LINT0009" rid = "YML109"
description = "YAML should contain document end marker" description = "YAML should contain document end marker"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlDocumentStart(RuleBase): class CheckYamlDocumentStart(RuleBase):
sid = "LINT0004" rid = "YML104"
description = "YAML should contain document start marker" description = "YAML should contain document start marker"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlEmptyLines(RuleBase): class CheckYamlEmptyLines(RuleBase):
sid = "LINT0001" rid = "YML101"
description = "YAML should not contain unnecessarily empty lines" description = "YAML should not contain unnecessarily empty lines"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlFile(RuleBase): class CheckYamlFile(RuleBase):
sid = "LINT0006" rid = "YML106"
description = "Roles file should be in yaml format" description = "Roles file should be in yaml format"
helptext = "file does not have a .yml extension" helptext = "file does not have a .yml extension"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlHasContent(RuleBase): class CheckYamlHasContent(RuleBase):
sid = "LINT0007" rid = "YML107"
description = "Files should contain useful content" description = "Files should contain useful content"
helptext = "the file appears to have no useful content" helptext = "the file appears to have no useful content"
types = ["playbook", "task", "handler", "rolevars", "defaults", "meta"] types = ["playbook", "task", "handler", "rolevars", "defaults", "meta"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlHyphens(RuleBase): class CheckYamlHyphens(RuleBase):
sid = "LINT0003" rid = "YML103"
description = "YAML should use consistent number of spaces after hyphens" description = "YAML should use consistent number of spaces after hyphens"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase
class CheckYamlIndent(RuleBase): class CheckYamlIndent(RuleBase):
sid = "LINT0002" rid = "YML102"
description = "YAML should not contain unnecessarily empty lines" description = "YAML should not contain unnecessarily empty lines"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]

View File

@ -123,8 +123,8 @@ class Settings:
"include_filter": [], "include_filter": [],
"exclude_filter": [], "exclude_filter": [],
"warning_filter": [ "warning_filter": [
"ANSIBLE9999", "ANS999",
"ANSIBLE9998", "ANS998",
], ],
"ignore_dotfiles": True, "ignore_dotfiles": True,
"exclude_files": [], "exclude_files": [],

View File

@ -9,7 +9,7 @@ A typical rule check will look like:
{{< highlight Python "linenos=table" >}} {{< highlight Python "linenos=table" >}}
class CheckBecomeUser(RuleBase): class CheckBecomeUser(RuleBase):
sid = "ANSIBLE0015" rid = "ANS115"
description = "Become should be combined with become_user" description = "Become should be combined with become_user"
helptext = "the task has `become` enabled but `become_user` is missing" helptext = "the task has `become` enabled but `become_user` is missing"
types = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]

View File

@ -16,19 +16,19 @@ ansible:
# directory will be auto-detected and don't need to be added to this list. # directory will be auto-detected and don't need to be added to this list.
custom_modules: [] custom_modules: []
# Settings for variable formatting rule (ANSIBLE0004) # Settings for variable formatting rule (ANS104)
double-braces: double-braces:
max-spaces-inside: 1 max-spaces-inside: 1
min-spaces-inside: 1 min-spaces-inside: 1
# List of allowed literal bools (ANSIBLE0014) # List of allowed literal bools (ANS114)
literal-bools: literal-bools:
- "True" - "True"
- "False" - "False"
- "yes" - "yes"
- "no" - "no"
# List of modules that don't need to be named (ANSIBLE0006). # List of modules that don't need to be named (ANS106).
# You must specify each individual module name, globs or wildcards do not work! # You must specify each individual module name, globs or wildcards do not work!
named-task: named-task:
exclude: exclude:
@ -41,7 +41,7 @@ ansible:
- "import_role" - "import_role"
- "import_tasks" - "import_tasks"
# List of modules that are allowed to use the key=value format instead of the native YAML format (LINT0008). # List of modules that are allowed to use the key=value format instead of the native YAML format (YML108).
# You must specify each individual module name, globs or wildcards do not work! # You must specify each individual module name, globs or wildcards do not work!
native-yaml: native-yaml:
exclude: [] exclude: []
@ -77,8 +77,8 @@ rules:
# List of rule ID's that should be displayed as a warning instead of an error. By default, # List of rule ID's that should be displayed as a warning instead of an error. By default,
# no rules are marked as warnings. This list allows to degrade errors to warnings for each rule. # no rules are marked as warnings. This list allows to degrade errors to warnings for each rule.
warning_filter: warning_filter:
- "ANSIBLE9999" - "ANS999"
- "ANSIBLE9998" - "ANS998"
# All dotfiles (including hidden folders) are excluded by default. # All dotfiles (including hidden folders) are excluded by default.
# You can disable this setting and handle dotfiles by yourself with `exclude_files`. # You can disable this setting and handle dotfiles by yourself with `exclude_files`.

View File

@ -4,42 +4,42 @@ title: Included rules
Reviews are useless without some rules to check against. `ansible-later` comes with a set of built-in checks, which are explained in the following table. Reviews are useless without some rules to check against. `ansible-later` comes with a set of built-in checks, which are explained in the following table.
| Rule | ID | Description | Parameter | | Rule | ID | Description | Parameter |
| ----------------------------- | ----------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------- | | ----------------------------- | ------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------- |
| CheckYamlEmptyLines | LINT0001 | YAML should not contain unnecessarily empty lines. | {max: 1, max-start: 0, max-end: 1} | | CheckYamlEmptyLines | YML101 | YAML should not contain unnecessarily empty lines. | {max: 1, max-start: 0, max-end: 1} |
| CheckYamlIndent | LINT0002 | YAML should be correctly indented. | {spaces: 2, check-multi-line-strings: false, indent-sequences: true} | | CheckYamlIndent | YML102 | YAML should be correctly indented. | {spaces: 2, check-multi-line-strings: false, indent-sequences: true} |
| CheckYamlHyphens | LINT0003 | YAML should use consistent number of spaces after hyphens (-). | {max-spaces-after: 1} | | CheckYamlHyphens | YML103 | YAML should use consistent number of spaces after hyphens (-). | {max-spaces-after: 1} |
| CheckYamlDocumentStart | LINT0004 | YAML should contain document start marker. | {document-start: {present: true}} | | CheckYamlDocumentStart | YML104 | YAML should contain document start marker. | {document-start: {present: true}} |
| CheckYamlColons | LINT0005 | YAML should use consistent number of spaces around colons. | {colons: {max-spaces-before: 0, max-spaces-after: 1}} | | CheckYamlColons | YML105 | YAML should use consistent number of spaces around colons. | {colons: {max-spaces-before: 0, max-spaces-after: 1}} |
| CheckYamlFile | LINT0006 | Roles file should be in YAML format. | | | CheckYamlFile | YML106 | Roles file should be in YAML format. | |
| CheckYamlHasContent | LINT0007 | Files should contain useful content. | | | CheckYamlHasContent | YML107 | Files should contain useful content. | |
| CheckNativeYaml | LINT0008 | Use YAML format for tasks and handlers rather than key=value. | {native-yaml: {exclude: []}} | | CheckNativeYaml | YML108 | Use YAML format for tasks and handlers rather than key=value. | {native-yaml: {exclude: []}} |
| CheckYamlDocumentEnd | LINT0009 | YAML should contain document end marker. | {document-end: {present: true}} | | CheckYamlDocumentEnd | YML109 | YAML should contain document end marker. | {document-end: {present: true}} |
| CheckTaskSeparation | ANSIBLE0001 | Single tasks should be separated by an empty line. | | | CheckTaskSeparation | ANS101 | Single tasks should be separated by an empty line. | |
| CheckMetaMain | ANSIBLE0002 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies | | CheckMetaMain | ANS102 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies |
| CheckUniqueNamedTask | ANSIBLE0003 | Tasks and handlers must be uniquely named within a file. | | | CheckUniqueNamedTask | ANS103 | Tasks and handlers must be uniquely named within a file. | |
| CheckBraces | ANSIBLE0004 | YAML should use consistent number of spaces around variables. | {double-braces: max-spaces-inside: 1, min-spaces-inside: 1} | | CheckBraces | ANS104 | YAML should use consistent number of spaces around variables. | {double-braces: max-spaces-inside: 1, min-spaces-inside: 1} |
| CheckScmInSrc | ANSIBLE0005 | Use SCM key rather than `src: scm+url` in requirements file. | | | CheckScmInSrc | ANS105 | Use SCM key rather than `src: scm+url` in requirements file. | |
| CheckNamedTask | ANSIBLE0006 | Tasks and handlers must be named. | {named-task: {exclude: [meta, debug, block, include\_\*, import\_\*]}} | | CheckNamedTask | ANS106 | Tasks and handlers must be named. | {named-task: {exclude: [meta, debug, block, include\_\*, import\_\*]}} |
| CheckNameFormat | ANSIBLE0007 | Name of tasks and handlers must be formatted. | formats: first letter capital | | CheckNameFormat | ANS107 | Name of tasks and handlers must be formatted. | formats: first letter capital |
| CheckCommandInsteadofModule | ANSIBLE0008 | Commands should not be used in place of modules. | | | CheckCommandInsteadofModule | ANS108 | Commands should not be used in place of modules. | |
| CheckInstallUseLatest | ANSIBLE0009 | Package managers should not install with state=latest. | | | CheckInstallUseLatest | ANS109 | Package managers should not install with state=latest. | |
| CheckShellInsteadCommand | ANSIBLE0010 | Use Shell only when piping, redirecting or chaining commands. | | | CheckShellInsteadCommand | ANS110 | Use Shell only when piping, redirecting or chaining commands. | |
| CheckCommandHasChanges | ANSIBLE0011 | Commands should be idempotent and only used with some checks. | | | CheckCommandHasChanges | ANS111 | Commands should be idempotent and only used with some checks. | |
| CheckCompareToEmptyString | ANSIBLE0012 | Don't compare to "" - use `when: var` or `when: not var`. | | | CheckCompareToEmptyString | ANS112 | Don't compare to "" - use `when: var` or `when: not var`. | |
| CheckCompareToLiteralBool | ANSIBLE0013 | Don't compare to True/False - use `when: var` or `when: not var`. | | | CheckCompareToLiteralBool | ANS113 | Don't compare to True/False - use `when: var` or `when: not var`. | |
| CheckLiteralBoolFormat | ANSIBLE0014 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} | | CheckLiteralBoolFormat | ANS114 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} |
| CheckBecomeUser | ANSIBLE0015 | Become should be combined with become_user. | | | CheckBecomeUser | ANS115 | Become should be combined with become_user. | |
| CheckFilterSeparation | ANSIBLE0016 | Jinja2 filters should be separated with spaces. | | | CheckFilterSeparation | ANS116 | Jinja2 filters should be separated with spaces. | |
| CheckCommandInsteadOfArgument | ANSIBLE0017 | Commands should not be used in place of module arguments. | | | CheckCommandInsteadOfArgument | ANS117 | Commands should not be used in place of module arguments. | |
| CheckFilePermissionMissing | ANSIBLE0018 | File permissions unset or incorrect. | | | CheckFilePermissionMissing | ANS118 | File permissions unset or incorrect. | |
| CheckFilePermissionOctal | ANSIBLE0019 | Octal file permissions must contain leading zero or be a string. | | | CheckFilePermissionOctal | ANS119 | Octal file permissions must contain leading zero or be a string. | |
| CheckGitHasVersion | ANSIBLE0020 | Git checkouts should use explicit version. | | | CheckGitHasVersion | ANS120 | Git checkouts should use explicit version. | |
| CheckMetaChangeFromDefault | ANSIBLE0021 | Roles meta/main.yml default values should be changed. | | | CheckMetaChangeFromDefault | ANS121 | Roles meta/main.yml default values should be changed. | |
| CheckWhenFormat | ANSIBLE0022 | Don't use Jinja2 in `when`. | | | CheckWhenFormat | ANS122 | Don't use Jinja2 in `when`. | |
| CheckNestedJinja | ANSIBLE0023 | Don't use nested Jinja2 pattern. | | | CheckNestedJinja | ANS123 | Don't use nested Jinja2 pattern. | |
| CheckLocalAction | ANSIBLE0024 | Don't use local_action. | | | CheckLocalAction | ANS124 | Don't use local_action. | |
| CheckRelativeRolePaths | ANSIBLE0025 | Don't use a relative path in a role. | | | CheckRelativeRolePaths | ANS125 | Don't use a relative path in a role. | |
| CheckChangedInWhen | ANSIBLE0026 | Use handlers instead of `when: changed`. | | | CheckChangedInWhen | ANS126 | Use handlers instead of `when: changed`. | |
| CheckChangedInWhen | ANSIBLE0027 | Deprecated bare variables in loops must not be used. | | | CheckChangedInWhen | ANS127 | Deprecated bare variables in loops must not be used. | |
| CheckDeprecated | ANSIBLE9999 | Deprecated features of `ansible-later` should not be used. | | | CheckDeprecated | ANS999 | Deprecated features of `ansible-later` should not be used. | |