Skip to content
← Back to rules

promise/avoid-new Style

What it does ​

Disallow creating promises with new Promise().

Why is this bad? ​

Many cases that use new Promise() could be refactored to use an async function. async is considered more idiomatic in modern JavaScript.

Examples ​

Examples of incorrect code for this rule:

javascript
function foo() {
  return new Promise((resolve, reject) => {
    /* ... */
  });
}

Examples of correct code for this rule:

javascript
async function foo() {
  // ...
}
const bar = await Promise.all([baz(), bang()]);

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["promise"],
  "rules": {
    "promise/avoid-new": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["promise"],
  rules: {
    "promise/avoid-new": "error",
  },
});
bash
oxlint --deny promise/avoid-new --promise-plugin

Version ​

This rule was added in v0.6.1.

References ​