coderaiser / putout

🐊 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 😏
https://putout.cloudcmd.io/
MIT License
712 stars 40 forks source link

[printer]: `protected constructor` and `private constructor` are fixed incorrectly. #172

Closed ElPrudi closed 1 year ago

ElPrudi commented 1 year ago

For example, I have this class:

export default class Test {
    protected x: number
    protected y: number

    private constructor(x: number, y: number) {
        if (typeof x === 'number') this.x = x  // example rule to trigger printer
        this.y = y
    }
}

The printer doesn't understand that the constructor can be scoped, so it transform it into this:

const isNumber = (a): a is number => typeof 'number'

export default class Test {
    protected x: number
    protected y: number
    constructorprivate(x: number, y: number) {
        if (isNumber(x)) this.x = x

        this.y = y
    }
}
coderaiser commented 1 year ago

Thanks! Just fixed 🎉, is it works for you?

ElPrudi commented 1 year ago

Yes, it doesn't try to fix it anymore. Thank you very much :)