Skip to content

Group Go imports with my opinionated preferences.

License

Notifications You must be signed in to change notification settings

haunt98/gofimports

Repository files navigation

gofimports

Go gitleaks Go Reference Latest Version

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 handle imports only. So please run gofumpt or gofmt to format you files after running this tool.

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 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

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

About

Group Go imports with my opinionated preferences.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published