Skip to content

Conversation

ARYPROGRAMMER
Copy link

Description

This PR implements the missing complexity[tasks] functionality for task and handler files that was documented but incompletely implemented in the complexity rule.

Problem

The complexity.md documentation described a complexity[tasks] tag that should trigger when the total number of tasks in a file exceeds the max_tasks threshold. However, this check was never implemented for task files and handler files, only the complexity[play] check existed for playbooks.

Changes:

  • Override matchtasks() to count and validate total tasks per file
  • Only applies to task/handler files (playbooks use complexity[play])
  • Uses task_in_list() utility for accurate task counting
  • Includes nested tasks within blocks in the count
  • Add test case for complexity[tasks] validation
  • Create test fixture: examples/playbooks/tasks/rule-complexity-tasks-fail.yml
  • Update documentation to clarify different complexity checks

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 counting
  • src/ansiblelint/rules/complexity.md - Updated documentation for clarity
  • examples/playbooks/tasks/rule-complexity-tasks-fail.yml - New test fixture (task file with 6 tasks)
  • ✅ Added pytest test case for the new functionality

Testing

All tests pass:

pytest src/ansiblelint/rules/complexity.py::test_complexity -v
# test_complexity[pass] PASSED   ✅
# test_complexity[fail] PASSED   ✅
# test_complexity[tasks] PASSED  ✅


Resolves: #2172 Completely
Type: Feature completion
Backward compatible: Yes
Breaking changes: None

@github-actions github-actions bot added feature and removed feature labels Oct 1, 2025
@ARYPROGRAMMER ARYPROGRAMMER changed the title feat: implement complexity[tasks] for task and handler files feat: complexity[tasks] for task and handler files Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant