mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-24 13:50:41 +00:00
feat: add config option to set allowed literal bools (#225)
This commit is contained in:
parent
0b625d3bb3
commit
c5f4f2212f
@ -6,19 +6,21 @@ from ansiblelater.standard import StandardBase
|
|||||||
class CheckLiteralBoolFormat(StandardBase):
|
class CheckLiteralBoolFormat(StandardBase):
|
||||||
|
|
||||||
sid = "ANSIBLE0014"
|
sid = "ANSIBLE0014"
|
||||||
description = "Literal bools should start with a capital letter"
|
description = "Literal bools should be consistent"
|
||||||
helptext = "literal bools should be written as `True/False` or `yes/no`"
|
helptext = "literal bools should be written as `{bools}`"
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
|
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
|
||||||
|
|
||||||
def check(self, candidate, settings):
|
def check(self, candidate, settings):
|
||||||
yamllines, errors = self.get_normalized_yaml(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:
|
if not errors:
|
||||||
for i, line in yamllines:
|
for i, line in yamllines:
|
||||||
if uppercase_bool.findall(line):
|
matches = litera_bools.findall(line)
|
||||||
errors.append(self.Error(i, self.helptext))
|
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)
|
return self.Result(candidate.path, errors)
|
||||||
|
@ -134,6 +134,7 @@ class Settings(object):
|
|||||||
"min-spaces-inside": 1,
|
"min-spaces-inside": 1,
|
||||||
"max-spaces-inside": 1,
|
"max-spaces-inside": 1,
|
||||||
},
|
},
|
||||||
|
"literal-bools": ["True", "False", "yes", "no"],
|
||||||
},
|
},
|
||||||
"yamllint": {
|
"yamllint": {
|
||||||
"empty-lines": {
|
"empty-lines": {
|
||||||
|
@ -19,6 +19,13 @@ ansible:
|
|||||||
max-spaces-inside: 1
|
max-spaces-inside: 1
|
||||||
min-spaces-inside: 1
|
min-spaces-inside: 1
|
||||||
|
|
||||||
|
# List of allowed literal bools (ANSIBLE0014)
|
||||||
|
literal-bools:
|
||||||
|
- "True"
|
||||||
|
- "False"
|
||||||
|
- "yes"
|
||||||
|
- "no"
|
||||||
|
|
||||||
# Global logging configuration
|
# Global logging configuration
|
||||||
# If you would like to force colored output (e.g. non-tty)
|
# If you would like to force colored output (e.g. non-tty)
|
||||||
# set environment variable `PY_COLORS=1`
|
# set environment variable `PY_COLORS=1`
|
||||||
|
@ -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. | |
|
| 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 |
|
| 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. | |
|
| 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. | |
|
| 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 |
|
| 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 |
|
| 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. | |
|
| 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`. | |
|
| 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`. | |
|
| 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. | |
|
| CheckBecomeUser | ANSIBLE0015 | Become should be combined with become_user. | |
|
||||||
| CheckFilterSeparation | ANSIBLE0016 | Jinja2 filters should be separated with spaces. | |
|
| CheckFilterSeparation | ANSIBLE0016 | Jinja2 filters should be separated with spaces. | |
|
||||||
| CheckCommandInsteadOfArgument | ANSIBLE0017 | Commands should not be used in place of module arguments. | |
|
| CheckCommandInsteadOfArgument | ANSIBLE0017 | Commands should not be used in place of module arguments. | |
|
||||||
|
Loading…
Reference in New Issue
Block a user