JamieMason / eslint-plugin-prefer-arrow-functions

Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
MIT License
43 stars 11 forks source link

Warn constructor of class when classPropertiesAllowed is true #29

Open dryrainbow opened 4 months ago

dryrainbow commented 4 months ago

Description

Constructor of class cannot be an arrow function, so, I think we need ignore it. I use Typescript 5+ and eslint 8+

scottgreenup commented 1 month ago

I think we're having the same issue.

Here is an example.

class Foo {
  constructor(private readonly s: string) {

  }

  foo = (): string => {
    return this.s
  }
}

Which gives me this error

  N:C  warning  Prefer using arrow functions over plain functions                      prefer-arrow-functions/prefer-arrow-functions

Here are our versions:

# npx node --version
v18.20.2

# npx tsc --version
Version 5.1.6

# npx eslint --version
v8.57.0

Let me know if I can provide any more information ^_^

mitchell-merry commented 1 month ago

For a fix, I think you can just add kind != 'constructor' here: https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/blob/main/src/prefer-arrow-functions.ts#L268