Note APIs are likely to change a few times before we reach 1.0.0
- 🚀 Drop-in replacement for
goimports
- 💯 Prettier than
goimports
- 🔨 Originally forked from
golang.org/x/tools/cmd/goimports
This gosimports
provides one solution to the goimports grouping/ordering problem.
go install github.com/rinchsan/gosimports/cmd/gosimports@latest
brew install rinchsan/tap/gosimports
Download binaries from GitHub Releases
import (
"bufio"
// basic comments
/*
block comments
*/
"github.com/rinchsan/gosimports/internal/imports"
"errors"
gocmd "github.com/rinchsan/gosimports/internal/gocommand"
"flag"
"runtime"
_ "runtime/pprof" // trailing inline comments
"strings"
)
↓ $ gosimports -w
👍
import (
"bufio"
"errors"
"flag"
"runtime"
_ "runtime/pprof" // trailing inline comments
"strings"
gocmd "github.com/rinchsan/gosimports/internal/gocommand"
"github.com/rinchsan/gosimports/internal/imports"
)
while goimports
formatting like below 👎
import (
"bufio"
// basic comments
/*
block comments
*/
"github.com/rinchsan/gosimports/internal/imports"
"errors"
"flag"
gocmd "github.com/rinchsan/gosimports/internal/gocommand"
"runtime"
_ "runtime/pprof" // trailing inline comments
"strings"
)
go get github.com/rinchsan/gosimports
package main
import (
"os"
"github.com/rinchsan/gosimports"
)
func main() {
src, err := os.ReadFile("gosimports.go")
if err != nil {
// error handling
}
formatted, err := gosimports.Process("", src, nil)
if err != nil {
// error handling
}
if err := os.WriteFile("gosimports.go", formatted, 0644); err != nil {
// error handling
}
}
Copyright 2013 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.