gofimports/README.md

66 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2022-11-24 15:25:13 +00:00
# gofimports
2022-11-24 18:29:27 +00:00
2022-11-28 04:29:16 +00:00
[![Go](https://github.com/haunt98/gofimports/workflows/Go/badge.svg?branch=main)](https://github.com/haunt98/gofimports/actions)
[![Go Reference](https://pkg.go.dev/badge/github.com/haunt98/gofimports.svg)](https://pkg.go.dev/github.com/haunt98/gofimports)
2023-09-23 07:10:05 +00:00
[![Latest Version](https://img.shields.io/github/v/tag/haunt98/gofimports)](https://github.com/haunt98/gofimports/tags)
2022-11-28 04:29:16 +00:00
2022-11-27 17:36:32 +00:00
Group Go imports with my opinionated preferences.
2023-09-23 07:10:05 +00:00
First is **standard**. Then **third party**, then **company** if exist. The last
is **local**.
2022-11-27 17:36:32 +00:00
2023-09-23 07:10:05 +00:00
Also main selling point of this tool is to handle imports only. So please run
`gofumpt` or `gofmt` to format you files after running this tool.
2022-11-27 17:36:32 +00:00
## Install
With Go version `>= 1.16`:
```sh
go install github.com/haunt98/gofimports/cmd/gofimports@latest
```
## Usage
```sh
2023-01-22 04:45:49 +00:00
# Format ./internal with:
# - print impacted file (-l),
# - write to file (-w),
# - print diff (-d)
# - company prefix, split using comma (,)
gofimports -l -w -d --company github.com/make-go-great,github.com/haunt98 ./internal
# Format ./internal with:
# - write
# - stock mode, only split standard and non standard
gofimports -w --stock ./internal
2022-11-27 17:36:32 +00:00
```
2022-11-24 18:29:27 +00:00
Example result:
```go
import (
2022-11-28 04:29:16 +00:00
"fmt"
2022-11-28 04:29:16 +00:00
"github.com/urfave/cli/v2"
"github.com/pkg/diff"
2022-11-28 04:29:16 +00:00
"github.com/make-go-great/color-go"
2022-11-28 04:29:16 +00:00
"github.com/haunt98/gofimports/internal/imports"
)
```
2022-11-26 18:23:06 +00:00
## Roadmap
- [ ] Diff with color
2023-01-22 04:45:49 +00:00
- [x] Add profiling
2022-11-27 17:36:32 +00:00
- [ ] Improve performance
2022-11-26 18:23:06 +00:00
2022-11-24 18:29:27 +00:00
## Thanks
- [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports)
- [mvdan/gofumpt](https://github.com/mvdan/gofumpt)
- [incu6us/goimports-reviser](https://github.com/incu6us/goimports-reviser)
2023-01-17 05:00:20 +00:00
- [dave/dst](https://github.com/dave/dst)