Skip to content

Commit 59e00f4

Browse files
committed
upgrade linter and fix linter issues
1 parent 930a240 commit 59e00f4

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

.golangci.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
11
run:
2-
deadline: 5m
2+
timeout: 5m
33

44
linters:
55
enable:
66
- asasalint # check for pass []any as any in variadic func(...any)
77
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
88
- bidichk # Checks for dangerous unicode character sequences
99
- containedctx # detects struct contained context.Context field
10-
- contextcheck # check the function whether to use a non-inherited context
10+
- contextcheck # check the function whether use a non-inherited context
1111
- cyclop # checks function and package cyclomatic complexity
1212
- decorder # check declaration order and count of types, constants, variables and functions
1313
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
1414
- durationcheck # check for two durations multiplied together
15+
- err113 # Golang linter to check the errors handling expressions
1516
- errcheck # checking for unchecked errors
1617
- errname # Checks that errors are prefixed with the `Err` and error types are suffixed with the `Error`
1718
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
18-
- exportloopref # checks for pointers to enclosing loop variables
1919
- funlen # Tool for detection of long functions
2020
- gci # controls golang package import order and makes it always deterministic
21+
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid
2122
- gocognit # Computes and checks the cognitive complexity of functions
2223
- gocritic # Provides diagnostics that check for bugs, performance and style issues
2324
- gocyclo # Computes and checks the cyclomatic complexity of functions
2425
- godot # Check if comments end in a period
25-
- goerr113 # Golang linter to check the errors handling expressions
2626
- gofmt # checks whether code was gofmt-ed
27+
- goimports # Check import statements are formatted according to the 'goimport' command
2728
- gosimple # Linter for Go source code that specializes in simplifying a code
2829
- govet # reports suspicious constructs, such as Printf calls with wrong arguments
30+
- grouper # An analyzer to analyze expression groups
2931
- ineffassign # Detects when assignments to existing variables are not used
3032
- maintidx # measures the maintainability index of each function
3133
- makezero # Finds slice declarations with non-zero initial length
34+
- mirror # reports wrong mirror patterns of bytes/strings usage
3235
- misspell # Finds commonly misspelled English words in comments
3336
- nakedret # Finds naked returns in functions
3437
- nestif # Reports deeply nested if statements
3538
- nilerr # Finds the code that returns nil even if it checks that the error is not nil
3639
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value
37-
- prealloc # Finds slice declarations that could potentially be pre-allocated
40+
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative
41+
- prealloc # Finds slice declarations that could potentially be preallocated
3842
- predeclared # find code that shadows one of Go's predeclared identifiers
43+
- reassign # Checks that package variables are not reassigned
3944
- revive # drop-in replacement of golint
4045
- staticcheck # drop-in replacement of go vet
41-
- stylecheck # replacement for golint
42-
- tenv # detects using os.Setenv instead of t.Setenv
46+
- stylecheck # Stylecheck is a replacement for golint
47+
- testifylint # Checks usage of github.com/stretchr/testify
4348
- thelper # checks the consistency of test helpers
4449
- tparallel # detects inappropriate usage of t.Parallel()
4550
- typecheck # parses and type-checks Go code
4651
- unconvert # Remove unnecessary type conversions
4752
- unparam # Reports unused function parameters
4853
- unused # Checks Go code for unused constants, variables, functions and types
4954
- usestdlibvars # detect the possibility to use variables/constants from the Go standard library
55+
- usetesting # Reports uses of functions with replacement inside the testing package
5056
- wastedassign # finds wasted assignment statements
5157
- whitespace # detects leading and trailing whitespace
58+
- wrapcheck # Checks that errors returned from external packages are wrapped
5259

5360
linters-settings:
5461
cyclop:
@@ -59,10 +66,12 @@ linters-settings:
5966
govet:
6067
disable:
6168
- unsafeptr
69+
staticcheck:
70+
# TODO SA1019 deprecated usage
71+
checks: [ "all", "-SA1019" ]
6272

