Skip to content

Commit 3ff549e

Browse files
committed
Upgraded go min version to 1.23, linter, workflow last 2 go versions
1 parent 9b7d49d commit 3ff549e

13 files changed

Lines changed: 82 additions & 87 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
timeout-minutes: 10
1414
strategy:
1515
matrix:
16-
go-version: [1.21.x, 1.22.x]
16+
go-version: [1.23.x, 1.24.x]
1717
platform: [ubuntu-latest, macos-latest, windows-latest]
1818
runs-on: ${{ matrix.platform }}
1919

@@ -50,4 +50,3 @@ jobs:
5050
file: cover.out
5151
flag-name: ${{ runner.os }}-go-${{ matrix.go-version }}
5252
fail-on-error: false
53-

.golangci-lint.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.golangci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: "2"
2+
3+
run:
4+
tests: true
5+
6+
linters:
7+
default: none
8+
enable:
9+
- goconst
10+
- gocritic
11+
- godot
12+
- govet
13+
- ineffassign
14+
- intrange
15+
- misspell
16+
- nlreturn
17+
- noctx
18+
- revive
19+
- staticcheck
20+
- unused
21+
- whitespace
22+
23+
formatters:
24+
enable:
25+
- gofmt
26+
settings:
27+
gofmt:
28+
rewrite-rules:
29+
- pattern: 'interface{}'
30+
replacement: 'any'
31+
- pattern: 'a[b:len(a)]'
32+
replacement: 'a[b:]'
33+
- pattern: 'a[0:b]'
34+
replacement: 'a[:b]'

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LINTER_VERSION=v1.57.1
1+
LINTER_VERSION=v2.1.6
22
LINTER=./bin/golangci-lint
33
ifeq ($(OS),Windows_NT)
44
LINTER=./bin/golangci-lint.exe
@@ -10,7 +10,7 @@ all: clean setup lint test ## Run sequentially clean, setup, lint and test.
1010

1111
.PHONY: lint
1212
lint: ## Run linter and detect go mod tidy changes.
13-
$(LINTER) run -c ./.golangci-lint.yml --fix
13+
$(LINTER) run -c ./.golangci.yml --fix
1414
@make tidy
1515
@if ! git diff --quiet; then \
1616
echo "'go mod tidy' resulted in changes or working tree is dirty:"; \

