promise/avoid-new
eslint-plugin-promise
No autofix
eslint.config.js
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/avoid-new": "error",
},
},
];Disallow creating new promises outside of utility libs (use [util.promisify][] instead).
function promisifiedFn(arg) {
return new Promise((resolve, reject) => {
callbackStyleFn(arg, (error, result) =>
error ? reject(error) : resolve(result),
)
})
}
new Promise((resolve, reject) => resolve(1))
new Promise((resolve, reject) => reject(new Error('oops')))import util from 'util'
const promisifiedFn = util.promisify(callbackStyleFn)
Promise.resolve(1)
Promise.reject(new Error('oops'))Examples from the ESLint documentation.
promise/avoid-new
eslint-plugin-promise
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/avoid-new": "error",
},
},
];promise/avoid-new
promise plugin · style
{
"plugins": [
"promise"
],
"rules": {
"promise/avoid-new": "error"
}
}Biome does not have this rule.
Disallow creating new promises with paths that resolve multiple times.
Prefer catch to then(a, b)/then(null, b) for handling errors.
Prefer async/await to the callback pattern.
Disallow use of non-standard Promise static methods.
Prefer await to then()/catch()/finally() for reading Promise values.
Enforces the proper number of arguments are passed to Promise functions.