Skip to content

Commit

Permalink
Add golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
timebertt committed Nov 1, 2023
1 parent 47ebc73 commit 2fea8df
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
68 changes: 68 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
run:
concurrency: 4
deadline: 10m

skip-files:
- "zz_generated\\..*\\.go$"

linters:
enable:
- exportloopref
- ginkgolinter
- gocritic
- gosec
- importas
- misspell
- nilerr
- nolintlint
- prealloc
- revive
- stylecheck
- unconvert
- unparam
- whitespace

linters-settings:
importas:
alias:
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
alias: $1$2
- pkg: k8s.io/apimachinery/pkg/apis/(\w+)/(v[\w\d]+)
alias: $1$2
- pkg: k8s.io/apimachinery/pkg/api/([^m]\w+)
alias: api${1}
- pkg: k8s.io/apimachinery/pkg/util/(\w+)
alias: util${1}
- pkg: k8s.io/client-go/tools/clientcmd/api/(\w+)
alias: clientcmd${1}
- pkg: k8s.io/client-go/tools/cache
alias: toolscache
- pkg: k8s.io/component-base/config/(v[\w\d]+)
alias: componentbaseconfig$1
- pkg: k8s.io/utils/clock/testing
alias: testclock
- pkg: sigs.k8s.io/controller-runtime/pkg/client/fake
alias: fakeclient
- pkg: sigs.k8s.io/controller-runtime/pkg/log/zap
alias: logzap
- pkg: sigs.k8s.io/controller-runtime/pkg/log
alias: logf
misspell:
locale: US
nolintlint:
require-specific: true
revive:
rules:
- name: context-as-argument
- name: duplicated-imports
- name: early-return
- name: exported
- name: unreachable-code
whitespace:
multi-func: true

issues:
exclude-rules:
- linters:
- stylecheck
text: "ST1003:.+func SetDefaults_"
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ test-kyverno: $(KYVERNO) ## Run kyverno policy tests.

##@ Verification

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci-lint against code.
$(GOLANGCI_LINT) run ./...

.PHONY: check
check: vet test test-kyverno ## Check everything (vet + test + test-kyverno).
check: lint test test-kyverno ## Check everything (lint + test + test-kyverno).

.PHONY: verify-fmt
verify-fmt: fmt ## Verify go code is formatted.
Expand All @@ -97,11 +97,11 @@ verify: verify-fmt verify-generate verify-modules check ## Verify everything (al
##@ Build

.PHONY: build
build: generate fmt vet ## Build the sharder binary.
build: ## Build the sharder binary.
go build -o bin/sharder ./cmd/sharder

.PHONY: run
run: generate fmt vet ## Run the sharder from your host.
run: ## Run the sharder from your host.
go run ./cmd/sharder

PUSH ?= false
Expand Down
5 changes: 5 additions & 0 deletions hack/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ CONTROLLER_GEN_VERSION ?= v0.13.0
$(CONTROLLER_GEN): $(call tool_version_file,$(CONTROLLER_GEN),$(CONTROLLER_GEN_VERSION))
GOBIN=$(abspath $(TOOLS_BIN_DIR)) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)

GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.55.1
$(GOLANGCI_LINT): $(call tool_version_file,$(GOLANGCI_LINT),$(GOLANGCI_LINT_VERSION))
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN_DIR) $(GOLANGCI_LINT_VERSION)

KIND := $(TOOLS_BIN_DIR)/kind
KIND_VERSION ?= v0.20.0
$(KIND): $(call tool_version_file,$(KIND),$(KIND_VERSION))
Expand Down

0 comments on commit 2fea8df

Please sign in to comment.