From 8834d1e1d86d2553424594455838f45c940b2370 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 28 Jun 2023 09:14:39 +0200 Subject: [PATCH] Revert "fix linting" This reverts commit f3646adf15922ed11ea8a1cf1787e8b2cb530f83. --- ansiblelater/candidate.py | 2 +- ansiblelater/rules/CheckBecomeUser.py | 4 +--- ansiblelater/rules/CheckBracesSpaces.py | 5 +---- ansiblelater/rules/CheckChangedInWhen.py | 4 +--- ansiblelater/rules/CheckCommandHasChanges.py | 4 +--- ansiblelater/rules/CheckCommandInsteadOfArgument.py | 3 +-- ansiblelater/rules/CheckCommandInsteadOfModule.py | 3 +-- ansiblelater/rules/CheckCompareToEmptyString.py | 3 +-- ansiblelater/rules/CheckCompareToLiteralBool.py | 3 +-- ansiblelater/rules/CheckDeprecated.py | 4 +--- ansiblelater/rules/CheckDeprecatedBareVars.py | 3 +-- ansiblelater/rules/CheckFilePermissionMissing.py | 7 +++---- ansiblelater/rules/CheckFilePermissionOctal.py | 4 +--- ansiblelater/rules/CheckFilterSeparation.py | 4 +--- ansiblelater/rules/CheckGitHasVersion.py | 4 +--- ansiblelater/rules/CheckInstallUseLatest.py | 4 +--- ansiblelater/rules/CheckLiteralBoolFormat.py | 4 +--- ansiblelater/rules/CheckLocalAction.py | 4 +--- ansiblelater/rules/CheckMetaChangeFromDefault.py | 4 +--- ansiblelater/rules/CheckMetaMain.py | 4 +--- ansiblelater/rules/CheckNameFormat.py | 3 +-- ansiblelater/rules/CheckNamedTask.py | 4 +--- ansiblelater/rules/CheckNativeYaml.py | 4 +--- ansiblelater/rules/CheckNestedJinja.py | 4 +--- ansiblelater/rules/CheckRelativeRolePaths.py | 4 +--- ansiblelater/rules/CheckScmInSrc.py | 4 +--- ansiblelater/rules/CheckShellInsteadCommand.py | 4 +--- ansiblelater/rules/CheckTaskSeparation.py | 3 +-- ansiblelater/rules/CheckUniqueNamedTask.py | 3 +-- ansiblelater/rules/CheckVersion.py | 5 +---- ansiblelater/rules/CheckWhenFormat.py | 4 +--- ansiblelater/rules/CheckYamlColons.py | 6 +----- ansiblelater/rules/CheckYamlDocumentEnd.py | 6 +----- ansiblelater/rules/CheckYamlDocumentStart.py | 6 +----- ansiblelater/rules/CheckYamlEmptyLines.py | 6 +----- ansiblelater/rules/CheckYamlFile.py | 3 +-- ansiblelater/rules/CheckYamlHasContent.py | 4 +--- ansiblelater/rules/CheckYamlHyphens.py | 6 +----- ansiblelater/rules/CheckYamlIndent.py | 6 +----- ansiblelater/standard.py | 2 +- ansiblelater/utils/__init__.py | 3 +-- ansiblelater/utils/yamlhelper.py | 6 ++++-- 42 files changed, 47 insertions(+), 126 deletions(-) diff --git a/ansiblelater/candidate.py b/ansiblelater/candidate.py index 007a122..12194e2 100644 --- a/ansiblelater/candidate.py +++ b/ansiblelater/candidate.py @@ -191,7 +191,7 @@ class Candidate: if sid: standard_id = f"[{sid}] " - return standard_id + return standard_id # noqa def __repr__(self): return f"{type(self).__name__} ({self.path})" diff --git a/ansiblelater/rules/CheckBecomeUser.py b/ansiblelater/rules/CheckBecomeUser.py index 5cab707..6eb3a1c 100644 --- a/ansiblelater/rules/CheckBecomeUser.py +++ b/ansiblelater/rules/CheckBecomeUser.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckBecomeUser(StandardBase): description = "Become should be combined with become_user" helptext = "the task has `become` enabled but `become_user` is missing" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckBracesSpaces.py b/ansiblelater/rules/CheckBracesSpaces.py index 1d95c27..3cf3cdf 100644 --- a/ansiblelater/rules/CheckBracesSpaces.py +++ b/ansiblelater/rules/CheckBracesSpaces.py @@ -1,5 +1,4 @@ import re -from typing import ClassVar from ansiblelater.standard import StandardBase from ansiblelater.utils import count_spaces @@ -11,9 +10,7 @@ class CheckBracesSpaces(StandardBase): description = "YAML should use consistent number of spaces around variables" helptext = "no suitable numbers of spaces (min: {min} max: {max})" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckChangedInWhen.py b/ansiblelater/rules/CheckChangedInWhen.py index faad404..09e63fd 100644 --- a/ansiblelater/rules/CheckChangedInWhen.py +++ b/ansiblelater/rules/CheckChangedInWhen.py @@ -18,8 +18,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -29,7 +27,7 @@ class CheckChangedInWhen(StandardBase): description = "Use handlers instead of `when: changed`" helptext = "tasks using `when: result.changed` setting are effectively acting as a handler" version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckCommandHasChanges.py b/ansiblelater/rules/CheckCommandHasChanges.py index 0dac9e1..6391178 100644 --- a/ansiblelater/rules/CheckCommandHasChanges.py +++ b/ansiblelater/rules/CheckCommandHasChanges.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -12,7 +10,7 @@ class CheckCommandHasChanges(StandardBase): "idempotent while using controls like `creates`, `removes` or `when`" ) version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task"] + types = ["playbook", "task"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckCommandInsteadOfArgument.py b/ansiblelater/rules/CheckCommandInsteadOfArgument.py index 482ca44..21f68e3 100644 --- a/ansiblelater/rules/CheckCommandInsteadOfArgument.py +++ b/ansiblelater/rules/CheckCommandInsteadOfArgument.py @@ -19,7 +19,6 @@ # THE SOFTWARE. import os -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -30,7 +29,7 @@ class CheckCommandInsteadOfArgument(StandardBase): description = "Commands should not be used in place of module arguments" helptext = "{exec} used in place of file modules argument {arg}" version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckCommandInsteadOfModule.py b/ansiblelater/rules/CheckCommandInsteadOfModule.py index f2ddf62..4902f5f 100644 --- a/ansiblelater/rules/CheckCommandInsteadOfModule.py +++ b/ansiblelater/rules/CheckCommandInsteadOfModule.py @@ -1,5 +1,4 @@ import os -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,7 +9,7 @@ class CheckCommandInsteadOfModule(StandardBase): description = "Commands should not be used in place of modules" helptext = "{exec} command used in place of {module} module" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckCompareToEmptyString.py b/ansiblelater/rules/CheckCompareToEmptyString.py index d24c191..2291320 100644 --- a/ansiblelater/rules/CheckCompareToEmptyString.py +++ b/ansiblelater/rules/CheckCompareToEmptyString.py @@ -1,5 +1,4 @@ import re -from typing import ClassVar from ansiblelater.candidate import Template from ansiblelater.standard import StandardBase @@ -11,7 +10,7 @@ class CheckCompareToEmptyString(StandardBase): description = "Don't compare to empty string \"\"" helptext = ("use `when: var` rather than `when: var !=` (or conversely `when: not var`)") version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler", "template"] + types = ["playbook", "task", "handler", "template"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckCompareToLiteralBool.py b/ansiblelater/rules/CheckCompareToLiteralBool.py index 9dc193d..fe4ce9a 100644 --- a/ansiblelater/rules/CheckCompareToLiteralBool.py +++ b/ansiblelater/rules/CheckCompareToLiteralBool.py @@ -1,5 +1,4 @@ import re -from typing import ClassVar from ansiblelater.candidate import Template from ansiblelater.standard import StandardBase @@ -11,7 +10,7 @@ class CheckCompareToLiteralBool(StandardBase): description = "Don't compare to True or False" helptext = ("use `when: var` rather than `when: var == True` (or conversely `when: not var`)") version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckDeprecated.py b/ansiblelater/rules/CheckDeprecated.py index 1ed5bf2..8301482 100644 --- a/ansiblelater/rules/CheckDeprecated.py +++ b/ansiblelater/rules/CheckDeprecated.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckDeprecated(StandardBase): description = "Deprecated features should not be used" helptext = "'{old}' is deprecated and should not be used anymore. Use '{new}' instead." version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings, full=True) diff --git a/ansiblelater/rules/CheckDeprecatedBareVars.py b/ansiblelater/rules/CheckDeprecatedBareVars.py index 8293326..26677c1 100644 --- a/ansiblelater/rules/CheckDeprecatedBareVars.py +++ b/ansiblelater/rules/CheckDeprecatedBareVars.py @@ -19,7 +19,6 @@ # THE SOFTWARE. import os -from typing import ClassVar from ansiblelater.standard import StandardBase from ansiblelater.utils import has_glob, has_jinja @@ -34,7 +33,7 @@ class CheckDeprecatedBareVars(StandardBase): "or be converted to a list" ) version = "0.3" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, self.errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckFilePermissionMissing.py b/ansiblelater/rules/CheckFilePermissionMissing.py index 5c2a7ef..30ab294 100644 --- a/ansiblelater/rules/CheckFilePermissionMissing.py +++ b/ansiblelater/rules/CheckFilePermissionMissing.py @@ -18,7 +18,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import re -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -32,9 +31,9 @@ class CheckFilePermissionMissing(StandardBase): "to avoid unexpected file permissions" ) version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] - _modules: ClassVar[dict] = { + _modules = { "archive", "assemble", "copy", @@ -42,7 +41,7 @@ class CheckFilePermissionMissing(StandardBase): "replace", "template", } - _create_modules: ClassVar[dict[str, bool]] = { + _create_modules = { "blockinfile": False, "htpasswd": True, "ini_file": True, diff --git a/ansiblelater/rules/CheckFilePermissionOctal.py b/ansiblelater/rules/CheckFilePermissionOctal.py index f6936df..61f9738 100644 --- a/ansiblelater/rules/CheckFilePermissionOctal.py +++ b/ansiblelater/rules/CheckFilePermissionOctal.py @@ -18,8 +18,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -29,7 +27,7 @@ class CheckFilePermissionOctal(StandardBase): description = "Octal file permissions must contain leading zero or be a string" helptext = "numeric file permissions without leading zero can behave in unexpected ways" version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckFilterSeparation.py b/ansiblelater/rules/CheckFilterSeparation.py index fe1e0af..248f96c 100644 --- a/ansiblelater/rules/CheckFilterSeparation.py +++ b/ansiblelater/rules/CheckFilterSeparation.py @@ -1,5 +1,4 @@ import re -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,8 +9,7 @@ class CheckFilterSeparation(StandardBase): description = "Jinja2 filters should be separated with spaces" helptext = "no suitable numbers of spaces (required: 1)" version = "0.1" - types: ClassVar[list[str] - ] = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckGitHasVersion.py b/ansiblelater/rules/CheckGitHasVersion.py index 114efa4..bdd45c2 100644 --- a/ansiblelater/rules/CheckGitHasVersion.py +++ b/ansiblelater/rules/CheckGitHasVersion.py @@ -18,8 +18,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -29,7 +27,7 @@ class CheckGitHasVersion(StandardBase): description = "Git checkouts should use explicit version" helptext = "git checkouts should point to an explicit commit or tag, not `latest`" version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckInstallUseLatest.py b/ansiblelater/rules/CheckInstallUseLatest.py index 9d15d89..7025c04 100644 --- a/ansiblelater/rules/CheckInstallUseLatest.py +++ b/ansiblelater/rules/CheckInstallUseLatest.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckInstallUseLatest(StandardBase): description = "Package installs should use present, not latest" helptext = "package installs should use `state=present` with or without a version" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckLiteralBoolFormat.py b/ansiblelater/rules/CheckLiteralBoolFormat.py index 42d3f2e..71e9ebb 100644 --- a/ansiblelater/rules/CheckLiteralBoolFormat.py +++ b/ansiblelater/rules/CheckLiteralBoolFormat.py @@ -1,5 +1,4 @@ import re -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,8 +9,7 @@ class CheckLiteralBoolFormat(StandardBase): description = "Literal bools should be consistent" helptext = "literal bools should be written as `{bools}`" version = "0.1" - types: ClassVar[list[str] - ] = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckLocalAction.py b/ansiblelater/rules/CheckLocalAction.py index 5ee3682..edf81ee 100644 --- a/ansiblelater/rules/CheckLocalAction.py +++ b/ansiblelater/rules/CheckLocalAction.py @@ -1,7 +1,5 @@ # Copyright (c) 2016, Tsukinowa Inc. # Copyright (c) 2018, Ansible Project -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -11,7 +9,7 @@ class CheckLocalAction(StandardBase): description = "Don't use local_action" helptext = ("`delegate_to: localhost` should be used instead of `local_action`") version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckMetaChangeFromDefault.py b/ansiblelater/rules/CheckMetaChangeFromDefault.py index 694f84b..2f9f599 100644 --- a/ansiblelater/rules/CheckMetaChangeFromDefault.py +++ b/ansiblelater/rules/CheckMetaChangeFromDefault.py @@ -1,6 +1,4 @@ # Copyright (c) 2018, Ansible Project -from typing import ClassVar - from nested_lookup import nested_lookup from ansiblelater.standard import StandardBase @@ -12,7 +10,7 @@ class CheckMetaChangeFromDefault(StandardBase): description = "Roles meta/main.yml default values should be changed" helptext = "meta/main.yml default values should be changed for: `{field}`" version = "0.2" - types: ClassVar[list[str]] = ["meta"] + types = ["meta"] def check(self, candidate, settings): content, errors = self.get_raw_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckMetaMain.py b/ansiblelater/rules/CheckMetaMain.py index 9ca96a1..1e1ca86 100644 --- a/ansiblelater/rules/CheckMetaMain.py +++ b/ansiblelater/rules/CheckMetaMain.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from nested_lookup import nested_lookup from ansiblelater.standard import StandardBase @@ -11,7 +9,7 @@ class CheckMetaMain(StandardBase): description = "Roles must contain suitable meta/main.yml" helptext = "file should contain `{key}` key" version = "0.1" - types: ClassVar[list[str]] = ["meta"] + types = ["meta"] def check(self, candidate, settings): content, errors = self.get_raw_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckNameFormat.py b/ansiblelater/rules/CheckNameFormat.py index 5ad17ef..8747db8 100644 --- a/ansiblelater/rules/CheckNameFormat.py +++ b/ansiblelater/rules/CheckNameFormat.py @@ -1,5 +1,4 @@ from collections import defaultdict -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,7 +9,7 @@ class CheckNameFormat(StandardBase): description = "Name of tasks and handlers must be formatted" helptext = "name '{name}' should start with uppercase" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckNamedTask.py b/ansiblelater/rules/CheckNamedTask.py index ae6d20f..f100097 100644 --- a/ansiblelater/rules/CheckNamedTask.py +++ b/ansiblelater/rules/CheckNamedTask.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckNamedTask(StandardBase): description = "Tasks and handlers must be named" helptext = "module '{module}' used without or empty `name` attribute" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckNativeYaml.py b/ansiblelater/rules/CheckNativeYaml.py index a9e646b..75554f8 100644 --- a/ansiblelater/rules/CheckNativeYaml.py +++ b/ansiblelater/rules/CheckNativeYaml.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckNativeYaml(StandardBase): 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" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_action_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckNestedJinja.py b/ansiblelater/rules/CheckNestedJinja.py index 041c74f..2d5f19b 100644 --- a/ansiblelater/rules/CheckNestedJinja.py +++ b/ansiblelater/rules/CheckNestedJinja.py @@ -20,7 +20,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import re -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -34,8 +33,7 @@ class CheckNestedJinja(StandardBase): "like `{{ list_one + {{ list_two | max }} }}`" ) version = "0.2" - types: ClassVar[list[str] - ] = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"] def check(self, candidate, settings): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckRelativeRolePaths.py b/ansiblelater/rules/CheckRelativeRolePaths.py index 293a5b8..01ad66f 100644 --- a/ansiblelater/rules/CheckRelativeRolePaths.py +++ b/ansiblelater/rules/CheckRelativeRolePaths.py @@ -1,7 +1,5 @@ # Copyright (c) 2016, Tsukinowa Inc. # Copyright (c) 2018, Ansible Project -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -11,7 +9,7 @@ class CheckRelativeRolePaths(StandardBase): description = "Don't use a relative path in a role" helptext = "`copy` and `template` modules don't need relative path for `src`" version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckScmInSrc.py b/ansiblelater/rules/CheckScmInSrc.py index 46e40d7..f0a2f7a 100644 --- a/ansiblelater/rules/CheckScmInSrc.py +++ b/ansiblelater/rules/CheckScmInSrc.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansible.parsing.yaml.objects import AnsibleMapping from ansiblelater.standard import StandardBase @@ -11,7 +9,7 @@ class CheckScmInSrc(StandardBase): description = "Use `scm:` key rather than `src: scm+url`" helptext = "usage of `src: scm+url` not recommended" version = "0.1" - types: ClassVar[list[str]] = ["rolesfile"] + types = ["rolesfile"] def check(self, candidate, settings): roles, errors = self.get_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckShellInsteadCommand.py b/ansiblelater/rules/CheckShellInsteadCommand.py index ce93612..b36a42f 100644 --- a/ansiblelater/rules/CheckShellInsteadCommand.py +++ b/ansiblelater/rules/CheckShellInsteadCommand.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckShellInsteadCommand(StandardBase): description = "Shell should only be used when essential" helptext = "shell should only be used when piping, redirecting or chaining commands" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckTaskSeparation.py b/ansiblelater/rules/CheckTaskSeparation.py index 1763a11..b7b58f5 100644 --- a/ansiblelater/rules/CheckTaskSeparation.py +++ b/ansiblelater/rules/CheckTaskSeparation.py @@ -1,6 +1,5 @@ import re from collections import defaultdict -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -11,7 +10,7 @@ class CheckTaskSeparation(StandardBase): description = "Single tasks should be separated by empty line" helptext = "missing task separation (required: 1 empty line)" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): options = defaultdict(dict) diff --git a/ansiblelater/rules/CheckUniqueNamedTask.py b/ansiblelater/rules/CheckUniqueNamedTask.py index f8ee2dc..558a145 100644 --- a/ansiblelater/rules/CheckUniqueNamedTask.py +++ b/ansiblelater/rules/CheckUniqueNamedTask.py @@ -1,5 +1,4 @@ from collections import defaultdict -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,7 +9,7 @@ class CheckUniqueNamedTask(StandardBase): description = "Tasks and handlers must be uniquely named within a single file" helptext = "name '{name}' appears multiple times" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckVersion.py b/ansiblelater/rules/CheckVersion.py index 4a057d8..b122164 100644 --- a/ansiblelater/rules/CheckVersion.py +++ b/ansiblelater/rules/CheckVersion.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,8 +6,7 @@ class CheckVersion(StandardBase): sid = "ANSIBLE9998" description = "Standards version should be pinned" helptext = "Standards version not set. Using latest standards version {version}" - types: ClassVar[list[str] - ] = ["task", "handler", "rolevars", "meta", "template", "file", "playbook"] + types = ["task", "handler", "rolevars", "meta", "template", "file", "playbook"] def check(self, candidate, settings): # noqa errors = [] diff --git a/ansiblelater/rules/CheckWhenFormat.py b/ansiblelater/rules/CheckWhenFormat.py index ad3a441..74acca4 100644 --- a/ansiblelater/rules/CheckWhenFormat.py +++ b/ansiblelater/rules/CheckWhenFormat.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -12,7 +10,7 @@ class CheckWhenFormat(StandardBase): "should be removed from variable(s)" ) version = "0.2" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): tasks, errors = self.get_normalized_tasks(candidate, settings) diff --git a/ansiblelater/rules/CheckYamlColons.py b/ansiblelater/rules/CheckYamlColons.py index 2b8daa9..8d48f8d 100644 --- a/ansiblelater/rules/CheckYamlColons.py +++ b/ansiblelater/rules/CheckYamlColons.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlColons(StandardBase): sid = "LINT0005" description = "YAML should use consistent number of spaces around colons" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{colons: {settings['yamllint']['colons']}}}" diff --git a/ansiblelater/rules/CheckYamlDocumentEnd.py b/ansiblelater/rules/CheckYamlDocumentEnd.py index 945063f..c8de70d 100644 --- a/ansiblelater/rules/CheckYamlDocumentEnd.py +++ b/ansiblelater/rules/CheckYamlDocumentEnd.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlDocumentEnd(StandardBase): sid = "LINT0009" description = "YAML should contain document end marker" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{document-end: {settings['yamllint']['document-end']}}}" diff --git a/ansiblelater/rules/CheckYamlDocumentStart.py b/ansiblelater/rules/CheckYamlDocumentStart.py index 2f636ef..89383ac 100644 --- a/ansiblelater/rules/CheckYamlDocumentStart.py +++ b/ansiblelater/rules/CheckYamlDocumentStart.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlDocumentStart(StandardBase): sid = "LINT0004" description = "YAML should contain document start marker" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}" diff --git a/ansiblelater/rules/CheckYamlEmptyLines.py b/ansiblelater/rules/CheckYamlEmptyLines.py index 34f9170..4a9504d 100644 --- a/ansiblelater/rules/CheckYamlEmptyLines.py +++ b/ansiblelater/rules/CheckYamlEmptyLines.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlEmptyLines(StandardBase): sid = "LINT0001" description = "YAML should not contain unnecessarily empty lines" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{empty-lines: {settings['yamllint']['empty-lines']}}}" diff --git a/ansiblelater/rules/CheckYamlFile.py b/ansiblelater/rules/CheckYamlFile.py index 636edab..dcae58d 100644 --- a/ansiblelater/rules/CheckYamlFile.py +++ b/ansiblelater/rules/CheckYamlFile.py @@ -1,5 +1,4 @@ import os -from typing import ClassVar from ansiblelater.standard import StandardBase @@ -10,7 +9,7 @@ class CheckYamlFile(StandardBase): description = "Roles file should be in yaml format" helptext = "file does not have a .yml extension" version = "0.1" - types: ClassVar[list[str]] = ["playbook", "task", "handler"] + types = ["playbook", "task", "handler"] def check(self, candidate, settings): errors = [] diff --git a/ansiblelater/rules/CheckYamlHasContent.py b/ansiblelater/rules/CheckYamlHasContent.py index 5c71799..1e489d9 100644 --- a/ansiblelater/rules/CheckYamlHasContent.py +++ b/ansiblelater/rules/CheckYamlHasContent.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -9,7 +7,7 @@ class CheckYamlHasContent(StandardBase): description = "Files should contain useful content" helptext = "the file appears to have no useful content" 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): yamllines, errors = self.get_normalized_yaml(candidate, settings) diff --git a/ansiblelater/rules/CheckYamlHyphens.py b/ansiblelater/rules/CheckYamlHyphens.py index bb58679..679bf74 100644 --- a/ansiblelater/rules/CheckYamlHyphens.py +++ b/ansiblelater/rules/CheckYamlHyphens.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlHyphens(StandardBase): sid = "LINT0003" description = "YAML should use consistent number of spaces after hyphens" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{hyphens: {settings['yamllint']['hyphens']}}}" diff --git a/ansiblelater/rules/CheckYamlIndent.py b/ansiblelater/rules/CheckYamlIndent.py index b2b0d19..79bf15e 100644 --- a/ansiblelater/rules/CheckYamlIndent.py +++ b/ansiblelater/rules/CheckYamlIndent.py @@ -1,5 +1,3 @@ -from typing import ClassVar - from ansiblelater.standard import StandardBase @@ -8,9 +6,7 @@ class CheckYamlIndent(StandardBase): sid = "LINT0002" description = "YAML should not contain unnecessarily empty lines" version = "0.1" - types: ClassVar[list[str]] = [ - "playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta" - ] + types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars", "meta"] def check(self, candidate, settings): options = f"rules: {{document-start: {settings['yamllint']['document-start']}}}" diff --git a/ansiblelater/standard.py b/ansiblelater/standard.py index f9760bf..4a66bc7 100644 --- a/ansiblelater/standard.py +++ b/ansiblelater/standard.py @@ -304,7 +304,7 @@ class StandardBase(metaclass=StandardExtendedMeta): return "\n".join([f"{self.candidate}:{error}" for error in self.errors]) -class StandardLoader: +class StandardLoader(): def __init__(self, source): self.rules = [] diff --git a/ansiblelater/utils/__init__.py b/ansiblelater/utils/__init__.py index 1f804b2..dac16f7 100644 --- a/ansiblelater/utils/__init__.py +++ b/ansiblelater/utils/__init__.py @@ -5,7 +5,6 @@ import re import sys from contextlib import suppress from distutils.version import LooseVersion -from typing import ClassVar import yaml @@ -115,7 +114,7 @@ def sysexit_with_message(msg, code=1): class Singleton(type): """Meta singleton class.""" - _instances: ClassVar[dict] = {} + _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: diff --git a/ansiblelater/utils/yamlhelper.py b/ansiblelater/utils/yamlhelper.py index 3807ac2..05207a9 100644 --- a/ansiblelater/utils/yamlhelper.py +++ b/ansiblelater/utils/yamlhelper.py @@ -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. # I guess the filter doesn't like empty vars... with suppress(AnsibleError, ValueError): - return ansible_template( + value = ansible_template( os.path.abspath(basedir), value, variables, **dict(kwargs, fail_on_undefined=fail_on_undefined) ) + return value def play_children(basedir, item, parent_type): @@ -372,7 +373,8 @@ def rolename(filepath): if idx < 0: return "" role = filepath[idx + 6:] - return role[:role.find("/")] + role = role[:role.find("/")] + return role def _kv_to_dict(v):