coderaiser/putout

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

ElPrudi opened this issue · 2 comments

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
    }
}

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

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