Skip to content

Commit

Permalink
Fix yaml rules being included regardless of tags (#4107)
Browse files Browse the repository at this point in the history
Co-authored-by: Kate Case <this.is@katherineca.se>
  • Loading branch information
cavcrosby and Qalthos authored Apr 25, 2024
1 parent 17194e6 commit 9a43cf1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 854
PYTEST_REQPASS: 855
steps:
- uses: actions/checkout@v4
with:
Expand Down
15 changes: 10 additions & 5 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,16 @@ def run(
or rule.has_dynamic_tags
or not set(rule.tags).union([rule.id]).isdisjoint(tags)
):
_logger.debug("Running rule %s", rule.id)
rule_definition = set(rule.tags)
rule_definition.add(rule.id)
if set(rule_definition).isdisjoint(skip_list):
matches.extend(rule.getmatches(file))
if tags and set(rule.tags).union(list(rule.ids().keys())).isdisjoint(
tags,
):
_logger.debug("Skipping rule %s", rule.id)
else:
_logger.debug("Running rule %s", rule.id)
rule_definition = set(rule.tags)
rule_definition.add(rule.id)
if set(rule_definition).isdisjoint(skip_list):
matches.extend(rule.getmatches(file))
else:
_logger.debug("Skipping rule %s", rule.id)

Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/molecule.json"
},
"playbook": {
"etag": "b86e7f78281e33eb16de9c5c066da0f88798243b647cc195573441d92e1e78a5",
"etag": "642a03707aadf49b54216f5882d6e91509fccaad7fc105fb83e24f15151bfafa",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json"
},
"requirements": {
"etag": "5ae3a6058ac626a341338c760db7cef7f02a8911c7293c7e129dbc6b0f8bb86d",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/requirements.json"
},
"role-arg-spec": {
"etag": "e0f25bc37f7b43d55b8e8f41929cab803179550e237d63c1134d51dfdd985ddf",
"etag": "74fc5d429919813f2c977a2e3ed2afee1ca3dba242f6978bded8199895642db6",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/role-arg-spec.json"
},
"rulebook": {
Expand Down
9 changes: 8 additions & 1 deletion test/test_with_skip_tagid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_negative_with_id() -> None:

def test_negative_with_tag() -> None:
"""Negative test with_tag."""
with_tag = "trailing-spaces"
with_tag = "yaml[trailing-spaces]"
bad_runner = Runner(FILE, rules=collection, tags=frozenset([with_tag]))
errs = bad_runner.run()
assert len(errs) == 1
Expand All @@ -40,6 +40,13 @@ def test_positive_skip_id() -> None:
assert [] == good_runner.run()


def test_positive_skip_id_2() -> None:
"""Positive test skip_id."""
skip_id = "key-order"
good_runner = Runner(FILE, rules=collection, tags=frozenset([skip_id]))
assert [] == good_runner.run()


def test_positive_skip_tag() -> None:
"""Positive test skip_tag."""
skip_tag = "yaml[trailing-spaces]"
Expand Down

0 comments on commit 9a43cf1

Please sign in to comment.