maintainability-index

ProComplexity

Flag functions with low maintainability index (MI) based on Halstead volume, cyclomatic complexity, and lines of code

maintainability-index

Flag functions with low maintainability index (MI) based on Halstead volume, cyclomatic complexity, and lines of code

Category: Complexity | Tier: Pro

Why This Matters

The maintainability index combines code volume, complexity, and documentation into a single score. AI-generated code often scores low because it produces dense, uncommented logic in oversized functions.

Bad Code

// Low maintainability: long, complex, uncommented
function calc(d) {
  let r = 0;
  for (let i = 0; i < d.length; i++) {
    if (d[i].t === 1) { r += d[i].v * 1.1; }
    else if (d[i].t === 2) { r += d[i].v * 0.9; }
    // ... 50 more lines of dense logic
  }
  return r;
}

Good Code

/** Calculate total with type-based pricing adjustments. */
function calculateTotal(items: Item[]): number {
  return items.reduce((total, item) => {
    const multiplier = PRICE_MULTIPLIERS[item.type] ?? 1;
    return total + item.value * multiplier;
  }, 0);
}

Configuration

This rule accepts configuration options:

[
  {
    "type": "object",
    "properties": {
      "threshold": {
        "type": "number",
        "minimum": 0,
        "maximum": 171
      }
    },
    "additionalProperties": false
  }
]

Enabled by default in lintmyai:recommended.