|
27 | 27 |
|
28 | 28 | import ansiblelint.skip_utils |
29 | 29 | import ansiblelint.utils |
30 | | -from ansiblelint._internal.rules import ( |
31 | | - BaseRule, |
32 | | - LoadingFailureRule, |
33 | | -) |
34 | 30 | from ansiblelint.app import App, get_app |
35 | 31 | from ansiblelint.constants import States |
36 | 32 | from ansiblelint.errors import LintWarning, MatchError, WarnSource |
|
40 | 36 | from ansiblelint.text import strip_ansi_escape |
41 | 37 | from ansiblelint.utils import ( |
42 | 38 | PLAYBOOK_DIR, |
43 | | - _include_children, |
44 | | - _roles_children, |
45 | | - _taskshandlers_children, |
| 39 | + HandleChildren, |
46 | 40 | parse_examples_from_plugin, |
47 | 41 | template, |
48 | 42 | ) |
49 | 43 |
|
50 | 44 | if TYPE_CHECKING: |
51 | 45 | from collections.abc import Callable, Generator |
52 | 46 |
|
| 47 | + from ansiblelint._internal.rules import BaseRule |
53 | 48 | from ansiblelint.config import Options |
54 | 49 | from ansiblelint.constants import FileType |
55 | 50 | from ansiblelint.rules import RulesCollection |
@@ -458,7 +453,7 @@ def _emit_matches(self, files: list[Lintable]) -> Generator[MatchError, None, No |
458 | 453 | except MatchError as exc: |
459 | 454 | if not exc.filename: # pragma: no branch |
460 | 455 | exc.filename = str(lintable.path) |
461 | | - exc.rule = LoadingFailureRule() |
| 456 | + exc.rule = self.rules["load-failure"] |
462 | 457 | yield exc |
463 | 458 | except AttributeError: |
464 | 459 | yield MatchError(lintable=lintable, rule=self.rules["load-failure"]) |
@@ -523,22 +518,28 @@ def play_children( |
523 | 518 | ) -> list[Lintable]: |
524 | 519 | """Flatten the traversed play tasks.""" |
525 | 520 | # 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, |
542 | 543 | } |
543 | 544 | (k, v) = item |
544 | 545 | add_all_plugin_dirs(str(basedir.resolve())) |
|
0 commit comments