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:
| Band | Percentile rank within repo |
|---|---|
High | top 25% (rank ≥ 0.75) |
Moderate | middle 50% (0.25 ≤ rank < 0.75) |
Low | bottom 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
Highband on the[0, 1]percentile-rank scale. - MI_
BAND_ MODERATE_ PERCENTILE - Lower bound of the
Moderateband on the[0, 1]percentile-rank scale. Anything below this isLow.