Skip to content

cmd/gofmt: formatting should sort and cluster imports in a standard way #48552

@jsgoupil

Description

@jsgoupil

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

go version go1.16.5 windows/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

The order of the imports is not something that "matters" to developers, yet the developers will comment during code reviews to order them the right way. Why? There is literally no reason for having them in a specific order other than the "look" of them.

Furthermore, by having them manually fiddled with, it causes avoidable merge issues.

Currently, the imports are ordered but by block only. If I separate my imports in different blocks, they will be all left untouched. It will take the solo import lines and sort them correctly. So there is some kind of logic applied so it "looks" good, but it should go all the way opiniated and not allow the dev to order them the way they want.

What did you expect to see?

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"strings"
	"time"

	_ "github.com/fake-a/package"
	"github.com/fake-b/package"
	fakeZ "github.com/fake-z/package"
}

What did you see instead?

import (
	"fmt"
	"log"

	"flag"
	"net/http"
	"os"
	"strings"
	"time"

	fakeZ "github.com/fake-z/package"

	_ "github.com/fake-a/package"
	"github.com/fake-b/package"
}

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