Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate linters and use gci for imports #9

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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