From 43575853aa0daab77d5775d2eac05b87ee9cbb60 Mon Sep 17 00:00:00 2001 From: Amol Kahat Date: Wed, 22 Feb 2023 15:23:17 +0530 Subject: [PATCH] Run pre-commit with make Updating pre-commit hook with make. pre-commit-golang repo is no longer maintained[1]. Instead of using unmaintained repo we can use make to run pre-commit. [1] https://github.com/dnephin/pre-commit-golang/issues/98 --- .pre-commit-config.yaml | 40 ++++++++++++++++++++++++++-------------- Makefile | 9 +++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6319c2903..1580899c9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,31 @@ repos: -- repo: https://github.com/dnephin/pre-commit-golang - rev: v0.5.1 - hooks: - - id: go-fmt - exclude: ^vendor - - id: go-vet - - id: go-mod-tidy - -- repo: https://github.com/golangci/golangci-lint - rev: v1.50.1 - hooks: - - id: golangci-lint - - repo: local hooks: + - id: golangci-lint + name: golangci-lint + language: golang + types: [go] + entry: make + args: ["golangci-lint"] + pass_filenames: false + - id: gofmt + name: gofmt + language: system + entry: make + args: ["fmt"] + pass_filenames: false + - id: govet + name: govet + language: system + entry: make + args: ["vet"] + pass_filenames: false + - id: gotidy + name: gotidy + language: system + entry: make + args: ["tidy"] + pass_filenames: false - id: make-manifests name: make-manifests language: system @@ -60,4 +72,4 @@ repos: rev: 2.1.1 hooks: - id: bashate - entry: bashate --error . --ignore=E006,E040,E043 + entry: bashate --error . --ignore=E006,E040,E011,E020,E012 diff --git a/Makefile b/Makefile index f565403e5..d813aec9a 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,15 @@ vet: gowork ## Run go vet against code. go vet ./... go vet ./api/... +.PHONY: tidy +tidy: fmt + go mod tidy + +.PHONY: golangci-lint +golangci-lint: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.2 + $(LOCALBIN)/golangci-lint run --fix + .PHONY: test test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out