Skip to content

noNestedPromises

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noNestedPromises": "error"
}
}
}
}

Disallow nested .then() or .catch() promise calls.

Nesting .then() or .catch() calls defeats the purpose of promises, which is to create a flat chain of asynchronous operations. Nested promise callbacks can make code harder to read and maintain.

However, nesting is allowed when the nested callback references variables from the outer scope, as flattening would break the code in such cases.

doThing().then(function() { return a.then() })
code-block.js:1:38 lint/suspicious/noNestedPromises ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid nesting promises.

> 1 │ doThing().then(function() { return a.then() })
^^^^
2 │

Nesting promises can lead to harder-to-read code because it creates multiple levels of indentation and makes the flow of asynchronous operations less clear.

Consider refactoring the code to use promise chaining (foo.then().then()) instead of nesting.

doThing().then(() => b.catch())
code-block.js:1:24 lint/suspicious/noNestedPromises ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid nesting promises.

> 1 │ doThing().then(() => b.catch())
^^^^^
2 │

Nesting promises can lead to harder-to-read code because it creates multiple levels of indentation and makes the flow of asynchronous operations less clear.

Consider refactoring the code to use promise chaining (foo.then().then()) instead of nesting.

doThing()
.then(a => getB(a)
.then(b => getC(b))
)
code-block.js:3:6 lint/suspicious/noNestedPromises ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid nesting promises.

1 │ doThing()
2 │ .then(a => getB(a)
> 3 │ .then(b => getC(b))
^^^^
4 │ )
5 │

Nesting promises can lead to harder-to-read code because it creates multiple levels of indentation and makes the flow of asynchronous operations less clear.

Consider refactoring the code to use promise chaining (foo.then().then()) instead of nesting.

// Simple returns
doThing().then(function() { return 4 })
doThing().then(() => 4)
// Chained promises (no nesting)
doThing()
.then(a => getB(a))
.then(b => getC(b))
// Nested but references outer scope variable 'a'
doThing()
.then(a => getB(a)
.then(b => getC(a, b))
)
// Promise.resolve/all are fine
doThing().then(function() { return Promise.all([a,b,c]) })
doThing().then(() => Promise.resolve(4))