Command gosortimports is a more aggressive version of goimports that handles very badly grouped imports and adds gofmt's simplify code option (-s). Otherwise it is the same as goimports.
Note: Since gosortimports undoes any existing import groupings it is
recommended to run it with the -local
flag so that it can properly group
local imports. At some point gosortimports will support automatically deducing
the value of the local flag.
go install github.com/charlievieth/gosortimports
The two following examples shows how gosortimports more aggressively handles oddly grouped imports compared to goimports.
import (
"io"
"m/a"
"math"
"fmt"
"m/b"
)
// formatted with: `goimports -local=m/`
import (
"io"
"m/a"
"math"
"fmt"
"m/b"
)
// formatted with: `gosortimports -local=m/`
import (
"fmt"
"io"
"math"
"m/a"
"m/b"
)