Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return statements should not be cuddled if block has more than two lines (wsl)

Tags:

go

My golint returns this error message but i don't really understand what it means.

As in title:

return statements should not be cuddled if block has more than two lines (wsl)

my code is this:

func validateCountry(product models.Product, countries []models.Country) bool {
    if !product.CountryCode.Valid {
        return true
    }

    for _, country := range countries {
        if country.Code == product.CountryCode.String {
            return !country.Enabled && country.Deprecated
        }
    }

    return false
}

What the linter does not like seems to be the last return false.

I'm very confused, i didn't setup the linter in this codebase, and i don't really know how to either skip this rules or how to fix it.

like image 668
Stefano Saitta Avatar asked Oct 10 '19 17:10

Stefano Saitta


1 Answers

This error means that, in your case, you need to put a blank line before any next return statement:

[empty line] <-- need this
return true
...
[empty line] <-- need this
return !country.Enabled && country.Deprecated

should not be cuddled means there must be no code lines near the return statement.

like image 109
KorbenDallas Avatar answered Oct 19 '22 19:10

KorbenDallas