Skip to content

Commit

Permalink
Allow tabs inside jinja strings (#4146)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 9, 2024
1 parent c82bffd commit f6d4702
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit f6d4702

Please sign in to comment.