Skip to content
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
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ switchport
sysvinit
taskshandlers
testinfra
thefoo
timesyncd
tmpfs
tombi
Expand Down
18 changes: 18 additions & 0 deletions examples/roles/role_vars_prefix_detection/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Echo thefoo
ansible.builtin.command: echo thefoo
changed_when: true
register: thefoo

- name: Echo thebar
ansible.builtin.command: echo thebar
changed_when: true
register: role_vars_prefix_detection_thebar

- name: Test ansible.builtin.set_fact without role prefix
ansible.builtin.set_fact:
foo: bar

- name: Test set_fact with role prefix
ansible.builtin.set_fact:
role_vars_prefix_detection_foo: bar
6 changes: 3 additions & 3 deletions src/ansiblelint/rules/var_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def matchtask(
results = []
task_prefix = Prefix()
role_prefix = Prefix()
if file and file.parent and file.parent.kind == "role":
role_prefix = Prefix(file.parent.path.name)
if file and file.role:
role_prefix = Prefix(file.role)
ansible_module = task["action"]["__ansible_module__"]
# If the task uses the 'vars' section to set variables
# only check role prefix for include_role and import_role tasks 'vars'
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_var_naming_with_role_prefix(
Lintable("examples/roles/role_vars_prefix_detection"),
rules=default_rules_collection,
).run()
assert len(results) == 2
assert len(results) == 4
for result in results:
assert result.tag == "var-naming[no-role-prefix]"

Expand Down