Skip to main content

Module mi

Module mi 

Expand description

Maintainability Index banding — repo-relative, not absolute.

complexity_metrics.mi stores the SEI-variant MI computed by the vendored codelore-rca fork of Mozilla rust-code-analysis. The formula (Coleman et al. 1994 + SEI 1997) is:

  mi_sei = 171 − 5.2·log₂(V) − 0.23·CC − 16.2·log₂(SLOC)
         + 50·sin(√(2.4·comments%))

where V is Halstead volume, CC is cyclomatic complexity, SLOC is source lines of code, and comments% is the comment-line ratio.

Why we don’t use the literature’s absolute thresholds. The Coleman/SEI convention (≥85 high, 65–85 moderate, <65 low) was calibrated on 1990s-era embedded-software modules typically <200 SLOC each. Modern source files at 500–5000 SLOC produce much lower MI because the −16.2·log₂(SLOC) term grows fast. Empirically validated on CodeLore’s own Rust codebase (see docs/research-foundations.md): MI values range [−137, +104] with median ≈2.7 — applying the literature thresholds verbatim would classify 100% of well-maintained files as “low maintainability”. CHM ships the literature thresholds because its JS/TS sample files are small; ours aren’t.

CodeLore’s choice: repo-relative percentile bands. The hotspots SQL computes PERCENT_RANK() OVER (ORDER BY mi) and the band is derived from that rank. This matches the existing relative-ranking convention used by hotspot_score (which is built on PERCENT_RANK(revs) × PERCENT_RANK(cognitive)).

Bands:

BandPercentile rank within repo
Hightop 25% (rank ≥ 0.75)
Moderatemiddle 50% (0.25 ≤ rank < 0.75)
Lowbottom 25% (rank < 0.25)
(unknown)file has no kind='unit' complexity entry — language not yet supported by codelore-rca, or file skipped at ingest

Trade-off: bands aren’t comparable across repos (a “moderate” file in a tightly-maintained repo could be a “high” file in a sprawling one). The raw mi value and mi_rank percentile are surfaced alongside the band on every emitter so users can see the absolute context too.

Structs§

MiRollup
Per-repo aggregate count of files per MI band. Feeds the SPA dashboard’s MI-band KPI tile and serializable summaries.

Enums§

MiBand
Repo-relative MI band. See module docs for the rationale on percentile bands vs absolute Coleman/SEI thresholds.

Constants§

MI_BAND_HIGH_PERCENTILE
Lower bound of the High band on the [0, 1] percentile-rank scale.
MI_BAND_MODERATE_PERCENTILE
Lower bound of the Moderate band on the [0, 1] percentile-rank scale. Anything below this is Low.