-
Notifications
You must be signed in to change notification settings - Fork 637
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
Allow rules to request original raw task data #1834
Conversation
If `needs_raw_task` (a class level attribute) is `True`, then the original task (before normalization) will be made available under `task["__raw_task__"]`.
AnsibleLintRule.needs_raw_task
optional property
AnsibleLintRule.needs_raw_task
optional propertyAnsibleLintRule.needs_raw_task
optional property
AnsibleLintRule.needs_raw_task
optional propertymatchtask()
via task["__raw_task__"]
(rules must opt-in to get it)
matchtask()
via task["__raw_task__"]
(rules must opt-in to get it)
I like this approach more than the alternative but you need to also add a simple test for it, one that verifies that a rule that requests this does receive it. This will also address the problem of decreasing the code coverage. I think we already have a custom rule inside tests that you may reuse for testing this, or you can add a new one. |
We have not had prematch()/postmatch() in a long time. Now test_rule_matching and test_rule_postmatching are effectively duplicates of each other. So drop the postmatching rule test.
Also adjust test counts now that I added another rule under test/rules.
K. I added a test Rule that uses this and adjusted the counts for RulesCollection since that uses the new rule now too. codecov is happier now. |
The test errors are failures to upload codecov reports. |
I seen it and did a recheck. If it happens again let's make the uploading optional. Even if we fail to upload half of the files we will likely see any coverage drop do no problems. |
Tests are green :) |
This allows a rule to opt-in to receiving a "raw" copy of the task (as it is before normalization) via
task["__raw_task__"]
.To use it, rules set
needs_raw_task = True
at the class level.For one of the rules I'm developing, I need to inspect the raw (not normalized via ansible) task to identify the target issue.
This rule flags tasks that use action shorthand.
normalize_task()
, however, parses the shorthand and puts it intask['action']
, so there's no good way to detect the action shorthand with the currentmatchtask()
interface. There are a variety of awkward workarounds like parsing the playbooks myself, but I would really like to take advantage of all the workansible-lint
already does to find the relevant tasks and skip them as needed.https://github.com/cognifloyd/ansible-lint/blob/fmt/src/ansiblelint/rules/TaskNoActionShorthand.py
For more discussion about this no-action-shorthand rule, see: #1609
The TaskNoActionShorthand rule will be extracted from #1805.
This is an alternative implementation to #1833 which was extracted from #1805. Only one of the PRs should be merged.