Skip to main content

Core analyzer

Maintainability Index

Composite 0-100 index (Oman & Hagemeister) of a file from its Halstead volume, its decision points and its executable statements, graded on the SEI and Visual Studio bands.

technical-debt core-maintainability

Maintainability Index

Composite 0-100 index (Oman & Hagemeister) of a file from its Halstead volume, its decision points and its executable statements, graded on the SEI and Visual Studio bands.

The Maintainability Index, formalized by Oman & Hagemeister (1992) and adopted by Microsoft Visual Studio's Code Metrics, folds three measurements of a file into one number: MI = 171 − 5.2×ln(V) − 0.23×CC − 16.2×ln(LOC), rescaled to 0-100 (max(0, MI × 100 / 171)).

All three inputs are totals of the whole file, measured over the same code: V is the Halstead volume (operators and operands of the program; type annotations, imports and exports are not counted), CC is the file's cyclomatic total (1 plus every decision point), and LOC is the number of executable statements at any depth — a statement inside a callback counts exactly like one in a function body. Because every input grows with the file, the index mostly tracks how much code a file holds; it does not single out a function. The per-function analyses do that.

Bands. The letters use the two published scales, converted to the 0-100 value: A from 50 (the SEI limit for highly maintainable code, 85 on the raw scale), B from 38 (the SEI limit for moderately maintainable code, raw 65), C from 20 (still the green band of Visual Studio), D from 10 (Visual Studio yellow), F below 10 (Visual Studio red). A and B produce no finding.

Severity guide

info
Rating C (20-37): under the SEI limit for moderately maintainable code, still green on Visual Studio's scale. Also used for the component findings that explain a C, D or F rating.
warning
Rating D (10-19): the yellow band of Visual Studio's scale. Changes carry meaningful risk.
critical
Rating F (below 10): the red band of Visual Studio's scale. Decompose the file.

Examples

Before

// 600 LOC file with 15 cyclomatic and dense expressions throughout
export function orchestrate(input, opts, ctx) {
  // ... many nested branches and inline transformations
}

After

// Decomposed into focused modules
// orchestrate.ts (80 LOC, cyclomatic 5)
// parse-input.ts (60 LOC, cyclomatic 3)
// apply-transformations.ts (80 LOC, cyclomatic 4)
// format-output.ts (40 LOC, cyclomatic 2)

All three inputs of the index are file totals, so splitting one large file into focused modules lowers every one of them for each module and lifts the rating.

Remediation

Split the file along its responsibilities; start with the function findings, which name the specific functions that hold most of the branching and length.

  • The index is computed from file totals. The component findings (volume, complexity, LOC) say which total is furthest above its threshold.
  • Volume: extract repeated expression patterns into named helpers; move large inline data into its own module.
  • Complexity: replace nested conditionals with early returns, move large switch blocks to lookup tables, extract boolean conditions into named predicates.
  • LOC: identify cohesive groups of functions and extract them into a dedicated module. Even moving a third of the file's logic out can move the rating up a grade.
  • Re-run analysis after each refactoring pass; a single significant extraction often yields more improvement than many micro-edits.

References

Documentation