can replace 'else {if cond {}}' with 'else if cond {}'
345 if err = ctxRepo.UploadAvatar(data); err != nil {
346 return fmt.Errorf("upload avatar: %v", err)
347 }
348 } else {349 // No avatar is uploaded and reset setting back.
350 if !com.IsFile(ctxRepo.CustomAvatarPath()) {
351 ctxRepo.UseCustomAvatar = false
Description
A single nested if
inside an else
block can be replaced with an else if
.
It's better to have as little nesting as possible. Hence, it's cleaner to
replace a single nested if
inside an else
with an else-if
.
Bad practice
if cond1 {
// do something
} else {
if x := cond2; x {
// do something else
}
}
Recommended
if cond1 {
// do something
} else if x := cond2; x {
// do something else
}