TristonJ / eslint-plugin-prefer-arrow

ESLint plugin to prefer arrow functions
MIT License
54 stars 10 forks source link

classPropertiesAllowed doesn't work? #19

Closed rafaelgomesxyz closed 4 years ago

rafaelgomesxyz commented 4 years ago

Take this example class:

class MyClass {
    constructor() {
        this.x = 0;
    }

    add(y) {
        this.x += y;
    }
}

I'd expect it to report an error, as the correct way would be:

class MyClass {
    constructor() {
        this.x = 0;
    }

    add = (y) => {
        this.x += y;
    };
}

Or have I misunderstood what this plugin does (there aren't examples in the docs)? This is the config I'm using:

"prefer-arrow/prefer-arrow-functions": [
    "error",
    {
        "disallowPrototype": true,
        "classPropertiesAllowed": false
    }
]

Edit: Wow, I need to learn how to read. Looks like what I want is "classPropertiesAllowed" set to true. I guess the wording confused me, I thought 'allowed' meant that it would ignore class methods. But it still doesn't work as expected, which is why I submitted #20.