Skip to content

Commit c4097a2

Browse files
committed
Improve results with broken multiline playbooks
- Reduce the logged exceptions caused by invalid data - Reduce number of errors cased by the same root cause Fixes: #4492
1 parent d427f59 commit c4097a2

File tree

16 files changed

+283
-308
lines changed

16 files changed

+283
-308
lines changed

.config/constraints.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was autogenerated by uv via the following command:
2-
# tox run deps
2+
# tox run -e deps
33
ansible-compat==25.1.1 # via ansible-lint (pyproject.toml)
44
astroid==3.3.8 # via pylint
55
attrs==25.1.0 # via jsonschema, referencing
@@ -92,7 +92,6 @@ regex==2024.11.6 # via mkdocs-material
9292
requests==2.32.3 # via linkchecker, mkdocs-htmlproofer-plugin, mkdocs-material
9393
rpds-py==0.22.3 # via jsonschema, referencing
9494
ruamel-yaml==0.18.10 # via ansible-lint (pyproject.toml)
95-
ruamel-yaml-clib==0.2.12 # via ruamel-yaml, ansible-lint (pyproject.toml)
9695
setproctitle==1.3.4 # via pytest-xdist
9796
six==1.17.0 # via python-dateutil
9897
soupsieve==2.6 # via beautifulsoup4
@@ -119,4 +118,5 @@ zipp==3.21.0 # via importlib-metadata
119118
# ansible-core
120119
# pip
121120
# resolvelib
121+
# ruamel-yaml-clib
122122
# uv

.config/requirements-lock.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was autogenerated by uv via the following command:
2-
# tox run deps
2+
# tox run -e deps
33
ansible-compat==25.1.1 # via ansible-lint (pyproject.toml)
44
attrs==25.1.0 # via jsonschema, referencing
55
black==25.1.0 # via ansible-lint (pyproject.toml)
@@ -22,7 +22,6 @@ pyyaml==6.0.2 # via ansible-compat, ansible-core, yamllint, ansible-
2222
referencing==0.36.2 # via jsonschema, jsonschema-specifications, ansible-lint (pyproject.toml)
2323
rpds-py==0.22.3 # via jsonschema, referencing
2424
ruamel-yaml==0.18.10 # via ansible-lint (pyproject.toml)
25-
ruamel-yaml-clib==0.2.12 # via ruamel-yaml
2625
subprocess-tee==0.4.2 # via ansible-compat, ansible-lint (pyproject.toml)
2726
tomli==2.2.1 # via black
2827
typing-extensions==4.12.2 # via black, referencing
@@ -33,3 +32,4 @@ zipp==3.21.0 # via importlib-metadata
3332
# The following packages were excluded from the output:
3433
# ansible-core
3534
# resolvelib
35+
# ruamel-yaml-clib

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
- name: Install tox
135135
run: |
136136
python3 -m pip install --upgrade pip
137-
python3 -m pip install --upgrade "tox>=4.0.0" "tox-uv>=1.16.0" uv
137+
python3 -m pip install --upgrade "tox>=4.0.0" "tox-uv>=1.20.2" uv
138138
139139
- name: Log installed dists
140140
run: python3 -m pip freeze --all

