Skip to content

Add xenon complexity monitoring and refactor high-complexity code #15

@cholmes

Description

@cholmes

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

  1. Add xenon to dev dependencies in pyproject.toml:

    "xenon>=0.9.3",
  2. 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']
  3. Run xenon to identify high-complexity code:

    xenon --max-absolute=A --max-modules=A --max-average=A src/ftw_dataset_tools/
  4. 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
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions