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

Make go list run with non-root packages #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

txomon
Copy link

@txomon txomon commented May 27, 2020

No description provided.

@dnephin
Copy link
Owner

dnephin commented Jun 4, 2020

Thanks for the contribution!

I believe the current version does run on all the packages where there are files that have changed. Is that not working for you?

If you wanted to run on all files I think you could use the golangci-lint hook and enable the vet linter.

@txomon
Copy link
Author

txomon commented Aug 20, 2020

This doesn't work in the case where there are no .go files in the root directory.

@dnephin
Copy link
Owner

dnephin commented Sep 3, 2020

Oh, why is that? Do you get an error?

@txomon
Copy link
Author

txomon commented Sep 9, 2020

go list by default will return "no Go files in /absolute/path" through stderr, which would effectively skip checks

@dnephin
Copy link
Owner

dnephin commented Sep 13, 2020

Ah, yes that makes sense. Unfortunately I don't think changing it to go list ./... works. The variable that captures the value requires a single path, not a list.

One option is to create a pkg.go or doc.go in the root package. This file can contain the package godoc.

Another option would be to use the golangci-lint hook, and run vet on all files.

If we wanted to make this vet check work with non-root packages I think changing the go list to go list -m would work, but it would require that go modules are being used.

@txomon
Copy link
Author

txomon commented Sep 18, 2020

If it outputs a list, wouldn't it then make sense to run go vet in a for loop iterating over the packages?

@dnephin
Copy link
Owner

dnephin commented Sep 21, 2020

My understanding is that the args passed to this script ($@) will be a list of paths to files. So echo $@|xargs -n1 dirname|sort -u files all the paths to directories of files that are modified and iterates over them. The $pkg/$dir line makes the directories into package paths.

Iterating over all the packages returned by go list ./... does not work.

Maybe one way to fix this is would be to iterate over the directories, then use go list ./$dir to get the package name.

for dir in $(echo $@|xargs -n1 dirname|sort -u); do
    go vet $(go list ./$dir)
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants