Skip to content

Commit

Permalink
build: replace gofmt with goimports
Browse files Browse the repository at this point in the history
goimports formats the import lines and also formats the code style
as per gofmt so now `make fmt` will fix both

this usefull in the absence of a full ide with golang support
  • Loading branch information
anjannath authored and praveenkumar committed Mar 21, 2023
1 parent 8296a0e commit 7f08c46
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ e2e-story-registry: install


.PHONY: fmt
fmt:
@gofmt -l -w $(SOURCE_DIRS)
fmt: $(TOOLS_BINDIR)/goimports
@$(TOOLS_BINDIR)/goimports -l -w $(SOURCE_DIRS)

# Run golangci-lint against code
.PHONY: lint cross-lint
Expand Down
2 changes: 2 additions & 0 deletions tools/bin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ golangci-lint.exe
gomod2rpmdeps
makefat
mockery
goimports
goimports.exe
1 change: 1 addition & 0 deletions tools/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import (
_ "github.com/cfergeau/gomod2rpmdeps/cmd/gomod2rpmdeps"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/randall77/makefat"
_ "golang.org/x/tools/cmd/goimports"
)
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/cfergeau/gomod2rpmdeps v0.0.0-20210223144124-2042c4850ca8
github.com/golangci/golangci-lint v1.51.2
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844
golang.org/x/tools v0.6.0
)

require (
Expand Down Expand Up @@ -171,7 +172,6 @@ require (
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions tools/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ $(TOOLS_BINDIR)/gomod2rpmdeps: $(TOOLS_DIR)/go.mod

$(TOOLS_BINDIR)/mockery: $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && GOBIN="$(TOOLS_BINDIR)" go install github.com/vektra/mockery/v2@latest

$(TOOLS_BINDIR)/goimports: $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && GOBIN="$(TOOLS_BINDIR)" go install golang.org/x/tools/cmd/goimports@latest
50 changes: 50 additions & 0 deletions tools/vendor/golang.org/x/tools/cmd/goimports/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f08c46

Please sign in to comment.