-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add go mod init
to quick-start
#1835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey, thank you for opening your first Pull Request ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really true, as you noticed in your issue you can keep avoiding go modules if you set GO111MODULE
to a proper value (off if not using go modules). See the changelog.
Ok, instead of this, could we add a question to the FAQ with that information? |
Alternatively, a new paragraph on the quick-start page detailing how Something along the lines of:
|
I think this is totally fine and an OK place to put it, was just missing some more background like why this is needed and/or the mention of Let's wait for some other voices from @golangci/team, maybe I'm the only one who thinks this way and others will approve it. |
I'll change the PR to do that instead while we wait for more feedback. Thanks @bombsimon ! |
Updated documentation to make it clear that a `go.mod` file is required to run `golangci-lint`
|
||
## How does `golangci-lint` find go source files? | ||
|
||
`golangci-lint` uses go modules to find golang files. If your project is a go module, it should *just work*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golangci-lint
uses go modules to find golang files.
This is false or at least not precise: the use of go modules by default is related to the behavior of your local go version.
go1.11
$ go version
go version go1.11.13 linux/amd64
$ env | rg GO111MODULE
$ go env | grep GO111MODULE
$ golangci-lint run
go1.12
$ go version
go version go1.12.17 linux/amd64
$ env | rg GO111MODULE
$ go env | grep GO111MODULE
$ golangci-lint run
go1.13
$ go version
go version go1.13.15 linux/amd64
$ env | rg GO111MODULE
$ go env | grep GO111MODULE
GO111MODULE=""
$ golangci-lint run
go1.14
$ go version
go version go1.14.15 linux/amd64
$ env | rg GO111MODULE
$ go env | grep GO111MODULE
GO111MODULE=""
$ golangci-lint run
go1.15
$ go version
go version go1.15.9 linux/amd64
$ env | rg GO111MODULE
$ go env | grep GO111MODULE
GO111MODULE=""
$ golangci-lint run
go1.16
$ go version
go version go1.16.1 linux/amd64
$ go env | grep GO111MODULE
GO111MODULE=""
$ golangci-lint run
ERRO Running error: context loading failed: no go files to analyze
In go1.16 the go modules are on
by default instead of auto
or off
Also note:
We plan to drop support for GOPATH mode in Go 1.17. In other words, Go 1.17 will ignore GO111MODULE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this specifically state this applies to go 1.16 and up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relation between the local go version and GO111MODULE
exists since go1.11.
If GO111MODULE
is on
, even with go<1.16, golangci-lint
will use Go modules.
go1.11
$ go version
go version go1.11.13 linux/amd64
$ GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: cannot determine module path for source directory /home/ldez/sources/go/src/github.com/golangci/sandbox (outside GOPATH, no import comments)
go1.12
$ go version
go version go1.12.17 linux/amd64
$GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: cannot determine module path for source directory /home/ldez/sources/go/src/github.com/golangci/sandbox (outside GOPATH, no import comments)
go1.13
$ go version
go version go1.13.15 linux/amd64
$ GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: no go files to analyze
go1.14
$ go version
go version go1.14.15 linux/amd64
$ GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: no go files to analyze
go1.15
$ go version
go version go1.15.9 linux/amd64
$ GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: no go files to analyze
go1.16
$ go version
go version go1.16.1 linux/amd64
$ GO111MODULE=on golangci-lint run
ERRO Running error: context loading failed: no go files to analyze
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be precise, golangci-lint
relies on Go internal behavior, there is no GO111MODULE
related code inside golangci-lint
code base.
|
||
`golangci-lint` uses go modules to find golang files. If your project is a go module, it should *just work*. | ||
|
||
If your project is not a go module, you can still use `golangci-lint` for your project. You can do this by setting the environment variable `GO111MODULE=off` when you run `golangci-lint`. Make sure you set this in your CI toolchain appropriately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your project is not a go module, you can still use
golangci-lint
for your project.
Same thing here.
Updated documentation to make it clear that a
go.mod
file is required to rungolangci-lint
closes #1833