-
Notifications
You must be signed in to change notification settings - Fork 18k
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/gofmt: should not update tool generated files #73181
Comments
I had it in the back of my mind to open a similar issue, notably this is necessary for generated code that generates FYI: Gopls already does this #49555. What about this case: go fmt file.go I think then is should format, as the user explicitly asked so (i think?) |
FYI: https://pkg.go.dev/go/ast#IsGenerated |
Does your tool generate source with |
See #55157. We expect generated code to be formatted. |
@seankhliao @mateusz834 The tool that generates the code is https://github.com/microsoft/kiota . This generates code based on an openapi spec (for example https://github.com/microsoftgraph/msgraph-sdk-go). As it's based on dotnet and generates go code, there is no way to do a |
Thanks, but i still believe that such code should be indeed formatted. I think after every code generation using this tool you can just run |
In that case, we expect you to run gofmt as part of your code generation pipeline. it's only 3s for the entire msgraph-sdk-go repo. |
Go version
1.24.2
Output of
go env
in your module/workspace:What did you do?
I have a lot of tool generated code in my project directory. If I run
go fmt ./...
it also touches these filesWhat did you see happen?
go fmt ./...
also updates all generated filesWhat did you expect to see?
Go fmt should not touch auto generated files. According to https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source these files should start with a string matching the regex
^// Code generated .* DO NOT EDIT\.$
.I think go fmt should not touch files matching this regex as they are generated by tools.
The text was updated successfully, but these errors were encountered: