Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(cmd/gf): Fixed an issue where formatting caused import errors in gf init#4598

Merged
hailaz merged 1 commit intomasterfrom
fix/gfinit0108
Jan 9, 2026
Merged

fix(cmd/gf): Fixed an issue where formatting caused import errors in gf init#4598
hailaz merged 1 commit intomasterfrom
fix/gfinit0108

Conversation

@hailaz
Copy link
Contributor

@hailaz hailaz commented Jan 9, 2026

This pull request refactors the way Go files are formatted after project generation in the geninit package. The main change is replacing the previous formatting utility with a new function that uses the standard library's go/format package, ensuring that only code formatting is applied and import paths are not inadvertently modified.

Formatting improvements:

  • Replaced the use of utils.GoFmt with a new formatGoFiles function that utilizes go/format for formatting Go files, avoiding unwanted changes to local import paths. (cmd/gf/internal/cmd/geninit/geninit_generator.go)
  • Added the formatGoFiles function, which recursively formats all Go files in a directory using go/format and logs any formatting errors. (cmd/gf/internal/cmd/geninit/geninit_generator.go)
  • Updated comments and references in the code to clarify that formatting is now handled by formatGoFiles instead of utils.GoFmt. (cmd/gf/internal/cmd/geninit/geninit_ast.go)

Dependency changes:

  • Removed the import of the custom utils package and added the standard go/format package to support the new formatting approach. (cmd/gf/internal/cmd/geninit/geninit_generator.go)

Copilot AI review requested due to automatic review settings January 9, 2026 02:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.GoFmt with a new formatGoFiles function that uses go/format instead of imports.Process
  • Updated code comments to reflect the new formatting approach
  • Removed the dependency on the custom utils package

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.

@hailaz hailaz requested a review from houseme January 9, 2026 02:26
@hailaz hailaz merged commit a6485d5 into master Jan 9, 2026
38 checks passed
@hailaz hailaz deleted the fix/gfinit0108 branch January 9, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants