3 回答

TA貢獻(xiàn)1824條經(jīng)驗 獲得超5個贊
我嘗試按照 Nico Huysamen 的建議添加允許規(guī)則,但這打開了一罐蠕蟲。最后我還是想相信ireturnlinter,還不想禁用它。我認(rèn)為解決此問題的最簡潔方法是為兩個 linter 添加一個異常,ireturn如下nolintlint所示:
//nolint:nolintlint,ireturn
func NewClientCredentialsTokenSource(
issuer string,
clientId string,
clientSecret string,
scope []string,
) (oauth2.TokenSource, error) {
2022 年 5 月 25 日更新:
也許更好的解決方案如下所示。由于某種原因,ireturn異常必須進(jìn)入函數(shù)簽名。
func NewPasswordGrantTokenSource( //nolint:ireturn
issuer string,
clientId string,
clientSecret string,
username string,
password string,
scope []string,
) (oauth2.TokenSource, error) {

TA貢獻(xiàn)1852條經(jīng)驗 獲得超1個贊
.golangci.yml您可以如上所述允許這樣做,但由于它取代了標(biāo)準(zhǔn)的 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貢獻(xiàn)1873條經(jīng)驗 獲得超9個贊
您可以將接口添加到ireturn的允許接口列表中。
ireturn --allow="golang.org/x/oauth2.TokenSource"
或通過中的linter-settings部分.golangci.yml
linters-settings:
ireturn:
allow:
- golang.org/x/oauth2.TokenSource
- 3 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報