diff --git a/.dictionary b/.dictionary index 46d753b..0d9b2b6 100644 --- a/.dictionary +++ b/.dictionary @@ -18,8 +18,8 @@ HostVars Rolesfile Makefile Jinja2 -ANSIBLE([0-9]{4}) -LINT([0-9]{4}) +ANS([0-9]{3}) +YML([0-9]{3}) SCM bools Check[A-Z].+ diff --git a/ansiblelater/candidate.py b/ansiblelater/candidate.py index 1c0ecd2..0fd8bd2 100644 --- a/ansiblelater/candidate.py +++ b/ansiblelater/candidate.py @@ -41,10 +41,10 @@ class Candidate: excludes = self.config["rules"]["exclude_filter"] 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: - 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) return target_rules @@ -60,7 +60,7 @@ class Candidate: result = rule.check(self, self.config) 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 labels = { @@ -70,23 +70,23 @@ class Candidate: "passed": True, } - if rule.sid and rule.sid.strip(): - labels["sid"] = rule.sid + if rule.rid and rule.rid.strip(): + labels["rid"] = rule.rid for err in result.errors: err_labels = copy.copy(labels) err_labels["passed"] = False - sid = self._format_id(rule.sid) + rid = self._format_id(rule.rid) path = self.path description = rule.description if isinstance(err, RuleBase.Error): 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)) errors = errors + 1 else: @@ -138,9 +138,9 @@ class Candidate: return None def _format_id(self, rule_id): - sid = rule_id.strip() - if sid: - rule_id = f"[{sid}] " + rid = rule_id.strip() + if rid: + rule_id = f"[{rid}] " return rule_id diff --git a/ansiblelater/rule.py b/ansiblelater/rule.py index 4bd6e71..c275e57 100644 --- a/ansiblelater/rule.py +++ b/ansiblelater/rule.py @@ -30,7 +30,7 @@ from ansiblelater.utils.yamlhelper import ( class RuleMeta(type): def __call__(cls, *args): mcls = type.__call__(cls, *args) - mcls.sid = cls.sid + mcls.rid = cls.rid mcls.description = getattr(cls, "description", "__unknown__") mcls.helptext = getattr(cls, "helptext", "") mcls.types = getattr(cls, "types", []) @@ -46,7 +46,7 @@ class RuleBase(metaclass=RuleExtendedMeta): @property @abstractmethod - def sid(self): + def rid(self): pass @abstractmethod @@ -334,10 +334,10 @@ class RulesLoader: ) def validate(self): - normalized_std = list(toolz.remove(lambda x: x.sid == "", self.rules)) - unique_std = len(list(toolz.unique(normalized_std, key=lambda x: x.sid))) - all_std = len(normalized_std) - if all_std != unique_std: + normalize_rule = list(toolz.remove(lambda x: x.rid == "", self.rules)) + unique_rule = len(list(toolz.unique(normalize_rule, key=lambda x: x.rid))) + all_rules = len(normalize_rule) + if all_rules != unique_rule: sysexit_with_message( "Found duplicate tags in rules definition. Please use unique tags only." ) diff --git a/ansiblelater/rules/CheckBecomeUser.py b/ansiblelater/rules/CheckBecomeUser.py index 89703c9..39977ab 100644 --- a/ansiblelater/rules/CheckBecomeUser.py +++ b/ansiblelater/rules/CheckBecomeUser.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckBecomeUser(RuleBase): - sid = "ANSIBLE0015" + rid = "ANS115" description = "Become should be combined with become_user" helptext = "the task has `become` enabled but `become_user` is missing" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckBracesSpaces.py b/ansiblelater/rules/CheckBracesSpaces.py index 58f56d6..9f3e921 100644 --- a/ansiblelater/rules/CheckBracesSpaces.py +++ b/ansiblelater/rules/CheckBracesSpaces.py @@ -5,7 +5,7 @@ from ansiblelater.utils import count_spaces class CheckBracesSpaces(RuleBase): - sid = "ANSIBLE0004" + rid = "ANS104" description = "YAML should use consistent number of spaces around variables" helptext = "no suitable numbers of spaces (min: {min} max: {max})" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckChangedInWhen.py b/ansiblelater/rules/CheckChangedInWhen.py index 36bf9d2..a604df0 100644 --- a/ansiblelater/rules/CheckChangedInWhen.py +++ b/ansiblelater/rules/CheckChangedInWhen.py @@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase class CheckChangedInWhen(RuleBase): - sid = "ANSIBLE0026" + rid = "ANS126" description = "Use handlers instead of `when: changed`" helptext = "tasks using `when: result.changed` setting are effectively acting as a handler" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckCommandHasChanges.py b/ansiblelater/rules/CheckCommandHasChanges.py index 21a1f18..a055cb8 100644 --- a/ansiblelater/rules/CheckCommandHasChanges.py +++ b/ansiblelater/rules/CheckCommandHasChanges.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckCommandHasChanges(RuleBase): - sid = "ANSIBLE0011" + rid = "ANS111" description = "Commands should be idempotent" helptext = ( "commands should only read while using `changed_when` or try to be " diff --git a/ansiblelater/rules/CheckCommandInsteadOfArgument.py b/ansiblelater/rules/CheckCommandInsteadOfArgument.py index 756548b..c7b099e 100644 --- a/ansiblelater/rules/CheckCommandInsteadOfArgument.py +++ b/ansiblelater/rules/CheckCommandInsteadOfArgument.py @@ -24,7 +24,7 @@ from ansiblelater.rule import RuleBase class CheckCommandInsteadOfArgument(RuleBase): - sid = "ANSIBLE0017" + rid = "ANS117" description = "Commands should not be used in place of module arguments" helptext = "{exec} used in place of file modules argument {arg}" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckCommandInsteadOfModule.py b/ansiblelater/rules/CheckCommandInsteadOfModule.py index e031985..3ea5f2a 100644 --- a/ansiblelater/rules/CheckCommandInsteadOfModule.py +++ b/ansiblelater/rules/CheckCommandInsteadOfModule.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckCommandInsteadOfModule(RuleBase): - sid = "ANSIBLE0008" + rid = "ANS108" description = "Commands should not be used in place of modules" helptext = "{exec} command used in place of {module} module" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckCompareToEmptyString.py b/ansiblelater/rules/CheckCompareToEmptyString.py index 00e1e01..1a23547 100644 --- a/ansiblelater/rules/CheckCompareToEmptyString.py +++ b/ansiblelater/rules/CheckCompareToEmptyString.py @@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase class CheckCompareToEmptyString(RuleBase): - sid = "ANSIBLE0012" + rid = "ANS112" description = 'Don\'t compare to empty string ""' helptext = "use `when: var` rather than `when: var !=` (or conversely `when: not var`)" types = ["playbook", "task", "handler", "template"] diff --git a/ansiblelater/rules/CheckCompareToLiteralBool.py b/ansiblelater/rules/CheckCompareToLiteralBool.py index 9824c9c..c884c7c 100644 --- a/ansiblelater/rules/CheckCompareToLiteralBool.py +++ b/ansiblelater/rules/CheckCompareToLiteralBool.py @@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase class CheckCompareToLiteralBool(RuleBase): - sid = "ANSIBLE0013" + rid = "ANS113" description = "Don't compare to True or False" helptext = "use `when: var` rather than `when: var == True` (or conversely `when: not var`)" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckDeprecated.py b/ansiblelater/rules/CheckDeprecated.py index 6ab1770..67bc0b7 100644 --- a/ansiblelater/rules/CheckDeprecated.py +++ b/ansiblelater/rules/CheckDeprecated.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckDeprecated(RuleBase): - sid = "ANSIBLE9999" + rid = "ANS999" description = "Deprecated features should not be used" helptext = "`{old}` is deprecated and should not be used anymore. Use `{new}` instead." types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckDeprecatedBareVars.py b/ansiblelater/rules/CheckDeprecatedBareVars.py index 7a66f7f..2a29cf9 100644 --- a/ansiblelater/rules/CheckDeprecatedBareVars.py +++ b/ansiblelater/rules/CheckDeprecatedBareVars.py @@ -25,7 +25,7 @@ from ansiblelater.utils import has_glob, has_jinja class CheckDeprecatedBareVars(RuleBase): - sid = "ANSIBLE0027" + rid = "ANS127" description = "Deprecated bare variables in loops must not be used" helptext = ( "bare var '{barevar}' in '{loop_type}' must use full var syntax '{{{{ {barevar} }}}}' " diff --git a/ansiblelater/rules/CheckFilePermissionMissing.py b/ansiblelater/rules/CheckFilePermissionMissing.py index 3ca1856..a665f48 100644 --- a/ansiblelater/rules/CheckFilePermissionMissing.py +++ b/ansiblelater/rules/CheckFilePermissionMissing.py @@ -23,7 +23,7 @@ from ansiblelater.rule import RuleBase class CheckFilePermissionMissing(RuleBase): - sid = "ANSIBLE0018" + rid = "ANS118" description = "File permissions unset or incorrect" helptext = ( "`mode` parameter should set permissions explicitly (e.g. `mode: 0644`) " diff --git a/ansiblelater/rules/CheckFilePermissionOctal.py b/ansiblelater/rules/CheckFilePermissionOctal.py index 18d3dcd..91956ab 100644 --- a/ansiblelater/rules/CheckFilePermissionOctal.py +++ b/ansiblelater/rules/CheckFilePermissionOctal.py @@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase class CheckFilePermissionOctal(RuleBase): - sid = "ANSIBLE0019" + rid = "ANS119" description = "Octal file permissions must contain leading zero or be a string" helptext = "numeric file permissions without leading zero can behave in unexpected ways" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckFilterSeparation.py b/ansiblelater/rules/CheckFilterSeparation.py index 64efac2..affa197 100644 --- a/ansiblelater/rules/CheckFilterSeparation.py +++ b/ansiblelater/rules/CheckFilterSeparation.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckFilterSeparation(RuleBase): - sid = "ANSIBLE0016" + rid = "ANS116" description = "Jinja2 filters should be separated with spaces" helptext = "no suitable numbers of spaces (required: 1)" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] diff --git a/ansiblelater/rules/CheckGitHasVersion.py b/ansiblelater/rules/CheckGitHasVersion.py index 5bd9f5a..8044306 100644 --- a/ansiblelater/rules/CheckGitHasVersion.py +++ b/ansiblelater/rules/CheckGitHasVersion.py @@ -22,7 +22,7 @@ from ansiblelater.rule import RuleBase class CheckGitHasVersion(RuleBase): - sid = "ANSIBLE0020" + rid = "ANS120" description = "Git checkouts should use explicit version" helptext = "git checkouts should point to an explicit commit or tag, not `latest`" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckInstallUseLatest.py b/ansiblelater/rules/CheckInstallUseLatest.py index 200fd89..95e3667 100644 --- a/ansiblelater/rules/CheckInstallUseLatest.py +++ b/ansiblelater/rules/CheckInstallUseLatest.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckInstallUseLatest(RuleBase): - sid = "ANSIBLE0009" + rid = "ANS109" description = "Package installs should use present, not latest" helptext = "package installs should use `state=present` with or without a version" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckLiteralBoolFormat.py b/ansiblelater/rules/CheckLiteralBoolFormat.py index 69530e8..e79e613 100644 --- a/ansiblelater/rules/CheckLiteralBoolFormat.py +++ b/ansiblelater/rules/CheckLiteralBoolFormat.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckLiteralBoolFormat(RuleBase): - sid = "ANSIBLE0014" + rid = "ANS114" description = "Literal bools should be consistent" helptext = "literal bools should be written as `{bools}`" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] diff --git a/ansiblelater/rules/CheckLocalAction.py b/ansiblelater/rules/CheckLocalAction.py index 1234ed2..20c4bd5 100644 --- a/ansiblelater/rules/CheckLocalAction.py +++ b/ansiblelater/rules/CheckLocalAction.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckLocalAction(RuleBase): - sid = "ANSIBLE0024" + rid = "ANS124" description = "Don't use local_action" helptext = "`delegate_to: localhost` should be used instead of `local_action`" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckMetaChangeFromDefault.py b/ansiblelater/rules/CheckMetaChangeFromDefault.py index 776042e..f92259e 100644 --- a/ansiblelater/rules/CheckMetaChangeFromDefault.py +++ b/ansiblelater/rules/CheckMetaChangeFromDefault.py @@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase class CheckMetaChangeFromDefault(RuleBase): - sid = "ANSIBLE0021" + rid = "ANS121" description = "Roles meta/main.yml default values should be changed" helptext = "meta/main.yml default values should be changed for: `{field}`" types = ["meta"] diff --git a/ansiblelater/rules/CheckMetaMain.py b/ansiblelater/rules/CheckMetaMain.py index 21c8b76..08b3912 100644 --- a/ansiblelater/rules/CheckMetaMain.py +++ b/ansiblelater/rules/CheckMetaMain.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckMetaMain(RuleBase): - sid = "ANSIBLE0002" + rid = "ANS102" description = "Roles must contain suitable meta/main.yml" helptext = "file should contain `{key}` key" types = ["meta"] diff --git a/ansiblelater/rules/CheckNameFormat.py b/ansiblelater/rules/CheckNameFormat.py index 5ac930e..e6d18f3 100644 --- a/ansiblelater/rules/CheckNameFormat.py +++ b/ansiblelater/rules/CheckNameFormat.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckNameFormat(RuleBase): - sid = "ANSIBLE0007" + rid = "ANS107" description = "Name of tasks and handlers must be formatted" helptext = "name `{name}` should start with uppercase" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckNamedTask.py b/ansiblelater/rules/CheckNamedTask.py index dff26a3..aefc5f1 100644 --- a/ansiblelater/rules/CheckNamedTask.py +++ b/ansiblelater/rules/CheckNamedTask.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckNamedTask(RuleBase): - sid = "ANSIBLE0006" + rid = "ANS106" description = "Tasks and handlers must be named" helptext = "module `{module}` used without or empty `name` attribute" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckNativeYaml.py b/ansiblelater/rules/CheckNativeYaml.py index df6760d..792f352 100644 --- a/ansiblelater/rules/CheckNativeYaml.py +++ b/ansiblelater/rules/CheckNativeYaml.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckNativeYaml(RuleBase): - sid = "LINT0008" + rid = "YML108" 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" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckNestedJinja.py b/ansiblelater/rules/CheckNestedJinja.py index ff6616c..3714a51 100644 --- a/ansiblelater/rules/CheckNestedJinja.py +++ b/ansiblelater/rules/CheckNestedJinja.py @@ -25,7 +25,7 @@ from ansiblelater.rule import RuleBase class CheckNestedJinja(RuleBase): - sid = "ANSIBLE0023" + rid = "ANS123" description = "Don't use nested Jinja2 pattern" helptext = ( "there should not be any nested jinja pattern " diff --git a/ansiblelater/rules/CheckRelativeRolePaths.py b/ansiblelater/rules/CheckRelativeRolePaths.py index 6682347..a6ac35b 100644 --- a/ansiblelater/rules/CheckRelativeRolePaths.py +++ b/ansiblelater/rules/CheckRelativeRolePaths.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckRelativeRolePaths(RuleBase): - sid = "ANSIBLE0025" + rid = "ANS125" description = "Don't use a relative path in a role" helptext = "`copy` and `template` modules don't need relative path for `src`" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckScmInSrc.py b/ansiblelater/rules/CheckScmInSrc.py index b1b666c..1e367ae 100644 --- a/ansiblelater/rules/CheckScmInSrc.py +++ b/ansiblelater/rules/CheckScmInSrc.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckScmInSrc(RuleBase): - sid = "ANSIBLE0005" + rid = "ANS105" description = "Use `scm:` key rather than `src: scm+url`" helptext = "usage of `src: scm+url` not recommended" types = ["rolesfile"] diff --git a/ansiblelater/rules/CheckShellInsteadCommand.py b/ansiblelater/rules/CheckShellInsteadCommand.py index 4f26a83..da50dee 100644 --- a/ansiblelater/rules/CheckShellInsteadCommand.py +++ b/ansiblelater/rules/CheckShellInsteadCommand.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckShellInsteadCommand(RuleBase): - sid = "ANSIBLE0010" + rid = "ANS110" description = "Shell should only be used when essential" helptext = "shell should only be used when piping, redirecting or chaining commands" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckTaskSeparation.py b/ansiblelater/rules/CheckTaskSeparation.py index 2d60479..d8ae2d4 100644 --- a/ansiblelater/rules/CheckTaskSeparation.py +++ b/ansiblelater/rules/CheckTaskSeparation.py @@ -5,7 +5,7 @@ from ansiblelater.rule import RuleBase class CheckTaskSeparation(RuleBase): - sid = "ANSIBLE0001" + rid = "ANS101" description = "Single tasks should be separated by empty line" helptext = "missing task separation (required: 1 empty line)" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckUniqueNamedTask.py b/ansiblelater/rules/CheckUniqueNamedTask.py index 68f4dec..2d1d26a 100644 --- a/ansiblelater/rules/CheckUniqueNamedTask.py +++ b/ansiblelater/rules/CheckUniqueNamedTask.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckUniqueNamedTask(RuleBase): - sid = "ANSIBLE0003" + rid = "ANS103" description = "Tasks and handlers must be uniquely named within a single file" helptext = "name `{name}` appears multiple times" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckWhenFormat.py b/ansiblelater/rules/CheckWhenFormat.py index 15d8d24..2d1f2fc 100644 --- a/ansiblelater/rules/CheckWhenFormat.py +++ b/ansiblelater/rules/CheckWhenFormat.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckWhenFormat(RuleBase): - sid = "ANSIBLE0022" + rid = "ANS122" description = "Don't use Jinja2 in when" helptext = ( "`when` is a raw Jinja2 expression, redundant {{ }} " "should be removed from variable(s)" diff --git a/ansiblelater/rules/CheckYamlColons.py b/ansiblelater/rules/CheckYamlColons.py index c32cc68..908c188 100644 --- a/ansiblelater/rules/CheckYamlColons.py +++ b/ansiblelater/rules/CheckYamlColons.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlColons(RuleBase): - sid = "LINT0005" + rid = "YML105" description = "YAML should use consistent number of spaces around colons" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckYamlDocumentEnd.py b/ansiblelater/rules/CheckYamlDocumentEnd.py index e333d51..4e71535 100644 --- a/ansiblelater/rules/CheckYamlDocumentEnd.py +++ b/ansiblelater/rules/CheckYamlDocumentEnd.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlDocumentEnd(RuleBase): - sid = "LINT0009" + rid = "YML109" description = "YAML should contain document end marker" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckYamlDocumentStart.py b/ansiblelater/rules/CheckYamlDocumentStart.py index d795a81..c7503d7 100644 --- a/ansiblelater/rules/CheckYamlDocumentStart.py +++ b/ansiblelater/rules/CheckYamlDocumentStart.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlDocumentStart(RuleBase): - sid = "LINT0004" + rid = "YML104" description = "YAML should contain document start marker" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckYamlEmptyLines.py b/ansiblelater/rules/CheckYamlEmptyLines.py index dc8376c..9788b22 100644 --- a/ansiblelater/rules/CheckYamlEmptyLines.py +++ b/ansiblelater/rules/CheckYamlEmptyLines.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlEmptyLines(RuleBase): - sid = "LINT0001" + rid = "YML101" description = "YAML should not contain unnecessarily empty lines" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckYamlFile.py b/ansiblelater/rules/CheckYamlFile.py index c26cf90..aa4a506 100644 --- a/ansiblelater/rules/CheckYamlFile.py +++ b/ansiblelater/rules/CheckYamlFile.py @@ -4,7 +4,7 @@ from ansiblelater.rule import RuleBase class CheckYamlFile(RuleBase): - sid = "LINT0006" + rid = "YML106" description = "Roles file should be in yaml format" helptext = "file does not have a .yml extension" types = ["playbook", "task", "handler"] diff --git a/ansiblelater/rules/CheckYamlHasContent.py b/ansiblelater/rules/CheckYamlHasContent.py index e0c0126..2003350 100644 --- a/ansiblelater/rules/CheckYamlHasContent.py +++ b/ansiblelater/rules/CheckYamlHasContent.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlHasContent(RuleBase): - sid = "LINT0007" + rid = "YML107" description = "Files should contain useful content" helptext = "the file appears to have no useful content" types = ["playbook", "task", "handler", "rolevars", "defaults", "meta"] diff --git a/ansiblelater/rules/CheckYamlHyphens.py b/ansiblelater/rules/CheckYamlHyphens.py index f45c3a3..b1e77e8 100644 --- a/ansiblelater/rules/CheckYamlHyphens.py +++ b/ansiblelater/rules/CheckYamlHyphens.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlHyphens(RuleBase): - sid = "LINT0003" + rid = "YML103" description = "YAML should use consistent number of spaces after hyphens" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/rules/CheckYamlIndent.py b/ansiblelater/rules/CheckYamlIndent.py index 8f74b57..29e6fa2 100644 --- a/ansiblelater/rules/CheckYamlIndent.py +++ b/ansiblelater/rules/CheckYamlIndent.py @@ -2,7 +2,7 @@ from ansiblelater.rule import RuleBase class CheckYamlIndent(RuleBase): - sid = "LINT0002" + rid = "YML102" description = "YAML should not contain unnecessarily empty lines" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] diff --git a/ansiblelater/settings.py b/ansiblelater/settings.py index 530b747..64cff2c 100644 --- a/ansiblelater/settings.py +++ b/ansiblelater/settings.py @@ -123,8 +123,8 @@ class Settings: "include_filter": [], "exclude_filter": [], "warning_filter": [ - "ANSIBLE9999", - "ANSIBLE9998", + "ANS999", + "ANS998", ], "ignore_dotfiles": True, "exclude_files": [], diff --git a/docs/content/build_rules/rule.md b/docs/content/build_rules/rule.md index 8b224ea..672105f 100644 --- a/docs/content/build_rules/rule.md +++ b/docs/content/build_rules/rule.md @@ -9,7 +9,7 @@ A typical rule check will look like: {{< highlight Python "linenos=table" >}} class CheckBecomeUser(RuleBase): - sid = "ANSIBLE0015" + rid = "ANS115" description = "Become should be combined with become_user" helptext = "the task has `become` enabled but `become_user` is missing" types = ["playbook", "task", "handler"] diff --git a/docs/content/configuration/defaults.md b/docs/content/configuration/defaults.md index da6372a..180209f 100644 --- a/docs/content/configuration/defaults.md +++ b/docs/content/configuration/defaults.md @@ -16,19 +16,19 @@ ansible: # directory will be auto-detected and don't need to be added to this list. custom_modules: [] - # Settings for variable formatting rule (ANSIBLE0004) + # Settings for variable formatting rule (ANS104) double-braces: max-spaces-inside: 1 min-spaces-inside: 1 - # List of allowed literal bools (ANSIBLE0014) + # List of allowed literal bools (ANS114) literal-bools: - "True" - "False" - "yes" - "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! named-task: exclude: @@ -41,7 +41,7 @@ ansible: - "import_role" - "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! native-yaml: exclude: [] @@ -77,8 +77,8 @@ rules: # 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. warning_filter: - - "ANSIBLE9999" - - "ANSIBLE9998" + - "ANS999" + - "ANS998" # All dotfiles (including hidden folders) are excluded by default. # You can disable this setting and handle dotfiles by yourself with `exclude_files`. diff --git a/docs/content/included_rules/_index.md b/docs/content/included_rules/_index.md index b8c32aa..0fc6c04 100644 --- a/docs/content/included_rules/_index.md +++ b/docs/content/included_rules/_index.md @@ -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. -| Rule | ID | Description | Parameter | -| ----------------------------- | ----------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------- | -| CheckYamlEmptyLines | LINT0001 | 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} | -| CheckYamlHyphens | LINT0003 | 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}} | -| CheckYamlColons | LINT0005 | 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. | | -| CheckYamlHasContent | LINT0007 | Files should contain useful content. | | -| CheckNativeYaml | LINT0008 | 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}} | -| CheckTaskSeparation | ANSIBLE0001 | 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 | -| CheckUniqueNamedTask | ANSIBLE0003 | 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} | -| CheckScmInSrc | ANSIBLE0005 | 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\_\*]}} | -| CheckNameFormat | ANSIBLE0007 | Name of tasks and handlers must be formatted. | formats: first letter capital | -| CheckCommandInsteadofModule | ANSIBLE0008 | Commands should not be used in place of modules. | | -| CheckInstallUseLatest | ANSIBLE0009 | Package managers should not install with state=latest. | | -| CheckShellInsteadCommand | ANSIBLE0010 | Use Shell only when piping, redirecting or chaining commands. | | -| CheckCommandHasChanges | ANSIBLE0011 | Commands should be idempotent and only used with some checks. | | -| CheckCompareToEmptyString | ANSIBLE0012 | 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`. | | -| CheckLiteralBoolFormat | ANSIBLE0014 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} | -| CheckBecomeUser | ANSIBLE0015 | Become should be combined with become_user. | | -| CheckFilterSeparation | ANSIBLE0016 | Jinja2 filters should be separated with spaces. | | -| CheckCommandInsteadOfArgument | ANSIBLE0017 | Commands should not be used in place of module arguments. | | -| CheckFilePermissionMissing | ANSIBLE0018 | File permissions unset or incorrect. | | -| CheckFilePermissionOctal | ANSIBLE0019 | Octal file permissions must contain leading zero or be a string. | | -| CheckGitHasVersion | ANSIBLE0020 | Git checkouts should use explicit version. | | -| CheckMetaChangeFromDefault | ANSIBLE0021 | Roles meta/main.yml default values should be changed. | | -| CheckWhenFormat | ANSIBLE0022 | Don't use Jinja2 in `when`. | | -| CheckNestedJinja | ANSIBLE0023 | Don't use nested Jinja2 pattern. | | -| CheckLocalAction | ANSIBLE0024 | Don't use local_action. | | -| CheckRelativeRolePaths | ANSIBLE0025 | Don't use a relative path in a role. | | -| CheckChangedInWhen | ANSIBLE0026 | Use handlers instead of `when: changed`. | | -| CheckChangedInWhen | ANSIBLE0027 | Deprecated bare variables in loops must not be used. | | -| CheckDeprecated | ANSIBLE9999 | Deprecated features of `ansible-later` should not be used. | | +| Rule | ID | Description | Parameter | +| ----------------------------- | ------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------- | +| CheckYamlEmptyLines | YML101 | YAML should not contain unnecessarily empty lines. | {max: 1, max-start: 0, max-end: 1} | +| CheckYamlIndent | YML102 | YAML should be correctly indented. | {spaces: 2, check-multi-line-strings: false, indent-sequences: true} | +| CheckYamlHyphens | YML103 | YAML should use consistent number of spaces after hyphens (-). | {max-spaces-after: 1} | +| CheckYamlDocumentStart | YML104 | YAML should contain document start marker. | {document-start: {present: true}} | +| CheckYamlColons | YML105 | YAML should use consistent number of spaces around colons. | {colons: {max-spaces-before: 0, max-spaces-after: 1}} | +| CheckYamlFile | YML106 | Roles file should be in YAML format. | | +| CheckYamlHasContent | YML107 | Files should contain useful content. | | +| CheckNativeYaml | YML108 | Use YAML format for tasks and handlers rather than key=value. | {native-yaml: {exclude: []}} | +| CheckYamlDocumentEnd | YML109 | YAML should contain document end marker. | {document-end: {present: true}} | +| CheckTaskSeparation | ANS101 | Single tasks should be separated by an empty line. | | +| CheckMetaMain | ANS102 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies | +| CheckUniqueNamedTask | ANS103 | Tasks and handlers must be uniquely named within a file. | | +| CheckBraces | ANS104 | YAML should use consistent number of spaces around variables. | {double-braces: max-spaces-inside: 1, min-spaces-inside: 1} | +| CheckScmInSrc | ANS105 | Use SCM key rather than `src: scm+url` in requirements file. | | +| CheckNamedTask | ANS106 | Tasks and handlers must be named. | {named-task: {exclude: [meta, debug, block, include\_\*, import\_\*]}} | +| CheckNameFormat | ANS107 | Name of tasks and handlers must be formatted. | formats: first letter capital | +| CheckCommandInsteadofModule | ANS108 | Commands should not be used in place of modules. | | +| CheckInstallUseLatest | ANS109 | Package managers should not install with state=latest. | | +| CheckShellInsteadCommand | ANS110 | Use Shell only when piping, redirecting or chaining commands. | | +| CheckCommandHasChanges | ANS111 | Commands should be idempotent and only used with some checks. | | +| CheckCompareToEmptyString | ANS112 | Don't compare to "" - use `when: var` or `when: not var`. | | +| CheckCompareToLiteralBool | ANS113 | Don't compare to True/False - use `when: var` or `when: not var`. | | +| CheckLiteralBoolFormat | ANS114 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} | +| CheckBecomeUser | ANS115 | Become should be combined with become_user. | | +| CheckFilterSeparation | ANS116 | Jinja2 filters should be separated with spaces. | | +| CheckCommandInsteadOfArgument | ANS117 | Commands should not be used in place of module arguments. | | +| CheckFilePermissionMissing | ANS118 | File permissions unset or incorrect. | | +| CheckFilePermissionOctal | ANS119 | Octal file permissions must contain leading zero or be a string. | | +| CheckGitHasVersion | ANS120 | Git checkouts should use explicit version. | | +| CheckMetaChangeFromDefault | ANS121 | Roles meta/main.yml default values should be changed. | | +| CheckWhenFormat | ANS122 | Don't use Jinja2 in `when`. | | +| CheckNestedJinja | ANS123 | Don't use nested Jinja2 pattern. | | +| CheckLocalAction | ANS124 | Don't use local_action. | | +| CheckRelativeRolePaths | ANS125 | Don't use a relative path in a role. | | +| CheckChangedInWhen | ANS126 | Use handlers instead of `when: changed`. | | +| CheckChangedInWhen | ANS127 | Deprecated bare variables in loops must not be used. | | +| CheckDeprecated | ANS999 | Deprecated features of `ansible-later` should not be used. | |