How to Fix some golangci-lint errors

1. How to Fix File is not gofumpt-ed (gofumpt) error

gofumpt is a stricter version of gofmt. The lint tool finds more errors and reports. One such error is that File is not gofumpt-ed. The solution to the problem is as follows:

Please install gofumpt

The easiest solution is to run gofumpt on the troubled files.

gofumpt -w <fileame>

2. File is not gci-ed with -local github.com/golangci/golangci-lint

GCI, a tool that control golang package import order and make it always deterministic.

It handles empty lines more smartly than goimport does.

  1. install go get github.com/daixiang0/gci
  2. run gci -w -local github.com/daixiang0/gci main.go

3. File is not goimports-ed with -local github.com/golangci/golangci-lint

方案 1 手动执行格式化。

go get golang.org/x/tools/cmd/goimports

goimports -e -d -local github.com/golangci/golangci-lint internal/net/http/handler.go

goimports -w internal/net/http/handler.go

方案 2 配置 goland 的代码格式化规则。参考 Running ‘goimports’ on save in GoLand

相关阅读

如果觉得我的文章对您有用,请在支付宝公益平台找个项目捐点钱。 @Victor Aug 5, 2020

奉献爱心