Skip to content

Commit 9a43cf1

Browse files
cavcrosbyQalthos
andauthored
Fix yaml rules being included regardless of tags (#4107)
Co-authored-by: Kate Case <this.is@katherineca.se>
1 parent 17194e6 commit 9a43cf1

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
env:
7272
# Number of expected test passes, safety measure for accidental skip of
7373
# tests. Update value if you add/remove tests.
74-
PYTEST_REQPASS: 854
74+
PYTEST_REQPASS: 855
7575
steps:
7676
- uses: actions/checkout@v4
7777
with:

src/ansiblelint/rules/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,16 @@ def run(
503503
or rule.has_dynamic_tags
504504
or not set(rule.tags).union([rule.id]).isdisjoint(tags)
505505
):
506-
_logger.debug("Running rule %s", rule.id)
507-
rule_definition = set(rule.tags)
508-
rule_definition.add(rule.id)
509-
if set(rule_definition).isdisjoint(skip_list):
510-
matches.extend(rule.getmatches(file))
506+
if tags and set(rule.tags).union(list(rule.ids().keys())).isdisjoint(
507+
tags,
508+
):
509+
_logger.debug("Skipping rule %s", rule.id)
510+
else:
511+
_logger.debug("Running rule %s", rule.id)
512+
rule_definition = set(rule.tags)
513+
rule_definition.add(rule.id)
514+
if set(rule_definition).isdisjoint(skip_list):
515+
matches.extend(rule.getmatches(file))
511516
else:
512517
_logger.debug("Skipping rule %s", rule.id)
513518

src/ansiblelint/schemas/__store__.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/molecule.json"
3737
},
3838
"playbook": {
39-
"etag": "b86e7f78281e33eb16de9c5c066da0f88798243b647cc195573441d92e1e78a5",
39+
"etag": "642a03707aadf49b54216f5882d6e91509fccaad7fc105fb83e24f15151bfafa",
4040
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json"
4141
},
4242
"requirements": {
4343
"etag": "5ae3a6058ac626a341338c760db7cef7f02a8911c7293c7e129dbc6b0f8bb86d",
4444
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/requirements.json"
4545
},
4646
"role-arg-spec": {
47-
"etag": "e0f25bc37f7b43d55b8e8f41929cab803179550e237d63c1134d51dfdd985ddf",
47+
"etag": "74fc5d429919813f2c977a2e3ed2afee1ca3dba242f6978bded8199895642db6",
4848
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/role-arg-spec.json"
4949
},
5050
"rulebook": {

test/test_with_skip_tagid.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_negative_with_id() -> None:
2727

2828
def test_negative_with_tag() -> None:
2929
"""Negative test with_tag."""
30-
with_tag = "trailing-spaces"
30+
with_tag = "yaml[trailing-spaces]"
3131
bad_runner = Runner(FILE, rules=collection, tags=frozenset([with_tag]))
3232
errs = bad_runner.run()
3333
assert len(errs) == 1
@@ -40,6 +40,13 @@ def test_positive_skip_id() -> None:
4040
assert [] == good_runner.run()
4141

4242

43+
def test_positive_skip_id_2() -> None:
44+
"""Positive test skip_id."""
45+
skip_id = "key-order"
46+
good_runner = Runner(FILE, rules=collection, tags=frozenset([skip_id]))
47+
assert [] == good_runner.run()
48+
49+
4350
def test_positive_skip_tag() -> None:
4451
"""Positive test skip_tag."""
4552
skip_tag = "yaml[trailing-spaces]"

0 commit comments

Comments
 (0)