promise/spec-only
Disallow Promise static methods that are not part of the language
Libraries such as Bluebird add methods like Promise.map and Promise.props. The built-in Promise doesn't have them, so the call throws a TypeError wherever the library's Promise isn't the one in scope.
The rule allows all, allSettled, any, race, reject, resolve, try and withResolvers. It reports every other property read from Promise, called or not. That includes Promise.prototype.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"promise/spec-only" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"promise/spec-only" = ["error", {
allowedMethods = [], # list of strings
}]Examples#
example.js1 problem
const pages = await Promise.mapAvoid using non-standard Promise.map method.(urls, url => fetch(url));example.js1 problem
const then = Promise.prototypeAvoid using non-standard Promise.prototype method..then;example.jsNo problems
const pages = await Promise.all(urls.map(url => fetch(url)));Options#
| Option | Default | What it does |
|---|---|---|
allowedMethods | [] | More names to allow, for example from a polyfill. Names are case-sensitive. |
example.jswith
{ "allowedMethods": ["map", "prototype"] }No problemsconst pages = await Promise.map(urls, url => fetch(url));
const then = Promise.prototype.then;example.jswith
{ "allowedMethods": ["map"] }1 problemconst user = await Promise.propsAvoid using non-standard Promise.props method.({ profile: loadProfile(), orders: loadOrders() });