Skip to content

Remove double formatting in AST import replacer#4594

Merged
hailaz merged 2 commits intofix/gfinit0107from
copilot/sub-pr-4592
Jan 7, 2026
Merged

Remove double formatting in AST import replacer#4594
hailaz merged 2 commits intofix/gfinit0107from
copilot/sub-pr-4592

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

Addresses feedback from PR #4592 regarding inefficient double formatting of Go files during project generation.

Changes

  • Replace format.Node with printer.Fprint in AST replacer to skip intermediate formatting
  • Defer all formatting to final utils.GoFmt call which uses golang.org/x/tools/imports

Previously, files modified by the AST replacer were formatted twice—once during import path replacement and again by the final utils.GoFmt call. Now the AST replacer writes unformatted AST, and a single utils.GoFmt pass handles both formatting and import organization.

// Before: formatted output
if err := format.Node(&buf, r.fset, file); err != nil {
    return err
}

// After: unformatted output, formatting deferred
if err := printer.Fprint(&buf, r.fset, file); err != nil {
    return err
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The AST replacer now uses printer.Fprint instead of format.Node,
deferring all formatting to the final utils.GoFmt call. This avoids
double formatting of modified files and is more efficient since
utils.GoFmt also handles import organization via golang.org/x/tools/imports.

Co-authored-by: hailaz <29968474+hailaz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues from review on init command improvements Remove double formatting in AST import replacer Jan 7, 2026
Copilot AI requested a review from hailaz January 7, 2026 04:44
@hailaz hailaz marked this pull request as ready for review January 7, 2026 04:53
@hailaz hailaz merged commit bc0433b into fix/gfinit0107 Jan 7, 2026
@hailaz hailaz deleted the copilot/sub-pr-4592 branch January 7, 2026 04:53
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