Skip to content

Commit 3cb50f8

Browse files
committed
upgrade linter and fix linter issues
1 parent 9159df6 commit 3cb50f8

4 files changed

Lines changed: 36 additions & 40 deletions

File tree

.golangci.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
version: "2"
12
run:
2-
timeout: 5m
3+
modules-download-mode: readonly
34

45
linters:
56
enable:
@@ -8,6 +9,7 @@ linters:
89
- bidichk # Checks for dangerous unicode character sequences
910
- containedctx # detects struct contained context.Context field
1011
- contextcheck # check the function whether use a non-inherited context
12+
- copyloopvar # detects places where loop variables are copied
1113
- cyclop # checks function and package cyclomatic complexity
1214
- decorder # check declaration order and count of types, constants, variables and functions
1315
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
@@ -17,18 +19,15 @@ linters:
1719
- errname # Checks that errors are prefixed with the `Err` and error types are suffixed with the `Error`
1820
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
1921
- funlen # Tool for detection of long functions
20-
- gci # controls golang package import order and makes it always deterministic
2122
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid
2223
- gocognit # Computes and checks the cognitive complexity of functions
2324
- gocritic # Provides diagnostics that check for bugs, performance and style issues
2425
- gocyclo # Computes and checks the cyclomatic complexity of functions
2526
- godot # Check if comments end in a period
26-
- gofmt # checks whether code was gofmt-ed
27-
- goimports # Check import statements are formatted according to the 'goimport' command
28-
- gosimple # Linter for Go source code that specializes in simplifying a code
2927
- govet # reports suspicious constructs, such as Printf calls with wrong arguments
3028
- grouper # An analyzer to analyze expression groups
3129
- ineffassign # Detects when assignments to existing variables are not used
30+
- intrange # finds places where for loops could make use of an integer range.
3231
- maintidx # measures the maintainability index of each function
3332
- makezero # Finds slice declarations with non-zero initial length
3433
- mirror # reports wrong mirror patterns of bytes/strings usage
@@ -43,35 +42,38 @@ linters:
4342
- reassign # Checks that package variables are not reassigned
4443
- revive # drop-in replacement of golint
4544
- staticcheck # drop-in replacement of go vet
46-
- stylecheck # Stylecheck is a replacement for golint
4745
- testifylint # Checks usage of github.com/stretchr/testify
4846
- thelper # checks the consistency of test helpers
4947
- tparallel # detects inappropriate usage of t.Parallel()
50-
- typecheck # parses and type-checks Go code
5148
- unconvert # Remove unnecessary type conversions
5249
- unparam # Reports unused function parameters
5350
- unused # Checks Go code for unused constants, variables, functions and types
5451
- 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
5652
- wastedassign # finds wasted assignment statements
5753
- whitespace # detects leading and trailing whitespace
5854
- wrapcheck # Checks that errors returned from external packages are wrapped
5955

60-
linters-settings:
61-
cyclop:
62-
max-complexity: 15
63-
gocritic:
64-
disabled-checks:
65-
- newDeref
66-
govet:
67-
disable:
68-
- unsafeptr
69-
staticcheck:
70-
# TODO SA1019 deprecated usage
71-
checks: [ "all", "-SA1019" ]
56+
settings:
57+
cyclop:
58+
max-complexity: 15
59+
govet:
60+
disable:
61+
- unsafeptr
62+
staticcheck:
63+
checks:
64+
- all
65+
- '-SA1019' # should not use deprecated functions
66+
whitespace:
67+
multi-if: true # Enforces newlines (or comments) after every multi-line if statement
68+
multi-func: true # Enforces newlines (or comments) after every multi-line function signature
69+
exclusions:
70+
rules:
71+
- linters:
72+
- err113
73+
text: do not define dynamic errors
7274

73-
issues:
74-
exclude-rules:
75-
- linters:
76-
- err113
77-
text: "do not define dynamic errors"
75+
formatters:
76+
enable:
77+
- gci # controls golang package import order and makes it always deterministic
78+
- gofmt # checks whether code was gofmt-ed
79+
- goimports # Check import statements are formatted according to the 'goimport' command

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GOLANGCI_VERSION = v1.64.6
1+
GOLANGCI_VERSION = v2.3.0
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}'
@@ -26,4 +26,4 @@ test-coverage-web: test-coverage ## run unit tests and show test coverage in bro
2626
go tool cover -html=.testCoverage
2727

2828
install-linters: ## install all used linters
29-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_VERSION}
29+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_VERSION}

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestAPICounter(t *testing.T) {
1313
t.Parallel()
1414
m := New[string, *int64]()
1515

16-
for i := 0; i < 100; i++ {
16+
for i := range 100 {
1717
s := fmt.Sprintf("/api%d/", i%4)
1818

1919
counter := int64(0)

hashmap_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ func TestGrow(t *testing.T) {
166166
m := New[int, string]()
167167
m.Grow(uintptr(63))
168168

169-
for { // make sure to wait for resize operation to finish
170-
if m.resizing.Load() == 0 {
171-
break
172-
}
169+
for m.resizing.Load() != 0 { // make sure to wait for resize operation to finish
173170
time.Sleep(time.Microsecond * 50)
174171
}
175172

@@ -190,10 +187,7 @@ func TestResize(t *testing.T) {
190187

191188
assert.Equal(t, itemCount, m.Len())
192189

193-
for { // make sure to wait for resize operation to finish
194-
if m.resizing.Load() == 0 {
195-
break
196-
}
190+
for m.resizing.Load() != 0 { // make sure to wait for resize operation to finish
197191
time.Sleep(time.Microsecond * 50)
198192
}
199193

@@ -324,7 +318,7 @@ func TestHashMap_parallel(t *testing.T) {
324318
defer timer.Stop()
325319
InfLoop:
326320
for {
327-
for i := 0; i < maxVal; i++ {
321+
for i := range maxVal {
328322
select {
329323
case <-timer.C:
330324
break InfLoop
@@ -347,7 +341,7 @@ func TestHashMap_parallel(t *testing.T) {
347341
}
348342

349343
// Initial fill.
350-
for i := 0; i < maxVal; i++ {
344+
for i := range maxVal {
351345
m.Set(i, i)
352346
}
353347
t.Run("set_get", func(t *testing.T) {
@@ -383,7 +377,7 @@ func TestHashMap_SetConcurrent(t *testing.T) {
383377
m := New[string, int]()
384378

385379
var wg sync.WaitGroup
386-
for i := 0; i < 100; i++ {
380+
for i := range 100 {
387381
wg.Add(1)
388382

389383
go func(i int) {
@@ -406,7 +400,7 @@ func TestHashMap_SetConcurrent(t *testing.T) {
406400
func TestConcurrentInsertDelete(t *testing.T) {
407401
t.Parallel()
408402

409-
for i := 0; i < 200; i++ {
403+
for range 200 {
410404
el1 := &ListElement[int, int]{
411405
key: 111,
412406
keyHash: 111,

0 commit comments

Comments
 (0)