Go to file
dependabot[bot] 8cbb7e79f1 chore(deps): bump github.com/urfave/cli/v2 from 2.23.5 to 2.23.6
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.23.5 to 2.23.6.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v2.23.5...v2.23.6)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-05 17:52:18 +07:00
.github chore: add github action, Makefile 2022-11-24 23:16:32 +07:00
cmd/gofimports feat: flags from gofmt 2022-11-24 23:11:15 +07:00
internal chore: more comment 2022-11-28 12:22:10 +07:00
.gitignore chore: init go.mod 2022-11-24 22:25:13 +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.2 2022-11-28 11:29:28 +07:00
LICENSE chore: add MIT license 2022-11-24 23:16:50 +07:00
Makefile chore: format this project using this project :) 2022-11-28 01:11:04 +07:00
README.md chore: fix typo 2022-11-28 11:36:53 +07:00
go.mod chore(deps): bump github.com/urfave/cli/v2 from 2.23.5 to 2.23.6 2022-12-05 17:52:18 +07:00
go.sum chore(deps): bump github.com/urfave/cli/v2 from 2.23.5 to 2.23.6 2022-12-05 17:52:18 +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.

There is side effect of course, because we do not create empty line but we add empty import, so there is trailing space in that line (Go indent that empty import). That why I suggest you need to re-format after.

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