fix(cmd/gf): Fixed an issue where formatting caused import errors in gf init#4598
Merged
fix(cmd/gf): Fixed an issue where formatting caused import errors in gf init#4598
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an import path issue in gf init by replacing the formatting utility that was inadvertently modifying import paths. The change switches from using imports.Process (which reorganizes imports) to go/format.Source (which only formats code).
- Replaced
utils.GoFmtwith a newformatGoFilesfunction that usesgo/formatinstead ofimports.Process - Updated code comments to reflect the new formatting approach
- Removed the dependency on the custom
utilspackage
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/gf/internal/cmd/geninit/geninit_generator.go | Removed utils import, added go/format import; replaced utils.GoFmt call with new formatGoFiles function; added formatGoFiles implementation that formats Go files without modifying imports |
| cmd/gf/internal/cmd/geninit/geninit_ast.go | Updated comment to reference formatGoFiles instead of utils.GoFmt |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
houseme
approved these changes
Jan 9, 2026
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.
This pull request refactors the way Go files are formatted after project generation in the
geninitpackage. The main change is replacing the previous formatting utility with a new function that uses the standard library'sgo/formatpackage, ensuring that only code formatting is applied and import paths are not inadvertently modified.Formatting improvements:
utils.GoFmtwith a newformatGoFilesfunction that utilizesgo/formatfor formatting Go files, avoiding unwanted changes to local import paths. (cmd/gf/internal/cmd/geninit/geninit_generator.go)formatGoFilesfunction, which recursively formats all Go files in a directory usinggo/formatand logs any formatting errors. (cmd/gf/internal/cmd/geninit/geninit_generator.go)formatGoFilesinstead ofutils.GoFmt. (cmd/gf/internal/cmd/geninit/geninit_ast.go)Dependency changes:
utilspackage and added the standardgo/formatpackage to support the new formatting approach. (cmd/gf/internal/cmd/geninit/geninit_generator.go)