promise/prefer-await-to-then
eslint-plugin-promise
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/prefer-await-to-then": "error",
},
},
];Prefer await to then()/catch()/finally() for reading Promise values.
function example() {
return myPromise.then(doSomethingSync).then(doSomethingElseAsync)
}
function exampleTwo() {
return myPromise
.then(doSomethingSync)
.then(doSomethingElseAsync)
.catch(errors)
}
function exampleThree() {
return myPromise.catch(errors)
}
function exampleFour() {
return myPromise.finally(cleanup)
}async function example() {
let val = await myPromise()
val = doSomethingSync(val)
return doSomethingElseAsync(val)
}
async function exampleTwo() {
try {
let val = await myPromise()
val = doSomethingSync(val)
return await doSomethingElseAsync(val)
} catch (err) {
errors(err)
}
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
promise/prefer-await-to-then
eslint-plugin-promise
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/prefer-await-to-then": "error",
},
},
];promise/prefer-await-to-then
promise plugin · style
{
"plugins": [
"promise"
],
"rules": {
"promise/prefer-await-to-then": "error"
}
}Biome does not have this rule.
Disallow use of non-standard Promise static methods.
Prefer async/await to the callback pattern.
Prefer catch to then(a, b)/then(null, b) for handling errors.
Disallow creating new promises with paths that resolve multiple times.
Disallow creating new promises outside of utility libs (use [util.promisify][] instead).
Require creating a Promise constructor before using it in an ES5 environment.