Go to file
sudo pacman -Syu 8d5c63b8db chore: improve docs 2023-01-17 23:58:44 +07:00
.github chore: add github action, Makefile 2022-11-24 23:16:32 +07:00
cmd/gofimports feat: improve perf by use astFile for dstFile 2023-01-17 17:52:29 +07:00
internal chore: improve docs 2023-01-17 23:58:44 +07:00
.gitignore feat: add profiler 2023-01-17 18:17:28 +07:00
.golangci.yml chore: add github action, Makefile 2022-11-24 23:16:32 +07:00
.goreleaser.yml chore: add github action, Makefile 2022-11-24 23:16:32 +07:00
CHANGELOG.md chore(changelog): generate v0.0.5 2023-01-17 23:55:08 +07:00
LICENSE chore: add MIT license 2022-11-24 23:16:50 +07:00
Makefile chore: add make clean 2023-01-17 10:27:31 +07:00
README.md chore: remove buggy side effect 2023-01-17 12:00:20 +07:00
go.mod feat: improve perf by use astFile for dstFile 2023-01-17 17:52:29 +07:00
go.sum feat: improve perf by use astFile for dstFile 2023-01-17 17:52:29 +07:00

README.md

gofimports

Go Go Reference

Group Go imports with my opinionated preferences.

First is standard. Then third party, then company if exist. The last is local.

Also main selling point of this tool is to group imports not sort them. So please run gofumpt or gofmt after running this tool.

Under the hood, this tool get all imports, then group them into 4 groups (std, third party, company, local). Remember, no sort here. Then insert empty import (empty path) between each group to get final imports Then update Go ast decls import with final imports.

Install

With Go version >= 1.16:

go install github.com/haunt98/gofimports/cmd/gofimports@latest

Usage

# Format ./internal
# with print impacted file (-l),
# write to file (-w),
# print diff (-d)
# company is github.com/make-go-great
gofimports -l -company github.com/make-go-great -w -d ./internal

Example result:

import (
    "fmt"

    "github.com/urfave/cli/v2"
    "github.com/pkg/diff"

    "github.com/make-go-great/color-go"

    "github.com/haunt98/gofimports/internal/imports"
)

Roadmap

  • Diff with color
  • Add profiling
  • Improve performance

Thanks