deslop/simplifiable-expression

Disallow expressions that collapse to a simpler equivalent, e.g. !!x → Boolean(x).

  • Category: Correctness
  • 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 when deslop's simplifiable-expression detector matches one of five AST shapes and emits a reason/suggestion: self-fallback-ternary (test text equals consequent text, reason x ? x : y is a self-fallback ternary), ternary-returns-boolean (cond ? true : false collapses to Boolean(cond) / cond ? false : true collapses to !cond), double-bang-boolean (!!x is a double-negation boolean coercion), nullish-coalescing-with-nullish (x ?? null or x ?? undefined), or redundant-null-and-undefined-check (x !== null && x !== undefined is equivalent to x != null). False positive: the nullish-coalescing-with-nullish case is often intentional — deslop's own reason flags that x ?? null may be required by a caller's signature (PropTypes, a form-control onChange that demands null not undefined) where the ?? null coercion changes the resolved type; also rare cases where a !!x is kept as an explicit, readable boolean coercion at a JSX render guard like {!!items.length && <List/>} (still generally worth simplifying). Suppress when the coercion is load-bearing for a downstream type or contract; otherwise confirm.

Fix prompt

Use this once validation confirms the diagnostic is real.

Apply deslop's suggestion for the matched kind: rewrite cond ? true : false to Boolean(cond) (or just cond when the type already is boolean) and cond ? false : true to !cond; rewrite !!x to Boolean(x); collapse x !== null && x !== undefined to x != null; and rewrite a self-fallback x ? x : y to x ?? y (nullish-only) or x || y (falsy fallback) per intent. For x ?? null/x ?? undefined, only drop the ?? null when x is already typed T | null (the coalesce is then a no-op); if the literal is required to satisfy a prop or callback signature, keep it. These are behavior-preserving simplifications that remove noise and signal intent more directly. See https://github.com/millionco/deslop-js