From 1ede26aa76de6d3c019641d969cbbefa287bfe05 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 6 Oct 2023 17:24:47 +0100 Subject: [PATCH] Update linters (#3821) --- .pre-commit-config.yaml | 6 +++--- pyproject.toml | 5 ++++- src/ansiblelint/__main__.py | 2 +- src/ansiblelint/config.py | 3 +-- src/ansiblelint/file_utils.py | 2 +- src/ansiblelint/rules/__init__.py | 1 - src/ansiblelint/rules/args.py | 2 +- src/ansiblelint/rules/avoid_implicit.py | 4 ++-- src/ansiblelint/rules/command_instead_of_module.py | 5 +++-- src/ansiblelint/rules/command_instead_of_shell.py | 5 +++-- src/ansiblelint/rules/complexity.py | 5 +++-- src/ansiblelint/rules/deprecated_local_action.py | 4 ++-- src/ansiblelint/rules/empty_string_compare.py | 4 ++-- src/ansiblelint/rules/fqcn.py | 2 +- src/ansiblelint/rules/galaxy.py | 1 - src/ansiblelint/rules/ignore_errors.py | 2 +- src/ansiblelint/rules/jinja.py | 12 ++++-------- src/ansiblelint/rules/key_order.py | 5 +++-- src/ansiblelint/rules/literal_compare.py | 5 +++-- src/ansiblelint/rules/loop_var_prefix.py | 5 +++-- src/ansiblelint/rules/meta_incorrect.py | 4 ++-- src/ansiblelint/rules/meta_runtime.py | 5 +++-- src/ansiblelint/rules/meta_video_links.py | 5 +++-- src/ansiblelint/rules/name.py | 1 - src/ansiblelint/rules/no_changed_when.py | 5 +++-- src/ansiblelint/rules/no_free_form.py | 5 +++-- src/ansiblelint/rules/no_handler.py | 5 +++-- src/ansiblelint/rules/no_log_password.py | 2 +- src/ansiblelint/rules/no_prompting.py | 4 ++-- src/ansiblelint/rules/no_relative_paths.py | 5 +++-- src/ansiblelint/rules/no_same_owner.py | 5 +++-- src/ansiblelint/rules/no_tabs.py | 4 ++-- src/ansiblelint/rules/partial_become.py | 4 ++-- src/ansiblelint/rules/playbook_extension.py | 3 ++- src/ansiblelint/rules/risky_file_permissions.py | 5 +++-- src/ansiblelint/rules/risky_shell_pipe.py | 5 +++-- src/ansiblelint/rules/role_name.py | 5 +++-- src/ansiblelint/rules/run_once.py | 6 +++--- src/ansiblelint/rules/sanity.py | 5 +++-- src/ansiblelint/runner.py | 1 - src/ansiblelint/testing/__init__.py | 1 - src/ansiblelint/testing/fixtures.py | 2 +- src/ansiblelint/transformer.py | 1 - src/ansiblelint/utils.py | 7 +------ src/ansiblelint/yaml_utils.py | 9 ++++----- .../test_collection/plugins/filter/test_filter.py | 1 - .../roles/role2/test_plugins/b_failed_complete.py | 1 - test/rules/test_inline_env_var.py | 2 +- test/test_examples.py | 2 +- test/test_formatter_base.py | 8 ++------ 50 files changed, 98 insertions(+), 100 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed19257ae4..ac49de5e31 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -101,7 +101,7 @@ repos: - id: debug-statements language_version: python3 - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.2.6 hooks: - id: codespell exclude: > @@ -130,7 +130,7 @@ repos: types: [file, yaml] entry: yamllint --strict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.0.291" + rev: "v0.0.292" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -169,7 +169,7 @@ repos: plugins/.* )$ - repo: https://github.com/pycqa/pylint - rev: v3.0.0b0 + rev: v3.0.1 hooks: - id: pylint args: diff --git a/pyproject.toml b/pyproject.toml index 538bedeb40..681251aa3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -160,6 +160,9 @@ enable = [ "useless-suppression", # Identify unneeded pylint disable statements ] +[tool.pylint.REPORTING] +output-format = "colorized" + [tool.pylint.TYPECHECK] # pylint is unable to detect Namespace attributes and will throw a E1101 generated-members = "options.*" @@ -233,7 +236,7 @@ python_files = [ xfail_strict = true [tool.ruff] -required-version = "0.0.291" +required-version = "0.0.292" ignore = [ "D203", # incompatible with D211 "D213", # incompatible with D212 diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index f4edbf8cd7..6df19d2dad 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -271,7 +271,7 @@ def fix(runtime_options: Options, result: LintResult, rules: RulesCollection) -> result.matches.pop(idx) -# pylint: disable=too-many-statements,too-many-locals +# pylint: disable=too-many-locals def main(argv: list[str] | None = None) -> int: """Linter CLI entry point.""" # alter PATH if needed (venv support) diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 39188574bd..b65dc26782 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -104,7 +104,7 @@ @dataclass -class Options: # pylint: disable=too-many-instance-attributes,too-few-public-methods +class Options: # pylint: disable=too-many-instance-attributes """Store ansible-lint effective configuration options.""" # Private attributes @@ -247,7 +247,6 @@ def guess_install_method() -> str: else: logging.debug("Skipping %s as it is not installed.", package_name) use_pip = False - # pylint: disable=broad-except except (AttributeError, ModuleNotFoundError) as exc: # On Fedora 36, we got a AttributeError exception from pip that we want to avoid # On NixOS, we got a ModuleNotFoundError exception from pip that we want to avoid diff --git a/src/ansiblelint/file_utils.py b/src/ansiblelint/file_utils.py index a39a7de805..4452d029e9 100644 --- a/src/ansiblelint/file_utils.py +++ b/src/ansiblelint/file_utils.py @@ -254,7 +254,7 @@ def __init__( self.parent = _guess_parent(self) if self.kind == "yaml": - _ = self.data # pylint: disable=pointless-statement + _ = self.data if self.kind == "plugin": # pylint: disable=consider-using-with diff --git a/src/ansiblelint/rules/__init__.py b/src/ansiblelint/rules/__init__.py index 305ffde565..05949b8c3b 100644 --- a/src/ansiblelint/rules/__init__.py +++ b/src/ansiblelint/rules/__init__.py @@ -328,7 +328,6 @@ def transform(self, match, lintable, data): return target -# pylint: disable=too-many-nested-blocks def load_plugins( dirs: list[str], ) -> Iterator[AnsibleLintRule]: diff --git a/src/ansiblelint/rules/args.py b/src/ansiblelint/rules/args.py index 2acf32e18b..272de1e271 100644 --- a/src/ansiblelint/rules/args.py +++ b/src/ansiblelint/rules/args.py @@ -103,7 +103,7 @@ def matchtask( task: Task, file: Lintable | None = None, ) -> list[MatchError]: - # pylint: disable=too-many-locals,too-many-return-statements + # pylint: disable=too-many-return-statements results: list[MatchError] = [] module_name = task["action"]["__ansible_module_original__"] failed_msg = None diff --git a/src/ansiblelint/rules/avoid_implicit.py b/src/ansiblelint/rules/avoid_implicit.py index 8d1fe26058..d2c683a331 100644 --- a/src/ansiblelint/rules/avoid_implicit.py +++ b/src/ansiblelint/rules/avoid_implicit.py @@ -40,8 +40,8 @@ def matchtask( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_template_instead_of_copy_positive() -> None: """Positive test for avoid-implicit.""" diff --git a/src/ansiblelint/rules/command_instead_of_module.py b/src/ansiblelint/rules/command_instead_of_module.py index d792a4364c..a2fe8bc0b9 100644 --- a/src/ansiblelint/rules/command_instead_of_module.py +++ b/src/ansiblelint/rules/command_instead_of_module.py @@ -108,8 +108,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/command_instead_of_shell.py b/src/ansiblelint/rules/command_instead_of_shell.py index 09675c431d..0278f27d9c 100644 --- a/src/ansiblelint/rules/command_instead_of_shell.py +++ b/src/ansiblelint/rules/command_instead_of_shell.py @@ -83,8 +83,9 @@ def transform( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/complexity.py b/src/ansiblelint/rules/complexity.py index 2b93690c98..b48937faab 100644 --- a/src/ansiblelint/rules/complexity.py +++ b/src/ansiblelint/rules/complexity.py @@ -76,8 +76,9 @@ def calculate_block_depth(self, task: Task) -> int: if "pytest" in sys.modules: import pytest - from ansiblelint.config import options # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.config import options + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected_results"), diff --git a/src/ansiblelint/rules/deprecated_local_action.py b/src/ansiblelint/rules/deprecated_local_action.py index b7557d3bbd..c1a77b0b2c 100644 --- a/src/ansiblelint/rules/deprecated_local_action.py +++ b/src/ansiblelint/rules/deprecated_local_action.py @@ -84,8 +84,8 @@ def transform( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_local_action(default_rules_collection: RulesCollection) -> None: """Positive test deprecated_local_action.""" diff --git a/src/ansiblelint/rules/empty_string_compare.py b/src/ansiblelint/rules/empty_string_compare.py index 5c7cafc88d..74ae117c82 100644 --- a/src/ansiblelint/rules/empty_string_compare.py +++ b/src/ansiblelint/rules/empty_string_compare.py @@ -54,8 +54,8 @@ def matchtask( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_rule_empty_string_compare_fail() -> None: """Test rule matches.""" diff --git a/src/ansiblelint/rules/fqcn.py b/src/ansiblelint/rules/fqcn.py index 5f1fcf9933..5a7b335db0 100644 --- a/src/ansiblelint/rules/fqcn.py +++ b/src/ansiblelint/rules/fqcn.py @@ -241,7 +241,7 @@ def transform( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: from ansiblelint.rules import RulesCollection - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.runner import Runner def test_fqcn_builtin_fail() -> None: """Test rule matches.""" diff --git a/src/ansiblelint/rules/galaxy.py b/src/ansiblelint/rules/galaxy.py index 5aad4d75e4..5c1b28e447 100644 --- a/src/ansiblelint/rules/galaxy.py +++ b/src/ansiblelint/rules/galaxy.py @@ -122,7 +122,6 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]: results.append( self.create_matcherror( message="collection version should be greater than or equal to 1.0.0", - # pylint: disable=protected-access lineno=version._line_number, # noqa: SLF001 tag="galaxy[version-incorrect]", filename=file, diff --git a/src/ansiblelint/rules/ignore_errors.py b/src/ansiblelint/rules/ignore_errors.py index 4144f2d5e7..5b87cbe2c5 100644 --- a/src/ansiblelint/rules/ignore_errors.py +++ b/src/ansiblelint/rules/ignore_errors.py @@ -44,7 +44,7 @@ def matchtask( import pytest if TYPE_CHECKING: - from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports + from ansiblelint.testing import RunFromText IGNORE_ERRORS_TRUE = """ - hosts: all diff --git a/src/ansiblelint/rules/jinja.py b/src/ansiblelint/rules/jinja.py index ff147d420c..a00eaea17f 100644 --- a/src/ansiblelint/rules/jinja.py +++ b/src/ansiblelint/rules/jinja.py @@ -219,7 +219,6 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if str(file.kind) == "vars": data = parse_yaml_from_file(str(file.path)) - # pylint: disable=unused-variable for key, v, _path in nested_items_path(data): if isinstance(v, AnsibleUnicode): reformatted, details, tag = self.check_whitespace( @@ -287,7 +286,7 @@ def unlex(self, tokens: list[Token]) -> str: last_value = value return result - # pylint: disable=too-many-statements,too-many-locals + # pylint: disable=too-many-locals def check_whitespace( self, text: str, @@ -386,8 +385,6 @@ def uncook(value: str, *, implicit: bool = False) -> str: except jinja2.exceptions.TemplateSyntaxError as exc: return "", str(exc.message), "invalid" - # https://github.com/PyCQA/pylint/issues/7433 - py311 only - # pylint: disable=c-extension-no-member except (NotImplementedError, black.parsing.InvalidInput) as exc: # black is not able to recognize all valid jinja2 templates, so we # just ignore InvalidInput errors. @@ -482,11 +479,10 @@ def blacken(text: str) -> str: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner - # pylint: disable=ungrouped-imports - from ansiblelint.transformer import Transformer # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner + from ansiblelint.transformer import Transformer @pytest.fixture(name="error_expected_lines") def fixture_error_expected_lines() -> list[int]: diff --git a/src/ansiblelint/rules/key_order.py b/src/ansiblelint/rules/key_order.py index 16b058914c..06b8b53d3c 100644 --- a/src/ansiblelint/rules/key_order.py +++ b/src/ansiblelint/rules/key_order.py @@ -116,8 +116,9 @@ def transform( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/literal_compare.py b/src/ansiblelint/rules/literal_compare.py index 1129d1dd2b..5c49c3b9b5 100644 --- a/src/ansiblelint/rules/literal_compare.py +++ b/src/ansiblelint/rules/literal_compare.py @@ -55,8 +55,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/loop_var_prefix.py b/src/ansiblelint/rules/loop_var_prefix.py index 8f1bb5659a..056636b2e8 100644 --- a/src/ansiblelint/rules/loop_var_prefix.py +++ b/src/ansiblelint/rules/loop_var_prefix.py @@ -81,8 +81,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/meta_incorrect.py b/src/ansiblelint/rules/meta_incorrect.py index 4252254e07..0981f49088 100644 --- a/src/ansiblelint/rules/meta_incorrect.py +++ b/src/ansiblelint/rules/meta_incorrect.py @@ -56,8 +56,8 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_default_galaxy_info( default_rules_collection: RulesCollection, diff --git a/src/ansiblelint/rules/meta_runtime.py b/src/ansiblelint/rules/meta_runtime.py index 18c7d788ab..99f2f96661 100644 --- a/src/ansiblelint/rules/meta_runtime.py +++ b/src/ansiblelint/rules/meta_runtime.py @@ -80,8 +80,9 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures", "tags"), diff --git a/src/ansiblelint/rules/meta_video_links.py b/src/ansiblelint/rules/meta_video_links.py index 5d4941abf0..806e73f429 100644 --- a/src/ansiblelint/rules/meta_video_links.py +++ b/src/ansiblelint/rules/meta_video_links.py @@ -86,8 +86,9 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/name.py b/src/ansiblelint/rules/name.py index a6ae7ca422..ced0e74ca0 100644 --- a/src/ansiblelint/rules/name.py +++ b/src/ansiblelint/rules/name.py @@ -255,6 +255,5 @@ def test_name_template() -> None: def test_when_no_lintable() -> None: """Test when lintable is None.""" name_rule = NameRule() - # pylint: disable=protected-access result = name_rule._prefix_check("Foo", None, 1) # noqa: SLF001 assert len(result) == 0 diff --git a/src/ansiblelint/rules/no_changed_when.py b/src/ansiblelint/rules/no_changed_when.py index 28ba4275fe..110d414ad2 100644 --- a/src/ansiblelint/rules/no_changed_when.py +++ b/src/ansiblelint/rules/no_changed_when.py @@ -75,8 +75,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/no_free_form.py b/src/ansiblelint/rules/no_free_form.py index 6fb1dbcf48..7d6faa8cee 100644 --- a/src/ansiblelint/rules/no_free_form.py +++ b/src/ansiblelint/rules/no_free_form.py @@ -164,8 +164,9 @@ def filter_values( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/no_handler.py b/src/ansiblelint/rules/no_handler.py index 165bbf43e0..8cbb111578 100644 --- a/src/ansiblelint/rules/no_handler.py +++ b/src/ansiblelint/rules/no_handler.py @@ -86,8 +86,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/no_log_password.py b/src/ansiblelint/rules/no_log_password.py index 29b06f948c..5156dad7c7 100644 --- a/src/ansiblelint/rules/no_log_password.py +++ b/src/ansiblelint/rules/no_log_password.py @@ -97,7 +97,7 @@ def transform( import pytest if TYPE_CHECKING: - from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports + from ansiblelint.testing import RunFromText NO_LOG_UNUSED = """ - name: Test diff --git a/src/ansiblelint/rules/no_prompting.py b/src/ansiblelint/rules/no_prompting.py index 662277157f..1a2db27cd7 100644 --- a/src/ansiblelint/rules/no_prompting.py +++ b/src/ansiblelint/rules/no_prompting.py @@ -61,8 +61,8 @@ def matchtask( if "pytest" in sys.modules: from ansiblelint.config import options - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_no_prompting_fail() -> None: """Negative test for no-prompting.""" diff --git a/src/ansiblelint/rules/no_relative_paths.py b/src/ansiblelint/rules/no_relative_paths.py index 470b1b840d..f1700782c2 100644 --- a/src/ansiblelint/rules/no_relative_paths.py +++ b/src/ansiblelint/rules/no_relative_paths.py @@ -53,8 +53,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/no_same_owner.py b/src/ansiblelint/rules/no_same_owner.py index 021900e984..b4956ce647 100644 --- a/src/ansiblelint/rules/no_same_owner.py +++ b/src/ansiblelint/rules/no_same_owner.py @@ -84,8 +84,9 @@ def handle_unarchive(task: Any, action: dict[str, Any]) -> bool: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures"), diff --git a/src/ansiblelint/rules/no_tabs.py b/src/ansiblelint/rules/no_tabs.py index c53f1bbd4b..7bc48fe75b 100644 --- a/src/ansiblelint/rules/no_tabs.py +++ b/src/ansiblelint/rules/no_tabs.py @@ -53,8 +53,8 @@ def matchtask( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_no_tabs_rule(default_rules_collection: RulesCollection) -> None: """Test rule matches.""" diff --git a/src/ansiblelint/rules/partial_become.py b/src/ansiblelint/rules/partial_become.py index b8dc417052..3988951d75 100644 --- a/src/ansiblelint/rules/partial_become.py +++ b/src/ansiblelint/rules/partial_become.py @@ -233,8 +233,8 @@ def _attach_comment_end( # testing code to be loaded only with pytest or when executed the rule file if "pytest" in sys.modules: - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner def test_partial_become_pass() -> None: """No errors found for partial-become.""" diff --git a/src/ansiblelint/rules/playbook_extension.py b/src/ansiblelint/rules/playbook_extension.py index b4ca41ca28..e853b6b645 100644 --- a/src/ansiblelint/rules/playbook_extension.py +++ b/src/ansiblelint/rules/playbook_extension.py @@ -39,7 +39,8 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/risky_file_permissions.py b/src/ansiblelint/rules/risky_file_permissions.py index f4494eb41e..7fe3870509 100644 --- a/src/ansiblelint/rules/risky_file_permissions.py +++ b/src/ansiblelint/rules/risky_file_permissions.py @@ -137,8 +137,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.testing import RunFromText @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/risky_shell_pipe.py b/src/ansiblelint/rules/risky_shell_pipe.py index 58a6f5f08f..68e0609349 100644 --- a/src/ansiblelint/rules/risky_shell_pipe.py +++ b/src/ansiblelint/rules/risky_shell_pipe.py @@ -62,8 +62,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("file", "expected"), diff --git a/src/ansiblelint/rules/role_name.py b/src/ansiblelint/rules/role_name.py index 499c0869a9..a15f95538e 100644 --- a/src/ansiblelint/rules/role_name.py +++ b/src/ansiblelint/rules/role_name.py @@ -151,8 +151,9 @@ def _infer_role_name(meta: Path, default: str) -> str: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failure"), diff --git a/src/ansiblelint/rules/run_once.py b/src/ansiblelint/rules/run_once.py index 78968b669f..eebdb4128c 100644 --- a/src/ansiblelint/rules/run_once.py +++ b/src/ansiblelint/rules/run_once.py @@ -43,7 +43,6 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]: message="Play uses strategy: free", filename=file, tag=f"{self.id}[play]", - # pylint: disable=protected-access lineno=strategy._line_number, # noqa: SLF001 ), ] @@ -74,8 +73,9 @@ def matchtask( if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failure"), diff --git a/src/ansiblelint/rules/sanity.py b/src/ansiblelint/rules/sanity.py index 632f8768b4..a8ad6dd2eb 100644 --- a/src/ansiblelint/rules/sanity.py +++ b/src/ansiblelint/rules/sanity.py @@ -125,8 +125,9 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if "pytest" in sys.modules: import pytest - from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports - from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports + # pylint: disable=ungrouped-imports + from ansiblelint.rules import RulesCollection + from ansiblelint.runner import Runner @pytest.mark.parametrize( ("test_file", "failures", "tags"), diff --git a/src/ansiblelint/runner.py b/src/ansiblelint/runner.py index 04fcb15b23..6c2db41436 100644 --- a/src/ansiblelint/runner.py +++ b/src/ansiblelint/runner.py @@ -240,7 +240,6 @@ def _run(self) -> list[MatchError]: app = get_app(offline=True) def worker(lintable: Lintable) -> list[MatchError]: - # pylint: disable=protected-access return self._get_ansible_syntax_check_matches( lintable=lintable, app=app, diff --git a/src/ansiblelint/testing/__init__.py b/src/ansiblelint/testing/__init__.py index e7f6c1b57f..a19a1e0d1d 100644 --- a/src/ansiblelint/testing/__init__.py +++ b/src/ansiblelint/testing/__init__.py @@ -13,7 +13,6 @@ if TYPE_CHECKING: # https://github.com/PyCQA/pylint/issues/3240 - # pylint: disable=unsubscriptable-object CompletedProcess = subprocess.CompletedProcess[Any] from ansiblelint.errors import MatchError from ansiblelint.rules import RulesCollection diff --git a/src/ansiblelint/testing/fixtures.py b/src/ansiblelint/testing/fixtures.py index 6d0cca4587..415e3ce889 100644 --- a/src/ansiblelint/testing/fixtures.py +++ b/src/ansiblelint/testing/fixtures.py @@ -61,7 +61,7 @@ def rule_runner(request: SubRequest, config_options: Options) -> RunFromText: @pytest.fixture(name="config_options") def fixture_config_options() -> Iterator[Options]: """Return configuration options that will be restored after testrun.""" - global options # pylint: disable=global-statement,invalid-name # noqa: PLW0603 + global options # pylint: disable=global-statement # noqa: PLW0603 original_options = copy.deepcopy(options) yield options options = original_options diff --git a/src/ansiblelint/transformer.py b/src/ansiblelint/transformer.py index 5e7d828d2e..1eca524863 100644 --- a/src/ansiblelint/transformer.py +++ b/src/ansiblelint/transformer.py @@ -20,7 +20,6 @@ _logger = logging.getLogger(__name__) -# pylint: disable=too-few-public-methods class Transformer: """Transformer class marshals transformations. diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index 85e91177e3..a16d4d8236 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -186,7 +186,6 @@ def ansible_template( _logger.warning(err) raise - # pylint: disable=protected-access templar.environment.filters._delegatee[ # noqa: SLF001 missing_filter ] = mock_filter @@ -566,7 +565,6 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]: skip_action_validation=options.skip_action_validation, ) except AnsibleParserError as exc: - # pylint: disable=raise-missing-from raise MatchError( rule=AnsibleParserErrorRule(), message=exc.message, @@ -878,9 +876,7 @@ def construct_mapping( if hasattr(node, "__line__"): mapping[LINE_NUMBER_KEY] = node.__line__ else: - mapping[ - LINE_NUMBER_KEY - ] = mapping._line_number # pylint: disable=protected-access # noqa: SLF001 + mapping[LINE_NUMBER_KEY] = mapping._line_number # noqa: SLF001 mapping[FILENAME_KEY] = lintable.path return mapping @@ -983,7 +979,6 @@ def is_playbook(filename: str) -> bool: return False -# pylint: disable=too-many-statements def get_lintables( opts: Options = options, args: list[str] | None = None, diff --git a/src/ansiblelint/yaml_utils.py b/src/ansiblelint/yaml_utils.py index 4d2490f4d9..851f96ca13 100644 --- a/src/ansiblelint/yaml_utils.py +++ b/src/ansiblelint/yaml_utils.py @@ -33,7 +33,7 @@ if TYPE_CHECKING: # noinspection PyProtectedMember - from ruamel.yaml.comments import LineCol # pylint: disable=ungrouped-imports + from ruamel.yaml.comments import LineCol from ruamel.yaml.nodes import ScalarNode from ruamel.yaml.representer import RoundTripRepresenter from ruamel.yaml.tokens import CommentToken @@ -233,7 +233,7 @@ def get_path_to_play( raise ValueError(msg) if lintable.kind != "playbook" or not isinstance(ruamel_data, CommentedSeq): return [] - lc: LineCol # lc uses 0-based counts # pylint: disable=invalid-name + lc: LineCol # lc uses 0-based counts # lineno is 1-based. Convert to 0-based. line_index = lineno - 1 @@ -246,7 +246,7 @@ def get_path_to_play( else: next_play_line_index = None - lc = play.lc # pylint: disable=invalid-name + lc = play.lc if not isinstance(lc.line, int): msg = f"expected lc.line to be an int, got {lc.line!r}" raise RuntimeError(msg) @@ -462,7 +462,6 @@ def represent_octal(representer: RoundTripRepresenter, data: OctalIntYAML11) -> v = format(data, "o") anchor = data.yaml_anchor(any=True) # noinspection PyProtectedMember - # pylint: disable=protected-access return representer.insert_underscore( "0", v, @@ -981,7 +980,7 @@ def _prevent_wrapping_flow_style(self, data: Any) -> None: for key, value, parent_path in nested_items_path(data): if not isinstance(value, (CommentedMap, CommentedSeq)): continue - fa: Format = value.fa # pylint: disable=invalid-name + fa: Format = value.fa if fa.flow_style(): predicted_indent = self._predict_indent_length(parent_path, key) predicted_width = len(str(value)) diff --git a/test/local-content/collections/ansible_collections/testns/test_collection/plugins/filter/test_filter.py b/test/local-content/collections/ansible_collections/testns/test_collection/plugins/filter/test_filter.py index 58bc269b8c..6244329662 100644 --- a/test/local-content/collections/ansible_collections/testns/test_collection/plugins/filter/test_filter.py +++ b/test/local-content/collections/ansible_collections/testns/test_collection/plugins/filter/test_filter.py @@ -1,5 +1,4 @@ """A filter plugin.""" -# pylint: disable=invalid-name def a_test_filter(a, b): diff --git a/test/local-content/test-roles-failed-complete/roles/role2/test_plugins/b_failed_complete.py b/test/local-content/test-roles-failed-complete/roles/role2/test_plugins/b_failed_complete.py index 92bd6e7323..63f4532afd 100644 --- a/test/local-content/test-roles-failed-complete/roles/role2/test_plugins/b_failed_complete.py +++ b/test/local-content/test-roles-failed-complete/roles/role2/test_plugins/b_failed_complete.py @@ -1,5 +1,4 @@ """A test plugin.""" -# pylint: disable=invalid-name def compatibility_in_test(a, b): diff --git a/test/rules/test_inline_env_var.py b/test/rules/test_inline_env_var.py index 98f337e7d2..78d757e1f3 100644 --- a/test/rules/test_inline_env_var.py +++ b/test/rules/test_inline_env_var.py @@ -68,7 +68,7 @@ command: HELLO=hello echo $HELLO - name: Typo some stuff - command: cerates=/tmp/blah warn=no touch /tmp/blah + command: crates=/tmp/blah warn=no touch /tmp/blah """ diff --git a/test/test_examples.py b/test/test_examples.py index 2842930b8b..246c4a385f 100644 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -67,7 +67,7 @@ def test_vault_partial( default_rules_collection: RulesCollection, caplog: pytest.LogCaptureFixture, ) -> None: - """Check ability to precess files that container !vault inside.""" + """Check ability to process files that container !vault inside.""" result = Runner( "examples/playbooks/vars/vault_partial.yml", rules=default_rules_collection, diff --git a/test/test_formatter_base.py b/test/test_formatter_base.py index 8a91bb2d85..1199b5e263 100644 --- a/test/test_formatter_base.py +++ b/test/test_formatter_base.py @@ -28,10 +28,8 @@ def test_base_formatter_when_base_dir( base_formatter = BaseFormatter(base_dir, relative_path) # type: ignore[var-annotated] # When - output_path = ( - base_formatter._format_path( # pylint: disable=protected-access # noqa: SLF001 - path, - ) + output_path = base_formatter._format_path( # noqa: SLF001 + path, ) # Then @@ -60,12 +58,10 @@ def test_base_formatter_when_base_dir_is_given_and_relative_is_true( base_formatter = BaseFormatter(base_dir, True) # type: ignore[var-annotated] # When - # pylint: disable=protected-access output_path = base_formatter._format_path(path) # noqa: SLF001 # Then assert isinstance(output_path, (str, Path)) - # pylint: disable=protected-access assert isinstance(base_formatter.base_dir, (str, Path)) assert output_path == Path(path).name