assert_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// assertEqual checks if 2 values are equal.
1616
// Returns successful assertion status.
17-
func assertEqual(t *testing.T, expected interface{}, actual interface{}) bool {
17+
func assertEqual(t *testing.T, expected, actual any) bool {
1818
t.Helper()
1919
if !reflect.DeepEqual(expected, actual) {
2020
t.Errorf(
@@ -32,7 +32,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) bool {
3232

3333
// assertNotNil checks if value passed is not nil.
3434
// Returns successful assertion status.
35-
func assertNotNil(t *testing.T, actual interface{}) bool {
35+
func assertNotNil(t *testing.T, actual any) bool {
3636
t.Helper()
3737
if isNil(actual) {
3838
t.Error("should not be nil")
@@ -45,7 +45,7 @@ func assertNotNil(t *testing.T, actual interface{}) bool {
4545

4646
// assertNil checks if value passed is nil.
4747
// Returns successful assertion status.
48-
func assertNil(t *testing.T, actual interface{}) bool {
48+
func assertNil(t *testing.T, actual any) bool {
4949
t.Helper()
5050
if !isNil(actual) {
5151
t.Errorf("expected nil, but got %+v", actual)
@@ -70,7 +70,7 @@ func assertTrue(t *testing.T, actual bool) bool {
7070
}
7171

7272
// isNil checks an interface if it is nil.
73-
func isNil(object interface{}) bool {
73+
func isNil(object any) bool {
7474
if object == nil {
7575
return true
7676
}

cmd/pprof/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func setUpTmpCsvFile(rowsCount int64) (string, error) {
9393
fName := f.Name()
9494

9595
var id int64
96-
var buf = make([]byte, 0, 1280)
96+
buf := make([]byte, 0, 1280)
9797
bufLenConst := 4 + 2 + 1 + len(colValueNamePrefix) + len(colValueDescription) + len(colValuePrice) + len(colValueStock) // 4 x comma, 2 x quote, 1 x \n,
9898
for id = 1; id <= rowsCount; id++ {
9999
buf = buf[0:0:1280]
@@ -110,7 +110,7 @@ func setUpTmpCsvFile(rowsCount int64) (string, error) {
110110
buf = append(buf, colValueStock...)
111111
buf = append(buf, "\n"...)
112112
bufLen := bufLenConst + 2*len(idStr)
113-
_, err := f.Write(buf[0:bufLen])
113+
_, err := f.Write(buf[:bufLen])
114114
if err != nil {
115115
_ = f.Close()
116116
tearDownTmpCsvFile(fName)
@@ -205,7 +205,7 @@ func consumeBigCsvReaderResults(rowsChans []bigcsvreader.RowsChan, errsChan bigc
205205
wg sync.WaitGroup
206206
)
207207

208-
for i := 0; i < len(rowsChans); i++ {
208+
for i := range rowsChans {
209209
wg.Add(1)
210210
go func(rowsChan bigcsvreader.RowsChan, waitGr *sync.WaitGroup) {
211211
var localCount int64

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func ExampleCsvReader() {
4848

4949
// process rows and errors:
5050

51-
for i := 0; i < len(rowsChans); i++ {
51+
for i := range rowsChans {
5252
wg.Add(1)
5353
go rowWorker(rowsChans[i], &wg)
5454
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/actforgood/bigcsvreader
22

3-
go 1.16
3+
go 1.23

internal/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ComputeGoroutineOffsets(totalBytes, maxGoroutines, minBytesReadByAGoroutine
3838
bytesPerGoroutine := totalBytes / totalGoroutines
3939
distribution := make([][2]int, totalGoroutines)
4040
start, end := 0, bytesPerGoroutine-1
41-
for goroutineNo := 0; goroutineNo < totalGoroutines-1; goroutineNo++ {
41+
for goroutineNo := range totalGoroutines - 1 {
4242
distribution[goroutineNo] = [2]int{start, end}
4343
start = end + 1
4444
end += bytesPerGoroutine

internal/helper_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,40 +117,39 @@ func TestComputeGoroutineOffsets(t *testing.T) {
117117
}
118118

119119
for _, testData := range tests {
120-
test := testData // capture range variable
121-
t.Run(test.name, func(t *testing.T) {
120+
t.Run(testData.name, func(t *testing.T) {
122121
// act
123122
result := internal.ComputeGoroutineOffsets(
124-
test.inputTotalBytes,
125-
test.inputMaxGoroutines,
126-
test.inputMinBytesReadByAGoroutine,
123+
testData.inputTotalBytes,
124+
testData.inputMaxGoroutines,
125+
testData.inputMinBytesReadByAGoroutine,
127126
)
128127

129128
// assert
130-
if !reflect.DeepEqual(result, test.expectedResult) {
131-
t.Errorf("expected %v, but got %v | %s", test.expectedResult, result, test.name)
129+
if !reflect.DeepEqual(result, testData.expectedResult) {
130+
t.Errorf("expected %v, but got %v | %s", testData.expectedResult, result, testData.name)
132131
}
133132
})
134133
}
135134
}
136135

137136
func BenchmarkComputeGoroutineOffsets_1(b *testing.B) {
138137
b.ReportAllocs()
139-
for n := 0; n < b.N; n++ {
138+
for range b.N {
140139
_ = internal.ComputeGoroutineOffsets(1024, 32, 1)
141140
}
142141
}
143142

144143
func BenchmarkComputeGoroutineOffsets_2(b *testing.B) {
145144
b.ReportAllocs()
146-
for n := 0; n < b.N; n++ {
145+
for range b.N {
147146
_ = internal.ComputeGoroutineOffsets(1024, 32, 1025)
148147
}
149148
}
150149

151150
func BenchmarkComputeGoroutineOffsets_3(b *testing.B) {
152151
b.ReportAllocs()
153-
for n := 0; n < b.N; n++ {
152+
for range b.N {
154153
_ = internal.ComputeGoroutineOffsets(1024, 32, 1023)
155154
}
156155
}

0 commit comments

Comments
 (0)