How is Code Health Calculated?

Code Health is an aggregated metric based on 25+ factors scanned from the source code. The code health factors correlate with increased maintenance costs and an increased risk for defects. Code Health is a model that correlates measurable aspects of your code with positive or negative outcomes for your project.

Each file with source code is categorized as either:

  • Green (healthy code that’s easy to change)
  • Yellow (complex code with maintenance issues and increased defect risk)
  • Red (code with severe technical debt and maintainability challenges)

 

Code Health_ an aggregated metric based on 25 factors

Module Smells

  • Low Cohesion
    Multiple unrelated responsibilities in a module/class, violating the Single Responsibility Principle (measured by LCOM4).
  • Brain Class (God Class)
    Large module with many lines of code, numerous functions, and at least one complex central method.
  • Developer Congestion
    Bottlenecks when multiple developers work on the same code.
  • Complex Code by Former Contributors
    If a developer behind a hotspot with low Code Health leaves the organization, the maintenance risk increases significantly. 

Function Smells

  • Brain Method (God Function)
    Complex function centralizing behavior, becoming a local hotspot.
  • DRY (Don't Repeat Yourself) Violations
    Duplicated logic changed together predictably.
  • Complex Method
    Many conditional statements (e.g., if, for, while) reduce code health (cyclomatic complexity).
  • Primitive Obssession
    Overuse of built-in primitives without encapsulation.
  • Large Method
    Functions with many lines of code are harder to understand.

Implementation Smells

  • Nested Complexity
    If-statements or loops inside others increase defect risk.
  • Bumpy Road
    Functions with multiple logical chunks; needed for encapsulation into smaller functions.
  • Complex Conditional
    Expression with multiple logical operators (AND/OR) inside branches complicates understanding.
  • Large Assertion Blocks
    Consecutive assert statements indicate missing abstractions.
  • Duplicated Assertion Blocks
    Copy-pasted assertion blocks in tests indicate DRY violations.

You can get the complete list of the code health rules from your project's configuration:

  • Navigate to your CodeScene project.
  • Click on its “Configuration”.
  • Select the “Code Health” config tab.
  • Click on the template (JSON file) link:

image (36)