我的 golint 返回此错误消息,但我真的不明白它的含义。
如标题:
return statements should not be cuddled if block has more than two lines (wsl)
我的代码是这样的:
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
}
Run Code Online (Sandbox Code Playgroud)
linter 不喜欢的似乎是最后一个return false。
我很困惑,我没有在这个代码库中设置 linter,我真的不知道如何跳过这个规则或如何修复它。
此错误意味着,在您的情况下,您需要在任何下一个 return 语句之前放置一个空行:
[empty line] <-- need this
return true
...
[empty line] <-- need this
return !country.Enabled && country.Deprecated
Run Code Online (Sandbox Code Playgroud)
should not be cuddled 意味着 return 语句附近不能有代码行。
| 归档时间: |
|
| 查看次数: |
4213 次 |
| 最近记录: |