https://github.com/bonsai-oss/goimportssort
automatically fix the order of golang imports. Repository mirrored from GitLab. 🦊
https://github.com/bonsai-oss/goimportssort
golang improvement programming tools
Last synced: about 1 year ago
JSON representation
automatically fix the order of golang imports. Repository mirrored from GitLab. 🦊
- Host: GitHub
- URL: https://github.com/bonsai-oss/goimportssort
- Owner: bonsai-oss
- License: mit
- Created: 2022-11-04T07:10:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-02-18T05:40:51.000Z (about 1 year ago)
- Last Synced: 2025-02-18T06:31:43.957Z (about 1 year ago)
- Topics: golang, improvement, programming, tools
- Language: Go
- Homepage:
- Size: 87.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
_fork of https://github.com/AanZee/goimportssort_
# go-imports-sort



This tool aims to automatically fix the order of golang imports. It will split your imports into three categories.
## Features
- Automatically split your imports in three categories: inbuilt, external and local.
- Written fully in Golang, no dependencies, works on any platform.
- Detects Go module name automatically.
- Orders your imports alphabetically.
- Removes additional line breaks.
- No more manually fixing import orders.
## Why use this over `goimports`?
Goimports will not categorize your imports when wrongly formatted. PRs to add in the
functionality [were denied](https://github.com/golang/tools/pull/68#issuecomment-450897493).
## Installation
```
$ go install github.com/bonsai-oss/goimportssort@latest
```
## Usage
```
usage: goimportssort [flags] [path ...]
-l write results to stdout
-local string
put imports beginning with this string after 3rd-party packages; comma-separated list
-o string
custom the order of the section of imports. e.g. ixl means inbuilt, external, and local (default "iel")
-p int
number of files to process concurrently (default 8)
-v verbose logging
-w write result to (source) file instead of stdout
```
Imports will be sorted according to their categories.
```
$ goimportssort -v -w .
```
For example:
```go
package main
import (
"fmt"
"log"
APZ "bitbucket.org/example/package/name"
APA "bitbucket.org/example/package/name"
"github.com/bonsai-oss/goimportssort/package2"
"github.com/bonsai-oss/goimportssort/package1"
)
import (
"net/http/httptest"
)
import "bitbucket.org/example/package/name2"
import "bitbucket.org/example/package/name3"
import "bitbucket.org/example/package/name4"
```
will be transformed into:
```go
package main
import (
"fmt"
"log"
"net/http/httptest"
APA "bitbucket.org/example/package/name"
APZ "bitbucket.org/example/package/name"
"bitbucket.org/example/package/name2"
"bitbucket.org/example/package/name3"
"bitbucket.org/example/package/name4"
"github.com/bonsai-oss/goimportssort/package1"
"github.com/bonsai-oss/goimportssort/package2"
)
```