Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
x/tools/cmd/goimports: add --format-only flag #31745
Proposal - allow goimports to "just format"
Add a flag or some such that skips all the time-intensive adding/removing of imports, and just formats the file(s).
A Compromise Between gofmt and goimports
Some people like goimports, some people don't. But when the two meet... everyone is sad, because goimports and gofmt don't format the same, causing spurious changes in files when goimports "fixes" files that gofmt thinks are fine.... i.e. sorting stdlib imports into their own section.
If goimports had a way to just format, then a compromise could be reached where a project standardizes on goimports' format, but then wouldn't require people to actually use goimports import add/ remove logic.
Additionally, right now there's no way to ensure that an entire codebase is properly formatted using goimports' style. Running
I presume if we skipped all the import checking, that the goimports formatting would be approximately as fast as go fmt.