Skip to content

noExcessiveNestedCallbacks (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"complexity": {
"noExcessiveNestedCallbacks": "error"
}
}
}
}

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.

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);
}

The maximum callback nesting depth allowed (default: 5).

biome.json
{
"linter": {
"rules": {
"complexity": {
"noExcessiveNestedCallbacks": {
"level": "on",
"options": {
"max": 3
}
}
}
}
}
}
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 () {});
});
});