Skip to content

unicorn/prefer-native-coercion-functions Pedantic

🚧 An auto-fix is still under development.

What it does

Prefers built in functions, over custom ones with the same functionality.

Why is this bad?

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.

Examples

Examples of incorrect code for this rule:

javascript
const foo = (v) => String(v);
foo(1);
const foo = (v) => Number(v);
array.some((v) => /* comment */ v);

Examples of correct code for this rule:

javascript
String(1);
Number(1);
array.some(Boolean);

References

Released under the MIT License.