diff --git a/pyproject.toml b/pyproject.toml index 9b6afd61be..6db894f6d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -239,7 +239,6 @@ ignore = [ "PTH", "PLR", "PLW", - "RUF", "S", "SLF", "T", diff --git a/src/ansiblelint/_mockings.py b/src/ansiblelint/_mockings.py index d1d6bb8a7d..06ade76d42 100644 --- a/src/ansiblelint/_mockings.py +++ b/src/ansiblelint/_mockings.py @@ -55,7 +55,7 @@ def _write_module_stub( # pylint: disable=too-many-branches -def _perform_mockings() -> None: # noqa: C901 +def _perform_mockings() -> None: """Mock modules and roles.""" for role_name in options.mock_roles: if re.match(r"\w+\.\w+\.\w+$", role_name): @@ -74,7 +74,7 @@ def _perform_mockings() -> None: # noqa: C901 _make_module_stub(module_name) -def _perform_mockings_cleanup() -> None: # noqa: C901 +def _perform_mockings_cleanup() -> None: """Clean up mocked modules and roles.""" for role_name in options.mock_roles: if re.match(r"\w+\.\w+\.\w+$", role_name): diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 6983bc9695..6e93a6fda4 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -103,7 +103,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me cache_dir: str | None = None colored: bool = True configured: bool = False - cwd: Path = Path(".") + cwd: Path = Path(".") # noqa: RUF009 display_relative_path: bool = True exclude_paths: list[str] = field(default_factory=list) format: str = "brief" diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index 59dcb71f34..0b578d0bf1 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -324,7 +324,7 @@ def transform(self, match, lintable, data): # pylint: disable=too-many-nested-blocks -def load_plugins( # noqa: max-complexity: 11 +def load_plugins( # : max-complexity: 11 dirs: list[str], ) -> Iterator[AnsibleLintRule]: """Yield a rule class.""" @@ -437,7 +437,7 @@ def extend(self, more: list[AnsibleLintRule]) -> None: """Combine rules.""" self.rules.extend(more) - def run( # noqa: max-complexity: 12 + def run( # : max-complexity: 12 self, file: Lintable, tags: set[str] | None = None, diff --git a/src/ansiblelint/rules/command_instead_of_module.py b/src/ansiblelint/rules/command_instead_of_module.py index e66fc32c41..ef4cfe47dc 100644 --- a/src/ansiblelint/rules/command_instead_of_module.py +++ b/src/ansiblelint/rules/command_instead_of_module.py @@ -104,7 +104,7 @@ def matchtask( return False -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/fqcn.py b/src/ansiblelint/rules/fqcn.py index d7f2d8e4fd..803e9beed6 100644 --- a/src/ansiblelint/rules/fqcn.py +++ b/src/ansiblelint/rules/fqcn.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from ruamel.yaml.comments import CommentedMap, CommentedSeq - from ansiblelint.file_utils import Lintable # noqa: F811 + from ansiblelint.file_utils import Lintable _logger = logging.getLogger(__name__) diff --git a/src/ansiblelint/rules/galaxy.py b/src/ansiblelint/rules/galaxy.py index 4f846fd4c5..a7191e7aa8 100644 --- a/src/ansiblelint/rules/galaxy.py +++ b/src/ansiblelint/rules/galaxy.py @@ -155,7 +155,7 @@ def _coerce(other: object) -> Version: raise NotImplementedError(f"Unable to coerce object type {type(other)} to Version") -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/jinja.py b/src/ansiblelint/rules/jinja.py index bfa6310709..3fe2588918 100644 --- a/src/ansiblelint/rules/jinja.py +++ b/src/ansiblelint/rules/jinja.py @@ -369,7 +369,7 @@ def blacken(text: str) -> str: ).rstrip("\n") -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/name.py b/src/ansiblelint/rules/name.py index bb3f6dd9c7..0948a8c3df 100644 --- a/src/ansiblelint/rules/name.py +++ b/src/ansiblelint/rules/name.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from ruamel.yaml.comments import CommentedMap, CommentedSeq - from ansiblelint.file_utils import Lintable # noqa: F811 + from ansiblelint.file_utils import Lintable class NameRule(AnsibleLintRule, TransformMixin): @@ -172,7 +172,7 @@ def transform( match.fixed = True -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: from ansiblelint.config import options from ansiblelint.file_utils import Lintable # noqa: F811 from ansiblelint.rules import RulesCollection diff --git a/src/ansiblelint/rules/no_free_form.py b/src/ansiblelint/rules/no_free_form.py index f88bc42fa3..048970683c 100644 --- a/src/ansiblelint/rules/no_free_form.py +++ b/src/ansiblelint/rules/no_free_form.py @@ -85,7 +85,7 @@ def matchtask( return results -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/no_log_password.py b/src/ansiblelint/rules/no_log_password.py index e2df48f814..d80781edf9 100644 --- a/src/ansiblelint/rules/no_log_password.py +++ b/src/ansiblelint/rules/no_log_password.py @@ -73,7 +73,7 @@ def matchtask( ) -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/only_builtins.py b/src/ansiblelint/rules/only_builtins.py index 6d1a9510fc..99ee8caf3e 100644 --- a/src/ansiblelint/rules/only_builtins.py +++ b/src/ansiblelint/rules/only_builtins.py @@ -29,7 +29,8 @@ def matchtask( allowed_collections = [ "ansible.builtin", "ansible.legacy", - ] + options.only_builtins_allow_collections + *options.only_builtins_allow_collections, + ] allowed_modules = builtins + options.only_builtins_allow_modules is_allowed = ( diff --git a/src/ansiblelint/rules/playbook_extension.py b/src/ansiblelint/rules/playbook_extension.py index 491b1fcd99..250e308341 100644 --- a/src/ansiblelint/rules/playbook_extension.py +++ b/src/ansiblelint/rules/playbook_extension.py @@ -34,7 +34,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: return result -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/risky_file_permissions.py b/src/ansiblelint/rules/risky_file_permissions.py index 6f154ab125..3d0dcca334 100644 --- a/src/ansiblelint/rules/risky_file_permissions.py +++ b/src/ansiblelint/rules/risky_file_permissions.py @@ -128,7 +128,7 @@ def matchtask( return mode is None -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/rules/risky_shell_pipe.py b/src/ansiblelint/rules/risky_shell_pipe.py index 367793b43f..66f9b84b54 100644 --- a/src/ansiblelint/rules/risky_shell_pipe.py +++ b/src/ansiblelint/rules/risky_shell_pipe.py @@ -58,7 +58,7 @@ def matchtask( ) -if "pytest" in sys.modules: # noqa: C901 +if "pytest" in sys.modules: import pytest from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports diff --git a/src/ansiblelint/skip_utils.py b/src/ansiblelint/skip_utils.py index b0d64a4684..def12ab099 100644 --- a/src/ansiblelint/skip_utils.py +++ b/src/ansiblelint/skip_utils.py @@ -1,4 +1,4 @@ -# (c) 2019–2020, Ansible by Red Hat +# (c) 2019-2020, Ansible by Red Hat # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/src/ansiblelint/testing/__init__.py b/src/ansiblelint/testing/__init__.py index a153917324..22c1f3071c 100644 --- a/src/ansiblelint/testing/__init__.py +++ b/src/ansiblelint/testing/__init__.py @@ -15,12 +15,12 @@ # https://github.com/PyCQA/pylint/issues/3240 # pylint: disable=unsubscriptable-object CompletedProcess = subprocess.CompletedProcess[Any] - from ansiblelint.errors import MatchError # noqa: E402 + from ansiblelint.errors import MatchError else: CompletedProcess = subprocess.CompletedProcess # pylint: disable=wrong-import-position -from ansiblelint.runner import Runner # noqa: E402 +from ansiblelint.runner import Runner class RunFromText: diff --git a/src/ansiblelint/testing/fixtures.py b/src/ansiblelint/testing/fixtures.py index 41b954e56a..a138f369fb 100644 --- a/src/ansiblelint/testing/fixtures.py +++ b/src/ansiblelint/testing/fixtures.py @@ -14,7 +14,7 @@ import pytest from _pytest.fixtures import SubRequest -from ansiblelint.config import Options, options # noqa: F401 +from ansiblelint.config import Options, options from ansiblelint.constants import DEFAULT_RULESDIR from ansiblelint.rules import RulesCollection from ansiblelint.testing import RunFromText diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index fd3ab47b66..32ccebe76e 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -617,7 +617,7 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]: _extract_ansible_parsed_keys_from_task( result, task, - ansible_parsed_keys + (action,), + (*ansible_parsed_keys, action), ) if not isinstance(action, str): diff --git a/src/ansiblelint/yaml_utils.py b/src/ansiblelint/yaml_utils.py index bd6155d344..d87109f9e2 100644 --- a/src/ansiblelint/yaml_utils.py +++ b/src/ansiblelint/yaml_utils.py @@ -212,7 +212,7 @@ def _nested_items_path( if isinstance(value, (dict, list)): yield from _nested_items_path( data_collection=value, - parent_path=parent_path + [key], + parent_path=[*parent_path, key], ) @@ -423,7 +423,7 @@ def _get_path_to_task_in_nested_tasks_block( last_lineno_in_block, # 1-based ) if subtask_path: - return [task_key] + list(subtask_path) + return [task_key, *list(subtask_path)] # line is not part of this nested tasks block return [] @@ -623,7 +623,7 @@ def add_octothorpe_protection(string: str) -> str: """Modify strings to protect "#" from full-line-comment post-processing.""" try: if "#" in string: - # # is \uFF03 (fullwidth number sign) + # # is \uFF03 (fullwidth number sign) # ﹟ is \uFE5F (small number sign) string = string.replace("#", "\uFF03#\uFE5F") # this is safe even if this sequence is present @@ -638,7 +638,7 @@ def drop_octothorpe_protection(string: str) -> str: """Remove string protection of "#" after full-line-comment post-processing.""" try: if "\uFF03#\uFE5F" in string: - # # is \uFF03 (fullwidth number sign) + # # is \uFF03 (fullwidth number sign) # ﹟ is \uFE5F (small number sign) string = string.replace("\uFF03#\uFE5F", "#") except (ValueError, TypeError): diff --git a/test/test_cli.py b/test/test_cli.py index 5754cbe0ca..8bd6681a09 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -113,21 +113,21 @@ def test_ensure_write_cli_does_not_consume_lintables( def test_config_can_be_overridden(base_arguments: list[str]) -> None: """Check that config can be overridden from CLI.""" - no_override = cli.get_config(base_arguments + ["-t", "bad_tag"]) + no_override = cli.get_config([*base_arguments, "-t", "bad_tag"]) overridden = cli.get_config( - base_arguments + ["-t", "bad_tag", "-c", "test/fixtures/tags.yml"], + [*base_arguments, "-t", "bad_tag", "-c", "test/fixtures/tags.yml"], ) - assert no_override.tags + ["skip_ansible_lint"] == overridden.tags + assert [*no_override.tags, "skip_ansible_lint"] == overridden.tags def test_different_config_file(base_arguments: list[str]) -> None: """Ensures an alternate config_file can be used.""" diff_config = cli.get_config( - base_arguments + ["-c", "test/fixtures/ansible-config.yml"], + [*base_arguments, "-c", "test/fixtures/ansible-config.yml"], ) - no_config = cli.get_config(base_arguments + ["-v"]) + no_config = cli.get_config([*base_arguments, "-v"]) assert diff_config.verbosity == no_config.verbosity @@ -135,11 +135,16 @@ def test_different_config_file(base_arguments: list[str]) -> None: def test_expand_path_user_and_vars_config_file(base_arguments: list[str]) -> None: """Ensure user and vars are expanded when specified as exclude_paths.""" config1 = cli.get_config( - base_arguments + ["-c", "test/fixtures/exclude-paths-with-expands.yml"], + [*base_arguments, "-c", "test/fixtures/exclude-paths-with-expands.yml"], ) config2 = cli.get_config( - base_arguments - + ["--exclude", "~/.ansible/roles", "--exclude", "$HOME/.ansible/roles"], + [ + *base_arguments, + "--exclude", + "~/.ansible/roles", + "--exclude", + "$HOME/.ansible/roles", + ], ) assert str(config1.exclude_paths[0]) == os.path.expanduser("~/.ansible/roles") @@ -171,7 +176,8 @@ def test_path_from_cli_depend_on_cwd( ) -> None: """Check that CLI-provided paths are relative to CWD.""" # Issue 572 - arguments = base_arguments + [ + arguments = [ + *base_arguments, "--exclude", "test/fixtures/config-with-relative-path.yml", ] @@ -196,13 +202,13 @@ def test_path_from_cli_depend_on_cwd( def test_config_failure(base_arguments: list[str], config_file: str) -> None: """Ensures specific config files produce error code 3.""" with pytest.raises(SystemExit, match="^3$"): - cli.get_config(base_arguments + ["-c", config_file]) + cli.get_config([*base_arguments, "-c", config_file]) def test_extra_vars_loaded(base_arguments: list[str]) -> None: """Ensure ``extra_vars`` option is loaded from file config.""" config = cli.get_config( - base_arguments + ["-c", "test/fixtures/config-with-extra-vars.yml"], + [*base_arguments, "-c", "test/fixtures/config-with-extra-vars.yml"], ) assert config.extra_vars == {"foo": "bar", "knights_favorite_word": "NI"} @@ -214,5 +220,5 @@ def test_extra_vars_loaded(base_arguments: list[str]) -> None: ) def test_config_dev_null(base_arguments: list[str], config_file: str) -> None: """Ensures specific config files produce error code 3.""" - cfg = cli.get_config(base_arguments + ["-c", config_file]) + cfg = cli.get_config([*base_arguments, "-c", config_file]) assert cfg.config_file == "/dev/null"