We are using
golangci-lintversion1.40.1together with- golang version
1.16.4
in our project for linting our Golang code.
Until now, what we did is running this bash script (from the root directory of our repository):
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go mod tidy
fi
golangci-lint run --build-tags="unit contract container"
With some recent updates of Golang and golangci-lint, we suddenly face this error message:
ERRO Running error: context loading failed: no go files to analyze
There is a lengthy post on GitHub regarding this issue but the only useful suggestion there is to turn off the GO111MODULE env variable. When I run the linter with GO111MODULE turned off like
GO111MODULE=off golangci-lint run --build-tags="unit contract container"
the upper error message disappears but instead I am getting lots of false linting errors like:
api/router.go:152:5: undeclared name: `PermissionUpdatePackage` (typecheck)
PermissionUpdatePackage,
^
My go environment looks like this:
GO111MODULE=on
GOPATH=/Users/USER/workspace/go
GOROOT=/usr/local/opt/go/libexec
GOPRIVATE=*.CUSTOMER.com
GOSS_PATH=/usr/local/bin/goss
I tried to install the linter via go get... as well as go install ... and finally brew install golangci-lint which seems to be the recommended way following this documentation.
GO111MODULE=off golangci-lint run --build-tags="unit contract container", i.e. disabling modules for the execution of the command? (I didn't quite get where exactly you placed theexport GO111MODULE=off. Also you mention "With some recent updates", what updates?GO111MODULE=off golangci-lint run --build-tags="unit contract container"go mod tidy, this error went away