如何在 golangci-lint 中跳过文件?

bat*_*zor 5 go golint

我尝试go1.16

import "embed"
Run Code Online (Sandbox Code Playgroud)

我明白了

> golangci-lint run ./...
> Can't run linter goanalysis_metalinter: bodyclose: failed prerequisites ... could not import embed
Run Code Online (Sandbox Code Playgroud)

如何在 golangci-lint 中跳过文件/包?

Ste*_*ley 9

使用配置文件

您可以使用配置文件自定义行为。文档位于https://golangci-lint.run/usage/configuration/。创建一个.golangci.yml如下所示的文件:

run:
  skip-files:
    - main.go

Run Code Online (Sandbox Code Playgroud)

//nolint

您可以添加//nolint到文件的顶部。

//nolint
package foo
Run Code Online (Sandbox Code Playgroud)

请参阅https://golangci-lint.run/usage/false-positives/