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

Deep Nesting (ARCH5184)

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

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

Deeply nested if/for blocks hurt readability and raise cognitive load. Flatten them with early returns (guard clauses).

func handle(u *User) error {
if u != nil {
if u.Active {
if u.Quota > 0 {
return process(u)
}
}
}
return errSkip
}
func handle(u *User) error {
if u == nil || !u.Active || u.Quota <= 0 {
return errSkip
}
return process(u)
}

Convert conditions into early returns to flatten the nested blocks.