Skip to content

Commit 4920416

Browse files
author
jgheewala
committed
enabling linters that were suppose to be enabled with --enable-all flag
fixing build breakage too by adding a bigger box & migrating testing on go1.17.3
1 parent baa19c9 commit 4920416

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+479
-238
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ jobs:
33
build:
44
working_directory: ~/repo
55
docker:
6-
- image: circleci/golang:1.17.2
6+
- image: circleci/golang:1.17.3
7+
resource_class: xlarge # to avoid sfxclient timeouts lets use a bigger box
78
steps:
89
- checkout
910
- restore_cache:
@@ -20,7 +21,7 @@ jobs:
2021
name: Run tests
2122
command: |
2223
set -x
23-
go test -covermode atomic -race -timeout 120s -parallel 4 -coverprofile ./coverage.out $(go list ./...)
24+
go test -covermode atomic -race -timeout 120s -coverprofile ./coverage.out $(go list ./...)
2425
cov="$(go tool cover -func coverage.out | grep -v 100.0% || true)"
2526
echo $cov
2627
test -z "$cov"

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: golangci-lint
1717
uses: golangci/golangci-lint-action@v2
1818
with:
19-
version: v1.41.1
19+
version: v1.42.1
2020
# Optional: golangci-lint command line arguments.
2121
args: '--config=.golangci.yml -v'
2222

.golangci.yml

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
run:
2-
timeout: 2m
2+
timeout: 5m
33
tests: true
44
skip-dirs:
5+
- src/external_libs
6+
- gocat
57
- genfiles$
68
- vendor$
9+
- ketama
710
# which files to skip: they will be analyzed, but issues from them
811
# won't be reported. Default value is empty list, but there is
912
# no need to include all autogenerated files, we confidently recognize
@@ -91,33 +94,131 @@ linters-settings:
9194
funlen:
9295
lines: 500 # TODO: need to set this to 150 statements and work on it
9396
statements: 150
97+
ifshort:
98+
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
99+
# Has higher priority than max-decl-chars.
100+
max-decl-lines: 1
101+
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
102+
max-decl-chars: 30
103+
cyclop:
104+
# the maximal code complexity to report
105+
max-complexity: 15
106+
# should ignore tests (default false)
107+
skip-tests: false
108+
gosec:
109+
# To select a subset of rules to run.
110+
# Available rules: https://github.com/securego/gosec#available-rules
111+
includes:
112+
- G101 # Look for hard coded credentials
113+
- G102 # Bind to all interfaces
114+
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
115+
- G107 # Url provided to HTTP request as taint input
116+
- G108 # Profiling endpoint automatically exposed on /debug/pprof
117+
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
118+
- G110 # Potential DoS vulnerability via decompression bomb
119+
- G306 # Poor file permissions used when writing to a new file
120+
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
121+
- G501 # Import blocklist: crypto/md5
122+
- G502 # Import blocklist: crypto/des
123+
- G503 # Import blocklist: crypto/rc4
124+
- G504 # Import blocklist: net/http/cgi
125+
- G505 # Import blocklist: crypto/sha1
126+
- G601 # Implicit memory aliasing of items from a range statement
127+
# To specify a set of rules to explicitly exclude.
128+
# Available rules: https://github.com/securego/gosec#available-rules
129+
excludes:
130+
- G204 # Audit use of command execution
131+
# To specify the configuration of rules.
132+
# The configuration of rules is not fully documented by gosec:
133+
# https://github.com/securego/gosec#configuration
134+
# https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102
135+
config:
136+
G306: "0600"
137+
G101:
138+
pattern: "(?i)pwd|password|private_key|secret"
139+
ignore_entropy: false
140+
entropy_threshold: "80.0"
141+
per_char_threshold: "3.0"
142+
truncate: "32"
143+
staticcheck:
144+
# Select the Go version to target. The default is '1.13'.
145+
go: "1.17"
146+
# https://staticcheck.io/docs/options#checks
147+
checks: [ "all" ]
148+
dupl:
149+
# tokens count to trigger issue, 150 by default
150+
threshold: 100
94151

95152
linters:
153+
enable: # please use alphabetical order when enabling any linters
154+
- asciicheck
155+
- bodyclose
156+
- cyclop
157+
- deadcode
158+
- depguard
159+
- dupl
160+
- durationcheck
161+
- errorlint
162+
- errname
163+
- exportloopref
164+
- forbidigo
165+
- forcetypeassert
166+
- gci
167+
- gocognit
168+
- goconst
169+
- gocyclo
170+
- godox
171+
- gofmt
172+
- gofumpt
173+
- goheader
174+
- goimports
175+
- gomodguard
176+
- goprintffuncname
177+
- gosec
178+
- gosimple
179+
- govet
180+
- ifshort
181+
- ineffassign
182+
- makezero
183+
- megacheck
184+
- misspell
185+
- nakedret
186+
- nilerr
187+
- noctx
188+
- prealloc
189+
- predeclared
190+
- revive
191+
- staticcheck
192+
- structcheck
193+
- stylecheck
194+
- testpackage
195+
- thelper
196+
- tparallel
197+
- typecheck
198+
- unconvert
199+
- unparam
200+
- unused
201+
- wastedassign
202+
- whitespace
96203
enable-all: true
97204
disable:
98-
- ifshort
99-
- forcetypeassert
100-
# need to enable linters above this line
101205
- lll
102-
- gochecknoinits
103206
- paralleltest # this has lots of test cases that needs to be added as parallel and some of them have race condition so disabling after some effort
104207
- gochecknoglobals
105-
- errcheck
106-
- unparam
107-
- interfacer
108-
- dupl
109-
- exhaustive # not urgent this currently as its complaining mainly about switch statements in sharecache
208+
- exhaustive
110209
# TODO: need to enable this two low priority for better coding guidelines in terms of space between condition
111-
- whitespace
112210
- wsl
113211
- godot
114-
- gomnd
115-
- nestif
212+
- gomnd # we cannot enable this as there are lots of magic numbers
213+
- nestif # cannot enable this given the way the code structure is organized for unit testing
116214
- nlreturn
117215
- nolintlint
118216
- tagliatelle # cannot be enabled as it's asking to modify `json` which is not possible
119217
- promlinter # we do not care above prometheus linter for metrics
120218
- gomoddirectives # needs to be disabled as we need replacement for jaeger & redis
219+
- scopelint # deprecated and hence disabled it
220+
- interfacer # deprecated and hence disabled
221+
- wrapcheck # Checks that errors returned from external packages are wrapped
121222
fast: true
122223

