Skip to content

Conversation

@Jkhall81
Copy link
Contributor

@Jkhall81 Jkhall81 commented Jan 7, 2026

Summary

This fix addresses an issue where ansible-lint was being too "broad" when asked to check for specific sub-rules.

The Problem

Previously, if you asked the linter to check for one specific item (like yaml[truthy]), it would often "leak" and show you every other YAML-related error as well. It couldn't distinguish between a general category and a specific, bracketed sub-tag.

The Fix

This update makes the filtering process much more precise. Now:

  • Specific Requests: If you ask for a specific sub-rule in brackets, the linter will only show that exact match.
  • Smart Skipping: If you tell the linter to ignore one specific sub-rule, it will do so without accidentally ignoring the entire rule or failing to hide the specific tag.
  • Better Overlap Handling: If you ask for a broad category (like "formatting") but also specify a single rule (like yaml[truthy]), the linter now understands you want to narrow your focus to that specific item.

I have added new tests to ensure these scenarios work correctly.

Fixes #4675

Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that coverage does not go down, you missed one line from coverage, check codecov report. Other than this it looks quite nice.

@Jkhall81 Jkhall81 force-pushed the fix/4675-fix-yaml-subtag-filtering branch from e87eca7 to c4f97ba Compare January 8, 2026 12:59
@github-actions github-actions bot added fix and removed fix labels Jan 8, 2026
@Jkhall81
Copy link
Contributor Author

Jkhall81 commented Jan 8, 2026

It looks like that code was actually unreachable / an uneceesary extra check. The rule pre filtering (the is_skipped) check was preventing the generation of matches for skipped rules, so there was nothing to trigger that if statment and the code on line 536.

I figured out how to get a code coverage report locally:

uv run --group dev python -m pytest -p pytest_cov --cov=src/ansiblelint --cov-report=term-missing test/test_rules_collection.py | grep "rules/__init__.py"

For whatever file I have messed with. I had never used it before, but it's pretty neat. So I'll start checking this on my machine before I push from now on.

@github-project-automation github-project-automation bot moved this from In Progress to Review in 🧰 devtools project board Jan 8, 2026
@github-actions github-actions bot added fix and removed fix labels Jan 8, 2026
@ssbarnea ssbarnea enabled auto-merge (squash) January 8, 2026 13:24
@ssbarnea ssbarnea merged commit a9f8a4e into ansible:main Jan 8, 2026
22 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in 🧰 devtools project board Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

unable to lint a limited subset of yaml tags on command line

2 participants