تخطَّ إلى المحتوى

Deep Nesting (ARCH3184)

هذا المحتوى غير متوفر بلغتك بعد.

Key typescript.quality.deep-nesting · Severity warning · Category quality

if/for/while/switch/try blocks nested beyond the threshold raise the code’s cognitive load and make flow hard to follow. Depth should be reduced with early returns (guard clauses) and extraction.

function handle(user?: User) {
if (user) {
if (user.active) {
if (user.roles.length) {
return user.roles[0];
}
}
}
return null;
}
function handle(user?: User) {
if (!user || !user.active || !user.roles.length) return null;
return user.roles[0];
}

Flatten conditions with early returns (guard clauses) and extract the inner block into a separate function.