🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement 💪 with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏
function test(a: any, b: any) {
if (typeof a === 'number' && typeof b === 'number') return a + b
return undefined
}
will turn into this:
const isNumber = (a): a is number => typeof 'number'
function test(a: any, b: any) {
if (isNumber(a) && isNumber(b)) return a + b
return undefined
}
But, if I change one condition back:
const isNumber = (a): a is number => typeof 'number'
function test(a: any, b: any) {
if (isNumber(a) && typeof b === 'number') return a + b // no eslint issues
return undefined
}
the plugin can not detect typeof b === 'number' as the first part is already fixed. It will only fix it again, if you remove the generated guard.
There is an edge case where this plugin fails:
will turn into this:
But, if I change one condition back:
the plugin can not detect
typeof b === 'number'
as the first part is already fixed. It will only fix it again, if you remove the generated guard.