Skip to content

Commit 2dcdc97

Browse files
authored
Update linters (#4640)
1 parent 4bc37cb commit 2dcdc97

17 files changed

+79
-54
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,14 @@ repos:
145145
- id: tox-ini-fmt
146146

147147
- repo: https://github.com/astral-sh/ruff-pre-commit
148-
rev: v0.11.12
148+
rev: v0.11.13
149149
hooks:
150-
- id: ruff
151-
args:
152-
- --fix
153-
- --exit-non-zero-on-fix
154-
types_or: [python, pyi]
155-
# - id: ruff-format # must be after ruff
156-
# types_or: [python, pyi]
150+
- id: ruff-format
151+
alias: ruff
152+
- id: ruff-check
153+
alias: ruff
157154
- repo: https://github.com/pre-commit/mirrors-mypy
158-
rev: v1.16.0
155+
rev: v1.16.1
159156
hooks:
160157
- id: mypy
161158
# "." and pass_files are used to make pre-commit mypy behave the same as standalone mypy
@@ -181,7 +178,7 @@ repos:
181178
- wcmatch
182179
- yamllint>=1.34.0
183180
- repo: https://github.com/RobertCraigie/pyright-python
184-
rev: v1.1.401
181+
rev: v1.1.402
185182
hooks:
186183
- id: pyright
187184
additional_dependencies: *deps

src/ansiblelint/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,14 @@ def main(argv: list[str] | None = None) -> int:
392392
# load ignore file
393393
ignore_map = load_ignore_txt(options.ignore_file)
394394
# prune qualified skips from ignore file
395-
result.matches = [m for m in result.matches if not _rule_is_skipped(m.tag, ignore_map[m.filename])]
395+
result.matches = [
396+
m for m in result.matches if not _rule_is_skipped(m.tag, ignore_map[m.filename])
397+
]
396398
# others entries are ignored
397399
for match in result.matches:
398-
if match.tag in [i.rule for i in ignore_map[match.filename]]: # pragma: no cover
400+
if match.tag in [
401+
i.rule for i in ignore_map[match.filename]
402+
]: # pragma: no cover
399403
match.ignored = True
400404
_logger.debug("Ignored: %s", match)
401405

src/ansiblelint/formatters/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def apply(self, match: MatchError) -> str:
9696
result = (
9797
f"[repr.path]{self._format_path(match.filename or '')}[/][dim]:{match.position}:[/] "
9898
f"[{match.level}][bold]{self.escape(match.tag)}[/]"
99-
f"{ f': {match.message}' if not options.quiet else '' }[/]"
99+
f"{f': {match.message}' if not options.quiet else ''}[/]"
100100
)
101101
if match.level != "error":
102102
result += f" [dim][{match.level}]({match.level})[/][/]"
@@ -307,9 +307,9 @@ def _to_sarif_result(self, match: MatchError) -> dict[str, Any]:
307307
],
308308
}
309309
if match.column:
310-
result["locations"][0]["physicalLocation"]["region"][
311-
"startColumn"
312-
] = match.column
310+
result["locations"][0]["physicalLocation"]["region"]["startColumn"] = (
311+
match.column
312+
)
313313
return result
314314

315315
@staticmethod

src/ansiblelint/loaders.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@
2424

2525
class IgnoreFile(NamedTuple):
2626
"""IgnoreFile n."""
27+
2728
default: str
2829
alternative: str
2930

3031

3132
class IgnoreRuleQualifier(enum.Enum):
3233
"""Extra flags for ignored rules."""
34+
3335
SKIP = "Force skip, not warning"
3436

3537

3638
class IgnoreRule(NamedTuple):
3739
"""Ignored rule."""
40+
3841
rule: str
3942
qualifiers: frozenset[IgnoreRuleQualifier]
4043

src/ansiblelint/rules/risky_octal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class OctalPermissionsRule(AnsibleLintRule):
3838

3939
id = "risky-octal"
4040
description = (
41-
"Numeric file permissions without leading zero can behave "
42-
"in unexpected ways."
41+
"Numeric file permissions without leading zero can behave in unexpected ways."
4342
)
4443
link = "https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html"
4544
severity = "VERY_HIGH"

