can replace 'else {if cond {}}' with 'else if cond {}'
2830 if pos, ok := visited[loc.GetUuid()]; !ok {
2831 locs.Locations = append(locs.GetLocations(), loc)
2832 visited[loc.GetUuid()] = len(locs.Locations) - 1
2833 } else {2834 if pos < len(locs.GetLocations()) {
2835 locs.GetLocations()[pos].Ips = append(locs.GetLocations()[pos].Ips, loc.GetIps()...)
2836 if s := locs.GetLocations()[pos].Name; len(s) == 0 {
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
}