noNestedPromises
Это содержимое пока не доступно на вашем языке.
Summary
Section titled “Summary”- Rule available since:
v2.3.15 - Diagnostic Category:
lint/nursery/noNestedPromises - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
promise/no-nesting
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noNestedPromises": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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 returnsdoThing().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 finedoThing().then(function() { return Promise.all([a,b,c]) })doThing().then(() => Promise.resolve(4))Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.