Skip to content

Commit 2b597d2

Browse files
authored
Introduce GoLang CI lint, and fix some of the violations found (stackrox/rox#5965)
1 parent 29df65d commit 2b597d2

14 files changed

Lines changed: 415 additions & 25 deletions

File tree

‎.golangci.yml‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
run:
2+
timeout: 2m
3+
4+
linters-settings:
5+
gocritic:
6+
enabled-tags:
7+
- diagnostic
8+
- experimental
9+
- opinionated
10+
- performance
11+
- style
12+
disabled-checks:
13+
- dupImport # https://github.com/go-critic/go-critic/issues/845
14+
- commentFormatting
15+
- octalLiteral
16+
- unnamedResult
17+
- unnecessaryDefer
18+
- importShadow
19+
- emptyStringTest
20+
nolintlint:
21+
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
22+
allow-unused: false # report any unused nolint directives
23+
require-explanation: false # don't require an explanation for nolint directives
24+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
25+
26+
linters:
27+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
28+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
29+
disable-all: true
30+
enable:
31+
- asciicheck
32+
# - bodyclose
33+
# - deadcode
34+
# - depguard
35+
# - dogsled
36+
# - dupl
37+
# - errcheck
38+
# - funlen
39+
# - gochecknoglobals
40+
# - gochecknoinits
41+
# - gocognit
42+
# - goconst
43+
- exportloopref
44+
# - gocritic TODO: add in follow-up
45+
# - gocyclo
46+
# - godot
47+
# - godox
48+
# - goerr113
49+
# - gofmt TODO: see if we can migrate our gofmt to this
50+
# - goimports TODO: see if we can migrate our goimports to this
51+
# - golint TODO: see if we can migrate our golint to this
52+
# - gomnd
53+
# - goprintffuncname
54+
# - gosec
55+
- gosimple
56+
# - govet TODO: see if we can migrate our govet to this
57+
- ineffassign
58+
# - interfacer
59+
# - lll
60+
# - maligned
61+
# - misspell
62+
# - nakedret TODO: add in follow-up
63+
# - nestif
64+
- nolintlint
65+
# - prealloc
66+
- rowserrcheck
67+
# - scopelint
68+
# - staticcheck
69+
# - structcheck
70+
# - stylecheck
71+
# - testpackage
72+
# - typecheck
73+
# - unconvert TODO: add in follow-up
74+
# - unparam TODO: add in follow-up
75+
# - unused
76+
# - varcheck
77+
# - whitespace
78+
# - wsl

‎Makefile‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ all: deps style test image
4040
###### Binaries we depend on (need to be defined on top) ############
4141
#####################################################################
4242

43+
GOLANGCILINT_BIN := $(GOPATH)/bin/golangci-lint
44+
$(GOLANGCILINT_BIN): deps
45+
@echo "+ $@"
46+
go install github.com/golangci/golangci-lint/cmd/golangci-lint
47+
4348
EASYJSON_BIN := $(GOPATH)/bin/easyjson
4449
$(EASYJSON_BIN): deps
4550
@echo "+ $@"
@@ -105,7 +110,7 @@ $(PROTOLOCK_BIN): deps
105110
## Style ##
106111
###########
107112
.PHONY: style
108-
style: fmt imports lint vet roxvet blanks validateimports no-large-files storage-protos-compatible ui-lint qa-tests-style
113+
style: fmt imports lint vet roxvet blanks validateimports golangci-lint no-large-files storage-protos-compatible ui-lint qa-tests-style
109114

110115
# staticcheck is useful, but extremely computationally intensive on some people's machines.
111116
# Therefore, to allow people to continue running `make style`, staticcheck is not run along with
@@ -121,6 +126,11 @@ ifdef RUN_STATIC_CHECK
121126
style: staticcheck
122127
endif
123128

129+
.PHONY: golangci-lint
130+
golangci-lint: $(GOLANGCILINT_BIN)
131+
@echo "+ $@"
132+
golangci-lint run
133+
124134
.PHONY: qa-tests-style
125135
qa-tests-style:
126136
@echo "+ $@"

‎central/processwhitelist/evaluator/evaluator_impl.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,5 @@ func (e *evaluator) EvaluateWhitelistsAndPersistResult(deployment *storage.Deplo
132132
return nil, errors.Wrap(err, "failed to persist whitelist results")
133133
}
134134
}
135-
return
135+
return violatingProcesses, nil
136136
}

‎go.mod‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
3939
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
4040
github.com/golang/mock v1.3.1
4141
github.com/golang/protobuf v1.3.5
42+
github.com/golangci/golangci-lint v1.27.1-0.20200616100528-38d298c2c859
4243
github.com/google/certificate-transparency-go v1.0.21
4344
github.com/googleapis/gnostic v0.2.0
4445
github.com/gorilla/schema v1.1.0
@@ -52,7 +53,7 @@ require (
5253
github.com/heroku/docker-registry-client v0.0.0
5354
github.com/jstemmer/go-junit-report v0.9.1
5455
github.com/machinebox/graphql v0.2.2
55-
github.com/magiconair/properties v1.8.0
56+
github.com/magiconair/properties v1.8.1
5657
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63
5758
github.com/matryer/is v1.3.0 // indirect
5859
github.com/mattn/goveralls v0.0.2
@@ -64,40 +65,40 @@ require (
6465
github.com/openshift/api v3.9.1-0.20191201231411-9f834e337466+incompatible
6566
github.com/openshift/client-go v3.9.0+incompatible
6667
github.com/pkg/errors v0.9.1
67-
github.com/prometheus/client_golang v0.9.2
68+
github.com/prometheus/client_golang v0.9.3
6869
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
6970
github.com/prometheus/common v0.4.1
7071
github.com/russellhaering/gosaml2 v0.3.1
7172
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
7273
github.com/satori/go.uuid v1.2.0
73-
github.com/spf13/cobra v0.0.5
74-
github.com/spf13/pflag v1.0.3
74+
github.com/spf13/cobra v1.0.0
75+
github.com/spf13/pflag v1.0.5
7576
github.com/stackrox/anchore-client v0.0.0-20190929180200-981e05834836
7677
github.com/stackrox/default-authz-plugin v0.0.0-20190708153800-070801f52e6e
7778
github.com/stackrox/k8s-istio-cve-pusher v0.0.0-20191029220117-2a73008e51a9
7879
github.com/stackrox/scanner v0.0.0-20191202203519-a2a15f33f41a
79-
github.com/stretchr/testify v1.5.1
80+
github.com/stretchr/testify v1.6.1
8081
github.com/tecbot/gorocksdb v0.0.0-20190705090504-162552197222
8182
github.com/tkuchiki/go-timezone v0.1.3
8283
github.com/vbauerster/mpb/v4 v4.11.1
8384
go.uber.org/atomic v1.4.0
8485
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
8586
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
86-
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
87+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
8788
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
8889
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
89-
golang.org/x/sys v0.0.0-20200116001909-b77594299b42
90+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
9091
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
91-
golang.org/x/tools v0.0.0-20200306191617-51e69f71924f
92+
golang.org/x/tools v0.0.0-20200519015757-0d0afa43d58a
9293
golang.stackrox.io/grpc-http1 v0.1.0
93-
google.golang.org/api v0.11.0
94-
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
94+
google.golang.org/api v0.13.0
95+
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a
9596
google.golang.org/grpc v1.29.1
9697
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
9798
gopkg.in/square/go-jose.v2 v2.3.1
98-
gopkg.in/yaml.v2 v2.2.8
99+
gopkg.in/yaml.v2 v2.3.0
99100
gotest.tools v2.2.0+incompatible
100-
honnef.co/go/tools v0.0.1-2019.2.3
101+
honnef.co/go/tools v0.0.1-2020.1.4
101102
k8s.io/api v0.0.0-20191114100352-16d7abae0d2a
102103
k8s.io/apimachinery v0.0.0-20191028221656-72ed19daf4bb
103104
k8s.io/apiserver v0.0.0-20191114103151-9ca1dc586682

0 commit comments

Comments
 (0)