Skip to content

Commit

Permalink
Fix line number on var-naming error for 'register' (#2840)
Browse files Browse the repository at this point in the history
To avoid this ignored exception: 'WARNING  Ignored exception from VariableNamingRule.<bound method AnsibleLintRule.matchtasks of var-naming: All variables should be named using only lowercase and underscores.> while processing examples/playbooks/rule-var-naming-fail.yml (playbook): MatchError called incorrectly as line numbers start with 1'
  • Loading branch information
zigarn committed Dec 24, 2022
1 parent 539fcbe commit b432044
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/playbooks/rule-var-naming-fail.yml
Expand Up @@ -26,3 +26,7 @@
ALL_CAPS_ARE_BAD_TOO: "{{ MoreBad }}" # invalid
ansible.builtin.set_fact:
CamelCaseIsBad: "{{ BAD }}" # invalid
- name: Test on register
ansible.builtin.debug:
var: test_var
register: CamelCaseIsBad # invalid
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/var_naming.py
Expand Up @@ -143,7 +143,7 @@ def matchtask(
results.append(
self.create_matcherror(
filename=file,
linenumber=0,
linenumber=task[LINE_NUMBER_KEY],
message=f"Task registers a variable that violates variable naming standards: {registered_var}",
tag=f"var-naming[{registered_var}]",
)
Expand Down Expand Up @@ -198,7 +198,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
def test_invalid_var_name_playbook(rule_runner: RunFromText) -> None:
"""Test rule matches."""
results = rule_runner.run("examples/playbooks/rule-var-naming-fail.yml")
assert len(results) == 6
assert len(results) == 7
for result in results:
assert result.rule.id == VariableNamingRule.id
# We are not checking line numbers because they can vary between
Expand Down

0 comments on commit b432044

Please sign in to comment.