-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: vet fails when listing files unless all files in the package are listed #24668
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
Comments
This is how all go tools work (including “go build” for instance). You either don’t give arguments (= current directory), specify a relative path pointing to a package, or specify a list of files that most form a full package. go vet is now much more precise because it has access to full type information, but it requires to see and vet a whole package. In your case, assuming you don’t want to fix issues in the generated file, I’d just filter out those files from vet’s output (eg: with grep) |
What happens if you pass the |
I could filter output, yes. I just worry about the fragility of that approach, though; is For example, in the output here:
I suppose what I would do is iterate over every line of output. Discard ones that start with a This would work today, but I think it could easily break in the future, unless vet's output is part of the compatibility guarantees.
Unkeyed composite literals have shown up in github.com/golang/protobuf/protoc-gen-go's output. See golang/protobuf#214. I see now that this has been fixed three weeks ago, though, in golang/protobuf#560, so maybe it's no longer an issue. Maybe I should regenerate and vet all code now. The reason I want to skip generated files isn't that vet is incorrectly flagging code, though. It's really that I rarely have the ability to fix the problem myself, because the code generator is typically written by someone else. They have to agree that making their generated output pass vet is worthwhile (which isn't always easy!) and then make changes, and then I need to regenerate code. |
I think step 1 is to determine whether |
This is just not supported. Vet works on whole packages. As it gets more sophisticated that's going to become more important. I would suggest grepping away things in generated code, or else writing the generated code in a way that doesn't produce vet errors. The latter (adjusting the generated code) should always be possible. If not, then please open a different issue (and link to it here) for the specific vet error that you can't avoid.
Yes, it was a (design) bug. Vet wasn't sophisticated enough to insist, and now it is. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10.1 darwin/amd64
(also occurs in
go1.10 darwin/amd64
)Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
I ran
go vet
, passing it a subset of files in a package.github.com/spenczar/testvet/file1.go
:github.com/spenczar/testvet/file2.go
:I ran
go vet ./file2.go
.What did you expect to see?
No output, and a 0 exit code.
What did you see instead?
Vet complained that it doesn't know about
f
, because it's in a file in the same package but which wasn't explicitly listed:This is a change in behavior from go1.9.5. Previously, this would exit with no output and code 0.
Listing files explicitly is important in my case because I have a package which contains some generated code and some hand-written code. The hand-written code references objects in the generated code. I want to vet the hand-written code, but I don't care about vet issues in the generated code.
This issue makes that workflow very difficult, maybe impossible, as I have to list all the files to get things to work.
The text was updated successfully, but these errors were encountered: