Перейти к содержимому

noNestedPromises

Это содержимое пока не доступно на вашем языке.

biome.json
{
"linter": {
"rules": {
"nursery": {
"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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

doThing().then(() => b.catch())
code-block.js:1:24 lint/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

doThing()
.then(a => getB(a)
.then(b => getC(b))
)
code-block.js:3:6 lint/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

// 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))