Skip to content

Commit ce2ebd7

Browse files
Fix error suppression when syntax is incorrect (#4026)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ee7ede5 commit ce2ebd7

File tree

5 files changed

+212
-163
lines changed

5 files changed

+212
-163
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
env:
7272
# Number of expected test passes, safety measure for accidental skip of
7373
# tests. Update value if you add/remove tests.
74-
PYTEST_REQPASS: 852
74+
PYTEST_REQPASS: 853
7575
steps:
7676
- uses: actions/checkout@v4
7777
with:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Demonstrate linting issue.
3+
hosts: all
4+
tasks:
5+
- name: Include a role with the wrong syntax
6+
ansible.builtin.include_role:
7+
role: foo

src/ansiblelint/runner.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
import ansiblelint.skip_utils
2929
import ansiblelint.utils
30-
from ansiblelint._internal.rules import (
31-
BaseRule,
32-
LoadingFailureRule,
33-
)
3430
from ansiblelint.app import App, get_app
3531
from ansiblelint.constants import States
3632
from ansiblelint.errors import LintWarning, MatchError, WarnSource
@@ -40,16 +36,15 @@
4036
from ansiblelint.text import strip_ansi_escape
4137
from ansiblelint.utils import (
4238
PLAYBOOK_DIR,
43-
_include_children,
44-
_roles_children,
45-
_taskshandlers_children,
39+
HandleChildren,
4640
parse_examples_from_plugin,
4741
template,
4842
)
4943

5044
if TYPE_CHECKING:
5145
from collections.abc import Callable, Generator
5246

47+
from ansiblelint._internal.rules import BaseRule
5348
from ansiblelint.config import Options
5449
from ansiblelint.constants import FileType
5550
from ansiblelint.rules import RulesCollection
@@ -458,7 +453,7 @@ def _emit_matches(self, files: list[Lintable]) -> Generator[MatchError, None, No
458453
except MatchError as exc:
459454
if not exc.filename: # pragma: no branch
460455
exc.filename = str(lintable.path)
461-
exc.rule = LoadingFailureRule()
456+
exc.rule = self.rules["load-failure"]
462457
yield exc
463458
except AttributeError:
464459
yield MatchError(lintable=lintable, rule=self.rules["load-failure"])
@@ -523,22 +518,28 @@ def play_children(
523518
) -> list[Lintable]:
524519
"""Flatten the traversed play tasks."""
525520
# pylint: disable=unused-argument
526-
delegate_map: dict[str, Callable[[str, Any, Any, FileType], list[Lintable]]] = {
527-
"tasks": _taskshandlers_children,
528-
"pre_tasks": _taskshandlers_children,
529-
"post_tasks": _taskshandlers_children,
530-
"block": _taskshandlers_children,
531-
"include": _include_children,
532-
"ansible.builtin.include": _include_children,
533-
"import_playbook": _include_children,
534-
"ansible.builtin.import_playbook": _include_children,
535-
"roles": _roles_children,
536-
"dependencies": _roles_children,
537-
"handlers": _taskshandlers_children,
538-
"include_tasks": _include_children,
539-
"ansible.builtin.include_tasks": _include_children,
540-
"import_tasks": _include_children,
541-
"ansible.builtin.import_tasks": _include_children,
521+
522+
handlers = HandleChildren(self.rules)
523+
524+
delegate_map: dict[
525+
str,
526+
Callable[[str, Any, Any, FileType], list[Lintable]],
527+
] = {
528+
"tasks": handlers.taskshandlers_children,
529+
"pre_tasks": handlers.taskshandlers_children,
530+
"post_tasks": handlers.taskshandlers_children,
531+
"block": handlers.taskshandlers_children,
532+
"include": handlers.include_children,
533+
"ansible.builtin.include": handlers.include_children,
534+
"import_playbook": handlers.include_children,
535+
"ansible.builtin.import_playbook": handlers.include_children,
536+
"roles": handlers.roles_children,
537+
"dependencies": handlers.roles_children,
538+
"handlers": handlers.taskshandlers_children,
539+
"include_tasks": handlers.include_children,
540+
"ansible.builtin.include_tasks": handlers.include_children,
541+
"import_tasks": handlers.include_children,
542+
"ansible.builtin.import_tasks": handlers.include_children,
542543
}
543544
(k, v) = item
544545
add_all_plugin_dirs(str(basedir.resolve()))

0 commit comments

Comments
 (0)