This is a fork of goimports
, inspired by the gosimports
project.
goimports-wasabi
also tries to solve the import grouping/ordering problem, but in a different way.
goimports
and gosimports
have the following issues (as of 2022/11).
goimports
doesn't sort import specs deterministically.goimports
doesn't treat comments associated with import specs properly.goimports
doesn't work well for artificial inputs.gosimports
removes comments associated with import specs.
goimports-wasabi
is designed to work deterministically with any valid input, leaving as many comments as possible in the (supposedly) correct place.
go install github.com/homuler/goimports-wasabi@latest
import (
// doc comment for fmt
"fmt"
/*
* block comments
*/
// doc comment for foo
"github.com/homuler/foo"
"context"
// footer comment (maybe for context)
"strings" // line comment for strings
b "github.com/homuler/bar"
_ "runtime/pprof" // line comment for pprof
)
import (
"context"
// footer comment (maybe for context)
// doc comment for fmt
"fmt"
_ "runtime/pprof" // line comment for pprof
"strings" // line comment for strings
/*
* block comments
*/
b "github.com/homuler/bar"
// doc comment for foo
"github.com/homuler/foo"
)
goimports
import (
// doc comment for fmt
"fmt"
/*
* block comments
*/
// doc comment for foo
"context"
"github.com/homuler/foo"
// footer comment (maybe for context)
"strings" // line comment for strings
b "github.com/homuler/bar"
_ "runtime/pprof" // line comment for pprof
)
// doc comment for fmt
import "fmt"
// doc comment for context
import "context"
// doc comment
import (
// doc comment for errors
"errors"
)
goimports-wasabi
// doc comment
import (
// doc comment for context
"context"
// doc comment for errors
"errors"
// doc comment for fmt
"fmt"
)
goimports
// doc comment for fmt
import (
"context"
"errors"
"fmt"
)
// doc comment for context
// doc comment
// doc comment for errors
import ("fmt";"fmt";"context";"github.com/homuler/foo")
goimports-wasabi -format-only
import (
"context"
"fmt"
"github.com/homuler/foo"
)
goimports -format-only
panic: invalid line number 2 (should be < 2)
Copyright (c) 2009 The Go Authors. All rights reserved.