Skip to content

Commit

Permalink
Accept underline prefix when checking var-naming
Browse files Browse the repository at this point in the history
Fixes: #3760
  • Loading branch information
ssbarnea committed Sep 29, 2023
1 parent e4ee3e6 commit 0c0edd4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/playbooks/role_vars_prefix_detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
name: role_vars_prefix_detection
vars:
role_vars_prefix_detection_var2: val2
_role_vars_prefix_detection_var2: val2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_tasks: ../tasks/included-task-with-vars.yml
vars:
var_naming_pattern_foo: bar
_var_naming_pattern_2: ... # we allow _ before the prefix
_var_naming_pattern_3: ... # we allow __ before the prefix

- name: include_task_with_vars | Foo
ansible.builtin.include_role:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/var_naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Possible errors messages:
- `var-naming[no-jinja]`: Variables names must not contain jinja2 templating.
- `var-naming[pattern]`: Variables names should match ... regex.
- `var-naming[no-role-prefix]`: Variables names from within roles should use
`role_name_` as a prefix.
`role_name_` as a prefix. Underlines are accepted before the prefix.
- `var-naming[no-reserved]`: Variables names must not be Ansible reserved names.
- `var-naming[read-only]`: This special variable is read-only.

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/var_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_var_naming_matcherror(

if (
prefix
and not ident.startswith(f"{prefix}_")
and not ident.lstrip("_").startswith(f"{prefix}_")
and not has_jinja(prefix)
and is_fqcn_or_name(prefix)
):
Expand Down

0 comments on commit 0c0edd4

Please sign in to comment.