.pre-commit-config.yaml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ exclude: >
1414
(?x)^(
1515
.config/constraints.txt|
1616
.config/.*requirements.*|
17-
.vscode/extensions.json|
18-
.vscode/settings.json|
1917
examples/broken/encoding.yml|
2018
examples/broken/encoding.j2|
2119
examples/broken/yaml-with-tabs/invalid-due-tabs.yaml|
@@ -31,9 +29,9 @@ repos:
3129
- repo: meta
3230
hooks:
3331
- id: check-useless-excludes
34-
- repo: https://github.com/pre-commit/mirrors-prettier
32+
- repo: https://github.com/rbubley/mirrors-prettier
3533
# keep it before yamllint
36-
rev: v4.0.0-alpha.8
34+
rev: v3.4.2
3735
hooks:
3836
- id: prettier
3937
# Temporary excludes so we can gradually normalize the formatting
@@ -76,6 +74,11 @@ repos:
7674
- repo: https://github.com/pre-commit/pre-commit-hooks.git
7775
rev: v5.0.0
7876
hooks:
77+
- id: check-added-large-files
78+
- id: check-merge-conflict
79+
- id: check-symlinks
80+
- id: debug-statements
81+
- id: detect-private-key
7982
- id: end-of-file-fixer
8083
# ignore formatting-prettier to have an accurate prettier comparison
8184
exclude: >
@@ -133,6 +136,12 @@ repos:
133136
rev: v0.24.2
134137
hooks:
135138
- id: toml-sort-fix
139+
140+
- repo: https://github.com/tox-dev/tox-ini-fmt
141+
rev: 1.5.0
142+
hooks:
143+
- id: tox-ini-fmt
144+
136145
- repo: https://github.com/astral-sh/ruff-pre-commit
137146
rev: v0.9.3
138147
hooks:
@@ -143,10 +152,6 @@ repos:
143152
types_or: [python, pyi]
144153
# - id: ruff-format # must be after ruff
145154
# types_or: [python, pyi]
146-
- repo: https://github.com/psf/black # must be after ruff
147-
rev: 25.1.0
148-
hooks:
149-
- id: black
150155
- repo: https://github.com/pre-commit/mirrors-mypy
151156
rev: v1.14.1
152157
hooks:
@@ -242,33 +247,34 @@ repos:
242247
# stages: [manual]
243248
- id: deps
244249
name: Upgrade constraints files and requirements
245-
files: ^(pyproject\.toml|requirements\.txt)$
250+
files: ^(pyproject\.toml|.config/.*)$
251+
always_run: true
246252
language: python
247253
language_version: "3.10" # minimal we support officially
248254
entry: python3 -m uv pip compile -q --all-extras --output-file=.config/constraints.txt pyproject.toml --upgrade
249255
pass_filenames: false
250256
stages:
251257
- manual
252258
additional_dependencies:
253-
- uv>=0.4.3
259+
- uv>=0.5.21
254260
- id: pip-compile
255261
name: Check constraints files and requirements
256-
files: ^(pyproject\.toml|requirements\.txt)$
262+
files: ^(pyproject\.toml|\.config/.*)$
257263
language: python
258264
language_version: "3.10" # minimal we support officially
259265
entry: python3 -m uv pip compile -q --all-extras --output-file=.config/constraints.txt pyproject.toml
260266
pass_filenames: false
261267
additional_dependencies:
262-
- uv>=0.4.3
268+
- uv>=0.5.21
263269
- id: lock
264270
name: Update requirements-lock.txt
265271
alias: lock
266272
always_run: true
267273
entry: python3 -m uv pip compile -q --upgrade --output-file=.config/requirements-lock.txt pyproject.toml --strip-extras
268-
files: ^.config\/.*requirements.*$
274+
files: ^(pyproject\.toml|\.config/.*)$
269275
language: python
270276
language_version: "3.10" # minimal we support officially
271277
pass_filenames: false
272278
stages: [manual]
273279
additional_dependencies:
274-
- uv>=0.4.3
280+
- uv>=0.5.21

.vscode/extensions.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"recommendations": [
3-
"Tyriar.sort-lines",
4-
"charliermarsh.ruff",
5-
"esbenp.prettier-vscode",
6-
"hbenl.vscode-test-explorer",
7-
"ms-python.black-formatter",
8-
"ms-python.isort",
9-
"ms-python.mypy-type-checker",
10-
"ms-python.pylint",
11-
"ms-python.python",
12-
"ms-python.vscode-pylance",
13-
"ms-vscode.live-server",
14-
"redhat.ansible",
15-
"redhat.vscode-yaml",
16-
"ryanluker.vscode-coverage-gutters",
17-
"shardulm94.trailing-spaces",
18-
"tamasfe.even-better-toml",
19-
"timonwong.shellcheck",
20-
"znck.grammarly",
21-
]
2+
"recommendations": [
3+
"Tyriar.sort-lines",
4+
"charliermarsh.ruff",
5+
"esbenp.prettier-vscode",
6+
"hbenl.vscode-test-explorer",
7+
"ms-python.black-formatter",
8+
"ms-python.isort",
9+
"ms-python.mypy-type-checker",
10+
"ms-python.pylint",
11+
"ms-python.python",
12+
"ms-python.vscode-pylance",
13+
"ms-vscode.live-server",
14+
"redhat.ansible",
15+
"redhat.vscode-yaml",
16+
"ryanluker.vscode-coverage-gutters",
17+
"shardulm94.trailing-spaces",
18+
"tamasfe.even-better-toml",
19+
"timonwong.shellcheck",
20+
"znck.grammarly"
21+
]
2222
}