6373
issues:
64-
exclude-use-default: false
6574
exclude-rules:
6675
- linters:
67-
- goerr113
76+
- err113
6877
text: "do not define dynamic errors"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GOLANGCI_VERSION = v1.53.3
1+
GOLANGCI_VERSION = v1.64.6
22

33
help: ## show help, shown by default if no target is specified
44
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

assert/assert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func fail(t *testing.T, message string, errorMessage ...string) {
3333
if len(errorMessage) != 0 {
3434
message = fmt.Sprintf("%s\n%s", message, errorMessage)
3535
}
36-
t.Errorf(message)
36+
t.Error(message)
3737
t.FailNow()
3838
}
3939

hashmap_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hashmap
22

33
import (
4+
"errors"
45
"fmt"
56
"math"
67
"math/rand"
@@ -298,10 +299,10 @@ func TestRange(t *testing.T) {
298299
func TestHashMap_parallel(t *testing.T) {
299300
m := New[int, int]()
300301

301-
max := 10
302+
maxVal := 10
302303
dur := 2 * time.Second
303304

304-
do := func(t *testing.T, max int, d time.Duration, fn func(*testing.T, int)) <-chan error {
305+
do := func(t *testing.T, maxVal int, d time.Duration, fn func(*testing.T, int)) <-chan error {
305306
t.Helper()
306307
done := make(chan error)
307308
var times int64
@@ -311,7 +312,7 @@ func TestHashMap_parallel(t *testing.T) {
311312
select {
312313
case <-time.After(d + 500*time.Millisecond):
313314
if atomic.LoadInt64(&times) == 0 {
314-
done <- fmt.Errorf("closure was not executed even once, something blocks it")
315+
done <- errors.New("closure was not executed even once, something blocks it")
315316
}
316317
close(done)
317318
case <-done:
@@ -323,7 +324,7 @@ func TestHashMap_parallel(t *testing.T) {
323324
defer timer.Stop()
324325
InfLoop:
325326
for {
326-
for i := 0; i < max; i++ {
327+
for i := 0; i < maxVal; i++ {
327328
select {
328329
case <-timer.C:
329330
break InfLoop
@@ -346,15 +347,15 @@ func TestHashMap_parallel(t *testing.T) {
346347
}
347348

348349
// Initial fill.
349-
for i := 0; i < max; i++ {
350+
for i := 0; i < maxVal; i++ {
350351
m.Set(i, i)
351352
}
352353
t.Run("set_get", func(t *testing.T) {
353-
doneSet := do(t, max, dur, func(t *testing.T, i int) {
354+
doneSet := do(t, maxVal, dur, func(t *testing.T, i int) {
354355
t.Helper()
355356
m.Set(i, i)
356357
})
357-
doneGet := do(t, max, dur, func(t *testing.T, i int) {
358+
doneGet := do(t, maxVal, dur, func(t *testing.T, i int) {
358359
t.Helper()
359360
if _, ok := m.Get(i); !ok {
360361
t.Errorf("missing value for key: %d", i)
@@ -364,11 +365,11 @@ func TestHashMap_parallel(t *testing.T) {
364365
wait(t, doneGet)
365366
})
366367
t.Run("get-or-insert-and-delete", func(t *testing.T) {
367-
doneGetOrInsert := do(t, max, dur, func(t *testing.T, i int) {
368+
doneGetOrInsert := do(t, maxVal, dur, func(t *testing.T, i int) {
368369
t.Helper()
369370
m.GetOrInsert(i, i)
370371
})
371-
doneDel := do(t, max, dur, func(t *testing.T, i int) {
372+
doneDel := do(t, maxVal, dur, func(t *testing.T, i int) {
372373
t.Helper()
373374
m.Del(i)
374375
})

util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestLog2(t *testing.T) {
2525
func TestHashCollision(t *testing.T) {
2626
m := New[string, int]()
2727

28-
staticHasher := func(key string) uintptr {
28+
staticHasher := func(_ string) uintptr {
2929
return 4 // chosen by fair dice roll. guaranteed to be random.
3030
}
3131

0 commit comments

Comments
 (0)