Skip to content
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

Add go mod init to quick-start #1835

Closed
wants to merge 1 commit into from
Closed

Conversation

zealws
Copy link

@zealws zealws commented Mar 11, 2021

Updated documentation to make it clear that a go.mod file is required to run golangci-lint

closes #1833

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 11, 2021

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Mar 11, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@bombsimon bombsimon left a 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.

@zealws
Copy link
Author

zealws commented Mar 11, 2021

Ok, instead of this, could we add a question to the FAQ with that information?

@zealws
Copy link
Author

zealws commented Mar 11, 2021

Alternatively, a new paragraph on the quick-start page detailing how golangci-lint finds golang files might be helpful.

Something along the lines of:

golangci-lint uses go modules to find golang files. If your project is a go module, it'll just work.
But if your project is not a go module, you'll need to set the environment variable GO111MODULE=off when running golangci-lint to disable using go modules.
Make sure you set this in your CI toolchain appropriately.

@bombsimon
Copy link
Member

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 GO111MODULE=off. I guess the environment variable would be nice to know as well for those who want to keep staying away from modules but still have golangci-lint work.

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.

@zealws
Copy link
Author

zealws commented Mar 11, 2021

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`
@ldez ldez added area: docs blocked Need's direct action from maintainer labels Mar 11, 2021

## 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*.
Copy link
Member

@ldez ldez Mar 11, 2021

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.

https://blog.golang.org/go116-module-changes

Copy link
Author

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?

Copy link
Member

@ldez ldez Mar 11, 2021

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

Copy link
Member

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.
Copy link
Member

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.

@ldez ldez added feedback required Requires additional feedback and removed blocked Need's direct action from maintainer labels Mar 11, 2021
@ldez ldez added the stale No recent correspondence or work activity label Apr 25, 2021
@stale stale bot closed this Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs feedback required Requires additional feedback stale No recent correspondence or work activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

golangci-lint run cannot find golang files in the current directory
4 participants