Skip to content

SonarJS Complexity Metrics Integration

Status: Planned (Phase 0 ready to begin) Repository: arda-frontend-app Prerequisite: None — can start immediately Source proposal: workspace/projects/_planning/fe-quality-metrics/sonarjs-integration-proposal.md

Integrate eslint-plugin-sonarjs into the arda-frontend-app development workflow to surface cognitive and cyclomatic complexity metrics. The rollout uses a ratcheting strategy: generous initial thresholds that tighten over time.

The initial scan on the jmpicnic/stryker-exp branch found 453 problems (316 errors, 137 warnings) concentrated in 5 hotspot files. The two worst files have cognitive complexity scores over 80.

PhaseTimeframeCognitive thresholdCyclomatic thresholdCI max-warningsEffect
0 — BaselineWeek 1warn @ 25warn @ 209,999Install, measure, educate; CI always green
1 — AwarenessMonth 1warn @ 25warn @ 209,999Developers see warnings in IDE and PR artifacts
2 — Soft gateMonth 2warn @ 20warn @ 15500PRs with >500 warnings fail
3 — Hard gateQuarter 2warn @ 15warn @ 10300Meaningful enforcement; hotspots must be resolved first
4 — Steady stateOngoingwarn @ 15warn @ 10Ratchet -10/sprintMonotonically decreasing ceiling

Four rules only — no preset (avoids inheriting ~20 rules needing audit):

  • sonarjs/cognitive-complexity (warn @ 25)
  • sonarjs/cyclomatic-complexity (warn @ 20)
  • sonarjs/no-nested-conditional (warn)
  • sonarjs/no-identical-functions (warn)

A dedicated eslint.complexity.mjs config file runs the complexity-only analysis in CI to keep the job fast and focused.

A new complexity job runs on every PR:

  • Identifies changed source files via git diff.
  • Runs complexity analysis on changed files only (does not penalize PRs for pre-existing debt).
  • Uploads a complexity report artifact (retained 90 days) with per-file violation counts and worst scores.
  • The full-codebase snapshot is captured for trend tracking but does not gate PRs.

Hotspot Files (must be addressed before Phase 2)

Section titled “Hotspot Files (must be addressed before Phase 2)”
FileCognitive maxCyclomatic maxPriority
src/app/items/page.tsx11181P1
src/app/order-queue/page.tsx8994P1
src/components/scan/MobileScanView.tsx~40~40P2
src/components/items/ItemFormPanel.tsx~30~30P2
src/components/table/columnPresets.tsx~25~25P3

P1 hotspots require component decomposition before Phase 2 thresholds take effect. See Complexity Hotspot Remediation.

#DescriptionPersona
1Install eslint-plugin-sonarjs, update eslint.config.mjsFront End Engineer
2Create eslint.complexity.mjsFront End Engineer
3Add npm scripts and Makefile targetsFront End Engineer
4Create scripts/complexity-summary.mjsFront End Engineer
5Add complexity CI job (required check, --max-warnings 9999)DevOps Engineer
6Add reports/complexity/ to .gitignoreFront End Engineer
7Write developer training documentTechnical Writer
8Create complexity-metrics agent skillPrincipal Engineer
9Integrate skill into agent personasPrincipal Engineer
10Run baseline scan, commit snapshotFront End Engineer
11Team walkthrough sessionAll