Right imports sorting & code formatting tool (goimports alternative)
Right imports sorting & code formatting tool (goimports alternative)
Tool for Golang to sort goimports by 3-4 groups(with own linter): std, general, company(which is optional) and project dependencies.
Also, formatting for your code will be prepared(so, you don't need to use gofmt or goimports separately).
Use additional options -rm-unused to remove unused imports and -set-alias to rewrite import aliases for versioned packages or for packages with additional prefix/suffix(example: opentracing "github.com/opentracing/opentracing-go").
-company-prefixes - will create group for company imports(libs inside your organization). Values should be comma-separated.
goimports-reviser -rm-unused -set-alias -format ./reviser/reviser.goYou can also apply rules to a dir or recursively apply using ./... as a target:
goimports-reviser -rm-unused -set-alias -format -recursive revisergoimports-reviser -rm-unused -set-alias -format ./...You can also apply rules to multiple targets:
goimports-reviser -rm-unused -set-alias -format ./reviser/reviser.go ./pkg/...…go install -v github.com/incu6us/goimports-reviser/v3@latestbrew tap incu6us/homebrew-tap
brew install incu6us/homebrew-tap/goimports-revisersnap install goimports-reviserBefore usage:
package testdata
import (
"log"
"github.com/incu6us/goimports-reviser/testdata/innderpkg"
"bytes"
"golang.org/x/exp/slices"
)After usage:
package testdata
import (
"bytes"
"log"
"golang.org/x/exp/slices"
"github.com/incu6us/goimports-reviser/testdata/innderpkg"
)Comments(not Docs) for imports is acceptable. Example:
package testdata
import (
"fmt" // comments to the package here
)-company-prefixes-optionBefore usage:
package testdata // goimports-reviser/testdata
import (
"fmt" //fmt package
"golang.org/x/exp/slices" //custom package
"github.com/incu6us/goimports-reviser/pkg" // this is a company package which is not a part of the project, but is a part of your organization
"goimports-reviser/pkg"
)After usage:
package testdata // goimports-reviser/testdata
import (
"fmt" // fmt package
"golang.org/x/exp/slices" // custom package
"github.com/incu6us/goimports-reviser/pkg" // this is a company package which is not a part of the project, but is a part of your organization
"goimports-reviser/pkg"
)-imports-order std,general,company,project,blanked,dotted-optionBefore usage:
package testdata // goimports-reviser/testdata
import (
_ "github.com/pkg1"
. "github.com/pkg2"
"fmt" //fmt package
"golang.org/x/exp/slices" //custom package
"github.com/incu6us/goimports-reviser/pkg" // this is a company package which is not a part of the project, but is a part of your organization
"goimports-reviser/pkg"
)After usage:
package testdata // goimports-reviser/testdata
import (
"fmt" // fmt package
"golang.org/x/exp/slices" // custom package
"github.com/incu6us/goimports-reviser/pkg" // this is a company package which is not a part of the project, but is a part of your organization
"goimports-reviser/pkg"
_ "github.com/pkg1"
. "github.com/pkg2"
)-format-optionBefore usage:
package main
func test(){
}
func additionalTest(){
}After usage:
package main
func test(){
}
func additionalTest(){
}-separate-named-optionBefore usage:
package testdata // goimports-reviser/testdata
import (
"fmt"
"github.com/incu6us/goimports-reviser/pkg"
extpkg "google.com/golang/pkg"
"golang.org/x/exp/slices"
extslice "github.com/PeterRK/slices"
)After usage:
package testdata // goimports-reviser/testdata
import (
"fmt"
"github.com/incu6us/goimports-reviser/pkg"
"golang.org/x/exp/slices"
extpkg "google.com/golang/pkg"
extslice "github.com/PeterRK/slices"
)A big thank you to all the amazing people who contributed!
If you like or are using this project, please give it a star.
No open issues yet, or sync has not completed.