Skip to content

Commit b01299e

Browse files
authored
Merge pull request #73 from tinkerbell/ohlint
Add 'make lint' rule to run golangci-lint, shellcheck, hadolint
2 parents 6538653 + aa53ffc commit b01299e

File tree

2 files changed

+224
-0
lines changed

2 files changed

+224
-0
lines changed

.golangci.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
2+
linters-settings:
3+
cyclop:
4+
# NOTE: This is a very high transitional threshold
5+
max-complexity: 37
6+
package-average: 34.0
7+
skip-tests: true
8+
9+
gocognit:
10+
# NOTE: This is a very high transitional threshold
11+
min-complexity: 98
12+
13+
dupl:
14+
threshold: 200
15+
16+
goconst:
17+
min-len: 4
18+
min-occurrences: 5
19+
ignore-tests: true
20+
21+
errorlint:
22+
# these are still common in Go: for instance, exit errors.
23+
asserts: false
24+
25+
exhaustive:
26+
default-signifies-exhaustive: true
27+
28+
nestif:
29+
min-complexity: 8
30+
31+
nolintlint:
32+
require-explanation: true
33+
allow-unused: false
34+
require-specific: true
35+
36+
revive:
37+
ignore-generated-header: true
38+
severity: warning
39+
rules:
40+
- name: atomic
41+
- name: blank-imports
42+
- name: bool-literal-in-expr
43+
- name: confusing-naming
44+
- name: constant-logical-expr
45+
- name: context-as-argument
46+
- name: context-keys-type
47+
- name: deep-exit
48+
- name: defer
49+
- name: range-val-in-closure
50+
- name: range-val-address
51+
- name: dot-imports
52+
- name: empty-block
53+
- name: error-naming
54+
- name: error-return
55+
- name: error-strings
56+
- name: errorf
57+
- name: exported
58+
- name: identical-branches
59+
- name: if-return
60+
- name: import-shadowing
61+
- name: increment-decrement
62+
- name: indent-error-flow
63+
- name: indent-error-flow
64+
- name: package-comments
65+
- name: range
66+
- name: receiver-naming
67+
- name: redefines-builtin-id
68+
- name: superfluous-else
69+
- name: struct-tag
70+
- name: time-naming
71+
- name: unexported-naming
72+
- name: unexported-return
73+
- name: unnecessary-stmt
74+
- name: unreachable-code
75+
- name: unused-parameter
76+
- name: var-declaration
77+
- name: var-naming
78+
- name: unconditional-recursion
79+
- name: waitgroup-by-value
80+
81+
staticcheck:
82+
go: "1.16"
83+
84+
unused:
85+
go: "1.16"
86+
87+
output:
88+
sort-results: true
89+
90+
linters:
91+
disable-all: true
92+
enable:
93+
- asciicheck
94+
- bodyclose
95+
- cyclop
96+
- deadcode
97+
- dogsled
98+
- dupl
99+
- durationcheck
100+
- errcheck
101+
# errname is only available in golangci-lint v1.42.0+ - wait until v1.43 is available to settle
102+
#- errname
103+
- errorlint
104+
- exhaustive
105+
- exportloopref
106+
- forcetypeassert
107+
- gocognit
108+
- goconst
109+
- gocritic
110+
- godot
111+
- gofmt
112+
- goheader
113+
- goimports
114+
- goprintffuncname
115+
- gosimple
116+
- govet
117+
- ifshort
118+
- importas
119+
- ineffassign
120+
- makezero
121+
- misspell
122+
- nakedret
123+
- nestif
124+
- nilerr
125+
- noctx
126+
- nolintlint
127+
- predeclared
128+
- promlinter
129+
- revive
130+
- rowserrcheck
131+
- sqlclosecheck
132+
- staticcheck
133+
- structcheck
134+
- stylecheck
135+
- thelper
136+
- tparallel
137+
- typecheck
138+
- unconvert
139+
- unparam
140+
- unused
141+
- varcheck
142+
- wastedassign
143+
- whitespace
144+
145+
# Disabled linters, due to being misaligned with Go practices
146+
# - exhaustivestruct
147+
# - gochecknoglobals
148+
# - gochecknoinits
149+
# - goconst
150+
# - godox
151+
# - goerr113
152+
# - gomnd
153+
# - lll
154+
# - nlreturn
155+
# - testpackage
156+
# - wsl
157+
158+
# Disabled linters, due to not being relevant to our code base:
159+
# - maligned
160+
# - prealloc "For most programs usage of prealloc will be a premature optimization."
161+
162+
# Disabled linters due to bad error messages or bugs
163+
# - gofumpt
164+
# - gosec
165+
# - tagliatelle
166+
167+
168+
issues:
169+
# Excluding configuration per-path, per-linter, per-text and per-source
170+
exclude-rules:
171+
- path: _test\.go
172+
linters:
173+
- gocyclo
174+
- errcheck
175+
- dupl
176+
- gosec
177+
178+
- path: cmd.*
179+
linters:
180+
- noctx
181+
182+
- path: main\.go
183+
linters:
184+
- noctx
185+
186+
# This check is of questionable value
187+
- linters:
188+
- tparallel
189+
text: "call t.Parallel on the top level as well as its subtests"
190+
191+
# Don't hide lint issues just because there are many of them
192+
max-same-issues: 0
193+
max-issues-per-linter: 0

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,34 @@ endif
115115
clean:
116116
rm ./hook-${GIT_VERSION}.tar.gz
117117
rm -rf dist/ out/ tink-docker/local/ bootkit/local/
118+
119+
# BEGIN: lint-install ../hook
120+
121+
GOLINT_VERSION ?= v1.42.0
122+
HADOLINT_VERSION ?= v2.6.1
123+
SHELLCHECK_VERSION ?= v0.7.2
124+
LINT_OS := $(shell uname)
125+
LINT_LOWER_OS = $(shell echo $OS | tr '[:upper:]' '[:lower:]')
126+
LINT_ARCH := $(shell uname -m)
127+
GOLINT_CONFIG:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/.golangci.yml
128+
129+
lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck out/linters/hadolint-$(HADOLINT_VERSION) out/linters/golangci-lint-$(GOLINT_VERSION)
130+
find . -name go.mod | xargs -n1 dirname | xargs -n1 -I{} sh -c "cd {} && golangci-lint run -c $(GOLINT_CONFIG)"
131+
out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck $(shell find . -name "*.sh")
132+
out/linters/hadolint-$(HADOLINT_VERSION) $(shell find . -name "*Dockerfile")
133+
134+
out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck:
135+
mkdir -p out/linters
136+
curl -sfL https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-$(SHELLCHECK_VERSION).$(LINT_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
137+
138+
out/linters/hadolint-$(HADOLINT_VERSION):
139+
mkdir -p out/linters
140+
curl -sfL https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-$(LINT_OS)-$(LINT_ARCH) > out/linters/hadolint-$(HADOLINT_VERSION)
141+
chmod u+x out/linters/hadolint-$(HADOLINT_VERSION)
142+
143+
out/linters/golangci-lint-$(GOLINT_VERSION):
144+
mkdir -p out/linters
145+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
146+
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)
147+
148+
# END: lint-install ../hook

0 commit comments

Comments
 (0)