builtinCoercions
Reports functions that wrap native coercion functions like
String,Number,BigInt,Boolean, orSymbol.
✅ This rule is included in the ts stylistic preset.
JavaScript’s built-in coercion functions Boolean, BigInt, Number, String, and Symbol can be passed directly where a function is expected.
Wrapping them in another function adds unnecessary indirection and reduces code clarity.
This rule also detects identity functions used as callbacks to array filtering methods like .filter(), .some(), .every(), .find(), .findIndex(), .findLast(), and .findLastIndex().
These identity functions are equivalent to passing Boolean directly, which filters out falsy values.
Examples
Section titled “Examples”const toString = (value) => String(value);const toNumber = function (value) { return Number(value);};const truthy = values.filter((value) => value);const hasTruthy = values.some((item) => item);const toString = String;const toNumber = Number;const truthy = values.filter(Boolean);const hasTruthy = values.some(Boolean);const transform = (value) => String(value) + "!";Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer the explicit function wrapper style for consistency with other callbacks that do transform their arguments, you may disable this rule. Some codebases may prefer the visual consistency of always using arrow functions in callbacks, even when a direct function reference would work.