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

go-generate: Does not work for multiple files in different packages #76

Closed
mattayes opened this issue Sep 23, 2021 · 2 comments
Closed

Comments

@mattayes
Copy link

Hi folks,

I tried to use the new go-generate hook and ran into an error:

go-generate..............................................................Failed
- hook id: go-generate
- exit code: 1

named files must all be in one directory; have path/to/a/package and path/to/another/package

As per the generate documentation it appears go generate can handle multiple files in the same package and multiple packages, however it can't handle multiple files in the same package.

@larsks
Copy link
Contributor

larsks commented Sep 29, 2021

I came here to report the same problem. I don't think it makes sense for go-generate to operate on the list of modified files; typically, things generated with go generate are required to build, so if you're running these tests in CI you need to run go generate on all files.

The run-go-generate.sh script should probably do nothing more than...

go generate ./...

...which will generate all required files.

@dnephin
Copy link
Owner

dnephin commented Oct 17, 2021

Hmm, right, I forget that "accepts files" does not mean the files can be in separate packages. This sounds similar to #47, #62, #63, but for go generate instead of go vet.

I don't think it makes sense for go-generate to operate on the list of modified files; typically, things generated with go generate are required to build, so if you're running these tests in CI you need to run go generate on all files.

I don't think it's fair to assume that everyone wants to run go generate on all files. The command run by go generate could be slow, so running on only the files that have changed seems like the right default behaviour. That feels to me like the intent of the pre-commit framework, which is why it passes the list of changed files to the hooks.

I think we need to do something similar to what we have for go vet: go list to get all the packages, then iterate over any changed packages.

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

No branches or pull requests

3 participants