|
11 | 11 | from ansiblelint.config import options |
12 | 12 | from ansiblelint.constants import LINE_NUMBER_KEY, SUCCESS_RC |
13 | 13 | from ansiblelint.file_utils import Lintable |
14 | | -from ansiblelint.rules import AnsibleLintRule |
| 14 | +from ansiblelint.rules import AnsibleLintRule, RulesCollection |
| 15 | +from ansiblelint.runner import Runner |
15 | 16 | from ansiblelint.skip_utils import get_rule_skips_from_line |
16 | 17 | from ansiblelint.utils import parse_yaml_from_file |
17 | 18 |
|
@@ -74,7 +75,7 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]: |
74 | 75 | results: list[MatchError] = [] |
75 | 76 | raw_results: list[MatchError] = [] |
76 | 77 |
|
77 | | - if not data: |
| 78 | + if not data or file.kind not in ("tasks", "handlers", "playbook", "vars"): |
78 | 79 | return results |
79 | 80 | # If the Play uses the 'vars' section to set variables |
80 | 81 | our_vars = data.get("vars", {}) |
@@ -193,12 +194,19 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: |
193 | 194 | ) |
194 | 195 |
|
195 | 196 | @pytest.mark.parametrize( |
196 | | - "rule_runner", (VariableNamingRule,), indirect=["rule_runner"] |
| 197 | + ("file", "expected"), |
| 198 | + ( |
| 199 | + pytest.param("examples/playbooks/rule-var-naming-fail.yml", 7, id="0"), |
| 200 | + pytest.param("examples/Taskfile.yml", 0, id="1"), |
| 201 | + ), |
197 | 202 | ) |
198 | | - def test_invalid_var_name_playbook(rule_runner: RunFromText) -> None: |
| 203 | + def test_invalid_var_name_playbook(file: str, expected: int) -> None: |
199 | 204 | """Test rule matches.""" |
200 | | - results = rule_runner.run("examples/playbooks/rule-var-naming-fail.yml") |
201 | | - assert len(results) == 7 |
| 205 | + rules = RulesCollection(options=options) |
| 206 | + rules.register(VariableNamingRule()) |
| 207 | + results = Runner(Lintable(file), rules=rules).run() |
| 208 | + # results = rule_runner.run() |
| 209 | + assert len(results) == expected |
202 | 210 | for result in results: |
203 | 211 | assert result.rule.id == VariableNamingRule.id |
204 | 212 | # We are not checking line numbers because they can vary between |
|
0 commit comments