Skip to content

Commit

Permalink
Accept underline prefix when checking var-naming (#3789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Sep 29, 2023
1 parent e4ee3e6 commit a02e008
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/playbooks/role_vars_prefix_detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
ansible.builtin.include_role:
name: role_vars_prefix_detection
vars:
role_vars_prefix_detection_var2: val2
role_vars_prefix_detection_var1: val1
_role_vars_prefix_detection_var2: val2
__role_vars_prefix_detection_var3: val3
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
- name: include_task_with_vars | Foo
ansible.builtin.include_tasks: ../tasks/included-task-with-vars.yml
vars:
var_naming_pattern_foo: bar
var_naming_pattern_1: 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 a02e008

Please sign in to comment.