no-promise-executor-return
eslint
Suggestion
eslint.config.js
export default [
{
rules: {
"no-promise-executor-return": "error",
},
},
];Disallow returning values from Promise executor functions
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;
});
new Promise(r => r(1));// Turn return inline into two lines
new Promise((resolve, reject) => {
if (someCondition) {
resolve(defaultResult);
return;
}
getSomething((err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
// Add curly braces
new Promise((resolve, reject) => {
getSomething((err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
new Promise(r => { r(1) });
// or just use Promise.resolve
Promise.resolve(1);Examples from the ESLint documentation.
no-promise-executor-return
eslint
export default [
{
rules: {
"no-promise-executor-return": "error",
},
},
];no-promise-executor-return
eslint plugin · pedantic
{
"rules": {
"no-promise-executor-return": "error"
}
}nursery/noPromiseExecutorReturn
nursery · since 2.6.0
{
"linter": {
"rules": {
"nursery": {
"noPromiseExecutorReturn": "error"
}
}
}
}Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead
Require braces around arrow function bodies
Require grouped accessor pairs in object literals and classes
Disallow if statements as the only statement in else blocks
Disallow use of chained assignment expressions