Skip to content

Commit a4b1993

Browse files
committed
Add nilaway linter to golangci-lint
1 parent 52dbb71 commit a4b1993

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

.custom-gcl.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: v2.5.0
2+
name: golangci-lint-nilaway
3+
destination: ./bin
4+
plugins:
5+
- module: "go.uber.org/nilaway"
6+
import: "go.uber.org/nilaway/cmd/gclplugin"
7+
version: "v0.0.0-20250821055425-361559d802f0"

.golangci-nilaway.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
4+
output:
5+
formats:
6+
text:
7+
path: stdout
8+
linters:
9+
default: none
10+
enable:
11+
- nilaway
12+
settings:
13+
custom:
14+
nilaway:
15+
type: "module"
16+
description: Static analysis tool to detect potential nil panics in Go code.
17+
settings:
18+
include-pkgs: ""
19+
exclude-file-docstrings: ignore_autogenerated
20+
exclusions:
21+
rules:
22+
- path-except: "^api/"
23+
linters:
24+
- nilaway
25+
issues:
26+
max-issues-per-linter: 0
27+
max-same-issues: 0
28+
new: false

Makefile

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ LOCALBIN ?= $(CACHE_BIN)
99
DEVBOX_BIN ?= $(DEVBOX_PACKAGES_DIR)/bin
1010
HELM ?= $(LOCALBIN)/helm
1111
HELM_VERSION ?= v3.16.3
12+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
13+
GOLANGCI_LINT_VERSION ?= v2.5.0
14+
GOLANGCI_LINT_NILAWAY ?= $(CACHE_BIN)/golangci-lint-nilaway
1215

1316
#####################################################################
1417
# Dev Setup
@@ -31,7 +34,6 @@ LINODE_URL ?= https://api.linode.com
3134
KUBECONFIG_PATH ?= $(CURDIR)/test-cluster-kubeconfig.yaml
3235
SUBNET_KUBECONFIG_PATH ?= $(CURDIR)/subnet-testing-kubeconfig.yaml
3336
MGMT_KUBECONFIG_PATH ?= $(CURDIR)/mgmt-cluster-kubeconfig.yaml
34-
GOLANGCI_LINT_VERSION ?= v2.5.0
3537

3638
# if the $DEVBOX_PACKAGES_DIR env variable exists that means we are within a devbox shell and can safely
3739
# use devbox's bin for our tools
@@ -66,7 +68,11 @@ vet: fmt
6668

6769
.PHONY: lint
6870
lint:
69-
docker run --rm -w /workdir -v $(PWD):/workdir golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint run -c .golangci.yml --fix
71+
$(GOLANGCI_LINT) run -c .golangci.yml --fix
72+
73+
.PHONY: lint
74+
nilcheck: golangci-lint-nilaway ## Run nilaway against code.
75+
$(GOLANGCI_LINT_NILAWAY) run -c .golangci-nilaway.yml
7076

7177
.PHONY: gosec
7278
gosec: ## Run gosec against code.
@@ -273,3 +279,25 @@ helm-template: helm
273279
#Verify template works when region and apiToken are passed, and when it is passed as reference.
274280
@$(HELM) template foo deploy/chart --set apiToken="apiToken",region="us-east" > /dev/null
275281
@$(HELM) template foo deploy/chart --set secretRef.apiTokenRef="apiToken",secretRef.name="api",secretRef.regionRef="us-east" > /dev/null
282+
283+
.PHONY: kubectl
284+
kubectl: $(KUBECTL) ## Download kubectl locally if necessary.
285+
$(KUBECTL): $(LOCALBIN)
286+
curl -fsSL https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/$(OS)/$(ARCH_SHORT)/kubectl -o $(KUBECTL)
287+
chmod +x $(KUBECTL)
288+
289+
.PHONY: clusterctl
290+
clusterctl: $(CLUSTERCTL) ## Download clusterctl locally if necessary.
291+
$(CLUSTERCTL): $(LOCALBIN)
292+
curl -fsSL https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CLUSTERCTL_VERSION)/clusterctl-$(OS)-$(ARCH_SHORT) -o $(CLUSTERCTL)
293+
chmod +x $(CLUSTERCTL)
294+
295+
.phony: golangci-lint-nilaway
296+
golangci-lint-nilaway: $(GOLANGCI_LINT_NILAWAY)
297+
$(GOLANGCI_LINT_NILAWAY): $(GOLANGCI_LINT) # Build golangci-lint-nilaway from custom configuration.
298+
$(GOLANGCI_LINT) custom
299+
300+
.phony: golangci-lint
301+
golangci-lint: $(GOLANGCI_LINT)
302+
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
303+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

0 commit comments

Comments
 (0)