unicorn/no-useless-coercion
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-coercion": "error",
},
},
];Disallow useless type coercions of values that are already of the target type.
const a = Boolean(true);const b = String('hello');const c = Number(42);const a = true;const b = 'hello';const c = 42;Examples from the ESLint documentation.
unicorn/no-useless-coercion
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-coercion": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Disallow unnecessary Boolean() casts in array predicate callbacks.
Disallow useless compound assignments such as x += 0.
Disallow passing full URLs to URLSearchParams.
Disallow discarding lazy iterator helpers.
Disallow unnecessary existence checks before deletion.