Skip to content

Commit

Permalink
Update linters (#3821)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Oct 6, 2023
1 parent e710099 commit 1ede26a
Show file tree
Hide file tree
Showing 50 changed files with 98 additions and 100 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -169,7 +169,7 @@ repos:
plugins/.*
)$
- repo: https://github.com/pycqa/pylint
rev: v3.0.0b0
rev: v3.0.1
hooks:
- id: pylint
args:
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/avoid_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/command_instead_of_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/command_instead_of_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/deprecated_local_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/empty_string_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/fqcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/ignore_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]:
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/key_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/literal_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/loop_var_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/meta_incorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/meta_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/meta_video_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_changed_when.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_free_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/no_log_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/no_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_relative_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_same_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Loading

0 comments on commit 1ede26a

Please sign in to comment.