dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

Support golangci-lint for formatting #409

Closed autarch closed 1 year ago

autarch commented 1 year ago

We use golangci-lint for linting, including checking that code is formatted properly. It's formatting slightly differs from gofmt and goimports, so I'd prefer to use it to do formatting. I tried the following in my .emacs:

(setq gofmt-command "golangci-lint")
(setq gofmt-args '("run --disable-all -E goimports ./..."))

The problem is that go-mode is appending additional arguments like -w when it calls this command, and this isn't supported by golangci-lint.

dominikh commented 1 year ago

go-mode expects a proper gofmt-like command here, and I am not inclined to add a special case for a tool that isn't one and that, depending on the configuration, isn't capable of automatically applying fixes in the first place (golangci/golangci-lint#3230, golangci/golangci-lint#1577, golangci/golangci-lint#1510, golangci/golangci-lint#1726). It's also highly dubious that using just the goimports check in golangci-lint would disagree with actual goimports.

A formatter that is almost like gofmt but not quite would be gofumpt, but that is a proper drop-in replacement for gofmt and works with the existing gofmt-command setting.