Skip to content

cmd/gofmt: consider sorting imports in the same way as goimports (separating std lib from third party) #37719

@JeremyLoy

Description

@JeremyLoy

What version of Go are you using (go version)?

1.14

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

MacOS

What did you do?

ran go fmt ./.. on my codebase

What did you expect to see?

The builtin go fmt formats imports identically to goimports

What did you see instead?

go fmt works differently than goimports

Downloading of goimports is necessary to work in certain repos and adhere to their style guide. One impetus of having go fmt built in is to not have these sorts of disagreements, and instead just rally around a single tool. The existence and continued support for goimports goes against this philosophy. In addition, there is poor visibility in the public eye of goimports. Its not discoverable via the command line, as it isn't built in like vet and fmt. The only way people learn of this other tool is via blog posts or poking around Github.

I propose that the builtin go fmt sorts imports in the same way as goimports starting with next Go versioned release, and development of goimports ceases.

If we want to maintain two different sets of rules, I think a good compromise would be to add a -imports flag to the builtin go fmt so that we aren't maintaining two tools for one job

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions