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: add no-async-promise-executor rule (fixes #10217) #10661

Merged
merged 2 commits into from
Jul 27, 2018

Conversation

not-an-aardvark
Copy link
Member

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

[x] New rule (#10217)

What changes did you make? (Give an overview)

This implements the no-async-promise-executor rule, as described in #10217.

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

Nothing in particular

@not-an-aardvark not-an-aardvark added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint labels Jul 24, 2018
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.

Left some comments.

Wondering if the rule should allow non-global Promise references?


## Rule Details

This rule aims to...
Copy link
Member

Choose a reason for hiding this comment

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

Needs more 😄

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 was aiming for concise documentation but I think I overdid it.

meta: {
docs: {
description: "disallow using an async function as a Promise executor",
category: "Fill me in",
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be Possible Errors

return {
"NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) {
context.report({
node: context.getSourceCode().getFirstToken(node.arguments[0]),
Copy link
Member

Choose a reason for hiding this comment

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

I imagine this wouldn't point at the right token if the node is surrounded by parens?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it still would be. I'll add a test.

Copy link
Member

Choose a reason for hiding this comment

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

Well, I'm wondering if we should just use context.getSourceCode().getFirstToken(node.arguments[0], { filter: t => t.value === "async" }) or similar to be absolutely safe.

@not-an-aardvark
Copy link
Member Author

Wondering if the rule should allow non-global Promise references?

I think it's more common for people to do things like const Promise = require('bluebird') (i.e. create a Promise variable that has compatible semantics with the ES2015 Promise) than it is for people to create a Promise variable with different semantics. So I'm leaning towards having the rule treat non-global Promise references the same as it treats global ones.

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.

LGTM, thanks!

@not-an-aardvark not-an-aardvark merged commit 9e93d46 into master Jul 27, 2018
@not-an-aardvark not-an-aardvark deleted the no-async-promise-executor branch July 27, 2018 01:06
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 24, 2019
@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 Jan 24, 2019
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

2 participants