diff --git a/ansiblelater/rules/CheckLiteralBoolFormat.py b/ansiblelater/rules/CheckLiteralBoolFormat.py index 70013b4..71e9ebb 100644 --- a/ansiblelater/rules/CheckLiteralBoolFormat.py +++ b/ansiblelater/rules/CheckLiteralBoolFormat.py @@ -6,19 +6,21 @@ from ansiblelater.standard import StandardBase class CheckLiteralBoolFormat(StandardBase): sid = "ANSIBLE0014" - description = "Literal bools should start with a capital letter" - helptext = "literal bools should be written as `True/False` or `yes/no`" + description = "Literal bools should be consistent" + helptext = "literal bools should be written as `{bools}`" version = "0.1" types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) - uppercase_bool = re.compile(r"([=!]=|:)\s*(true|false|TRUE|FALSE|Yes|No|YES|NO)\s*$") + litera_bools = re.compile(r"(?:[=!]=|:)\s*(true|false|yes|no|on|off)\s*$", re.IGNORECASE) + allowed = settings["ansible"]["literal-bools"] if not errors: for i, line in yamllines: - if uppercase_bool.findall(line): - errors.append(self.Error(i, self.helptext)) + matches = litera_bools.findall(line) + if any(m not in allowed for m in matches): + errors.append(self.Error(i, self.helptext.format(bools=", ".join(allowed)))) return self.Result(candidate.path, errors) diff --git a/ansiblelater/settings.py b/ansiblelater/settings.py index fcf57f7..e3266c5 100644 --- a/ansiblelater/settings.py +++ b/ansiblelater/settings.py @@ -134,6 +134,7 @@ class Settings(object): "min-spaces-inside": 1, "max-spaces-inside": 1, }, + "literal-bools": ["True", "False", "yes", "no"], }, "yamllint": { "empty-lines": { diff --git a/docs/content/configuration/defaults.md b/docs/content/configuration/defaults.md index 6897254..ff1b1d8 100644 --- a/docs/content/configuration/defaults.md +++ b/docs/content/configuration/defaults.md @@ -19,6 +19,13 @@ ansible: max-spaces-inside: 1 min-spaces-inside: 1 + # List of allowed literal bools (ANSIBLE0014) + literal-bools: + - "True" + - "False" + - "yes" + - "no" + # Global logging configuration # If you would like to force colored output (e.g. non-tty) # set environment variable `PY_COLORS=1` diff --git a/docs/content/included_rules/_index.md b/docs/content/included_rules/_index.md index 1731686..85d55d5 100644 --- a/docs/content/included_rules/_index.md +++ b/docs/content/included_rules/_index.md @@ -18,7 +18,7 @@ Reviews are nothing without some rules or standards against which to review. ans | CheckLineBetweenTasks | 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. | | +| 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. | excludes: meta, debug, include\_\*, import\_\*, block | | CheckNameFormat | ANSIBLE0007 | Name of tasks and handlers must be formatted. | formats: first letter capital | @@ -28,7 +28,7 @@ Reviews are nothing without some rules or standards against which to review. ans | 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 written as `True/False` or `yes/no`. | forbidden values are `true false TRUE FALSE Yes No YES NO` | +| 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. | |