Skip to content

Commit

Permalink
Fix yaml rules being included regardless of tags
Browse files Browse the repository at this point in the history
with_tag within test_negative_with_tag has been changed to fix a failing
test, which should be fine as this models skip_tag within
test_positive_skip_tag.
  • Loading branch information
cavcrosby authored and audgirka committed Apr 17, 2024
1 parent 9e0f6f1 commit a261491
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 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: 853
PYTEST_REQPASS: 854
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
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 a261491

Please sign in to comment.