Skip to content

builtinCoercions

Reports functions that wrap native coercion functions like String, Number, BigInt, Boolean, or Symbol.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

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.

const
const toString: (value: any) => string
toString
= (
value: any
value
) =>
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
value: any
value
);
const
const toNumber: (value: any) => number
toNumber
= function (
value: any
value
) {
return
var Number: NumberConstructor
(value?: any) => number

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
(
value: any
value
);
};
const
const truthy: any
truthy
=
const values: any
values
.
any
filter
((
value: any
value
) =>
value: any
value
);
const
const hasTruthy: any
hasTruthy
=
const values: any
values
.
any
some
((
item: any
item
) =>
item: any
item
);

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.