123224
# output configuration options

datapoint/cast_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func TestCastMetricValueWithBool(t *testing.T) {
159159
}
160160
}
161161

162+
//nolint:dupl
162163
func TestCastFloatValue(t *testing.T) {
163164
type args struct {
164165
value interface{}
@@ -192,6 +193,7 @@ func TestCastFloatValue(t *testing.T) {
192193
}
193194
}
194195

196+
//nolint:dupl
195197
func TestCastUIntegerValue(t *testing.T) {
196198
type args struct {
197199
value interface{}
@@ -225,6 +227,7 @@ func TestCastUIntegerValue(t *testing.T) {
225227
}
226228
}
227229

230+
//nolint:dupl
228231
func TestCastIntegerValue(t *testing.T) {
229232
type args struct {
230233
value interface{}

datapoint/dpsink/counter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dpsink
22

33
import (
44
"context"
5+
goerrors "errors"
56
"sync/atomic"
67
"time"
78

@@ -67,6 +68,7 @@ func (c *Counter) logErrMsg(ctx context.Context, err error, msg string) {
6768
}
6869

6970
// AddDatapoints will send points to the next sink and track points send to the next sink
71+
//nolint:dupl
7072
func (c *Counter) AddDatapoints(ctx context.Context, points []*datapoint.Datapoint, next Sink) error {
7173
atomic.AddInt64(&c.TotalDatapoints, int64(len(points)))
7274
atomic.AddInt64(&c.TotalProcessCalls, 1)
@@ -91,6 +93,7 @@ func (c *Counter) logger() log.Logger {
9193
}
9294

9395
// AddEvents will send events to the next sink and track events sent to the next sink
96+
//nolint:dupl
9497
func (c *Counter) AddEvents(ctx context.Context, events []*event.Event, next Sink) error {
9598
atomic.AddInt64(&c.TotalEvents, int64(len(events)))
9699
atomic.AddInt64(&c.TotalProcessCalls, 1)
@@ -108,6 +111,7 @@ func (c *Counter) AddEvents(ctx context.Context, events []*event.Event, next Sin
108111
}
109112

110113
// AddSpans will send spans to the next sink and track spans sent to the next sink
114+
//nolint:dupl
111115
func (c *Counter) AddSpans(ctx context.Context, spans []*trace.Span, next trace.Sink) error {
112116
atomic.AddInt64(&c.TotalSpans, int64(len(spans)))
113117
atomic.AddInt64(&c.TotalProcessCalls, 1)
@@ -118,7 +122,8 @@ func (c *Counter) AddSpans(ctx context.Context, spans []*trace.Span, next trace.
118122
atomic.AddInt64(&c.CallsInFlight, -1)
119123
if err != nil && spanfilter.IsInvalid(err) {
120124
atomic.AddInt64(&c.TotalProcessErrors, 1)
121-
if m, ok := err.(*spanfilter.Map); ok {
125+
var m *spanfilter.Map
126+
if goerrors.As(err, &m) {
122127
atomic.AddInt64(&c.ProcessErrorSpans, int64(len(m.Invalid)))
123128
} else {
124129
atomic.AddInt64(&c.ProcessErrorSpans, int64(len(spans)))

datapoint/dptest/basicsink_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func TestContextErrorTrace(t *testing.T) {
8787
<-progressChan
8888
}
8989

90+
//nolint:dupl
9091
func TestNext(t *testing.T) {
9192
ctx := context.Background()
9293
b := NewBasicSink()
@@ -105,6 +106,7 @@ func TestNext(t *testing.T) {
105106
})
106107
}
107108

109+
//nolint:dupl
108110
func TestNextEvent(t *testing.T) {
109111
ctx := context.Background()
110112
b := NewBasicSink()
@@ -123,6 +125,7 @@ func TestNextEvent(t *testing.T) {
123125
})
124126
}
125127

128+
//nolint:dupl
126129
func TestNextSpan(t *testing.T) {
127130
ctx := context.Background()
128131
b := NewBasicSink()

datapoint/dptest/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type DatapointSource struct {
2525

2626
var globalSource DatapointSource
2727

28+
//nolint:gochecknoinits
2829
func init() {
2930
globalSource.Metric = "random"
3031
globalSource.Dims = map[string]string{"source": "randtest"}

0 commit comments

Comments
 (0)