.vscode/settings.json

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
{
2-
"[markdown]": {
3-
"editor.defaultFormatter": "esbenp.prettier-vscode"
2+
"[markdown]": {
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
},
5+
"editor.formatOnSave": true,
6+
"evenBetterToml.formatter.allowedBlankLines": 2,
7+
"files.exclude": {
8+
"*.egg-info": true,
9+
".pytest_cache": true,
10+
".tox": true,
11+
"__pycache__": true,
12+
"build": true
13+
},
14+
"git.ignoreLimitWarning": true,
15+
"grammarly.config.documentDomain": "academic",
16+
"grammarly.files.include": ["**/*.txt", "**/*.md"],
17+
"python.experiments.optInto": ["pythonTestAdapter"],
18+
"python.terminal.activateEnvironment": true,
19+
"python.testing.pytestEnabled": true,
20+
"python.testing.unittestEnabled": false,
21+
"mypy-type-checker.severity": {
22+
"error": "Warning"
23+
},
24+
"sortLines.filterBlankLines": true,
25+
"yaml.completion": true,
26+
"yaml.customTags": ["!encrypted/pkcs1-oaep scalar", "!vault scalar"],
27+
"yaml.format.enable": false,
28+
"yaml.validate": true,
29+
"evenBetterToml.formatter.alignComments": false,
30+
"[python]": {
31+
"editor.codeActionsOnSave": {
32+
"source.organizeImports": "explicit",
33+
"source.fixAll": "explicit"
434
},
5-
"editor.formatOnSave": true,
6-
"evenBetterToml.formatter.allowedBlankLines": 2,
7-
"files.exclude": {
8-
"*.egg-info": true,
9-
".pytest_cache": true,
10-
".tox": true,
11-
"__pycache__": true,
12-
"build": true
13-
},
14-
"git.ignoreLimitWarning": true,
15-
"grammarly.config.documentDomain": "academic",
16-
"grammarly.files.include": [
17-
"**/*.txt",
18-
"**/*.md"
19-
],
20-
"python.experiments.optInto": [
21-
"pythonTestAdapter"
22-
],
23-
"python.terminal.activateEnvironment": true,
24-
"python.testing.pytestEnabled": true,
25-
"python.testing.unittestEnabled": false,
26-
"mypy-type-checker.severity": {
27-
"error": "Warning",
28-
},
29-
"sortLines.filterBlankLines": true,
30-
"yaml.completion": true,
31-
"yaml.customTags": [
32-
"!encrypted/pkcs1-oaep scalar",
33-
"!vault scalar"
34-
],
35-
"yaml.format.enable": false,
36-
"yaml.validate": true,
37-
"evenBetterToml.formatter.alignComments": false,
38-
"[python]": {
39-
"editor.codeActionsOnSave": {
40-
"source.organizeImports": "explicit",
41-
"source.fixAll": "explicit"
42-
},
43-
"editor.defaultFormatter": "ms-python.black-formatter",
44-
"editor.formatOnSave": true
45-
},
46-
"evenBetterToml.formatter.arrayTrailingComma": true,
47-
"[toml]": {
48-
"editor.defaultFormatter": "panekj.even-betterer-toml"
49-
},
50-
"sonarlint.connectedMode.project": {
51-
"connectionId": "ansible",
52-
"projectKey": "ansible_ansible-lint"
53-
}
35+
"editor.defaultFormatter": "charliermarsh.ruff",
36+
"editor.formatOnSave": true
37+
},
38+
"evenBetterToml.formatter.arrayTrailingComma": true,
39+
"[toml]": {
40+
"editor.defaultFormatter": "panekj.even-betterer-toml"
41+
},
42+
"sonarlint.connectedMode.project": {
43+
"connectionId": "ansible",
44+
"projectKey": "ansible_ansible-lint"
45+
}
5446
}

cspell.config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ ignorePaths:
2121
- src/ansiblelint/schemas/*.json
2222
# Other
2323
- "*.svg"
24+
- ".vscode/**"

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ documentation = "https://ansible.readthedocs.io/projects/lint/"
5050
homepage = "https://github.com/ansible/ansible-lint"
5151
repository = "https://github.com/ansible/ansible-lint"
5252

53-
[tool.black]
54-
target-version = ["py310"]
55-
5653
[tool.codespell]
5754
# indention is a typo in ruamel.yaml's API
5855
ignore-words-list = "indention"
@@ -332,22 +329,18 @@ git_describe_command = [
332329
"v*.*"
333330
]
334331
local_scheme = "no-local-version"
335-
tag_regex = "^(?P<prefix>v)?(?P<version>[0-9.]+)(?P<suffix>.*)?$"
332+
tag_regex = "^(?P<prefix>v)?(?P<version>\\d+[^\\+]*)(?P<suffix>.*)?$"
336333
write_to = "src/ansiblelint/_version.py"
337334

338335
[tool.tomlsort]
339336
in_place = true
340337
sort_inline_tables = true
341338
sort_table_keys = true
342339

343-
[tool.uv]
344-
# incompatible with Windows
345-
environments = ["platform_system != 'Windows'"]
346-
347340
[tool.uv.pip]
348341
annotation-style = "line"
349-
custom-compile-command = "tox run deps"
350-
no-emit-package = ["ansible-core", "pip", "resolvelib", "uv"]
342+
custom-compile-command = "tox run -e deps"
343+
no-emit-package = ["ansible-core", "pip", "resolvelib", "ruamel-yaml-clib", "uv"]
351344

352345
[tool.vulture]
353346
exclude = [

src/ansiblelint/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ def main(argv: list[str] | None = None) -> int:
280280
if argv is None: # pragma: no cover
281281
argv = sys.argv
282282

283+
warnings.simplefilter(
284+
"ignore", ResourceWarning
285+
) # suppress "enable tracemalloc to get the object allocation traceback"
283286
with warnings.catch_warnings(record=True) as warns:
284287
# do not use "ignore" as we will miss to collect them
285288
warnings.simplefilter(action="default")

src/ansiblelint/file_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def is_owned_by_ansible(self) -> bool:
407407
def failed(self) -> bool:
408408
"""Return true if we already found syntax-check errors on this file."""
409409
return any(
410-
match.rule.id in ("syntax-check", "load-failure") for match in self.matches
410+
match.rule.id in ("syntax-check", "load-failure", "internal-error")
411+
for match in self.matches
411412
)
412413

413414
@property

src/ansiblelint/rules/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
241241
yaml = [yaml]
242242

243243
for play in yaml:
244-
# Bug #849
245-
if play is None:
244+
# Bug #849 and #4492
245+
if play is None or not hasattr(play, "get"):
246246
continue
247247

248248
if self.id in play.get(SKIPPED_RULES_KEY, ()):

0 commit comments

Comments
 (0)