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

Exception or error:

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.

How to solve:

This error means that you need to put blank line before next return statements:

  • return true
  • return !country.Enabled && country.Deprecated

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

Leave a Reply

Your email address will not be published. Required fields are marked *