feat: add rule CheckYamlOctalValues (#758)

This commit is contained in:
Robert Kaussow 2024-01-27 20:31:15 +01:00 committed by GitHub
parent 7b44647bec
commit da5d3c21c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 39 deletions

View File

@ -0,0 +1,13 @@
from ansiblelater.rule import RuleBase
class CheckYamlOctalValues(RuleBase):
rid = "YML110"
description = "YAML should not use forbidden implicit or explicit octal value"
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
def check(self, candidate, settings):
options = f"rules: {{octal-values: {settings['yamllint']['octal-values']}}}"
errors = self.run_yamllint(candidate, options)
return self.Result(candidate.path, errors)

View File

@ -180,6 +180,10 @@ class Settings:
"max-spaces-before": 0, "max-spaces-before": 0,
"max-spaces-after": 1, "max-spaces-after": 1,
}, },
"octal-values": {
"forbid-implicit-octal": True,
"forbid-explicit-octal": True,
},
}, },
} }

View File

@ -4,42 +4,43 @@ 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 | YML101 | 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 | YML102 | 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 | YML103 | 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 | YML104 | YAML should contain document start marker. | {document-start: {present: true}} | | 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}} | | 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. | | | CheckYamlFile | YML106 | Roles file should be in YAML format. | |
| CheckYamlHasContent | YML107 | Files should contain useful content. | | | CheckYamlHasContent | YML107 | Files should contain useful content. | |
| CheckNativeYaml | YML108 | 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 | YML109 | YAML should contain document end marker. | {document-end: {present: true}} | | CheckYamlDocumentEnd | YML109 | YAML should contain document end marker. | {document-end: {present: true}} |
| CheckTaskSeparation | ANS101 | Single tasks should be separated by an empty line. | | | CheckYamlOctalValues | YML110 | YAML should not use forbidden implicit or explicit octal value. | {octal-values: {forbid-implicit-octal: true, forbid-explicit-octal: true}} |
| CheckMetaMain | ANS102 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies | | CheckTaskSeparation | ANS101 | Single tasks should be separated by an empty line. | |
| CheckUniqueNamedTask | ANS103 | Tasks and handlers must be uniquely named within a file. | | | CheckMetaMain | ANS102 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies |
| CheckBraces | ANS104 | YAML should use consistent number of spaces around variables. | {double-braces: max-spaces-inside: 1, min-spaces-inside: 1} | | CheckUniqueNamedTask | ANS103 | Tasks and handlers must be uniquely named within a file. | |
| CheckScmInSrc | ANS105 | Use SCM key rather than `src: scm+url` in requirements file. | | | CheckBraces | ANS104 | YAML should use consistent number of spaces around variables. | {double-braces: max-spaces-inside: 1, min-spaces-inside: 1} |
| CheckNamedTask | ANS106 | Tasks and handlers must be named. | {named-task: {exclude: [meta, debug, block, include\_\*, import\_\*]}} | | CheckScmInSrc | ANS105 | Use SCM key rather than `src: scm+url` in requirements file. | |
| CheckNameFormat | ANS107 | Name of tasks and handlers must be formatted. | formats: first letter capital | | CheckNamedTask | ANS106 | Tasks and handlers must be named. | {named-task: {exclude: [meta, debug, block, include\_\*, import\_\*]}} |
| CheckCommandInsteadofModule | ANS108 | Commands should not be used in place of modules. | | | CheckNameFormat | ANS107 | Name of tasks and handlers must be formatted. | formats: first letter capital |
| CheckInstallUseLatest | ANS109 | Package managers should not install with state=latest. | | | CheckCommandInsteadofModule | ANS108 | Commands should not be used in place of modules. | |
| CheckShellInsteadCommand | ANS110 | Use Shell only when piping, redirecting or chaining commands. | | | CheckInstallUseLatest | ANS109 | Package managers should not install with state=latest. | |
| CheckCommandHasChanges | ANS111 | Commands should be idempotent and only used with some checks. | | | CheckShellInsteadCommand | ANS110 | Use Shell only when piping, redirecting or chaining commands. | |
| CheckCompareToEmptyString | ANS112 | Don't compare to "" - use `when: var` or `when: not var`. | | | CheckCommandHasChanges | ANS111 | Commands should be idempotent and only used with some checks. | |
| CheckCompareToLiteralBool | ANS113 | Don't compare to True/False - use `when: var` or `when: not var`. | | | CheckCompareToEmptyString | ANS112 | Don't compare to "" - use `when: var` or `when: not var`. | |
| CheckLiteralBoolFormat | ANS114 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} | | CheckCompareToLiteralBool | ANS113 | Don't compare to True/False - use `when: var` or `when: not var`. | |
| CheckBecomeUser | ANS115 | Become should be combined with become_user. | | | CheckLiteralBoolFormat | ANS114 | Literal bools should be consistent. | {literal-bools: [True, False, yes, no]} |
| CheckFilterSeparation | ANS116 | Jinja2 filters should be separated with spaces. | | | CheckBecomeUser | ANS115 | Become should be combined with become_user. | |
| CheckCommandInsteadOfArgument | ANS117 | Commands should not be used in place of module arguments. | | | CheckFilterSeparation | ANS116 | Jinja2 filters should be separated with spaces. | |
| CheckFilePermissionMissing | ANS118 | File permissions unset or incorrect. | | | CheckCommandInsteadOfArgument | ANS117 | Commands should not be used in place of module arguments. | |
| CheckFilePermissionOctal | ANS119 | Octal file permissions must contain leading zero or be a string. | | | CheckFilePermissionMissing | ANS118 | File permissions unset or incorrect. | |
| CheckGitHasVersion | ANS120 | Git checkouts should use explicit version. | | | CheckFilePermissionOctal | ANS119 | Octal file permissions must contain leading zero or be a string. | |
| CheckMetaChangeFromDefault | ANS121 | Roles meta/main.yml default values should be changed. | | | CheckGitHasVersion | ANS120 | Git checkouts should use explicit version. | |
| CheckWhenFormat | ANS122 | Don't use Jinja2 in `when`. | | | CheckMetaChangeFromDefault | ANS121 | Roles meta/main.yml default values should be changed. | |
| CheckNestedJinja | ANS123 | Don't use nested Jinja2 pattern. | | | CheckWhenFormat | ANS122 | Don't use Jinja2 in `when`. | |
| CheckLocalAction | ANS124 | Don't use local_action. | | | CheckNestedJinja | ANS123 | Don't use nested Jinja2 pattern. | |
| CheckRelativeRolePaths | ANS125 | Don't use a relative path in a role. | | | CheckLocalAction | ANS124 | Don't use local_action. | |
| CheckChangedInWhen | ANS126 | Use handlers instead of `when: changed`. | | | CheckRelativeRolePaths | ANS125 | Don't use a relative path in a role. | |
| CheckChangedInWhen | ANS127 | Deprecated bare variables in loops must not be used. | | | CheckChangedInWhen | ANS126 | Use handlers instead of `when: changed`. | |
| CheckDeprecated | ANS999 | Deprecated features of `ansible-later` should not be used. | | | CheckChangedInWhen | ANS127 | Deprecated bare variables in loops must not be used. | |
| CheckDeprecated | ANS999 | Deprecated features of `ansible-later` should not be used. | |