deslop/identity-wrapper
Flag a thin function that just forwards its args to another callable unchanged, e.g. const getUser = (id) => fetchUser(id).
- 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 (always at high confidence) on a module-level or exported const/variable declaration in a non-declaration file whose initializer is a non-async, non-generator arrow or function expression with a body that is a single call (direct => callee(...) or a one-statement block { return callee(...) }), where every call argument is a bare identifier matching the wrapper's parameters in the same order (or a single ...rest spread), with no default params and a callee whose text differs from the wrapper name; reason reads "name is a thin wrapper that forwards every argument to callee unchanged". Note it only walks top-level program statements, so wrappers nested inside functions, blocks, or class methods and plain function declarations are never scanned. Suppress when the wrapper is load-bearing rather than cosmetic: it narrows or brands the PUBLIC signature by giving a parameter a stricter type than the callee accepts (e.g. (id: UserId) => fetchUser(id) over a looser fetchUser(id: string), where id is still a bare identifier so the rule does fire), it is a documented extension/override seam meant to be swapped in tests or by consumers, or it exists only to satisfy a required higher-order/callback signature where the bare callee's shape would not fit.
Fix prompt
Use this once validation confirms the diagnostic is real.
Delete the wrapper and reference the inner callable directly: replace const getUser = (id) => fetchUser(id) with fetchUser at every call site, or export { fetchUser as getUser } if the name must be preserved. If the wrapper exists only to fix this binding or partially apply arguments, keep it but make that intent explicit; if it only adds a type, prefer const getUser: GetUser = fetchUser over a forwarding lambda so the runtime indirection disappears. An identity wrapper adds a stack frame and a name to maintain while changing nothing about behavior. See https://github.com/millionco/deslop-js