我的lint返回了此错误消息,但我真的不明白这是什么意思。
如标题所示: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
}
短绒棉布不喜欢的似乎是最后的
return false
。我很困惑,我没有在此代码库中设置lint,而且我真的不知道如何跳过此规则或如何解决它。
最佳答案
此错误意味着,就您而言,您需要在任何下一个return语句之前放置一个空行:
[empty line] <-- need this
return true
...
[empty line] <-- need this
return !country.Enabled && country.Deprecated
should not be cuddled
表示return语句附近必须没有代码行。
关于go - 如果 block 具有多于两行(wsl),则不应拥抱return语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58328069/