Summary
Add code complexity monitoring using xenon and refactor any code that exceeds the target thresholds.
Target Thresholds
- max-absolute: D (no function exceeds D complexity)
- max-modules: C (no module exceeds C average)
- max-average: B (project-wide average stays at B or better)
Long-term goal: Aim for grade 'A' complexity on all new code.
Tasks
-
Add xenon to dev dependencies in pyproject.toml:
-
Add xenon pre-commit hook to .pre-commit-config.yaml:
- repo: https://github.com/rubik/xenon
rev: v0.9.0
hooks:
- id: xenon
args: ['--max-absolute=D', '--max-modules=C', '--max-average=B']
-
Run xenon to identify high-complexity code:
xenon --max-absolute=A --max-modules=A --max-average=A src/ftw_dataset_tools/
-
Refactor any functions/modules that exceed the thresholds using:
- Extract helper functions
- Early returns (guard clauses)
- Dictionary dispatch instead of long if-elif chains
- Single responsibility per function
-
Update CLAUDE.md to remove the TODO marker from the Code Complexity section
Complexity Grades Reference
- A: Simple, easy to understand (TARGET)
- B: Acceptable, low complexity
- C-F: Needs refactoring
Summary
Add code complexity monitoring using xenon and refactor any code that exceeds the target thresholds.
Target Thresholds
Long-term goal: Aim for grade 'A' complexity on all new code.
Tasks
Add xenon to dev dependencies in
pyproject.toml:"xenon>=0.9.3",Add xenon pre-commit hook to
.pre-commit-config.yaml:Run xenon to identify high-complexity code:
Refactor any functions/modules that exceed the thresholds using:
Update CLAUDE.md to remove the TODO marker from the Code Complexity section
Complexity Grades Reference