-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/vet: warn about "// go:" comments (with space) #43698
Comments
embed.FS
that lack go:embed directives
Change https://golang.org/cl/283852 mentions this issue: |
If this never makes sense, why not a build error? |
Do we expect this restriction is necessary? Proposal restricts this to package level variables. The current draft of https://golang.org/cl/283852 does have an embed.FS at this level. Do we expect anyone else would have one intentionally? |
I'd be ok with that too, but I suspect that a |
I expect that it will catch a non-trivial number of real errors with few or no false-positives. I believe that meets the bar for a
Note that (a) the package-level variable in that CL is unnecessary (it could be a local variable instead), and (b) it would not trigger the proposed check anyway, because that variable is in a test source file. |
@timothy-king, Oh, I think I see what you're saying now. “Would it be ok to warn for package-level embed.FS variables in test source files?” I don't actually know. I suspect that we could warn for those cases too..? |
Agreed. I also think the cost of a false-positive is small. I believe
Yep that was my question.
I also suspect warning on tests would be okay. Maybe I am not being clever enough, but I can't think of a good use case for test files either. |
As described in the FS documentation. This prevents http.FS and other clients from panicking when the go:embed directive is missing. For #43682 Related #43698 Change-Id: Iecf26d229a099e55d24670c3119cd6c6d17ecc6e Reviewed-on: https://go-review.googlesource.com/c/go/+/283852 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
The spec in the adopted proposal was very clear that declaring an embed.FS with no
You don't want vet to complain about |
This proposal has been added to the active column of the proposals project |
@rsc The proposal is only to warn on package level variables. I think
That is saying fairly definitively that a strict reading of this proposal that it will warn on non-errors. It does seem like there should be something we can do to help in cases like #43682 though. What about instead just warning when there is no //go:embed and there is also a likely misspelling like "// go:embed" (with a space)? |
It seems fine to develop a vet checker that warns about "// go:" lines where "//go:" would have a meaning instead. |
Yep, that seems ok by me. A |
It might be worth looking at the buildtag analysis pass, which may already do this for //go:build. |
Does anyone object to the retitled proposal (a vet check to warn about "// go:foo" where "//go:foo" has a meaning)? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://golang.org/cl/381914 mentions this issue: |
I've mailed out CL https://go-review.googlesource.com/c/tools/+/381914 which fixes the problem and is simple. |
The
embed.FS
type added for #41191 documents the following behavior:I expect that package authors essentially never intend to end up with an empty read-only filesystem in a production package. (In tests, perhaps, but not otherwise.) For the few cases where they do, they should be able to add an explicit
//go:embed
directive indicating that the filesystem is intentionally empty.Otherwise, it is too easy for an unintentional typo in the
//go:embed
directive, such as the one discovered in #43682 (comment), to result in a difficult-to-debug failure at run time.I propose that
cmd/vet
should emit a warning when:embed.FS
,//go:embed
directive (not even one with an empty pattern list),The text was updated successfully, but these errors were encountered: