-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
Use standard function to check if a file is generated #1114
Use standard function to check if a file is generated #1114
Conversation
As of Go1.21, we can use https://pkg.go.dev/go/ast#IsGenerated to check if a file is generated. Probably we want to use this instead of own implementation.
https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source says: > This line must appear before the first non-comment, non-blank text in the file. Original test cases fail with the previous commit because test source does not comply with this spec. So, probably we should update test case to comply with the spec. (This is a breaking change, though)
I noticed that Ci is failing, I will look into it later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this update. Please could you fix the lint warning?
@ccojocar I've tried to fix it, but I don't understand the cause of the lint error:
I would appreciate any advice. |
I think you need to run the gci tool to format the two files. Something like this:
You can check if the warnings are fixed by running locally the golangci-lint tool. |
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
@nobishino I did the formatting. Let's see if now passes the lint. |
@ccojocar Thanks! |
As of Go1.21, we can utilize standard package function
ast.IsGenerated
to check if a file is generated or not. This PR replaceisGeneratedFile
with that new standard function.Second commit updates test source.
Standard
ast.IsGenerated
returnsfalse
for original test sources, because it does not comply withhttps://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source
Original test source does not satisfy this condition, so original
isGeneratedFile
function returnstrue
when it should returnfalse
.I would assume we should update the test cases, but this change can be breaking for some users. I wonder if we should do that.