no-implicit-coercion
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"no-implicit-coercion": "error",
},
},
];const b = !!foo;
const b1 = ~foo.indexOf(".");
// bitwise not is incorrect only with `indexOf`/`lastIndexOf` method calling.const n = +foo;
const n1 = -(-foo);
const n2 = foo - 0;
const n3 = 1 * foo;const s = "" + foo;
const s1 = `` + foo;
foo += "";
foo += ``;const b = Boolean(foo);
const b1 = foo.indexOf(".") !== -1;
const n = ~foo; // This is a just bitwise not.const n = Number(foo);
const n1 = parseFloat(foo);
const n2 = parseInt(foo, 10);
const n3 = foo * 1/4; // `* 1` is allowed when followed by the `/` operatorconst s = String(foo);
foo = String(foo);Examples from the ESLint documentation.
no-implicit-coercion
eslint
export default [
{
rules: {
"no-implicit-coercion": "error",
},
},
];no-implicit-coercion
eslint plugin · style
{
"rules": {
"no-implicit-coercion": "error"
}
}complexity/noImplicitCoercions
complexity · since 2.1.0
{
"linter": {
"rules": {
"complexity": {
"noImplicitCoercions": "error"
}
}
}
}Disallow shorthand type conversions in <template>
Enforce a maximum number of parameters in function definitions
Enforce or disallow capitalization of the first letter of a comment
Enforce a maximum number of lines per file
Enforce a maximum depth that blocks can be nested
Disallow use of this in contexts where the value of this is undefined