Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error suppression when syntax is incorrect #4026

Merged
merged 12 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 852
PYTEST_REQPASS: 853
steps:
- uses: actions/checkout@v4
with:
Expand Down
7 changes: 7 additions & 0 deletions examples/playbooks/incorrect_module_args.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Demonstrate linting issue.
hosts: all
tasks:
- name: Include a role with the wrong syntax
ansible.builtin.include_role:
role: foo
49 changes: 25 additions & 24 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

import ansiblelint.skip_utils
import ansiblelint.utils
from ansiblelint._internal.rules import (
BaseRule,
LoadingFailureRule,
)
from ansiblelint.app import App, get_app
from ansiblelint.constants import States
from ansiblelint.errors import LintWarning, MatchError, WarnSource
Expand All @@ -40,16 +36,15 @@
from ansiblelint.text import strip_ansi_escape
from ansiblelint.utils import (
PLAYBOOK_DIR,
_include_children,
_roles_children,
_taskshandlers_children,
HandleChildren,
parse_examples_from_plugin,
template,
)

if TYPE_CHECKING:
from collections.abc import Callable, Generator

from ansiblelint._internal.rules import BaseRule
from ansiblelint.config import Options
from ansiblelint.constants import FileType
from ansiblelint.rules import RulesCollection
Expand Down Expand Up @@ -458,7 +453,7 @@ def _emit_matches(self, files: list[Lintable]) -> Generator[MatchError, None, No
except MatchError as exc:
if not exc.filename: # pragma: no branch
exc.filename = str(lintable.path)
exc.rule = LoadingFailureRule()
exc.rule = self.rules["load-failure"]
yield exc
except AttributeError:
yield MatchError(lintable=lintable, rule=self.rules["load-failure"])
Expand Down Expand Up @@ -523,22 +518,28 @@ def play_children(
) -> list[Lintable]:
"""Flatten the traversed play tasks."""
# pylint: disable=unused-argument
delegate_map: dict[str, Callable[[str, Any, Any, FileType], list[Lintable]]] = {
"tasks": _taskshandlers_children,
"pre_tasks": _taskshandlers_children,
"post_tasks": _taskshandlers_children,
"block": _taskshandlers_children,
"include": _include_children,
"ansible.builtin.include": _include_children,
"import_playbook": _include_children,
"ansible.builtin.import_playbook": _include_children,
"roles": _roles_children,
"dependencies": _roles_children,
"handlers": _taskshandlers_children,
"include_tasks": _include_children,
"ansible.builtin.include_tasks": _include_children,
"import_tasks": _include_children,
"ansible.builtin.import_tasks": _include_children,

handlers = HandleChildren(self.rules)

delegate_map: dict[
str,
Callable[[str, Any, Any, FileType], list[Lintable]],
] = {
"tasks": handlers.taskshandlers_children,
"pre_tasks": handlers.taskshandlers_children,
"post_tasks": handlers.taskshandlers_children,
"block": handlers.taskshandlers_children,
"include": handlers.include_children,
"ansible.builtin.include": handlers.include_children,
"import_playbook": handlers.include_children,
"ansible.builtin.import_playbook": handlers.include_children,
"roles": handlers.roles_children,
"dependencies": handlers.roles_children,
"handlers": handlers.taskshandlers_children,
"include_tasks": handlers.include_children,
"ansible.builtin.include_tasks": handlers.include_children,
"import_tasks": handlers.include_children,
"ansible.builtin.import_tasks": handlers.include_children,
}
(k, v) = item
add_all_plugin_dirs(str(basedir.resolve()))
Expand Down
Loading
Loading