question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disallow returning value from Promise executor

See original GitHub issue

Please describe what the rule should do:

Disallows returning values of any kind from the Promise executor.

Value returned from Promise executor is ignored, but people may not be aware of it and they may think that returning e.g. another promise from the executor awaits that promise, or that the new promise (the outer one) is going to be rejected if the returned promise is rejected itself.

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

[x] Warns about a potential error (problem)

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

new Promise(() => {
    return Promise.resolve(42);
});
new Promise(() => {
    return false;
});

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

This rule would disallow returning anything from Promise executor function which is going to make original intent more clear, and prevent possible errors by expecting false behavior.

This rule is an extension of my previous (accepted) suggestion to help prevent issues when dealing with Promises.

Are you willing to submit a pull request to implement this rule?

Maybe.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Dec 5, 2019

Should the rule also disallow implicit return from arrow functions:

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

Valid code would be:

new Promise((resolve, reject) => {
    getSomething((err, data) => {
        if (err) {
            reject(err);
        } else {
            resolve(data);
        }
    });
});
1reaction
mdjermanoviccommented, Dec 19, 2019

return cleanUpSomething() could be also a false negative?

I think that by default only return; should be allowed, but we can consider adding an option to allow return resolve()/return reject() (or any call expression) later as an enhancement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-promise-executor-return - Pluggable JavaScript Linter
Rule Details. This rule disallows returning values from Promise executor functions. Only return without a value is allowed, as it's a control flow...
Read more >
Disallow returning values from Promise executor functions (no ...
Rule Details. This rule disallows returning values from Promise executor functions. Only return without a value is allowed, as it's a control flow...
Read more >
No-promise-executor-return - ESLint - W3cubDocs
Rule Details. This rule disallows returning values from Promise executor functions. Only return without a value is allowed, as it's a control flow...
Read more >
no-promise-executor-return - Rules - ESLint | Js中文网
Rule Details. This rule disallows returning values from Promise executor functions. Only return without a value is allowed, as it's a control flow...
Read more >
Dealing with Promise executor functions ESLint error
ESLint: Promise executor functions should not be async. (no-async-promise-executor) · ESLint: Promise returned in function argument where a void ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found