Skip to content

noExcessiveNestedCallbacks

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

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.

foo1(handleFoo1);
function handleFoo1() {
foo2(handleFoo2);
}

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

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveNestedCallbacks": {
"options": {
"max": 3
}
}
}
}
}
}
foo1(function () {
foo2(function () {
foo3(function () {
foo4(function () {});
});
});
});
code-block.js:4:18 lint/nursery/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.

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.

foo1(function () {
foo2(function () {
foo3(function () {});
});
});