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

fix(eslint-plugin): [pfa] Allow async getter/setter in classes #980

Merged

Conversation

scottohara
Copy link
Contributor

In #820, support was added for getters/setters that return async functions, e.g.

const someObject = {
  get asyncGetterFunc() {
    return async () => new Promise<void>();
  },
  set asyncGetterFunc(p: () => Promise<void>) {
    return p;
  }
}

Unfortunately, the previous fix only handles getters/setters on objects (the implementation specifically checks for node.parent.type === 'Property').

As it turns out, getter/setters on classes have node.parent.type === 'MethodDeclaration', so the following code still generates warnings:

class SomeClass = {
  get asyncGetterFunc() {
    return async () => new Promise<void>();
  },
  set asyncGetterFunc(p: () => Promise<void>) {
    return p;
  }
}

This PR addresses the class getter/setter case, by checking if node.parent.type === 'Property' || node.parent.type === 'MethodDefinition'.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @scottohara!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@bradzacher bradzacher added the bug Something isn't working label Sep 17, 2019
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for this

@bradzacher bradzacher changed the title fix(eslint-plugin): [promise-function-async] Allow async function getter/setter in classes fix(eslint-plugin): [pfa] Allow async getter/setter in classes Sep 17, 2019
@bradzacher bradzacher merged commit e348cb2 into typescript-eslint:master Sep 17, 2019
@scottohara scottohara deleted the promise-function-async branch September 17, 2019 02:56
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants