Skip to content

Commit 79359c6

Browse files
Merge pull request #190 from saschagrunert/lint
Apply golangci-lint config and fixes
2 parents 834909e + b432680 commit 79359c6

File tree

10 files changed

+409
-132
lines changed

10 files changed

+409
-132
lines changed

.github/workflows/test.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: test
44
on: ["push", "pull_request"]
55

66
env:
7-
GO_VERSION: "1.20"
7+
GO_VERSION: "1.22"
88
LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le"
99

1010
jobs:
@@ -37,11 +37,9 @@ jobs:
3737
- uses: actions/checkout@v4
3838

3939
- name: Install test binaries
40-
env:
41-
GO111MODULE: off
4240
run: |
43-
go get github.com/modocache/gover
44-
go get github.com/mattn/goveralls
41+
go install github.com/modocache/gover@latest
42+
go install github.com/mattn/goveralls@latest
4543
4644
- name: test
4745
run: PATH=$PATH:$(go env GOPATH)/bin COVERALLS=1 make check
@@ -53,3 +51,11 @@ jobs:
5351
PATH=$PATH:$(go env GOPATH)/bin
5452
gover
5553
goveralls -coverprofile=gover.coverprofile -service=github
54+
55+
lint:
56+
name: Run golangci-lint
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: actions/setup-go@v5
61+
- run: make lint

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/build
12
/_output/
23
*.o
34
*.orig
45
ocicnitool
56
*.coverprofile
7+
*.test

.golangci.yml

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
---
2+
run:
3+
concurrency: 6
4+
deadline: 10m
5+
linters:
6+
disable-all: true
7+
enable:
8+
- asasalint
9+
- asciicheck
10+
- bidichk
11+
- bodyclose
12+
- containedctx
13+
- contextcheck
14+
- decorder
15+
- dogsled
16+
- dupl
17+
- dupword
18+
- durationcheck
19+
- errcheck
20+
- errchkjson
21+
- errname
22+
- errorlint
23+
- execinquery
24+
- exhaustive
25+
- exportloopref
26+
- forbidigo
27+
- forcetypeassert
28+
- gocheckcompilerdirectives
29+
- gochecknoinits
30+
- gochecksumtype
31+
- goconst
32+
- gocritic
33+
- gocyclo
34+
- godox
35+
- gofmt
36+
- gofumpt
37+
- goheader
38+
- goimports
39+
- gomoddirectives
40+
- gomodguard
41+
- goprintffuncname
42+
- gosimple
43+
- gosmopolitan
44+
- govet
45+
- grouper
46+
- importas
47+
- inamedparam
48+
- ineffassign
49+
- interfacebloat
50+
- logrlint
51+
- maintidx
52+
- makezero
53+
- mirror
54+
- misspell
55+
- musttag
56+
- nakedret
57+
- nilerr
58+
- nilnil
59+
- noctx
60+
- nolintlint
61+
- nosprintfhostport
62+
- paralleltest
63+
- perfsprint
64+
- prealloc
65+
- predeclared
66+
- promlinter
67+
- protogetter
68+
- reassign
69+
- rowserrcheck
70+
- sloglint
71+
- spancheck
72+
- sqlclosecheck
73+
- staticcheck
74+
- stylecheck
75+
- tagalign
76+
- tenv
77+
- testableexamples
78+
- testifylint
79+
- thelper
80+
- tparallel
81+
- typecheck
82+
- unconvert
83+
- unparam
84+
- unused
85+
- usestdlibvars
86+
- wastedassign
87+
- whitespace
88+
- zerologlint
89+
# - cyclop
90+
# - depguard
91+
# - exhaustruct
92+
# - funlen
93+
# - gci
94+
# - ginkgolinter
95+
# - gochecknoglobals
96+
# - gocognit
97+
# - godot
98+
# - goerr113
99+
# - gomnd
100+
# - gosec
101+
# - ireturn
102+
# - lll
103+
# - nestif
104+
# - nlreturn
105+
# - nonamedreturns
106+
# - revive
107+
# - tagliatelle
108+
# - testpackage
109+
# - varnamelen
110+
# - wrapcheck
111+
# - wsl
112+
linters-settings:
113+
gocritic:
114+
enabled-checks:
115+
- appendAssign
116+
- appendCombine
117+
- argOrder
118+
- assignOp
119+
- badCall
120+
- badCond
121+
- badLock
122+
- badRegexp
123+
- badSorting
124+
- badSyncOnceFunc
125+
- boolExprSimplify
126+
- builtinShadow
127+
- builtinShadowDecl
128+
- captLocal
129+
- caseOrder
130+
- codegenComment
131+
- commentFormatting
132+
- commentedOutCode
133+
- commentedOutImport
134+
- defaultCaseOrder
135+
- deferInLoop
136+
- deferUnlambda
137+
- deprecatedComment
138+
- docStub
139+
- dupArg
140+
- dupBranchBody
141+
- dupCase
142+
- dupImport
143+
- dupSubExpr
144+
- dynamicFmtString
145+
- elseif
146+
- emptyDecl
147+
- emptyFallthrough
148+
- emptyStringTest
149+
- equalFold
150+
- evalOrder
151+
- exitAfterDefer
152+
- exposedSyncMutex
153+
- externalErrorReassign
154+
- filepathJoin
155+
- flagDeref
156+
- flagName
157+
- hexLiteral
158+
- httpNoBody
159+
- hugeParam
160+
- ifElseChain
161+
- importShadow
162+
- indexAlloc
163+
- initClause
164+
- mapKey
165+
- methodExprCall
166+
- nestingReduce
167+
- newDeref
168+
- nilValReturn
169+
- octalLiteral
170+
- offBy1
171+
- paramTypeCombine
172+
- preferDecodeRune
173+
- preferFilepathJoin
174+
- preferFprint
175+
- preferStringWriter
176+
- preferWriteByte
177+
- ptrToRefParam
178+
- rangeExprCopy
179+
- rangeValCopy
180+
- redundantSprint
181+
- regexpMust
182+
- regexpPattern
183+
- regexpSimplify
184+
- returnAfterHttpError
185+
- ruleguard
186+
- singleCaseSwitch
187+
- sliceClear
188+
- sloppyLen
189+
- sloppyReassign
190+
- sloppyTypeAssert
191+
- sortSlice
192+
- sprintfQuotedString
193+
- sqlQuery
194+
- stringConcatSimplify
195+
- stringXbytes
196+
- stringsCompare
197+
- switchTrue
198+
- syncMapLoadAndDelete
199+
- timeExprSimplify
200+
- todoCommentWithoutDetail
201+
- tooManyResultsChecker
202+
- truncateCmp
203+
- typeAssertChain
204+
- typeDefFirst
205+
- typeSwitchVar
206+
- typeUnparen
207+
- uncheckedInlineErr
208+
- underef
209+
- unlabelStmt
210+
- unlambda
211+
- unnamedResult
212+
- unnecessaryBlock
213+
- unnecessaryDefer
214+
- unslice
215+
- valSwap
216+
- weakCond
217+
- whyNoLint
218+
- wrapperFunc
219+
- yodaStyleExpr

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export GO111MODULE=off
2-
31
GO ?= go
42
EPOCH_TEST_COMMIT ?= b0fc980
53
PROJECT := github.com/cri-o/ocicni
@@ -16,6 +14,10 @@ ETCDIR ?= ${DESTDIR}/etc
1614
GIT_COMMIT := $(shell git rev-parse --short HEAD)
1715
BUILD_INFO := $(shell date +%s)
1816

17+
BUILD_PATH := $(shell pwd)/build
18+
GOLANGCI_LINT := ${BUILD_PATH}/golangci-lint
19+
GOLANGCI_LINT_VERSION := v1.56.2
20+
1921
# If GOPATH not specified, use one in the local directory
2022
ifeq ($(GOPATH),)
2123
export GOPATH := $(CURDIR)/_output
@@ -73,10 +75,20 @@ install.tools: .install.gitvalidation
7375
fi
7476

7577
vendor:
76-
export GO111MODULE=on \
77-
$(GO) mod tidy && \
78-
$(GO) mod vendor && \
79-
$(GO) mod verify
78+
$(GO) mod tidy && \
79+
$(GO) mod vendor && \
80+
$(GO) mod verify
81+
82+
$(GOLANGCI_LINT):
83+
export VERSION=$(GOLANGCI_LINT_VERSION) \
84+
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
85+
BINDIR=${BUILD_PATH} && \
86+
curl -sSfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
87+
88+
lint: ${GOLANGCI_LINT}
89+
${GOLANGCI_LINT} version
90+
${GOLANGCI_LINT} linters
91+
GL_DEBUG=gocritic ${GOLANGCI_LINT} run
8092

8193
.PHONY: \
8294
binaries \
@@ -87,4 +99,5 @@ vendor:
8799
check \
88100
install.tools \
89101
.gitvalidation \
90-
vendor
102+
vendor \
103+
lint

0 commit comments

Comments
 (0)