Skip to content

Latest commit

Β 

History

History
49 lines (35 loc) Β· 1.24 KB

File metadata and controls

49 lines (35 loc) Β· 1.24 KB

Disallow passing single-element arrays to Promise methods

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§πŸ’‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

Passing a single-element array to Promise.all(), Promise.any(), or Promise.race() is likely a mistake.

Examples

// ❌
const foo = await Promise.all([promise]);

// ❌
const foo = await Promise.any([promise]);

// ❌
const foo = await Promise.race([promise]);

// βœ…
const foo = await promise;
// ❌
const promise = Promise.all([nonPromise]);

// βœ…
const promise = Promise.resolve(nonPromise);
// βœ…
const foo = await Promise.all(promises);
// βœ…
const foo = await Promise.any([promise, anotherPromise]);
// βœ…
const [{value: foo, reason: error}] = await Promise.allSettled([promise]);