sonarjs/nested-control-flow
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/nested-control-flow": "error",
},
},
];Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply
if (condition1) { // Compliant - depth = 1
/* ... */
if (condition2) { // Compliant - depth = 2
/* ... */
for(let i = 0; i < 10; i++) { // Compliant - depth = 3, not exceeding the limit
/* ... */
if (condition4) { // Non-Compliant - depth = 4
if (condition5) { // Depth = 5, exceeding the limit, but issues are only reported on depth = 4
/* ... */
}
return;
}
}
}
}The documentation shows no correct example for this rule.
Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
sonarjs/nested-control-flow
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/nested-control-flow": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.