Skip to main content
Scanners

Code Quality Scanner

Fast AST-based quality checks for cyclomatic complexity and upgrade friction hotspots.

The Code Quality scanner performs fast AST-based analysis to identify upgrade friction hotspots. It measures complexity metrics that correlate with difficult migrations and maintenance burden.


Metrics Collected

Function-Level Metrics

MetricDescriptionWhy It Matters
Cyclomatic complexityNumber of decision pointsHigh complexity = harder to test and upgrade
Function lengthLines per functionLong functions often need refactoring
Parameter countArguments per functionMany parameters suggest refactoring needed
Nesting depthMaximum indentation levelDeep nesting is harder to understand

File-Level Metrics

MetricDescriptionWhy It Matters
File sizeLines of codeLarge files are upgrade bottlenecks
Export countNumber of exportsMany exports = high coupling
Import countNumber of importsMany imports = high dependencies
Circular dependenciesFiles that import each otherCircular imports complicate upgrades

Project-Level Metrics

MetricDescription
"God files"Files exceeding complexity thresholds
Dead code estimatePotentially unused exports
Test coverage gapsFiles without corresponding tests

Thresholds

Metric🟢 Healthy🟡 Warning🔴 Critical
Cyclomatic complexity<1010–20>20
Function length<50 lines50–100 lines>100 lines
Nesting depth<4 levels4–6 levels>6 levels
File size<300 lines300–500 lines>500 lines
Parameters<44–6>6

Use Cases

Pre-Upgrade Assessment

Identify files that will be hardest to upgrade:

vg scan --format json | jq '.codeQuality.godFiles | sort_by(-.complexity)'

Refactoring Prioritization

Rank files by complexity for refactoring sprints:

vg scan --format json | jq '.codeQuality | {avgComplexity, godFiles: (.godFiles | length)}'

Code Review Focus

During upgrades, focus review effort on high-complexity files.


Example Output

{
  "codeQuality": {
    "summary": {
      "filesAnalyzed": 245,
      "functionsAnalyzed": 1203,
      "healthScore": 72
    },
    "averages": {
      "cyclomaticComplexity": 8.3,
      "functionLength": 32,
      "nestingDepth": 2.8,
      "parametersPerFunction": 2.1
    },
    "maximums": {
      "cyclomaticComplexity": 45,
      "functionLength": 287,
      "nestingDepth": 7
    },
    "circularDependencies": [
      {
        "cycle": ["src/auth/index.ts", "src/api/middleware.ts", "src/auth/index.ts"],
        "severity": "high"
      }
    ],
    "godFiles": [
      {
        "path": "src/legacy/megaModule.ts",
        "complexity": 45,
        "lines": 892,
        "functions": 34,
        "recommendations": [
          "Consider splitting into multiple modules",
          "Extract pure utility functions"
        ]
      },
      {
        "path": "src/api/handlers.ts",
        "complexity": 32,
        "lines": 456,
        "functions": 22
      }
    ],
    "deadCodeEstimate": {
      "unusedExports": 12,
      "files": ["src/utils/deprecated.ts", "src/legacy/old-api.ts"]
    }
  }
}

Configuration

Customize thresholds in config:

// vibgrate.config.ts
const config: VibgrateConfig = {
  scanners: {
    codeQuality: {
      enabled: true,
      thresholds: {
        cyclomaticComplexity: { warning: 15, critical: 25 },
        functionLength: { warning: 75, critical: 150 },
        nestingDepth: { warning: 5, critical: 8 },
      },
      exclude: ['**/*.test.ts', '**/*.spec.ts'],
    },
  },
};

Related Documentation