Revert "fix linting"

This reverts commit f3646adf15.
This commit is contained in:
Robert Kaussow 2023-06-28 09:14:39 +02:00
parent f3646adf15
commit 8834d1e1d8
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
42 changed files with 47 additions and 126 deletions

View File

@ -191,7 +191,7 @@ class Candidate:
if sid: if sid:
standard_id = f"[{sid}] " standard_id = f"[{sid}] "
return standard_id return standard_id # noqa
def __repr__(self): def __repr__(self):
return f"{type(self).__name__} ({self.path})" return f"{type(self).__name__} ({self.path})"

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckBecomeUser(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,4 @@
import re import re
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
from ansiblelater.utils import count_spaces from ansiblelater.utils import count_spaces
@ -11,9 +10,7 @@ class CheckBracesSpaces(StandardBase):
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})"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
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)

View File

@ -18,8 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -29,7 +27,7 @@ class CheckChangedInWhen(StandardBase):
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"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -12,7 +10,7 @@ class CheckCommandHasChanges(StandardBase):
"idempotent while using controls like `creates`, `removes` or `when`" "idempotent while using controls like `creates`, `removes` or `when`"
) )
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task"] types = ["playbook", "task"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -19,7 +19,6 @@
# THE SOFTWARE. # THE SOFTWARE.
import os import os
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -30,7 +29,7 @@ class CheckCommandInsteadOfArgument(StandardBase):
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}"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,4 @@
import os import os
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,7 +9,7 @@ class CheckCommandInsteadOfModule(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,4 @@
import re import re
from typing import ClassVar
from ansiblelater.candidate import Template from ansiblelater.candidate import Template
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +10,7 @@ class CheckCompareToEmptyString(StandardBase):
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`)")
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler", "template"] types = ["playbook", "task", "handler", "template"]
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)

View File

@ -1,5 +1,4 @@
import re import re
from typing import ClassVar
from ansiblelater.candidate import Template from ansiblelater.candidate import Template
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +10,7 @@ class CheckCompareToLiteralBool(StandardBase):
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`)")
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
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)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckDeprecated(StandardBase):
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."
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings, full=True) tasks, errors = self.get_normalized_tasks(candidate, settings, full=True)

View File

@ -19,7 +19,6 @@
# THE SOFTWARE. # THE SOFTWARE.
import os import os
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
from ansiblelater.utils import has_glob, has_jinja from ansiblelater.utils import has_glob, has_jinja
@ -34,7 +33,7 @@ class CheckDeprecatedBareVars(StandardBase):
"or be converted to a list" "or be converted to a list"
) )
version = "0.3" version = "0.3"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, self.errors = self.get_normalized_tasks(candidate, settings) tasks, self.errors = self.get_normalized_tasks(candidate, settings)

View File

