Skip to content

Commit

Permalink
Remove duplicate linters and use gci for imports (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Anuraag Agrawal <[email protected]>
  • Loading branch information
anuraaga authored Nov 27, 2024
1 parent ed61ec6 commit 9c11a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ linters:
- exportloopref
- importas
- gci
- gofmt
- gofumpt
- goimports
- gocritic
- gosec
- govet
Expand Down Expand Up @@ -70,12 +68,6 @@ linters-settings:
- default
# Groups all imports with the specified Prefix.
- prefix(github.com/envoyproxy/ai-gateway)
gofmt:
simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/envoyproxy/ai-gateway
govet:
enable-all: true
disable:
Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ lint: golangci-lint
@$(GOLANGCI_LINT) run --build-tags=$(LINT_BUILD_TAGS) ./...

.PHONY: format
format: goimports gofumpt
format: gci gofumpt
@echo "format => *.go"
@find . -type f -name '*.go' | xargs gofmt -s -w
@find . -type f -name '*.go' | xargs $(GO_FUMPT) -l -w
@echo "goimports => *.go"
@for f in `find . -name '*.go'`; do \
awk '/^import \($$/,/^\)$$/{if($$0=="")next}{print}' $$f > /tmp/fmt; \
mv /tmp/fmt $$f; \
done
@$(GO_IMPORTS) -w -local github.com/envoyproxy/ai-gateway `find . -name '*.go'`
@echo "gci => *.go"
@$(GCI) write -s standard -s default -s "prefix(github.com/envoyproxy/ai-gateway)" `find . -name '*.go'`

.PHONY: tidy
tidy: ## Runs go mod tidy on every module
Expand Down
12 changes: 6 additions & 6 deletions Makefile.tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ $(LOCALBIN):
## Tool binary names.
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GO_FUMPT = $(LOCALBIN)/gofumpt
GO_IMPORTS = $(LOCALBIN)/goimports
GCI = $(LOCALBIN)/gci

## Tool versions.
GOLANGCI_LINT_VERSION ?= v1.60.1
GO_FUMPT_VERSION ?= v0.6.0
GO_IMPORTS_VERSION ?= v0.21.0
GCI_VERSION ?= v0.13.5

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
Expand All @@ -22,10 +22,10 @@ gofumpt: $(GO_FUMPT)
$(GO_FUMPT): $(LOCALBIN)
$(call go-install-tool,$(GO_FUMPT),mvdan.cc/gofumpt,$(GO_FUMPT_VERSION))

.PHONY: goimports
goimports: $(GO_IMPORTS)
$(GO_IMPORTS): $(LOCALBIN)
$(call go-install-tool,$(GO_IMPORTS),golang.org/x/tools/cmd/goimports,$(GO_IMPORTS_VERSION))
.PHONY: gci
gci: $(GCI)
$(GCI): $(LOCALBIN)
$(call go-install-tool,$(GCI),github.com/daixiang0/gci,$(GCI_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
Expand Down

0 comments on commit 9c11a36

Please sign in to comment.