-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
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).
Use Cases
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.
Formatting Everything
Additionally, right now there's no way to ensure that an entire codebase is properly formatted using goimports' style. Running goimports -w . on any non-trivial codebase is just amazingly slow (for good reason - it's doing a ton of work). In contrast, go fmt ./... is quite fast. Running go fmt on our 100,000-ish LOC project at work completes in less than a second. Running goimports on the same project... well, I stopped it after a half hour, so I don't know how long it actually takes.
I presume if we skipped all the import checking, that the goimports formatting would be approximately as fast as go fmt.