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

Extend no-empty-function to handle constructors with parameter properties #426

Closed
bradzacher opened this issue Apr 12, 2019 · 3 comments · Fixed by #626
Closed

Extend no-empty-function to handle constructors with parameter properties #426

bradzacher opened this issue Apr 12, 2019 · 3 comments · Fixed by #626
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@bradzacher
Copy link
Member

Spawning off of #48 for clarity.

What code were you trying to parse?

export default class Foo {
  constructor(private name: string) {}
}

What happened?

  2:36  error  Unexpected empty constructor  no-empty-function
@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin enhancement: new plugin rule New rule request for eslint-plugin labels Apr 12, 2019
@eyedean
Copy link

eyedean commented Jun 15, 2019

I was hoping for something like @typescript-eslint/no-empty-function to exist, just like what fixed no-useless-constructor. I believe that's what this issue is for! :)

Well, until that comes to existence, I am going to go with the following in my .eslintrc.js:

   "no-empty-function": ["error", { "allow": ["constructors"] }],

PS. Sorry for treating here like Stackoverflow.com. I'll come back and remove this temporary solution once this issue is resolved!

@bradzacher bradzacher added enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed enhancement: new plugin rule New rule request for eslint-plugin labels Jun 16, 2019
@scottohara
Copy link
Contributor

This hypothetical @typescript-eslint/no-empty-function rule extension would presumably allow for:

  • if node.kind === "constructor", and
  • node.body.body.length == 0, and
  • node.value.params.some(param => param.type === AST_NODE_TYPES.TSParameterProperty)

(in other words: IF the function is a constructor AND it has an empty body AND it has one or more parameter properties...don't flag it as an error).

If I can find some spare time over the next few days, I'll try to get a PR started.
(no promises, though)

@scottohara
Copy link
Contributor

PR is now up (#626)

@bradzacher bradzacher added the has pr there is a PR raised to close this label Jun 19, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants