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

Allow tabs inside jinja strings #4146

Merged
merged 1 commit into from
May 9, 2024
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
6 changes: 6 additions & 0 deletions examples/playbooks/rule-no-tabs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
path: some.txt
regexp: ^\t$
line: string with \t inside
- name: Should not trigger inside jinja
vars:
deep:
"some{{ '\t' }}stuff": true
ansible.builtin.debug:
msg: "{{ 'foo' + '\t' + 'bar' }}"
10 changes: 8 additions & 2 deletions src/ansiblelint/rules/no_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import TYPE_CHECKING

from ansiblelint.rules import AnsibleLintRule
from ansiblelint.text import has_jinja
from ansiblelint.yaml_utils import nested_items_path

if TYPE_CHECKING:
Expand Down Expand Up @@ -45,9 +46,14 @@ def matchtask(
) -> bool | str:
action = task["action"]["__ansible_module__"]
for k, v, _ in nested_items_path(task):
if isinstance(k, str) and "\t" in k:
if isinstance(k, str) and "\t" in k and not has_jinja(k):
return True
if isinstance(v, str) and "\t" in v and (action, k) not in self.allow_list:
if (
isinstance(v, str)
and "\t" in v
and (action, k) not in self.allow_list
and not has_jinja(v)
):
return True
return False

Expand Down
Loading