Skip to content

Commit 610c2e7

Browse files
akashsawan1tjons
authored andcommitted
feat: add golangci-lint integration and update Makefile
- Add .golangci.yaml for linting, following the OPA project approach. - Update Makefile to use golangci-lint (v1.64.5). Signed-off-by: Akash Sawan <[email protected]> refactor: remove check-lint.sh, check-vet.sh, check-fmt.sh, and golint package Signed-off-by: Akash Sawan <[email protected]> ci: switch to `make check` in CI workflow and increase timeout - Updated CI workflow to use `make check` instead of `make ci-go-check`, following the OPA project approach. - Previously, `ci-go-check` required spinning up a Go Docker environment on the first run; this is no longer needed with `make check`. - Increased job timeout from 15 to 30 minutes to allow more time for linting, following the OPA project. Signed-off-by: Akash Sawan <[email protected]> Signed-off-by: tjons <[email protected]>
1 parent e1b6ccb commit 610c2e7

File tree

14 files changed

+233
-2330
lines changed

14 files changed

+233
-2330
lines changed

.github/workflows/checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ jobs:
3939
uses: actions/checkout@v4
4040

4141
- name: Golang Style and Lint Check
42-
run: make ci-go-check
43-
timeout-minutes: 15
42+
run: make check
43+
timeout-minutes: 30
4444

4545
deploy:
4646
name: Push Latest Release

.golangci.yaml

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
run:
2+
timeout: 5m
3+
4+
issues:
5+
max-same-issues: 0 # don't hide issues in CI runs because they are the same type
6+
exclude-dirs:
7+
- internal/gojsonschema
8+
- internal/jwx
9+
exclude-rules:
10+
- path: ast/
11+
linters:
12+
- staticcheck
13+
text: "SA1019"
14+
- path: bundle/
15+
linters:
16+
- staticcheck
17+
text: "SA1019"
18+
- path: capabilities/
19+
linters:
20+
- staticcheck
21+
text: "SA1019"
22+
- path: compile/
23+
linters:
24+
- staticcheck
25+
text: "SA1019"
26+
- path: config/
27+
linters:
28+
- staticcheck
29+
text: "SA1019"
30+
- path: cover/
31+
linters:
32+
- staticcheck
33+
text: "SA1019"
34+
- path: debug/
35+
linters:
36+
- staticcheck
37+
text: "SA1019"
38+
- path: dependencies/
39+
linters:
40+
- staticcheck
41+
text: "SA1019"
42+
- path: download/
43+
linters:
44+
- staticcheck
45+
text: "SA1019"
46+
- path: format/
47+
linters:
48+
- staticcheck
49+
text: "SA1019"
50+
- path: hooks/
51+
linters:
52+
- staticcheck
53+
text: "SA1019"
54+
- path: ir/
55+
linters:
56+
- staticcheck
57+
text: "SA1019"
58+
- path: keys/
59+
linters:
60+
- staticcheck
61+
text: "SA1019"
62+
- path: loader/
63+
linters:
64+
- staticcheck
65+
text: "SA1019"
66+
- path: logging/
67+
linters:
68+
- staticcheck
69+
text: "SA1019"
70+
- path: metrics/
71+
linters:
72+
- staticcheck
73+
text: "SA1019"
74+
- path: plugins/
75+
linters:
76+
- staticcheck
77+
text: "SA1019"
78+
- path: profiler/
79+
linters:
80+
- staticcheck
81+
text: "SA1019"
82+
- path: refactor/
83+
linters:
84+
- staticcheck
85+
text: "SA1019"
86+
- path: repl/
87+
linters:
88+
- staticcheck
89+
text: "SA1019"
90+
- path: rego/
91+
linters:
92+
- staticcheck
93+
text: "SA1019"
94+
- path: resolver/
95+
linters:
96+
- staticcheck
97+
text: "SA1019"
98+
- path: runtime/
99+
linters:
100+
- staticcheck
101+
text: "SA1019"
102+
- path: schemas/
103+
linters:
104+
- staticcheck
105+
text: "SA1019"
106+
- path: sdk/
107+
linters:
108+
- staticcheck
109+
text: "SA1019"
110+
- path: server/
111+
linters:
112+
- staticcheck
113+
text: "SA1019"
114+
- path: storage/
115+
linters:
116+
- staticcheck
117+
text: "SA1019"
118+
- path: tester/
119+
linters:
120+
- staticcheck
121+
text: "SA1019"
122+
- path: topdown/
123+
linters:
124+
- staticcheck
125+
text: "SA1019"
126+
- path: tracing/
127+
linters:
128+
- staticcheck
129+
text: "SA1019"
130+
- path: types/
131+
linters:
132+
- staticcheck
133+
text: "SA1019"
134+
- path: util/
135+
linters:
136+
- staticcheck
137+
text: "SA1019"
138+
- path: version/
139+
linters:
140+
- staticcheck
141+
text: "SA1019"
142+
143+
linters-settings:
144+
lll:
145+
line-length: 200
146+
gocritic:
147+
disabled-checks:
148+
- appendAssign
149+
# NOTE(ae): this one should be enabled, but there were too
150+
# many violations to fix in one go... revisit later
151+
- singleCaseSwitch
152+
# Reasonable rule, but not sure what to replace with in
153+
# many locations, so disabling for now
154+
- exitAfterDefer
155+
# The following 3 rules are disabled from the perfomance tag
156+
# enabled further down. The first two are reasonable, but not
157+
# super important. appendCombine is really nice though! And
158+
# should be enabled. Just many places to fix..
159+
- hugeParam
160+
- preferFprint
161+
- appendCombine
162+
enabled-checks:
163+
# NOTE that these are rules enabled in addition to the default set
164+
- filepathJoin
165+
- dupImport
166+
- redundantSprint
167+
- stringConcatSimplify
168+
enabled-tags:
169+
- performance
170+
settings:
171+
ifElseChain:
172+
# ridiculous value set for now, but this should be
173+
# lowered to something more reasonable, as the rule
174+
# is reasonable (replace long if-else chains with
175+
# switch)... just too many violations right now
176+
minThreshold: 10
177+
govet:
178+
enable:
179+
- deepequalerrors
180+
- nilness
181+
perfsprint:
182+
# only rule disabled by default, but it's a good one
183+
err-error: true
184+
revive:
185+
rules:
186+
# this mainly complains about us using min/max for variable names,
187+
# which seems like an unlikely source of actual issues
188+
- name: redefines-builtin-id
189+
disabled: true
190+
- name: unused-receiver
191+
disabled: false
192+
193+
linters:
194+
disable-all: true
195+
enable:
196+
- mirror
197+
# - errcheck # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/723 is complete
198+
# - govet # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/727 is complete
199+
- ineffassign
200+
# - intrange # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/728 is complete
201+
# - revive # replacement for golint # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/724 is complete
202+
- gofmt
203+
- goimports
204+
- unused
205+
- misspell
206+
- usetesting
207+
- typecheck
208+
- staticcheck
209+
# - gosimple # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/726 is complete
210+
- prealloc
211+
- unconvert
212+
- copyloopvar
213+
# - perfsprint # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/729 is complete
214+
# - gocritic # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/725 is complete
215+
# - gosec # too many false positives

Makefile

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ CGO_ENABLED ?= 1
1717
WASM_ENABLED ?= 1
1818
GOARCH ?= $(shell go env GOARCH)
1919

20+
DOCKER_RUNNING ?= $(shell docker ps >/dev/null 2>&1 && echo 1 || echo 0)
21+
GOLANGCI_LINT_VERSION := v1.64.5
22+
2023
# GOPROXY=off: Don't pull anything off the network
2124
# see https://github.com/thepudds/go-module-knobs/blob/master/README.md
2225
GO := CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off go
@@ -192,19 +195,20 @@ clean:
192195
rm -f *.so
193196

194197
.PHONY: check
195-
check: check-fmt check-vet check-lint
196-
197-
.PHONY: check-fmt
198-
check-fmt:
199-
./build/check-fmt.sh
200-
201-
.PHONY: check-vet
202-
check-vet:
203-
./build/check-vet.sh
198+
check:
199+
ifeq ($(DOCKER_RUNNING), 1)
200+
docker run --rm -v $(shell pwd):/app:ro,Z -w /app golangci/golangci-lint:${GOLANGCI_LINT_VERSION} golangci-lint run -v
201+
else
202+
@echo "Docker not installed or running. Skipping golangci run."
203+
endif
204204

205-
.PHONY: check-lint
206-
check-lint:
207-
./build/check-lint.sh
205+
.PHONY: fmt
206+
fmt:
207+
ifeq ($(DOCKER_RUNNING), 1)
208+
docker run --rm -v $(shell pwd):/app:Z -w /app golangci/golangci-lint:${GOLANGCI_LINT_VERSION} golangci-lint run -v --fix
209+
else
210+
@echo "Docker not installed or running. Skipping golangci run."
211+
endif
208212

209213
.PHONY: generatepb
210214
generatepb:

build/check-fmt.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

build/check-lint.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

build/check-vet.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

vendor/golang.org/x/lint/.travis.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

vendor/golang.org/x/lint/CONTRIBUTING.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)