Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn constructor of class when classPropertiesAllowed is true #29

Open
dryrainbow opened this issue Feb 12, 2024 · 2 comments · May be fixed by #36
Open

Warn constructor of class when classPropertiesAllowed is true #29

dryrainbow opened this issue Feb 12, 2024 · 2 comments · May be fixed by #36

Comments

@dryrainbow
Copy link

Description

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

@scottgreenup
Copy link

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
Copy link
Contributor

mitchell-merry commented May 23, 2024

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

mitchell-merry added a commit to mitchell-merry/eslint-plugin-prefer-arrow-functions that referenced this issue May 23, 2024
mitchell-merry added a commit to mitchell-merry/eslint-plugin-prefer-arrow-functions that referenced this issue May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants