$ cnpm install @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.
npm i @putout/plugin-remove-useless-type-conversion
{
"rules": {
"remove-useless-type-conversion/named": "on",
"remove-useless-type-conversion/with-double-negations": "on"
}
}
const a = !![1].includes(1);
const b = Boolean([1].includes(1));
const a = [1].includes(1);
if (!!a) {
console.log('hi');
}
if (a) {
console.log('hi');
}
| Linter | Rule | Fix |
|---|---|---|
| ???? Putout | remove-useless-type-conversion |
✅ |
| ⏣ ESLint | no-implicit-coercion |
✅ |
MIT
Copyright 2013 - present © cnpmjs.org | Home |