noExcessiveNestedCallbacks (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.4.14 - Diagnostic Category:
lint/complexity/noExcessiveNestedCallbacks - This rule isn’t recommended, so you need to enable it.
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
max-nested-callbacks
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "complexity": { "noExcessiveNestedCallbacks": "error" } } }}Description
Section titled “Description”Enforce a maximum depth that callbacks can be nested.
Deeply nested callbacks make asynchronous control flow difficult to read and follow. This rule reports callback functions nested beyond the configured limit.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”foo1(function () { foo2(function () { foo3(function () { foo4(function () { foo5(function () { foo6(function () {}); }); }); }); });});code-block.js:6:26 lint/complexity/noExcessiveNestedCallbacks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This callback is nested too deeply.
4 │ foo4(function () {
5 │ foo5(function () {
> 6 │ foo6(function () {});
│ ^^^^^^^^^^^^^^
7 │ });
8 │ });
ℹ Callbacks nested 6 levels deep are harder to read and maintain. The configured maximum is 5.
ℹ Extract some callbacks into named functions to reduce nesting.
foo1(handleFoo1);
function handleFoo1() { foo2(handleFoo2);}Options
Section titled “Options”The maximum callback nesting depth allowed (default: 5).
{ "linter": { "rules": { "complexity": { "noExcessiveNestedCallbacks": { "level": "on", "options": { "max": 3 } } } } }}Invalid
Section titled “Invalid”foo1(function () { foo2(function () { foo3(function () { foo4(function () {}); }); });});code-block.js:4:18 lint/complexity/noExcessiveNestedCallbacks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This callback is nested too deeply.
2 │ foo2(function () {
3 │ foo3(function () {
> 4 │ foo4(function () {});
│ ^^^^^^^^^^^^^^
5 │ });
6 │ });
ℹ Callbacks nested 4 levels deep are harder to read and maintain. The configured maximum is 3.
ℹ Extract some callbacks into named functions to reduce nesting.
foo1(function () { foo2(function () { foo3(function () {}); });});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.