Is there a good linter + autoformat for golang projects?

I tried to use Golangci-lint, but it by default shows many alerts from standard lib instead of current project, not sure if there are existing solutions

Are you not using gofmt? Most major editors will gofmt your code on save.

Think I am using it without knowing. This was for CI use case where I have to alert linting errors before merging. Think that could work with gofmt, was just wondering if there were standard solutions for this.

I don’t know of anything I’d consider a “standard” solution. Formatting is never a problem for my projects because everybody uses VSCode which gofmt’s on save. Most of the stuff that linting would catch, I catch on code review. I’d see if you can set up Golangci-lint in such a way that it isn’t giving you alerts for the stdlib. That sounds like undesirable behavior and I imagine you can tweak it.

Yeah, it looks something like
WARN [linters_context] running gomoddirectives failed: failed to get module file: go.mod:3: invalid go version ‘1.22.2’: must match format 1.23: if you are not using go modules it is suggested to disable this linter
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/errors/join.go:57:16: String not declared by package unsafe (typecheck)
return unsafe.String(&b[0], len(b))
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:198:16: String not declared by package unsafe (typecheck)
return unsafe.String(n.data(1+i, “non-empty string”), l)
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:207:16: String not declared by package unsafe (typecheck)
return unsafe.String(n.data(1+i+l+i2, “non-empty string”), l2)
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:256:11: t.Uncommon undefined (type rtype has no field or method Uncommon, but does have uncommon) (typecheck)
return t.Uncommon()
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:260:19: t.Str undefined (type rtype has no field or method Str) (typecheck)
s := t.nameOff(t.Str).Name()
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:261:7: t.TFlag undefined (type rtype has no field or method TFlag) (typecheck)
if t.TFlag&abi.TFlagExtraStar != 0 {
^
…/…/…/…/opt/homebrew/Cellar/go/1.22.2/libexec/src/internal/reflectlite/type.go:286:7: t.TFlag undefined (type rtype has no field or method TFlag) (typecheck)
if t.TFlag&abi.TFlagNamed == 0 {
^

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.