💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
If a function is equivalent to String
, Number
, BigInt
, Boolean
, or Symbol
, you should use the built-in one directly. Wrapping the built-in in a function is moot.
const toBoolean = value => Boolean(value);
function toNumber(value) {
return Number(value);
}
if (toNumber(foo) === 1) {}
const hasTruthyValue = array.some(element => element);
const toBoolean = Boolean;
if (Number(foo) === 1) {}
const hasTruthyValue = array.some(Boolean);
const toStringObject = value => new String(value);
const toObject= value => Object(value);
We don't check implicit coercion like:
const toString = value => '' + value;
const toNumber = value => +value;
const toBoolean = value => !!value;
It is recommended to enable the built-in ESLint rule no-implicit-coercion
for a better experience.