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.
Returns the elements of an array that meet the condition specified in a callback function.
@param ― predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether the specified callback function returns true for any element of an array.
@param ― predicate A function that accepts up to three arguments. The some method calls
the predicate function for each element in the array until the predicate returns a value
which is coercible to the Boolean value true, or until the end of the array.
@param ― thisArg An object to which the this keyword can refer in the predicate function.
If thisArg is omitted, undefined is used as the this value.
some((
item: unknown
item) =>
item: unknown
item);
const
const toString:StringConstructor
toString =
var String:StringConstructor
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String;
const
const toNumber:NumberConstructor
toNumber =
var Number:NumberConstructor
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Returns the elements of an array that meet the condition specified in a callback function.
@param ― predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether the specified callback function returns true for any element of an array.
@param ― predicate A function that accepts up to three arguments. The some method calls
the predicate function for each element in the array until the predicate returns a value
which is coercible to the Boolean value true, or until the end of the array.
@param ― thisArg An object to which the this keyword can refer in the predicate function.
If thisArg is omitted, undefined is used as the this value.
some(
var Boolean:BooleanConstructor
Boolean);
const
const transform:(value:any) => string
transform = (
value: any
value) =>
var String:StringConstructor
(value?:any)=> string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
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.