Features

Code Quality Metrics

Understanding complexity and maintainability measurements

Stellarion measures code quality using industry-standard metrics that help you identify problematic code and track improvements over time.

Cyclomatic Complexity

Cyclomatic complexity counts the number of independent paths through a function. Higher numbers indicate more complex code that's harder to test and maintain.

ScoreRatingRecommendation
1-10LowCode is simple and maintainable
11-20ModerateConsider simplifying
21-30HighShould be refactored
31+Very HighRequires immediate attention

What Increases Cyclomatic Complexity

  • if / else statements
  • switch / case blocks
  • Loops (for, while, do-while)
  • Logical operators (&&, ||)
  • Ternary expressions
  • Catch blocks

Cognitive Complexity

Cognitive complexity measures how difficult code is for humans to understand. Unlike cyclomatic complexity, it considers nesting depth and cognitive "breaks" in linear flow.

ScoreRatingRecommendation
0-5LowEasy to understand
6-10ModerateAcceptable for most functions
11-15HighConsider breaking up
16+Very HighDifficult to maintain

Factors That Increase Cognitive Complexity

  • Nested control structures (each level adds more)
  • Breaks in linear flow (break, continue, goto)
  • Recursion
  • Boolean operators in conditions

Maintainability Index

The maintainability index is a composite score (0-100) based on:

  • Lines of code
  • Cyclomatic complexity
  • Halstead volume (vocabulary and length)
ScoreRating
85-100Highly maintainable
65-84Moderately maintainable
0-64Difficult to maintain

Using Metrics Effectively

Don't Optimize Blindly

Metrics are indicators, not rules. A complex function might be acceptable if:

  • It handles genuinely complex logic
  • It's well-documented
  • It's thoroughly tested

Individual scores matter less than trends. Track metrics over time to ensure quality doesn't degrade as the codebase grows.

Prioritize by Impact

Focus refactoring efforts on code that:

  • Has high complexity AND high change frequency
  • Is critical to business logic
  • Causes frequent bugs

Example Usage

Ask Claude Code to analyze your code quality:

Analyze the complexity of all functions in src/.
Show me anything with cyclomatic complexity over 15.
What's the maintainability index for this project?
Which files score lowest?