@ -18,7 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
import re import re
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -32,9 +31,9 @@ class CheckFilePermissionMissing(StandardBase):
"to avoid unexpected file permissions" "to avoid unexpected file permissions"
) )
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
_modules: ClassVar[dict] = { _modules = {
"archive", "archive",
"assemble", "assemble",
"copy", "copy",
@ -42,7 +41,7 @@ class CheckFilePermissionMissing(StandardBase):
"replace", "replace",
"template", "template",
} }
_create_modules: ClassVar[dict[str, bool]] = { _create_modules = {
"blockinfile": False, "blockinfile": False,
"htpasswd": True, "htpasswd": True,
"ini_file": True, "ini_file": True,

View File

@ -18,8 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -29,7 +27,7 @@ class CheckFilePermissionOctal(StandardBase):
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"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,4 @@
import re import re
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,8 +9,7 @@ class CheckFilterSeparation(StandardBase):
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)"
version = "0.1" version = "0.1"
types: ClassVar[list[str] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
] = ["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)

View File

@ -18,8 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -29,7 +27,7 @@ class CheckGitHasVersion(StandardBase):
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`"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckInstallUseLatest(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,4 @@
import re import re
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,8 +9,7 @@ class CheckLiteralBoolFormat(StandardBase):
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}`"
version = "0.1" version = "0.1"
types: ClassVar[list[str] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
] = ["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)

View File

@ -1,7 +1,5 @@
# Copyright (c) 2016, Tsukinowa Inc. <info@tsukinowa.jp> # Copyright (c) 2016, Tsukinowa Inc. <info@tsukinowa.jp>
# Copyright (c) 2018, Ansible Project # Copyright (c) 2018, Ansible Project
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +9,7 @@ class CheckLocalAction(StandardBase):
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`")
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
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)

View File

@ -1,6 +1,4 @@
# Copyright (c) 2018, Ansible Project # Copyright (c) 2018, Ansible Project
from typing import ClassVar
from nested_lookup import nested_lookup from nested_lookup import nested_lookup
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -12,7 +10,7 @@ class CheckMetaChangeFromDefault(StandardBase):
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}`"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["meta"] types = ["meta"]
def check(self, candidate, settings): def check(self, candidate, settings):
content, errors = self.get_raw_yaml(candidate, settings) content, errors = self.get_raw_yaml(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from nested_lookup import nested_lookup from nested_lookup import nested_lookup
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +9,7 @@ class CheckMetaMain(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["meta"] types = ["meta"]
def check(self, candidate, settings): def check(self, candidate, settings):
content, errors = self.get_raw_yaml(candidate, settings) content, errors = self.get_raw_yaml(candidate, settings)

View File

@ -1,5 +1,4 @@
from collections import defaultdict from collections import defaultdict
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,7 +9,7 @@ class CheckNameFormat(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckNamedTask(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckNativeYaml(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_action_tasks(candidate, settings) tasks, errors = self.get_action_tasks(candidate, settings)

View File

@ -20,7 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
import re import re
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -34,8 +33,7 @@ class CheckNestedJinja(StandardBase):
"like `{{ list_one + {{ list_two | max }} }}`" "like `{{ list_one + {{ list_two | max }} }}`"
) )
version = "0.2" version = "0.2"
types: ClassVar[list[str] types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
] = ["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)

View File

@ -1,7 +1,5 @@
# Copyright (c) 2016, Tsukinowa Inc. <info@tsukinowa.jp> # Copyright (c) 2016, Tsukinowa Inc. <info@tsukinowa.jp>
# Copyright (c) 2018, Ansible Project # Copyright (c) 2018, Ansible Project
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +9,7 @@ class CheckRelativeRolePaths(StandardBase):
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`"
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansible.parsing.yaml.objects import AnsibleMapping from ansible.parsing.yaml.objects import AnsibleMapping
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +9,7 @@ class CheckScmInSrc(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["rolesfile"] types = ["rolesfile"]
def check(self, candidate, settings): def check(self, candidate, settings):
roles, errors = self.get_tasks(candidate, settings) roles, errors = self.get_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckShellInsteadCommand(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,6 +1,5 @@
import re import re
from collections import defaultdict from collections import defaultdict
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -11,7 +10,7 @@ class CheckTaskSeparation(StandardBase):
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)"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
options = defaultdict(dict) options = defaultdict(dict)

View File

@ -1,5 +1,4 @@
from collections import defaultdict from collections import defaultdict
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,7 +9,7 @@ class CheckUniqueNamedTask(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,8 +6,7 @@ class CheckVersion(StandardBase):
sid = "ANSIBLE9998" sid = "ANSIBLE9998"
description = "Standards version should be pinned" description = "Standards version should be pinned"
helptext = "Standards version not set. Using latest standards version {version}" helptext = "Standards version not set. Using latest standards version {version}"
types: ClassVar[list[str] types = ["task", "handler", "rolevars", "meta", "template", "file", "playbook"]
] = ["task", "handler", "rolevars", "meta", "template", "file", "playbook"]
def check(self, candidate, settings): # noqa def check(self, candidate, settings): # noqa
errors = [] errors = []

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -12,7 +10,7 @@ class CheckWhenFormat(StandardBase):
"should be removed from variable(s)" "should be removed from variable(s)"
) )
version = "0.2" version = "0.2"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
tasks, errors = self.get_normalized_tasks(candidate, settings) tasks, errors = self.get_normalized_tasks(candidate, settings)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlColons(StandardBase):
sid = "LINT0005" sid = "LINT0005"
description = "YAML should use consistent number of spaces around colons" description = "YAML should use consistent number of spaces around colons"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{colons: {settings['yamllint']['colons']}}}" options = f"rules: {{colons: {settings['yamllint']['colons']}}}"

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlDocumentEnd(StandardBase):
sid = "LINT0009" sid = "LINT0009"
description = "YAML should contain document end marker" description = "YAML should contain document end marker"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{document-end: {settings['yamllint']['document-end']}}}" options = f"rules: {{document-end: {settings['yamllint']['document-end']}}}"

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlDocumentStart(StandardBase):
sid = "LINT0004" sid = "LINT0004"
description = "YAML should contain document start marker" description = "YAML should contain document start marker"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}" options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}"

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlEmptyLines(StandardBase):
sid = "LINT0001" sid = "LINT0001"
description = "YAML should not contain unnecessarily empty lines" description = "YAML should not contain unnecessarily empty lines"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{empty-lines: {settings['yamllint']['empty-lines']}}}" options = f"rules: {{empty-lines: {settings['yamllint']['empty-lines']}}}"

View File

@ -1,5 +1,4 @@
import os import os
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -10,7 +9,7 @@ class CheckYamlFile(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler"] types = ["playbook", "task", "handler"]
def check(self, candidate, settings): def check(self, candidate, settings):
errors = [] errors = []

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -9,7 +7,7 @@ class CheckYamlHasContent(StandardBase):
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"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = ["playbook", "task", "handler", "rolevars", "defaults", "meta"] types = ["playbook", "task", "handler", "rolevars", "defaults", "meta"]
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)

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlHyphens(StandardBase):
sid = "LINT0003" sid = "LINT0003"
description = "YAML should use consistent number of spaces after hyphens" description = "YAML should use consistent number of spaces after hyphens"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{hyphens: {settings['yamllint']['hyphens']}}}" options = f"rules: {{hyphens: {settings['yamllint']['hyphens']}}}"

View File

@ -1,5 +1,3 @@
from typing import ClassVar
from ansiblelater.standard import StandardBase from ansiblelater.standard import StandardBase
@ -8,9 +6,7 @@ class CheckYamlIndent(StandardBase):
sid = "LINT0002" sid = "LINT0002"
description = "YAML should not contain unnecessarily empty lines" description = "YAML should not contain unnecessarily empty lines"
version = "0.1" version = "0.1"
types: ClassVar[list[str]] = [ types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"]
"playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"
]
def check(self, candidate, settings): def check(self, candidate, settings):
options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}" options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}"

View File

@ -304,7 +304,7 @@ class StandardBase(metaclass=StandardExtendedMeta):
return "\n".join([f"{self.candidate}:{error}" for error in self.errors]) return "\n".join([f"{self.candidate}:{error}" for error in self.errors])
class StandardLoader: class StandardLoader():
def __init__(self, source): def __init__(self, source):
self.rules = [] self.rules = []

View File

@ -5,7 +5,6 @@ import re
import sys import sys
from contextlib import suppress from contextlib import suppress
from distutils.version import LooseVersion from distutils.version import LooseVersion
from typing import ClassVar
import yaml import yaml
@ -115,7 +114,7 @@ def sysexit_with_message(msg, code=1):
class Singleton(type): class Singleton(type):
"""Meta singleton class.""" """Meta singleton class."""
_instances: ClassVar[dict] = {} _instances = {}
def __call__(cls, *args, **kwargs): def __call__(cls, *args, **kwargs):
if cls not in cls._instances: if cls not in cls._instances:

View File

@ -209,10 +209,11 @@ def template(basedir, value, variables, fail_on_undefined=False, **kwargs):
# Hack to skip the following exception when using to_json filter on a variable. # Hack to skip the following exception when using to_json filter on a variable.
# I guess the filter doesn't like empty vars... # I guess the filter doesn't like empty vars...
with suppress(AnsibleError, ValueError): with suppress(AnsibleError, ValueError):
return ansible_template( value = ansible_template(
os.path.abspath(basedir), value, variables, os.path.abspath(basedir), value, variables,
**dict(kwargs, fail_on_undefined=fail_on_undefined) **dict(kwargs, fail_on_undefined=fail_on_undefined)
) )
return value
def play_children(basedir, item, parent_type): def play_children(basedir, item, parent_type):
@ -372,7 +373,8 @@ def rolename(filepath):
if idx < 0: if idx < 0:
return "" return ""
role = filepath[idx + 6:] role = filepath[idx + 6:]
return role[:role.find("/")] role = role[:role.find("/")]
return role
def _kv_to_dict(v): def _kv_to_dict(v):