You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
goimports speed issues probably belong in a different issue, but I don't see anything resembling this dramatic goimports/gofmt difference. On our 325,000 LOC Go codebase gofmt -l takes 2.5s to run and goimports -l takes 14s to run.
FYI goimports slowness might be from #22139. Code has changed since I filed that, but issue might be present. You can try passing absolute paths to goimports -w and see if that speeds it up.
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.
The text was updated successfully, but these errors were encountered: