3.0.1 β’ Published 3 years ago
@putout/plugin-remove-useless-type-conversion v3.0.1
@putout/plugin-remove-useless-type-conversion 
It is possible to use a couple of NOT operators (
!!) in series to explicitly force the conversion of any value to the corresponding boolean primitive. The conversion is based on the "truthyness" or "falsyness" of the value.The same conversion can be done through the
Booleanfunction.(c) MDN
πPutout plugin adds ability to remove useless type conversion. Merged to @putout/plugin-types.
Install
npm i @putout/plugin-remove-useless-type-conversionRule
{
"rules": {
"remove-useless-type-conversion/named": "on",
"remove-useless-type-conversion/with-double-negations": "on"
}
}named
β Example of incorrect code
const a = !![1].includes(1);
const b = Boolean([1].includes(1));β Example of correct code
const a = [1].includes(1);with-double-negations
β Example of incorrect code
if (!!a) {
console.log('hi');
}β Example of correct code
if (a) {
console.log('hi');
}Comparison
| Linter | Rule | Fix |
|---|---|---|
| π Putout | remove-useless-type-conversion | β |
| β£ ESLint | no-implicit-coercion | β |
License
MIT