|
|
|
|
|
by cybrexalpha
671 days ago
|
|
Go fmt is pretty good, but it's not ideal. My biggest gripe is imports. Go fmt will just sort imports alphabetically in lists that aren't separated by a blank line. Goimports will separate out core from 3rd party imports, unless you run it with the local flag then it'll add a third block of "local" imports. But this spread means that it's not consistent across projects which style is preferred. Some examples, based on cursory looking at big Go codebases:
- Kubernetes, one of the biggest public-facing Go projects, uses the 3-block style https://github.com/kubernetes/kubernetes/blob/master/pkg/con...
- TIDB uses 2-block style https://github.com/pingcap/tidb/blob/master/pkg/ddl/placemen...
- MinIO uses 2-block https://github.com/minio/minio/blob/master/internal/grid/con... In all of those cases if you make a change and just run 'go fmt' it very well could inject any new imports in the first block, which would be wrong and you wouldn't know until project CI picks it up. |
|