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

New: require-await rule (fixes #6820) #7435

Merged
merged 3 commits into from Nov 24, 2016
Merged

New: require-await rule (fixes #6820) #7435

merged 3 commits into from Nov 24, 2016

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] New rule (template)

Please describe what the rule should do:

This rule disallows async functions which have no await expression.
Async functions which have no await expression may be the unintentional result of refactoring.

See #6820 also.

What category of rule is this? (place an "X" next to just one item)

[X] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

/*eslint require-await: error*/

//------------------------------------------------------------------------------
// ✔ GOOD
async function foo() {
    await doSomething()
}

// This rule ignores empty functions as same as `require-yield` rule.
async function noop() {
    // do nothing.
}

function foo() {
    doSomething()
}

//------------------------------------------------------------------------------
// ✘ BAD
async function foo() {
    doSomething()
}

Why should this rule be included in ESLint (instead of a plugin)?

  • This is a general matter for JavaScript language.
  • ESLint has require-yield rule which does the same check for generator functions.

What changes did you make? (Give an overview)

This PR adds the require-await rule into core.

In addition, this PR adds 2 functions to ast-utils.

Is there anything you'd like reviewers to focus on?

  • Messages and documents.
  • Added 2 utilities.

@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 23, 2016
@mysticatea mysticatea self-assigned this Oct 23, 2016
@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @kaicataldo and @gyandeeps to be potential reviewers.

@eslintbot
Copy link

LGTM

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

One @fileoverview needs to be fleshed out, and I identified another possible ast-utils candidate, otherwise looks good.

@@ -0,0 +1,105 @@
/**
* @fileoverview Rule to
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be fleshed out, I think. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I have forgotten it since I use this template after a long time.

* @param {ASTNode} node - The function node to check.
* @returns {boolean} `true` if the function node is an empty function.
*/
function isEmpty(node) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should go in ast-utils?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably.

@eslintbot
Copy link

LGTM

@nzakas
Copy link
Member

nzakas commented Oct 31, 2016

Just a heads up: we have moved to a new CLA checker on pull requests. Even if you've previously signed our CLA, we will need to you sign the new one. To do so, look at the status checks for licence/cla and click the "Details" link. Sorry for the inconvenience.

@nzakas nzakas removed the CLA: Valid label Oct 31, 2016
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 21, 2016
@vitorbal
Copy link
Member

@platinumazure I believe your concerns have been addressed in the new commits from @mysticatea . Could you take a look when you have a chance?

@ilyavolodin ilyavolodin merged commit 89bd8de into master Nov 24, 2016
@mysticatea mysticatea deleted the issue6820 branch December 4, 2016 11:34
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants