Skip to content

Commit eec3a81

Browse files
authored
Merge pull request #100 from tstromberg/lint
Run 'lint-install', Address golangci-lint errors
2 parents 8550bae + acc8351 commit eec3a81

File tree

7 files changed

+258
-451
lines changed

7 files changed

+258
-451
lines changed

.github/workflows/ci-non-go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if ! shfmt -f . | xargs shfmt -s -l -d; then
1818
failed=1
1919
fi
2020

21-
if ! shfmt -f . | xargs shellcheck; then
21+
if ! make lint; then
2222
failed=1
2323
fi
2424

.golangci.yml

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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: error-naming
53+
- name: error-return
54+
- name: error-strings
55+
- name: errorf
56+
- name: exported
57+
- name: identical-branches
58+
- name: if-return
59+
- name: import-shadowing
60+
- name: increment-decrement
61+
- name: indent-error-flow
62+
- name: indent-error-flow
63+
- name: package-comments
64+
- name: range
65+
- name: receiver-naming
66+
- name: redefines-builtin-id
67+
- name: superfluous-else
68+
- name: struct-tag
69+
- name: time-naming
70+
- name: unexported-naming
71+
- name: unexported-return
72+
- name: unnecessary-stmt
73+
- name: unreachable-code
74+
- name: unused-parameter
75+
- name: var-declaration
76+
- name: var-naming
77+
- name: unconditional-recursion
78+
- name: waitgroup-by-value
79+
80+
staticcheck:
81+
go: "1.16"
82+
83+
unused:
84+
go: "1.16"
85+
86+
output:
87+
sort-results: true
88+
89+
linters:
90+
disable-all: true
91+
enable:
92+
- asciicheck
93+
- bodyclose
94+
- cyclop
95+
- deadcode
96+
- dogsled
97+
- dupl
98+
- durationcheck
99+
- errcheck
100+
# errname is only available in golangci-lint v1.42.0+ - wait until v1.43 is available to settle
101+
#- errname
102+
- errorlint
103+
- exhaustive
104+
- exportloopref
105+
- forcetypeassert
106+
- gocognit
107+
- goconst
108+
- gocritic
109+
- godot
110+
- gofmt
111+
- goheader
112+
- goimports
113+
- goprintffuncname
114+
- gosimple
115+
- govet
116+
- ifshort
117+
- importas
118+
- ineffassign
119+
- makezero
120+
- misspell
121+
- nakedret
122+
- nestif
123+
- nilerr
124+
- noctx
125+
- nolintlint
126+
- predeclared
127+
# disabling for the initial iteration of the linting tool
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+
# Disabled linters, due to not being relevant to our code base:
158+
# - maligned
159+
# - prealloc "For most programs usage of prealloc will be a premature optimization."
160+
# Disabled linters due to bad error messages or bugs
161+
# - gofumpt
162+
# - gosec
163+
# - tagliatelle
164+
165+
issues:
166+
# Excluding configuration per-path, per-linter, per-text and per-source
167+
exclude-rules:
168+
- path: _test\.go
169+
linters:
170+
- gocyclo
171+
- errcheck
172+
- dupl
173+
- gosec
174+
175+
- path: cmd.*
176+
linters:
177+
- noctx
178+
179+
- path: main\.go
180+
linters:
181+
- noctx
182+
183+
- path: cmd.*
184+
text: "deep-exit"
185+
186+
- path: main\.go
187+
text: "deep-exit"
188+
189+
# This check is of questionable value
190+
- linters:
191+
- tparallel
192+
text: "call t.Parallel on the top level as well as its subtests"
193+
194+
# Don't hide lint issues just because there are many of them
195+
max-same-issues: 0
196+
max-issues-per-linter: 0

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# BEGIN: lint-install ../sandbox
3+
# http://github.com/tinkerbell/lint-install
4+
5+
GOLINT_VERSION ?= v1.42.0
6+
7+
SHELLCHECK_VERSION ?= v0.7.2
8+
LINT_OS := $(shell uname)
9+
LINT_ARCH := $(shell uname -m)
10+
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
11+
12+
# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
13+
ifeq ($(LINT_OS),Darwin)
14+
ifeq ($(LINT_ARCH),arm64)
15+
LINT_ARCH=x86_64
16+
endif
17+
endif
18+
19+
LINT_LOWER_OS = $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]')
20+
GOLINT_CONFIG:=$(LINT_ROOT)/.golangci.yml
21+
22+
lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)
23+
find . -name go.mod | xargs -n1 dirname | xargs -n1 -I{} sh -c "cd {} && $(LINT_ROOT)/out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) run -c $(GOLINT_CONFIG)"
24+
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck $(shell find . -name "*.sh")
25+
26+
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck:
27+
mkdir -p out/linters
28+
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_LOWER_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
29+
mv out/linters/shellcheck-$(SHELLCHECK_VERSION) out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)
30+
31+
out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH):
32+
mkdir -p out/linters
33+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
34+
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)
35+
36+
# END: lint-install ../sandbox

releases/cmd/bump-version/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,4 @@ func getImageTagFromRepo(repoName string) (string, error) {
151151
}
152152

153153
return tag, nil
154-
155154
}

releases/go.mod

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ module github.com/tinkerbell/sandbox
33
go 1.15
44

55
require (
6+
github.com/containerd/containerd v1.4.1 // indirect
67
github.com/containers/image v3.0.2+incompatible
78
github.com/containers/image/v5 v5.10.5
8-
github.com/gianarb/vagrant-go v0.0.0-20200902133321-62ba563fe383
9+
github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible // indirect
910
github.com/go-git/go-git/v5 v5.2.0
11+
github.com/golang/protobuf v1.4.2 // indirect
12+
github.com/google/go-cmp v0.5.2 // indirect
1013
github.com/joho/godotenv v1.3.0
1114
github.com/pkg/errors v0.9.1
12-
github.com/tinkerbell/tink v0.0.0-20210315140655-1b178daeaeda
15+
github.com/prometheus/client_golang v1.3.0 // indirect
16+
go.opencensus.io v0.22.2 // indirect
17+
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
18+
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
19+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
20+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
21+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
22+
google.golang.org/genproto v0.0.0-20201026171402-d4b8fe4fd877 // indirect
23+
google.golang.org/grpc v1.32.0 // indirect
24+
google.golang.org/protobuf v1.25.0 // indirect
1325
)

0 commit comments

Comments
 (0)