Skip to content

Commit

Permalink
Allow tabs in win_lineinfile (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 13, 2024
1 parent c66c903 commit e8a71e5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
13 changes: 12 additions & 1 deletion examples/playbooks/rule-no-tabs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
- name: Should not trigger no-tabs rules # noqa fqcn
lineinfile:
path: some.txt
regexp: ^\t$
regexp: "^\t$"
line: string with \t inside
# Disabled as attempt to mock it would trigger an error validating its arguments
# - name: Should not trigger no-tabs rules # noqa fqcn
# win_lineinfile:
# path: some.txt
# regexp: "^\t$"
# line: string with \t inside
- name: Should not trigger no-tabs rules
community.windows.win_lineinfile:
path: some.txt
regexp: "^\t$"
line: string with \t inside
- name: Should not trigger inside jinja
vars:
Expand Down
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ collections:
- community.docker
- community.general
- community.molecule
- community.windows
2 changes: 1 addition & 1 deletion src/ansiblelint/_mockings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _make_module_stub(module_name: str, options: Options) -> None:
path.mkdir(exist_ok=True, parents=True)
_write_module_stub(
filename=module_file,
name=module_file,
name=module_name,
namespace=namespace,
collection=collection,
)
Expand Down
20 changes: 17 additions & 3 deletions src/ansiblelint/rules/no_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class NoTabsRule(AnsibleLintRule):
("lineinfile", "insertbefore"),
("lineinfile", "regexp"),
("lineinfile", "line"),
("win_lineinfile", "insertafter"),
("win_lineinfile", "insertbefore"),
("win_lineinfile", "regexp"),
("win_lineinfile", "line"),
("ansible.builtin.lineinfile", "insertafter"),
("ansible.builtin.lineinfile", "insertbefore"),
("ansible.builtin.lineinfile", "regexp"),
Expand All @@ -37,6 +41,10 @@ class NoTabsRule(AnsibleLintRule):
("ansible.legacy.lineinfile", "insertbefore"),
("ansible.legacy.lineinfile", "regexp"),
("ansible.legacy.lineinfile", "line"),
("community.windows.win_lineinfile", "insertafter"),
("community.windows.win_lineinfile", "insertbefore"),
("community.windows.win_lineinfile", "regexp"),
("community.windows.win_lineinfile", "line"),
]

def matchtask(
Expand Down Expand Up @@ -69,6 +77,12 @@ def test_no_tabs_rule(default_rules_collection: RulesCollection) -> None:
"examples/playbooks/rule-no-tabs.yml",
rules=default_rules_collection,
).run()
assert results[0].lineno == 10
assert results[0].message == NoTabsRule().shortdesc
assert len(results) == 2
expected_results = [
(10, NoTabsRule().shortdesc),
(13, NoTabsRule().shortdesc),
]
for i, expected in enumerate(expected_results):
assert len(results) >= i + 1
assert results[i].lineno == expected[0]
assert results[i].message == expected[1]
assert len(results) == len(expected), results

0 comments on commit e8a71e5

Please # to comment.