src/ansiblelint/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def _run(self) -> list[MatchError]:
222222
sub_tag = ""
223223
lintable.exc.__class__.__name__.lower()
224224
message = None
225-
if lintable.exc.__cause__ and isinstance(lintable.exc.__cause__, ScannerError | ParserError | RuamelParserError):
225+
if lintable.exc.__cause__ and isinstance(
226+
lintable.exc.__cause__,
227+
ScannerError | ParserError | RuamelParserError,
228+
):
226229
sub_tag = "yaml"
227230
if isinstance(lintable.exc.args, tuple):
228231
message = lintable.exc.args[0]

src/ansiblelint/skip_utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ def _continue_skip_next_lines(
268268
if _noqa_comment_line_re.fullmatch(line_content[line_no - 1]):
269269
# Find next non-empty line
270270
next_line_no = line_no
271-
while next_line_no < len(line_content) and not line_content[next_line_no].strip():
271+
while (
272+
next_line_no < len(line_content)
273+
and not line_content[next_line_no].strip()
274+
):
272275
next_line_no += 1
273276
if next_line_no >= len(line_content):
274277
continue
@@ -293,8 +296,12 @@ def traverse_yaml(obj: Any) -> None:
293296
traversable.append(obj.ca.comment)
294297
for entry in traversable:
295298
# flatten all lists we might have in entries. Some arcane ruamel CommentedMap magic
296-
entry = [item for sublist in entry if sublist is not None
297-
for item in (sublist if isinstance(sublist, list) else [sublist])]
299+
entry = [
300+
item
301+
for sublist in entry
302+
if sublist is not None
303+
for item in (sublist if isinstance(sublist, list) else [sublist])
304+
]
298305
for v in entry:
299306
if isinstance(v, CommentToken):
300307
comment_str = v.value

src/ansiblelint/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,9 @@ def _rolepath(self, basedir: str, role: str) -> str | None:
583583
# This ignores deeper structures than 1 level
584584
possible_paths.append(path_dwim(basedir, os.path.join("roles", *role_name)))
585585
possible_paths.append(path_dwim(basedir, os.path.join(*role_name)))
586-
possible_paths.append(path_dwim(basedir, os.path.join("..", "..", *role_name)))
586+
possible_paths.append(
587+
path_dwim(basedir, os.path.join("..", "..", *role_name))
588+
)
587589

588590
for loc in self.app.runtime.config.default_roles_path:
589591
loc = os.path.expanduser(loc)

test/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def test_profiles(default_rules_collection: RulesCollection) -> None:
1212
for rule in default_rules_collection.rules:
1313
if profile_rule_id == rule.id:
1414
forbidden_tags = profile_banned_tags & set(rule.tags)
15-
assert (
16-
not forbidden_tags
17-
), f"Rule {profile_rule_id} from {name} profile cannot use {profile_banned_tags & set(rule.tags)} tag."
15+
assert not forbidden_tags, (
16+
f"Rule {profile_rule_id} from {name} profile cannot use {profile_banned_tags & set(rule.tags)} tag."
17+
)

test/test_file_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ def test_discover_lintables_silent(
9898
my_options.lintables = [str(lint_path)]
9999
files = file_utils.discover_lintables(my_options)
100100
stderr = capsys.readouterr().err
101-
assert (
102-
not stderr
103-
), f"No stderr output is expected when the verbosity is off, got: {stderr}"
104-
assert (
105-
len(files) == yaml_count
106-
), "Expected to find {yaml_count} yaml files in {lint_path}".format_map(
107-
locals(),
101+
assert not stderr, (
102+
f"No stderr output is expected when the verbosity is off, got: {stderr}"
103+
)
104+
assert len(files) == yaml_count, (
105+
"Expected to find {yaml_count} yaml files in {lint_path}".format_map(
106+
locals(),
107+
)
108108
)
109109

110110

0 commit comments

Comments
 (0)