Format generated Go code to adhere to golang coding standards#6416
Open
firefart wants to merge 63 commits into
Open
Format generated Go code to adhere to golang coding standards#6416firefart wants to merge 63 commits into
firefart wants to merge 63 commits into
Conversation
baywet
requested changes
Apr 7, 2025
There was a problem hiding this comment.
Pull request overview
This PR updates the Go code generator to better match gofmt expectations (tabs for indentation, Go-style return type formatting, cleaner comments, import ordering, and switch/case indentation) so go fmt produces no diffs on generated output.
Changes:
- Switch Go generation indentation to tabs (via
LanguageWriter+GoWriter). - Adjust Go signatures/returns/comment formatting to align with
gofmtconventions. - Update Go writer logic and tests around imports, switch/case indentation, and return type formatting.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs | Updates assertions to match new Go formatting expectations. |
| src/Kiota.Builder/Writers/LanguageWriter.cs | Adds configurable indentation character/size to support tabs for Go. |
| src/Kiota.Builder/Writers/Go/GoWriter.cs | Configures Go writer to use tab indentation. |
| src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs | Simplifies namespace import string concatenation. |
| src/Kiota.Builder/Writers/Go/GoConventionService.cs | Adjusts doc comment prefix handling to avoid trailing spaces. |
| src/Kiota.Builder/Writers/Go/CodeProprietableBlockDeclarationWriter.cs | Changes import ordering/format in type declarations. |
| src/Kiota.Builder/Writers/Go/CodePropertyWriter.cs | Avoids emitting trailing spaces for typeless/embedded fields. |
| src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs | Refactors Go method prototype emission, removes semicolons, adjusts spacing/blocks. |
| src/Kiota.Builder/Writers/Go/CodeInterfaceDeclarationWriter.cs | Removes redundant string interpolation in output. |
| src/Kiota.Builder/Writers/Go/CodeFileDeclarationWriter.cs | Changes import ordering/format at file scope. |
| src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs | Refactors enum parsing switch generation for gofmt-style indentation. |
| src/Kiota.Builder/Writers/Go/CodeClassDeclarationWriter.cs | Removes redundant string interpolation in output. |
| src/Kiota.Builder/Refiners/GoRefiner.cs | Updates deserializer function return type formatting. |
| it/go/app.go | Reorders imports/indentation in Go integration test app. |
| CHANGELOG.md | Adds changelog entries for the Go formatting changes (and adjusts some older formatting). |
| .devcontainer/devcontainer.json | Updates recommended VS Code extensions in devcontainer configuration. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
@baywet sorry for the long silence, I totally forgot about this open PR. I just added the missing tests. Please let me know if you need anything else on this to get it ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Golang expects generated code to be properly
go fmt'ed (see golang/go#73181 (comment)).This PR tries to implement the changes so the code will be compatible and
go fmtwill not change anything in the generated code.Changes:
Test:
To test we will create a test client. Next go to the golangtest directory, init a git repo, and run go fmt to see the differences
Ideally the
git diffwill show no changes