Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept underline prefix when checking var-naming #3789

Merged
merged 1 commit into from
Sep 29, 2023
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
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