Skip to content

Commit ec4193f

Browse files
committed
Activate and address some ruff violations (preview)
1 parent 5ab7c7e commit ec4193f

File tree

18 files changed

+99
-82
lines changed

18 files changed

+99
-82
lines changed

.gitignore

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,18 @@ examples/playbooks/vars/strings.transformed.yml
6262
examples/playbooks/vars/transform_nested_data.yml
6363

6464
# other
65-
.cache
65+
*.tar.gz
66+
*.tmp.*
6667
.DS_Store
67-
.vscode
68+
.cache
69+
.envrc
6870
.idea
69-
src/ansiblelint/_version.py
70-
*.tar.gz
7171
.pytest_cache
72-
test/eco/CODENOTIFY.html
73-
test/eco
74-
test/schemas/node_modules
75-
test/local-content
76-
.envrc
77-
# collections
78-
# !/collections
79-
site
72+
.vscode/launch.json
8073
_readthedocs
81-
*.tmp.*
8274
coverage.lcov
75+
site
76+
src/ansiblelint/_version.py
77+
test/eco
78+
test/local-content
79+
test/schemas/node_modules

.taplo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[formatting]
2+
array_trailing_comma = false

pyproject.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# cspell: ignore FURB
2+
13
[build-system]
24
build-backend = "setuptools.build_meta"
35
requires = [
@@ -222,11 +224,13 @@ cache-dir = "./.cache/.ruff"
222224
fix = true
223225
# Same as Black.
224226
line-length = 88
227+
preview = true
225228
target-version = "py310"
226229

227230
[tool.ruff.lint]
228231
ignore = [
229232
"COM812", # conflicts with ISC001 on format
233+
"CPY001", # missing-copyright-notice
230234
"D203", # incompatible with D211
231235
"D213", # incompatible with D212
232236
"E501", # we use black
@@ -245,7 +249,21 @@ ignore = [
245249
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
246250
"PERF203",
247251
"PD011", # We are not using pandas, any .values attributes are unrelated
248-
"PLW0603" # global lock file in cache dir
252+
"PLW0603", # global lock file in cache dir
253+
# part of preview rules:
254+
"B909", # raise-missing-from
255+
"DOC201", # docstring-missing-returns
256+
"DOC402", # docstring-missing-summary
257+
"DOC501", # docstring-missing-exception
258+
"FURB101",
259+
"FURB103",
260+
"FURB110",
261+
"FURB113",
262+
"FURB118",
263+
"PLC0415",
264+
"PLC2701",
265+
"PLW1641",
266+
"S404"
249267
]
250268
select = ["ALL"]
251269

@@ -269,7 +287,7 @@ max-complexity = 20
269287
"src/ansiblelint/{utils,file_utils,runner,loaders,constants,config,cli,_mockings}.py" = [
270288
"PTH"
271289
]
272-
"test/**/*.py" = ["S"]
290+
"test/**/*.py" = ["DOC201", "DOC501", "PLC2701", "S"]
273291

274292
[tool.ruff.lint.pydocstyle]
275293
convention = "google"

src/ansiblelint/app.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ def report_outcome(
217217
os.environ.get("ANSIBLE_LINT_IGNORE_FILE", IGNORE_FILE.default),
218218
)
219219
console_stderr.print(f"Writing ignore file to {ignore_file_path}")
220-
lines = set()
221-
for rule in result.matches:
222-
lines.add(f"{rule.filename} {rule.tag}\n")
220+
lines: set[str] = set()
221+
lines.update(f"{rule.filename} {rule.tag}\n" for rule in result.matches)
223222
with ignore_file_path.open("w", encoding="utf-8") as ignore_file:
224223
ignore_file.write(
225224
"# This file contains ignores rule violations for ansible-lint\n",
@@ -330,7 +329,7 @@ def report_summary( # pylint: disable=too-many-locals # noqa: C901
330329
for tag, stats in summary.tag_stats.items():
331330
table.add_row(
332331
str(stats.count),
333-
f"[link={RULE_DOC_URL}{ tag.split('[')[0] }]{escape(tag)}[/link]",
332+
f"[link={RULE_DOC_URL}{tag.split('[')[0]}]{escape(tag)}[/link]",
334333
stats.profile,
335334
f"{', '.join(stats.associated_tags)}{' (warning)' if stats.warning else ''}",
336335
style="yellow" if stats.warning else "red",

src/ansiblelint/file_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def __init__(
242242
self.file = NamedTemporaryFile( # noqa: SIM115
243243
mode="w+",
244244
suffix="playbook.yml",
245+
encoding="utf-8",
245246
)
246247
self.filename = self.file.name
247248
self._content = sys.stdin.read()
@@ -479,7 +480,7 @@ def discover_lintables(options: Options) -> list[str]:
479480

480481
def strip_dotslash_prefix(fname: str) -> str:
481482
"""Remove ./ leading from filenames."""
482-
return fname[2:] if fname.startswith("./") else fname
483+
return fname.removeprefix("./")
483484

484485

485486
def find_project_root(

src/ansiblelint/loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def load_ignore_txt(filepath: Path | None = None) -> dict[str, set[str]]:
7474

7575

7676
__all__ = [
77+
"IGNORE_FILE",
78+
"YAMLError",
7779
"load_ignore_txt",
7880
"yaml_from_file",
7981
"yaml_load",
8082
"yaml_load_safe",
81-
"YAMLError",
82-
"IGNORE_FILE",
8383
]

src/ansiblelint/rules/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ def known_tags(self) -> list[str]:
533533
tags = set()
534534
for rule in self.rules:
535535
tags.add(rule.id)
536-
for tag in rule.tags:
537-
tags.add(tag)
536+
tags.update(rule.tags)
538537
return sorted(tags)
539538

540539
def list_tags(self) -> str:

src/ansiblelint/rules/inline_env_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def matchtask(
6464
task: Task,
6565
file: Lintable | None = None,
6666
) -> bool | str:
67-
if task["action"]["__ansible_module__"] in ["command"]:
67+
if task["action"]["__ansible_module__"] == "command":
6868
first_cmd_arg = get_first_cmd_arg(task)
6969
if not first_cmd_arg:
7070
return False

src/ansiblelint/rules/no_same_owner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ def handle_synchronize(task: Any, action: dict[str, Any]) -> bool:
6262
def handle_unarchive(task: Any, action: dict[str, Any]) -> bool:
6363
"""Process unarchive task."""
6464
delegate_to = task.get("delegate_to")
65-
if (
66-
delegate_to == "localhost"
67-
or delegate_to != "localhost"
68-
and not action.get("remote_src")
65+
if delegate_to == "localhost" or (
66+
delegate_to != "localhost" and not action.get("remote_src")
6967
):
7068
src = action.get("src")
7169
if not isinstance(src, str):

src/ansiblelint/rules/yaml_rule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def _combine_skip_rules(data: Any) -> set[str]:
115115
result = set(data.get(SKIPPED_RULES_KEY, []))
116116
tags = data.get("tags", [])
117117
if tags and (
118-
isinstance(tags, Iterable)
119-
and "skip_ansible_lint" in tags
118+
(isinstance(tags, Iterable) and "skip_ansible_lint" in tags)
120119
or tags == "skip_ansible_lint"
121120
):
122121
result.add("skip_ansible_lint")

0 commit comments

Comments
 (0)