From 6f3fe961b154571a9287151ff0c10c3022c0b722 Mon Sep 17 00:00:00 2001 From: "Huabing (Robin) Zhao" Date: Wed, 18 Dec 2024 17:30:42 +0800 Subject: [PATCH] chore: enable codespell check (#48) Fixes: https://github.com/envoyproxy/ai-gateway/issues/28 --------- Signed-off-by: Huabing Zhao --- .codespell.ignorewords | 0 .codespell.skip | 1 + Makefile | 13 ++++++++++--- Makefile.tools.mk | 8 ++++++++ internal/apischema/openai/openai.go | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .codespell.ignorewords create mode 100644 .codespell.skip diff --git a/.codespell.ignorewords b/.codespell.ignorewords new file mode 100644 index 000000000..e69de29bb diff --git a/.codespell.skip b/.codespell.skip new file mode 100644 index 000000000..95ebafa11 --- /dev/null +++ b/.codespell.skip @@ -0,0 +1 @@ +./manifests/charts/ai-gateway-helm/crds/* diff --git a/Makefile b/Makefile index 53aebec93..37eedf278 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,13 @@ lint: golangci-lint @echo "lint => ./..." @$(GOLANGCI_LINT) run --build-tags==celvalidation ./... +.PHONY: codespell +CODESPELL_SKIP := $(shell cat .codespell.skip | tr \\n ',') +CODESPELL_IGNORE_WORDS := ".codespell.ignorewords" +codespell: $(CODESPELL) + @echo "spell => ./..." + @$(CODESPELL) --skip $(CODESPELL_SKIP) --ignore-words $(CODESPELL_IGNORE_WORDS) + # This runs the formatter on the codebase as well as goimports via gci. .PHONY: format format: gci gofumpt @@ -48,7 +55,7 @@ apigen: controller-gen # This runs all necessary steps to prepare for a commit. .PHONY: precommit -precommit: tidy apigen format lint +precommit: tidy codespell apigen format lint # This runs precommit and checks for any differences in the codebase, failing if there are any. .PHONY: check @@ -81,14 +88,14 @@ test-cel: envtest apigen format # This builds a binary for the given command under the internal/cmd directory. # # Example: -# - `make build.controler`: will build the internal/cmd/controller directory. +# - `make build.controller`: will build the internal/cmd/controller directory. # - `make build.extproc`: will build the internal/cmd/extproc directory. # # By default, this will build for the current GOOS and GOARCH. # To build for multiple platforms, set the GOOS_LIST and GOARCH_LIST variables. # # Example: -# - `make build.controler GOOS_LIST="linux darwin" GOARCH_LIST="amd64 arm64"` +# - `make build.controller GOOS_LIST="linux darwin" GOARCH_LIST="amd64 arm64"` GOOS_LIST ?= $(shell go env GOOS) GOARCH_LIST ?= $(shell go env GOARCH) .PHONY: build.% diff --git a/Makefile.tools.mk b/Makefile.tools.mk index 487db0525..d6fd0a294 100644 --- a/Makefile.tools.mk +++ b/Makefile.tools.mk @@ -9,6 +9,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint GO_FUMPT = $(LOCALBIN)/gofumpt GCI = $(LOCALBIN)/gci EDITORCONFIG_CHECKER = $(LOCALBIN)/editorconfig-checker +CODESPELL = $(LOCALBIN)/.venv/codespell@v2.3.0/bin/codespell ## Tool versions. CONTROLLER_TOOLS_VERSION ?= v0.16.2 @@ -48,6 +49,13 @@ envtest: $(ENVTEST) $(ENVTEST): $(LOCALBIN) $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) +.bin/.venv/%: + mkdir -p $(@D) + python3 -m venv $@ + $@/bin/pip3 install $$(echo $* | sed 's/@/==/') + +$(CODESPELL): .bin/.venv/codespell@v2.3.0 + # 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 # $2 - package url which can be installed diff --git a/internal/apischema/openai/openai.go b/internal/apischema/openai/openai.go index 2db7ddd2b..d0f408f8c 100644 --- a/internal/apischema/openai/openai.go +++ b/internal/apischema/openai/openai.go @@ -1,4 +1,4 @@ -// Package openai contains the followings are the OpenAI API schema definitions. +// Package openai contains the following are the OpenAI API schema definitions. // Note that we intentionally do not use the code generation tools like OpenAPI Generator not only to keep the code simple // but also because the OpenAI's OpenAPI definition is not compliant with the spec and the existing tools do not work well. package openai