Compare commits

...

12 Commits

Author SHA1 Message Date
sudo pacman -Syu d0f5a35b4e chore(changelog): generate v0.0.8 2023-02-25 23:57:46 +07:00
sudo pacman -Syu 3db827a36c chore(changelog): generate v0.0.7 2023-02-25 23:57:24 +07:00
sudo pacman -Syu a4188fd5c6 chore: fix lint 2023-02-25 23:57:24 +07:00
sudo pacman -Syu 27f3083195 chore: update make 2023-02-25 23:57:24 +07:00
sudo pacman -Syu 004aeb8ec3 chore: bump go 1.20 github action 2023-02-25 23:57:24 +07:00
dependabot[bot] f73f3a756e chore(deps): bump github.com/urfave/cli/v2 from 2.24.3 to 2.24.4
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.24.3 to 2.24.4.
- [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.24.3...v2.24.4)

---
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>
2023-02-17 23:14:51 +07:00
dependabot[bot] b1af73e870 chore(deps): bump golang.org/x/tools from 0.5.0 to 0.6.0
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.5.0 to 0.6.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.5.0...v0.6.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-14 10:13:20 +07:00
dependabot[bot] 58d5a2877c chore(deps): bump golang.org/x/mod from 0.7.0 to 0.8.0
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.7.0 to 0.8.0.
- [Release notes](https://github.com/golang/mod/releases)
- [Commits](https://github.com/golang/mod/compare/v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-09 20:00:12 +07:00
dependabot[bot] df0cfc673d chore(deps): bump github.com/urfave/cli/v2 from 2.24.2 to 2.24.3
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.24.2 to 2.24.3.
- [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.24.2...v2.24.3)

---
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>
2023-02-03 17:50:04 +07:00
dependabot[bot] 0d2f71e215 chore(deps): bump github.com/urfave/cli/v2 from 2.24.1 to 2.24.2
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.24.1 to 2.24.2.
- [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.24.1...v2.24.2)

---
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>
2023-01-30 17:43:16 +07:00
dependabot[bot] 6acb5fecfc chore(deps): bump github.com/urfave/cli/v2 from 2.23.7 to 2.24.1
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.23.7 to 2.24.1.
- [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.7...v2.24.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-23 20:03:58 +07:00
sudo pacman -Syu 9680db81dd chore(changelog): generate v0.0.6 2023-01-22 11:51:15 +07:00
8 changed files with 272 additions and 34 deletions

View File

@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: "1.19" go-version: "1.20"
check-latest: true check-latest: true
cache: true cache: true
- run: go test -race -failfast ./... - run: go test -race -failfast ./...
@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: "1.19" go-version: "1.20"
check-latest: true check-latest: true
cache: true cache: true
- run: go build ./cmd/gofimports - run: go build ./cmd/gofimports
@ -43,7 +43,7 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: "1.19" go-version: "1.20"
check-latest: true check-latest: true
cache: true cache: true
- uses: golangci/golangci-lint-action@v3 - uses: golangci/golangci-lint-action@v3

View File

@ -17,7 +17,7 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: "1.19" go-version: "1.20"
check-latest: true check-latest: true
cache: true cache: true
- uses: goreleaser/goreleaser-action@v3 - uses: goreleaser/goreleaser-action@v3

View File

@ -1,10 +1,12 @@
run: run:
timeout: 2m
tests: false tests: false
skip-dirs: skip-dirs:
- ".*test.*" - ".*test.*"
- ".*mock.*" - ".*mock.*"
- ".*generated.*" - ".*generated.*"
- ".*example.*" - ".*example.*"
- ".*utils.*"
skip-files: skip-files:
- ".*Mock.*" - ".*Mock.*"
- ".*_mock.*" - ".*_mock.*"
@ -16,6 +18,7 @@ output:
linters: linters:
disable-all: true disable-all: true
enable: enable:
# Default
- errcheck - errcheck
- gosimple - gosimple
- govet - govet
@ -23,31 +26,30 @@ linters:
- staticcheck - staticcheck
- typecheck - typecheck
- unused - unused
# Custom
- errchkjson - errchkjson
- errname - errname
- errorlint - errorlint
- execinquery - execinquery
- forcetypeassert
- gocritic - gocritic
- goerr113 - goerr113
- gofumpt - gofumpt
- gomodguard
- gosec - gosec
- importas - importas
- makezero - makezero
- nilnil - nilnil
- prealloc - prealloc
- reassign
# - rowserrcheck
- sqlclosecheck
- unconvert - unconvert
# - wastedassign
fast: true fast: true
linters-settings: linters-settings:
gosec: # Default
excludes:
- G101
- G112
- G402
- G404
- G501
- G505
exclude-generated: true
govet: govet:
check-shadowing: false check-shadowing: false
disable-all: true disable-all: true
@ -67,9 +69,17 @@ linters-settings:
- unmarshal - unmarshal
- unreachable - unreachable
- unusedresult - unusedresult
staticcheck: # Custom
checks: ["all", "-SA1019"]
gocritic: gocritic:
disabled-checks:
- ifElseChain
- singleCaseSwitch
enabled-tags: enabled-tags:
- diagnostic
- style - style
- performance - performance
gosec:
exclude-generated: true
reassign:
patterns:
- ".*"

View File

@ -1,5 +1,223 @@
# CHANGELOG # CHANGELOG
## v0.0.8 (2023-02-25)
### Added
- feat: support multi company, split using , (2023-01-22)
- feat: cache module name even when read dir to improve perf (2023-01-17)
- feat: use sync.Pool to reuse bytes.Buffer (2023-01-17)
- feat: add profiler (2023-01-17)
- feat: add go profiler (2023-01-17)
- feat: improve perf by use astFile for dstFile (2023-01-17)
- feat: use errgroup to improve perf (2023-01-17)
- feat: use uber-go/automaxprocs (2023-01-17)
- feat: ignore empty imports (2023-01-17)
- feat: switch to use dst (2023-01-17)
- feat: custom printer ast (2022-11-28)
- feat: add parser.SkipObjectResolution (2022-11-28)
- feat: implement format dir (2022-11-28)
- feat: write file actually (2022-11-28)
- feat: remove sort imports (2022-11-28)
- feat: ignore empty import (2022-11-27)
- feat: sort imports using default Go (wip) (2022-11-27)
- feat: print diff (2022-11-27)
- feat: actually print file from ast (2022-11-27)
- feat: rewrite all logic to single loop ast.Decl (wip) (2022-11-26)
- feat: support combine multi import decl (wip) (2022-11-26)
- feat: split local, company, third party imports (2022-11-26)
- feat: cache module name of path (2022-11-26)
- feat: get module name from path (2022-11-26)
- feat: query go.mod (2022-11-26)
- feat: sort import (wip) (2022-11-26)
- feat: parse imports and group imports std (2022-11-26)
- feat: simple format file (without actually format) (2022-11-25)
- feat: init Formatter (2022-11-25)
- feat: flags from gofmt (2022-11-24)
### Fixed
- fix: update 2 times with dstFile (2023-01-17)
- fix: panic if format import spec empty (2023-01-17)
- fix: ignore not go file and go generated error (2022-11-28)
- fix: not copy import spec directly but use basic lit (2022-11-27)
- fix: force update ast decls when single import (2022-11-27)
- fix: formatter option missing value (2022-11-25)
### Others
- chore(changelog): generate v0.0.7 (2023-02-25)
- chore: fix lint (2023-02-25)
- chore: update make (2023-02-25)
- chore: bump go 1.20 github action (2023-02-25)
- chore(deps): bump github.com/urfave/cli/v2 from 2.24.3 to 2.24.4 (2023-02-17)
- chore(deps): bump golang.org/x/tools from 0.5.0 to 0.6.0 (2023-02-13)
- chore(deps): bump golang.org/x/mod from 0.7.0 to 0.8.0 (2023-02-09)
- chore(deps): bump github.com/urfave/cli/v2 from 2.24.2 to 2.24.3 (2023-02-03)
- chore(deps): bump github.com/urfave/cli/v2 from 2.24.1 to 2.24.2 (2023-01-30)
- chore(deps): bump github.com/urfave/cli/v2 from 2.23.7 to 2.24.1 (2023-01-23)
- chore(changelog): generate v0.0.6 (2023-01-22)
- chore: clarify company prefix guide (2023-01-22)
- chore: format using local ./gofimports (2023-01-22)
- chore: add golds (wip) (2023-01-18)
- chore: improve docs (2023-01-17)
- chore(changelog): generate v0.0.5 (2023-01-17)
- chore(changelog): generate v0.0.4 (2023-01-17)
- chore: re-format (2023-01-17)
- chore: log flags when verbose (2023-01-17)
- chore: remove buggy side effect (2023-01-17)
- chore(changelog): generate v0.0.3 (2023-01-17)
- chore: reformat a little bit (2023-01-17)
- chore: use bytes.Equal instead of bytes.Compare (2023-01-17)
- chore: add make clean (2023-01-17)
- chore(deps): bump golang.org/x/tools from 0.4.0 to 0.5.0 (2023-01-05)
- chore(deps): bump github.com/urfave/cli/v2 from 2.23.6 to 2.23.7 (2022-12-12)
- chore(deps): bump golang.org/x/tools from 0.3.0 to 0.4.0 (2022-12-07)
- chore(deps): bump github.com/urfave/cli/v2 from 2.23.5 to 2.23.6 (2022-12-05)
- chore: more comment (2022-11-28)
- chore: fix typo (2022-11-28)
- chore(changelog): generate v0.0.2 (2022-11-28)
- chore: add badges (2022-11-28)
- chore: better explain side effect README (2022-11-28)
- refactor: no need importNameAndPath (2022-11-28)
- refactor: rewrite parser mode (2022-11-28)
- chore: fix whitespace (2022-11-28)
- chore: format this project using this project :) (2022-11-28)
- chore(changelog): generate v0.0.1 (2022-11-28)
- chore: add install, usage in README (2022-11-28)
- chore: add roadmap (2022-11-27)
- chore: print path when diff (2022-11-27)
- refactor: rewrite formatImportSpecs to eliminate dupe (2022-11-27)
- chore: remove useless check import empty (2022-11-27)
- refactor: pkgName -> moduleName (2022-11-26)
- chore: update README (2022-11-25)
- chore: add TODO (2022-11-25)
- refactor: remove regex code generated (2022-11-25)
- chore: update comment (2022-11-25)
- refactor: accept both write and diff (2022-11-25)
- chore: remove fmt.Println (2022-11-24)
- chore: fix lint (2022-11-24)
- chore: add MIT license (2022-11-24)
- chore: add github action, Makefile (2022-11-24)
- chore: init go.mod (2022-11-24)
## v0.0.7 (2023-02-25)
### Others
- chore: fix lint (2023-02-25)
- chore: update make (2023-02-25)
- chore: bump go 1.20 github action (2023-02-25)
- chore(changelog): generate v0.0.6 (2023-01-22)
## v0.0.6 (2023-01-22)
### Added
- feat: support multi company, split using , (2023-01-22)
### Others
- chore: clarify company prefix guide (2023-01-22)
- chore: format using local ./gofimports (2023-01-22)
- chore: add golds (wip) (2023-01-18)
- chore: improve docs (2023-01-17)
- chore(changelog): generate v0.0.5 (2023-01-17)
## v0.0.5 (2023-01-17) ## v0.0.5 (2023-01-17)
### Added ### Added

View File

@ -5,6 +5,8 @@ all:
$(MAKE) test-color $(MAKE) test-color
$(MAKE) lint $(MAKE) lint
$(MAKE) format $(MAKE) format
$(MAKE) build
$(MAKE) clean
test: test:
go test -race -failfast ./... go test -race -failfast ./...
@ -29,13 +31,13 @@ lint:
format: format:
$(MAKE) build $(MAKE) build
# go install github.com/haunt98/gofimports/cmd/gofimports@latest
go install mvdan.cc/gofumpt@latest go install mvdan.cc/gofumpt@latest
./gofimports -w --company github.com/make-go-great,github.com/haunt98 . ./gofimports -w --company github.com/make-go-great,github.com/haunt98 .
gofumpt -w -extra . gofumpt -w -extra .
$(MAKE) clean $(MAKE) clean
build: build:
$(MAKE) clean
go build ./cmd/gofimports go build ./cmd/gofimports
clean: clean:

8
go.mod
View File

@ -6,10 +6,10 @@ require (
github.com/dave/dst v0.27.2 github.com/dave/dst v0.27.2
github.com/make-go-great/color-go v0.4.1 github.com/make-go-great/color-go v0.4.1
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
github.com/urfave/cli/v2 v2.23.7 github.com/urfave/cli/v2 v2.24.4
golang.org/x/mod v0.7.0 golang.org/x/mod v0.8.0
golang.org/x/sync v0.1.0 golang.org/x/sync v0.1.0
golang.org/x/tools v0.5.0 golang.org/x/tools v0.6.0
) )
require ( require (
@ -19,5 +19,5 @@ require (
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.4.0 // indirect golang.org/x/sys v0.5.0 // indirect
) )

16
go.sum
View File

@ -17,18 +17,18 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= github.com/urfave/cli/v2 v2.24.4 h1:0gyJJEBYtCV87zI/x2nZCPyDxD51K6xM8SkwjHFCNEU=
github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= github.com/urfave/cli/v2 v2.24.4/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4= golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=

View File

@ -36,6 +36,8 @@ var (
ErrEmptyImport = errors.New("empty import") ErrEmptyImport = errors.New("empty import")
ErrGoModNotExist = errors.New("go mod not exist") ErrGoModNotExist = errors.New("go mod not exist")
ErrGoModEmptyModule = errors.New("go mod empty module") ErrGoModEmptyModule = errors.New("go mod empty module")
ErrNotBytesBuffer = errors.New("not bytes.Buffer")
ErrNotDSTGenDecl = errors.New("not dst.GenDecl")
) )
// https://pkg.go.dev/sync#Pool // https://pkg.go.dev/sync#Pool
@ -78,7 +80,6 @@ func NewFormmater(opts ...FormatterOptionFn) (*Formatter, error) {
for _, stdPackage := range stdPackages { for _, stdPackage := range stdPackages {
ft.stdPackages[stdPackage.PkgPath] = struct{}{} ft.stdPackages[stdPackage.PkgPath] = struct{}{}
} }
// ft.log("NewFormmater: stdPackages: %+v\n", ft.stdPackages)
ft.moduleNames = make(map[string]string) ft.moduleNames = make(map[string]string)
ft.formattedPaths = make(map[string]struct{}) ft.formattedPaths = make(map[string]struct{})
@ -280,8 +281,12 @@ func (ft *Formatter) formatImports(
// First update // First update
dstFile.Imports = formattedDSTImportSpecs dstFile.Imports = formattedDSTImportSpecs
genSpecs := dstFile.Decls[0].(*dst.GenDecl).Specs genDecl, ok := dstFile.Decls[0].(*dst.GenDecl)
formattedGenSpecs := make([]dst.Spec, 0, len(genSpecs)) if !ok {
return nil, ErrNotDSTGenDecl
}
formattedGenSpecs := make([]dst.Spec, 0, len(genDecl.Specs))
// Append all imports first // Append all imports first
for _, importSpec := range formattedDSTImportSpecs { for _, importSpec := range formattedDSTImportSpecs {
@ -289,7 +294,7 @@ func (ft *Formatter) formatImports(
} }
// Append all non imports later // Append all non imports later
for _, genSpec := range genSpecs { for _, genSpec := range genDecl.Specs {
if _, ok := genSpec.(*dst.ImportSpec); !ok { if _, ok := genSpec.(*dst.ImportSpec); !ok {
formattedGenSpecs = append(formattedGenSpecs, genSpec) formattedGenSpecs = append(formattedGenSpecs, genSpec)
continue continue
@ -297,9 +302,12 @@ func (ft *Formatter) formatImports(
} }
// Second update // Second update
dstFile.Decls[0].(*dst.GenDecl).Specs = formattedGenSpecs genDecl.Specs = formattedGenSpecs
b := bufPool.Get().(*bytes.Buffer) b, ok := bufPool.Get().(*bytes.Buffer)
if !ok {
return nil, ErrNotBytesBuffer
}
b.Reset() b.Reset()
defer bufPool.Put(b) defer bufPool.Put(b)