deslop/complex-function

Flag functions exceeding configured cyclomatic/cognitive/param/line thresholds; suggest decomposing.

  • Category: Architecture
  • Severity: warn
  • Source: deslop-js
  • Framework: global
  • Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
  • Documentation: https://github.com/millionco/deslop-js

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires from deslop's detectComplexHotspots when a function breaches at least one ComplexityConfig threshold (defaults: cyclomatic 10, cognitive 15, paramCount 5, lineCount 80), with the reason reading like "fnName breaches N thresholds: cyclomatic 14 ≥ 10, cognitive 21 ≥ 15"; confidence is high when two or more thresholds breach, medium for one. False positive to SUPPRESS: irreducibly complex domain logic such as a parser, a state machine, or an exhaustive switch/case over a closed union where each branch is trivial (deslop adds +1 cyclomatic and a flat +1 cognitive per case, so case-heavy switches inflate both metrics faster than the actual reading difficulty), or generated/codegen code, where splitting would scatter the logic and hurt readability rather than help it.

Fix prompt

Use this once validation confirms the diagnostic is real.

Decompose the function: extract independent branches or loop bodies into named helpers (computeX, validateY) so each unit stays under the breached threshold, replace long if/else-if ladders with early returns or a lookup table, and collapse a 5+ argument list into a single options object (fn({ a, b, c })) to cut paramCount. For an exhaustive switch that only trips cyclomatic, leave it intact and raise cyclomaticThreshold via config rather than fragmenting it. The goal is lower cognitive load per unit, not just fewer lines. See https://github.com/millionco/deslop-js