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

Remove false positive on 'cacheable' property of set_fact #3490

Merged
merged 1 commit into from
May 24, 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
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ bracketsmatchtestfile
buildinfo
buildset
builtins
cacheable
cachier
capfd
caplog
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 800
PYTEST_REQPASS: 801
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: cacheable_set_fact | Using set_fact with cacheable
ansible.builtin.set_fact:
var_naming_pattern_fact: bar
cacheable: true
11 changes: 10 additions & 1 deletion src/ansiblelint/rules/var_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def matchtask( # noqa: C901
# If the task uses the 'set_fact' module
if ansible_module == "set_fact":
for key in filter(
lambda x: isinstance(x, str) and not x.startswith("__"),
lambda x: isinstance(x, str)
and not x.startswith("__")
and x != "cacheable",
task["action"].keys(),
):
match_error = self.get_var_naming_matcherror(key, prefix=prefix)
Expand Down Expand Up @@ -349,3 +351,10 @@ def test_var_naming_with_include_tasks_and_vars() -> None:
result = run_ansible_lint(role_path)
assert result.returncode == RC.SUCCESS
assert "var-naming" not in result.stdout

def test_var_naming_with_set_fact_and_cacheable() -> None:
"""Test with include tasks and vars."""
role_path = "examples/roles/var_naming_pattern/tasks/cacheable_set_fact.yml"
result = run_ansible_lint(role_path)
assert result.returncode == RC.SUCCESS
assert "var-naming" not in result.stdout
4 changes: 2 additions & 2 deletions src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/molecule.json"
},
"playbook": {
"etag": "352673fc239ca58ad41a2e5d160ff24d5714f91d0f082fda5a2204ee11880f64",
"etag": "9f6baaa61cc2bfaf32d00af12ef6dd0e8ca3dd3bb94581cabb66a92795d8f4e6",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json"
},
"requirements": {
Expand All @@ -52,7 +52,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-rulebook/main/ansible_rulebook/schema/ruleset_schema.json"
},
"tasks": {
"etag": "6d30ce47562d7fbed2cebf1385527946265c8153be657b9b2d67956777f39936",
"etag": "f9fbc0855680d1321fa3902181131d73838d922362d8dfb85a4f59402240cc07",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/tasks.json"
},
"vars": {
Expand Down