https://github.com/rinchsan/gosimports
alias goimports='gosimports'
https://github.com/rinchsan/gosimports
alternative go goimports
Last synced: 5 months ago
JSON representation
alias goimports='gosimports'
- Host: GitHub
- URL: https://github.com/rinchsan/gosimports
- Owner: rinchsan
- License: bsd-3-clause
- Created: 2020-12-28T10:23:24.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2026-01-10T01:28:07.000Z (5 months ago)
- Last Synced: 2026-01-10T23:35:03.433Z (5 months ago)
- Topics: alternative, go, goimports
- Language: Go
- Homepage: https://pkg.go.dev/github.com/rinchsan/gosimports
- Size: 419 KB
- Stars: 94
- Watchers: 1
- Forks: 7
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
> **Note**
> APIs are likely to change a few times before we reach 1.0.0
# gosimports - simpler goimports


[](https://pkg.go.dev/github.com/rinchsan/gosimports/cmd/gosimports)
- :rocket: Drop-in replacement for `goimports`
- :100: Prettier than `goimports`
- :hammer: Originally forked from `golang.org/x/tools/cmd/goimports`
## Motivation
This `gosimports` provides one solution to the [goimports grouping/ordering problem](https://github.com/golang/go/issues/20818).
## Installation
### Go
```bash
go install github.com/rinchsan/gosimports/cmd/gosimports@latest
```
### Homebrew
```bash
brew install rinchsan/tap/gosimports
```
### Binary
Download binaries from [GitHub Releases](https://github.com/rinchsan/gosimports/releases)
## Example
```go
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` :+1:
```go
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 :-1:
```go
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"
)
```
## Module Usage
### Installation
```bash
go get github.com/rinchsan/gosimports
```
### Example
```go
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
}
}
```
## License
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.