feat: complexity[tasks] for task and handler files #4799
+92
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements the missing
complexity[tasks]
functionality for task and handler files that was documented but incompletely implemented in thecomplexity
rule.Problem
The
complexity.md
documentation described acomplexity[tasks]
tag that should trigger when the total number of tasks in a file exceeds themax_tasks
threshold. However, this check was never implemented for task files and handler files, only thecomplexity[play]
check existed for playbooks.Changes:
The feature validates against the configurable max_tasks threshold
(default: 100) and provides clear, actionable error messages.
Changes
src/ansiblelint/rules/complexity.py
- Added matchtasks() override with task countingsrc/ansiblelint/rules/complexity.md
- Updated documentation for clarityexamples/playbooks/tasks/rule-complexity-tasks-fail.yml
- New test fixture (task file with 6 tasks)Testing
All tests pass: