#What is causing my golangci-lint to behave like this?

16 messages · Page 1 of 1 (latest)

silk pond
#

go run github.com/golangci/golangci-lint/cmd/golangci-lint version

# github.com/golangci/golangci-lint/pkg/golinters
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:68:63: too many arguments in call to whitespace.Run
        have (*"go/ast".File, *"go/token".FileSet, whitespace.Settings)
        want (*analysis.Pass, *whitespace.Settings)
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:79:17: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:80:17: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:82:39: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:93:12: i.Type undefined (type whitespace.Message has no field or method Type)
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:94:19: undefined: whitespace.MessageTypeLeading
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:96:19: undefined: whitespace.MessageTypeTrailing
../../../../go/bin/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:99:19: undefined: whitespace.MessageTypeAddAfter

go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest version

golangci-lint has version v1.55.2 built with go1.21.4 from (unknown, mod sum: "h1:yllEIsSJ7MtlDBwDJ9IMBkyEUz2fYE0b5B8IUgO1oP8=") on (unknown)

This is preventing me from running the linter in a repo with a tools package like:
internal/tools/tools.go

//go:build tools
// +build tools

package tools

import (
    // ...
    _ "github.com/golangci/golangci-lint/cmd/golangci-lint"
    // ...
)

I have tried removing it from $GOPATH and I have also tried go clean -modcache to no avail. I am really at a loss here, you can see the versions are the same regardless of the way I execute it so I don't know how I could run into this error. When I google it, there are literally 0 results so I imagine this is something to do with how Go is set up on my system but I'm out of ideas on what to look for, so in case it helps, the following is in my .zshrc file:

export GO_121_PATH="/Users/user/sdk/$GO_121/bin"
## Set go env vars
export GOPATH="$HOME/go/bin"
export GOBIN="$GOPATH"
export PATH="$GOBIN:$PATH"
export GOMAXPROCS=6
## Set current version of go command
export PATH="$GO_121_PATH:$PATH"
dense portal
#

You mixed up, GOPATH should be the parent dir of GOBIN

#

So what does GOPATH looks like:

$GOPATH
+-bin/
| +-golangci-lint
+-src/
| +-github.com/
+-pkg
  +-mod/
  +-sumdb
#

and, you should not set GOPATH in your zsh file, you should set it use go env -w

#

If you want to read the environment variable, for example, replace export PATH="$GOBIN:$PATH" to export PATH="$(go env GOBIN):$PATH"

silk pond
#

So I should update my GOPATH to "$HOME/go" and leave GOBIN as "$GOPATH/bin"

dense portal
#

yes

#

but DO NOT do it in your zshrc

silk pond
#

okay thanks, I will do that and fix my .zshrc so it isn't controlling GOBIN, or GOPATH

#

and I suppose also not GOMAXPROCS

dense portal
#

use go env, it will save them globaly

silk pond
#

aight, thanks I'll try that, hopefully it fixes the linter issues too.

silk pond
#

So that did not work - I instead uninstalled go by following this: https://go.dev/doc/manage-install#uninstalling

I had to also remove stuff with brew since I must have installed go and golangci-lint with brew originally years back. I made sure I removed all go stuff.

I then installed go fresh from here: https://go.dev/doc/install

Now however, I do not see a src directory in my $GOPATH which is at /Users/{user}/go. Also, the original issue still occurs:

../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:68:63: too many arguments in call to whitespace.Run
    have (*"go/ast".File, *"go/token".FileSet, whitespace.Settings)
    want (*analysis.Pass, *whitespace.Settings)
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:79:17: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:80:17: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:82:39: i.Pos undefined (type whitespace.Message has no field or method Pos)
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:93:12: i.Type undefined (type whitespace.Message has no field or method Type)
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:94:19: undefined: whitespace.MessageTypeLeading
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:96:19: undefined: whitespace.MessageTypeTrailing
../../../../go/pkg/mod/github.com/golangci/[email protected]/pkg/golinters/whitespace.go:99:19: undefined: whitespace.MessageTypeAddAfter

I have tried sudo rm -rf ../../../../go/pkg/mod/github.com/golangci based on these logs then go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest but it still gives me the exact same output

I have a hunch this has something to do with homebrew. Waiting for a sudo find / -name "*golangci*" 2>/dev/null to finish running so I can purge this shit.

#

Is it problematic that I have no src directory in my GOPATH now?

#

I assume once its needed by the go toolchain it will get created?

silk pond
#

This seems to be the root cause: https://github.com/ultraware/whitespace/blob/master/whitespace.go#L89 which is called improperly in golangci-lint here: https://github.com/golangci/golangci-lint/blob/e3c2265f4939976874989e159386b3bb7dcf8e1f/pkg/golinters/whitespace.go#L68C3-L68C78. Not sure why the way I'm running it solves that though.

GitHub

Contribute to ultraware/whitespace development by creating an account on GitHub.

GitHub

Fast linters Runner for Go. Contribute to golangci/golangci-lint development by creating an account on GitHub.