Navigation Menu

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-promise-executor-return rule (fixes #12640) #12648

Merged
merged 3 commits into from Jun 19, 2020

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Dec 6, 2019

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

[X] New rule

fixes #12640

Examples of incorrect code for this rule:

/*no-promise-executor-return: "error"*/

new Promise((resolve, reject) => {
    if (someCondition) {
        return defaultResult;
    }
    getSomething((err, result) => {
        if (err) {
            reject(err);
        } else {
            resolve(result);
        }
    });
});

new Promise((resolve, reject) => getSomething((err, data) => {
    if (err) {
        reject(err);
    } else {
        resolve(data);
    }
}));

new Promise(() => {
    return 1;
});

What changes did you make? (Give an overview)

no-promise-executor-return rule.

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

@mdjermanovic mdjermanovic 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 Dec 6, 2019
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Overall looks good. Just one question about the error message. Sorry we missed this.

@kaicataldo can you take a look when you get a chance?

schema: [],

messages: {
returnsValue: "Promise executor functions cannot return values."
Copy link
Member

Choose a reason for hiding this comment

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

Is this accurate? I think they can return values but the values are never exposed anywhere. Maybe, "Return values from promise executor functions cannot be read."?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, this message might be seen as technically incorrect. It's changed now, thanks!

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@btmills btmills 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 @mdjermanovic! I particularly appreciate how thorough the tests are.

@btmills btmills merged commit 9e1414e into master Jun 19, 2020
@btmills btmills deleted the no-promise-executor-return branch June 19, 2020 15:50
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 17, 2020
@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 Dec 17, 2020
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.

Disallow returning value from Promise executor
4 participants