Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Make go list run with non-root packages#47

Open
txomon wants to merge 2 commits into
dnephin:masterfrom
txomon:patch-1
Open

Make go list run with non-root packages#47
txomon wants to merge 2 commits into
dnephin:masterfrom
txomon:patch-1

Conversation

@txomon

@txomon txomon commented May 27, 2020

Copy link
Copy Markdown

No description provided.

@dnephin

dnephin commented Jun 4, 2020

Copy link
Copy Markdown
Owner

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

txomon commented Aug 20, 2020

Copy link
Copy Markdown
Author

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

@dnephin

dnephin commented Sep 3, 2020

Copy link
Copy Markdown
Owner

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

@txomon

txomon commented Sep 9, 2020

Copy link
Copy Markdown
Author

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

@dnephin

dnephin commented Sep 13, 2020

Copy link
Copy Markdown
Owner

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

txomon commented Sep 18, 2020

Copy link
Copy Markdown
Author

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

@dnephin

dnephin commented Sep 21, 2020

Copy link
Copy Markdown
Owner

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants