Skip to content

Commit 9030d07

Browse files
committed
chore: add golangci-lint to CI
1 parent 0907af9 commit 9030d07

5 files changed

Lines changed: 1105 additions & 171 deletions

File tree

‎.golangci.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "2"
2+
run:
3+
timeout: 5m
4+
linters:
5+
default: standard
6+
enable:
7+
- gosec
8+
settings:
9+
gosec:
10+
excludes:
11+
- G117
12+
- G120
13+
- G704
14+
exclusions:
15+
rules:
16+
- linters: [gosec]
17+
path: _test\.go
18+
text: "(G101|G104)"
19+
- linters: [errcheck, ineffassign]
20+
path: _test\.go
21+
- linters: [errcheck]
22+
path: cmd/admin_cmd.go
23+
- linters: [errcheck]
24+
path: cmd/migrate_cmd.go
25+
- linters: [errcheck]
26+
path: cmd/serve_cmd.go
27+
- linters: [errcheck]
28+
path: internal/conf/confload/loader.go
29+
- linters: [errcheck]
30+
path: internal/e2e/e2eapi/e2eapi.go
31+
- linters: [errcheck]
32+
path: internal/e2e/e2ehooks/e2ehooks.go
33+
- linters: [errcheck]
34+
path: internal/hooks/hookshttp/hookshttp.go
35+
- linters: [errcheck]
36+
path: internal/indexworker/indexworker.go
37+
- linters: [errcheck]
38+
path: internal/mailer/templatemailer/template.go
39+
- linters: [errcheck]
40+
path: internal/mailer/validateclient/validateclient.go
41+
- linters: [errcheck]
42+
path: internal/reloader/poller.go
43+
- linters: [errcheck]
44+
path: internal/reloader/reloader.go
45+
- linters: [errcheck]
46+
path: internal/utilities/oidc_discovery.go

‎Makefile‎

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build deps image migrate test vet sec vulncheck format hooks lint unused release
1+
.PHONY: all build deps image migrate test sec vulncheck format hooks lint unused release golangci-lint
22
.PHONY: check-gosec check-govulncheck check-oapi-codegen check-staticcheck check-go-version check-format
33
CHECK_FILES ?= ./...
44

@@ -33,15 +33,14 @@ RELEASE_ARCHIVES = \
3333

3434
TOOL_BIN_DIR = tools/bin
3535
TOOL_TARGETS = \
36-
$(TOOL_BIN_DIR)/gosec \
37-
$(TOOL_BIN_DIR)/staticcheck \
38-
$(TOOL_BIN_DIR)/govulncheck
36+
$(TOOL_BIN_DIR)/govulncheck \
37+
$(TOOL_BIN_DIR)/golangci-lint
3938

4039

4140
help: ## Show this help.
4241
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
4342

44-
all: check-go-version vet sec static build ## Run the tests and build the binary.
43+
all: check-go-version golangci-lint build ## Run the tests and build the binary.
4544

4645
build: auth auth-amd64 auth-arm64 auth-darwin-arm64 ## Build the binaries.
4746

@@ -74,9 +73,7 @@ deps: ## Install dependencies.
7473

7574
lint: \
7675
check-go-version \
77-
vet \
78-
static \
79-
sec \
76+
golangci-lint \
8077
vulncheck
8178

8279
release-test: lint test
@@ -117,41 +114,24 @@ test: auth ## Run tests.
117114
go test -failfast $(CHECK_FILES) -coverprofile=coverage.out -coverpkg ./... -p 1 -race -v -count=1
118115
./hack/coverage.sh
119116

120-
vet: # Vet the code
121-
go vet $(CHECK_FILES)
122-
123117
check-go-version: ## Verify the pinned Go version matches across go.mod, Dockerfiles, and submodules.
124118
./hack/check-go-version.sh
125119

126120
.NOTPARALLEL: $(TOOL_TARGETS)
127121
$(TOOL_TARGETS):
128122
$(MAKE) -C tools
129123

130-
sec: | $(TOOL_BIN_DIR)/gosec # Check for security vulnerabilities
131-
$(TOOL_BIN_DIR)/gosec \
132-
-quiet \
133-
-exclude-generated \
134-
-exclude=G117,G120,G704 \
135-
$(CHECK_FILES)
136-
$(TOOL_BIN_DIR)/gosec \
137-
-quiet \
138-
-tests \
139-
-exclude-generated \
140-
-exclude=G101,G104,G117,G120,G704 \
141-
$(CHECK_FILES)
124+
sec: | $(TOOL_BIN_DIR)/golangci-lint # Check for security issues (gosec)
125+
$(TOOL_BIN_DIR)/golangci-lint run --enable-only=gosec $(CHECK_FILES)
142126

143127
vulncheck: $(TOOL_BIN_DIR)/govulncheck # Check for known vulnerabilities
144128
$(TOOL_BIN_DIR)/govulncheck $(CHECK_FILES) | go run ./hack/vulncheck-filter
145129

146-
unused: | $(TOOL_BIN_DIR)/staticcheck # Look for unused code
147-
@echo "Unused code:"
148-
$(TOOL_BIN_DIR)/staticcheck -checks U1000 $(CHECK_FILES)
149-
@echo
150-
@echo "Code used only in _test.go (do move it in those files):"
151-
$(TOOL_BIN_DIR)/staticcheck -checks U1000 -tests=false $(CHECK_FILES)
130+
unused: | $(TOOL_BIN_DIR)/golangci-lint # Look for unused code
131+
$(TOOL_BIN_DIR)/golangci-lint run --enable-only=unused $(CHECK_FILES)
152132

153-
static: | $(TOOL_BIN_DIR)/staticcheck
154-
$(TOOL_BIN_DIR)/staticcheck ./...
133+
golangci-lint: | $(TOOL_BIN_DIR)/golangci-lint
134+
$(TOOL_BIN_DIR)/golangci-lint run $(CHECK_FILES)
155135

156136
generate: | check-oapi-codegen
157137
go generate ./...

‎tools/Makefile‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
BIN_DIR := $(CURDIR)/bin
22
BIN_TARGETS := \
3-
$(BIN_DIR)/gosec \
4-
$(BIN_DIR)/staticcheck \
5-
$(BIN_DIR)/govulncheck
3+
$(BIN_DIR)/govulncheck \
4+
$(BIN_DIR)/golangci-lint
65

76
.PHONY: all
87
all: $(BIN_TARGETS)
98

10-
$(BIN_DIR)/gosec: | $(BIN_DIR)
11-
GOBIN=$(BIN_DIR) go install github.com/securego/gosec/v2/cmd/gosec
12-
13-
$(BIN_DIR)/staticcheck: | $(BIN_DIR)
14-
GOBIN=$(BIN_DIR) go install honnef.co/go/tools/cmd/staticcheck
15-
169
$(BIN_DIR)/govulncheck: | $(BIN_DIR)
1710
GOBIN=$(BIN_DIR) go install golang.org/x/vuln/cmd/govulncheck
1811

12+
$(BIN_DIR)/golangci-lint: | $(BIN_DIR)
13+
GOBIN=$(BIN_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint
14+
1915
$(BIN_DIR):
2016
mkdir -p $(@)
2117

0 commit comments

Comments
 (0)