saurabhkumar8112/cyclomatic-complexity-skill
Claude skill: refactor code to reduce cyclomatic complexity
What it solves
It addresses the issue of AI-generated code that is functionally correct but overly complex and difficult to maintain. It prevents code from becoming a "jungle" of branches and nested logic by reducing cyclomatic complexity.
How it works
The tool measures the complexity of functions using various tools (such as radon, eslint, gocyclo, or lizard) or manual counts. It then identifies the most complex "hotspots" and refactors them using techniques like guard clauses, extracting functions, and using lookup tables. It ensures that complexity is not simply hidden in one-liners but is moved into clearly named functions.
Who it’s for
Developers who use Claude to generate or refactor code and want to ensure their codebase remains maintainable and human-readable.
Highlights
- Measures complexity per function using standard linting tools.
- Respects project-specific linter thresholds.
- Focuses on refactoring the worst hotspots first.
- Provides a before-and-after complexity table to quantify improvements.
Related
- Project
- Project
- Project
- Project