Skip to content

main: add -formatonly flag to avoid go toolchain dependency#58

Merged
RaduBerinde merged 1 commit into
masterfrom
radu-add-format-only-flag
Jun 11, 2026
Merged

main: add -formatonly flag to avoid go toolchain dependency#58
RaduBerinde merged 1 commit into
masterfrom
radu-add-format-only-flag

Conversation

@RaduBerinde

Copy link
Copy Markdown
Member

Previously, crlfmt's default path ran goimports with import resolution
enabled, which shells out to the go toolchain (go env, go list) to
add missing and remove unused imports. This made a go toolchain a
runtime requirement; without go on $PATH, crlfmt failed with
"go command required, not found".

This adds a -formatonly flag that sets goimports' FormatOnly option,
which skips import resolution. With the flag, crlfmt still applies gofmt
formatting, the simplify pass, signature wrapping, and import grouping,
but no longer requires the go toolchain. The trade-off is that missing
imports are not added and unused imports are not removed, since that
resolution fundamentally needs the module graph.

Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com

Previously, crlfmt's default path ran goimports with import resolution
enabled, which shells out to the go toolchain (`go env`, `go list`) to
add missing and remove unused imports. This made a go toolchain a
runtime requirement; without `go` on `$PATH`, crlfmt failed with
"go command required, not found".

This adds a `-formatonly` flag that sets goimports' `FormatOnly` option,
which skips import resolution. With the flag, crlfmt still applies gofmt
formatting, the simplify pass, signature wrapping, and import grouping,
but no longer requires the go toolchain. The trade-off is that missing
imports are not added and unused imports are not removed, since that
resolution fundamentally needs the module graph.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@RaduBerinde RaduBerinde requested a review from rail June 10, 2026 21:42
@RaduBerinde

Copy link
Copy Markdown
Member Author

TFTR!

@RaduBerinde RaduBerinde merged commit ee386e7 into master Jun 11, 2026
4 checks passed
@RaduBerinde RaduBerinde deleted the radu-add-format-only-flag branch June 11, 2026 00:20
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