3 回答
TA贡献1824条经验 获得超5个赞
我尝试按照 Nico Huysamen 的建议添加允许规则,但这打开了一罐蠕虫。最后我还是想相信ireturnlinter,还不想禁用它。我认为解决此问题的最简洁方法是为两个 linter 添加一个异常,ireturn如下nolintlint所示:
//nolint:nolintlint,ireturn
func NewClientCredentialsTokenSource(
issuer string,
clientId string,
clientSecret string,
scope []string,
) (oauth2.TokenSource, error) {
2022 年 5 月 25 日更新:
也许更好的解决方案如下所示。由于某种原因,ireturn异常必须进入函数签名。
func NewPasswordGrantTokenSource( //nolint:ireturn
issuer string,
clientId string,
clientSecret string,
username string,
password string,
scope []string,
) (oauth2.TokenSource, error) {
TA贡献1852条经验 获得超1个赞
.golangci.yml您可以如上所述允许这样做,但由于它取代了标准的 defaults,您也需要包含它们,因此您需要:
ireturn:
# ireturn allows using `allow` and `reject` settings at the same time.
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
# keywords:
# - `empty` for `interface{}`
# - `error` for errors
# - `stdlib` for standard library
# - `anon` for anonymous interfaces
# By default, it allows using errors, empty interfaces, anonymous interfaces,
# and interfaces provided by the standard library.
allow:
- anon
- error
- empty
- stdlib
# You can specify idiomatic endings for interface
- (or|er)$
# Your custom interfaces go here:
- golang.org/x/oauth2.TokenSource
TA贡献1873条经验 获得超9个赞
您可以将接口添加到ireturn的允许接口列表中。
ireturn --allow="golang.org/x/oauth2.TokenSource"
或通过中的linter-settings部分.golangci.yml
linters-settings:
ireturn:
allow:
- golang.org/x/oauth2.TokenSource
- 3 回答
- 0 关注
- 116 浏览
添加回答
举报