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
@ARYPROGRAMMER
Copy link
Author

can someone review this

@alisonlhart or other maintainers

@alisonlhart
Copy link
Contributor

@ARYPROGRAMMER Can you open an issue for this feature and link it here?
It's not entirely clear what the need for this is - can you provide current vs expected behavior in that issue?

@ARYPROGRAMMER
Copy link
Author

@ARYPROGRAMMER Can you open an issue for this feature and link it here? It's not entirely clear what the need for this is - can you provide current vs expected behavior in that issue?

hold up surely

@ARYPROGRAMMER
Copy link
Author

here you go @alisonlhart

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.

2 participants