Skip to content

Commit d447a97

Browse files
committed
Add Taskfile, fix lint errors, update to Go 1.24
- Added Taskfile.yml with test, lint, fmt, ci tasks - Fixed package comment (revive) - Fixed unused parameter warnings in tests - Updated go.mod to Go 1.24 - All linters passing, 100% test coverage
1 parent 7f98fae commit d447a97

File tree

5 files changed

+215
-48
lines changed

5 files changed

+215
-48
lines changed

.golangci.yml

Lines changed: 119 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,124 @@
1-
linters:
2-
enable-all: true
3-
disable:
4-
# Deprecated linters
5-
- exhaustivestruct
6-
- golint
7-
- ifshort
8-
- interfacer
9-
- maligned
10-
- scopelint
11-
- nosnakecase
12-
- structcheck
13-
- varcheck
14-
- deadcode
15-
16-
# Not needed for library
17-
- gochecknoglobals
18-
- gomnd
19-
- mnd
20-
- wrapcheck
21-
- exhaustruct
22-
- ireturn
23-
- varnamelen
24-
25-
linters-settings:
26-
lll:
27-
line-length: 120
28-
funlen:
29-
lines: 100
30-
statements: 50
31-
gocognit:
32-
min-complexity: 15
33-
cyclop:
34-
max-complexity: 15
1+
# golangci-lint configuration
2+
# v2.5.0-ready: explicit, stable linter set + v2 formatters
353

36-
issues:
37-
exclude-rules:
38-
# Allow long lines in tests
39-
- path: _test\.go
40-
linters:
41-
- lll
42-
- funlen
43-
- gocognit
44-
- cyclop
4+
version: "2"
455

466
run:
477
timeout: 5m
488
tests: true
9+
10+
# Formatters live here in v2 (not in linters.enable)
11+
formatters:
12+
enable:
13+
- gofumpt
14+
- gofmt
15+
- goimports
16+
settings:
17+
goimports:
18+
local-prefixes:
19+
- github.com/ndbroadbent/db_cutover_orchestrator
20+
gofumpt:
21+
extra-rules: true
22+
module-path: github.com/ndbroadbent/db_cutover_orchestrator
23+
24+
linters:
25+
default: none
26+
enable:
27+
# Core analysis (default enabled linters)
28+
- govet
29+
- staticcheck
30+
- errcheck
31+
- ineffassign
32+
- unused
33+
34+
# Error handling
35+
- nilerr
36+
- forcetypeassert
37+
38+
# Code quality
39+
- revive
40+
- gocritic
41+
42+
# Bugs/correctness
43+
- bodyclose
44+
- contextcheck
45+
- copyloopvar # v2 replacement for exportloopref
46+
- noctx
47+
48+
# Performance
49+
- prealloc
50+
51+
# Complexity
52+
- funlen
53+
- gocognit
54+
- gocyclo
55+
56+
# Security / policy
57+
- gosec
58+
- forbidigo
59+
- depguard
60+
61+
# Style
62+
- lll
63+
64+
exclusions:
65+
rules:
66+
# Allow longer test functions and some duplication in tests
67+
- path: _test\.go
68+
linters:
69+
- funlen
70+
- dupl
71+
- forbidigo
72+
- gosec
73+
- gocognit
74+
# Allow fmt.Print* in CLI commands (legitimate stdout output)
75+
- path: internal/cmd/
76+
linters:
77+
- forbidigo
78+
# Allow file operations in config and state packages
79+
- path: internal/(config|state)/
80+
text: "G304.*file inclusion"
81+
linters:
82+
- gosec
83+
84+
settings:
85+
lll:
86+
line-length: 120
87+
tab-width: 1
88+
89+
funlen:
90+
lines: 100
91+
statements: 50
92+
93+
gocognit:
94+
min-complexity: 15
95+
96+
gocyclo:
97+
min-complexity: 15
98+
99+
forbidigo:
100+
forbid:
101+
- pattern: '^fmt\.Print.*'
102+
msg: "use proper logging instead of fmt.Print"
103+
- pattern: "^panic"
104+
msg: "use error returns instead of panic"
105+
- pattern: '^time\.Sleep'
106+
msg: "use context with timeout instead of time.Sleep"
107+
exclude-godoc-examples: true
108+
analyze-types: true
109+
110+
depguard:
111+
rules:
112+
main:
113+
list-mode: lax
114+
files: [$all]
115+
allow:
116+
- $gostd
117+
- github.com/ndbroadbent/db_cutover_orchestrator
118+
deny:
119+
- pkg: io/ioutil$
120+
desc: "use io or os instead"
121+
122+
issues:
123+
max-issues-per-linter: 0
124+
max-same-issues: 0

Taskfile.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
version: "3"
2+
3+
tasks:
4+
default:
5+
desc: Show available tasks
6+
cmds:
7+
- task --list
8+
9+
test:
10+
desc: Run tests
11+
cmds:
12+
- go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
13+
14+
test:verbose:
15+
desc: Run tests with verbose output
16+
cmds:
17+
- go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
18+
19+
test:coverage:
20+
desc: Run tests with coverage report
21+
deps: [test]
22+
cmds:
23+
- go tool cover -html=coverage.out -o coverage.html
24+
- open coverage.html || xdg-open coverage.html || true
25+
26+
coverage:
27+
desc: Check test coverage percentage (requires 100%)
28+
deps: [test]
29+
cmds:
30+
- |
31+
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
32+
echo "Coverage: $coverage%"
33+
if (( $(echo "$coverage < 100" | bc -l) )); then
34+
echo "Error: Coverage is below 100%"
35+
exit 1
36+
fi
37+
38+
lint:config:
39+
desc: Verify golangci-lint configuration
40+
cmds:
41+
- golangci-lint config verify
42+
43+
lint:
44+
desc: Run linters
45+
deps: [lint:config]
46+
cmds:
47+
- golangci-lint run ./...
48+
49+
lint:fix:
50+
desc: Run linters with auto-fix
51+
deps: [lint:config]
52+
cmds:
53+
- golangci-lint run --fix ./...
54+
55+
fmt:
56+
desc: Format code
57+
cmds:
58+
- gofumpt -l -w .
59+
- goimports -local github.com/DocSpring/orderedmap -w .
60+
61+
ci:
62+
desc: Run all CI checks
63+
cmds:
64+
- task: lint
65+
- task: test
66+
- task: coverage
67+
68+
mod:tidy:
69+
desc: Tidy go modules
70+
cmds:
71+
- go mod tidy
72+
73+
mod:download:
74+
desc: Download go modules
75+
cmds:
76+
- go mod download
77+
78+
clean:
79+
desc: Clean build artifacts
80+
cmds:
81+
- rm -f coverage.out coverage.html
82+
83+
install:tools:
84+
desc: Install development tools
85+
cmds:
86+
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
87+
- go install mvdan.cc/gofumpt@latest
88+
- go install golang.org/x/tools/cmd/goimports@latest

go.mod

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

3-
go 1.21
3+
go 1.24

orderedmap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package orderedmap provides a thread-safe, generic ordered map that maintains insertion order
2+
// while providing O(1) lookups. Unlike Go's built-in map, OrderedMap iterates in the order items
3+
// were added, preventing UI flickering and enabling predictable, deterministic behavior.
14
package orderedmap
25

36
import "sync"

orderedmap_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestOrderedMap_Range_Empty(t *testing.T) {
237237
om := NewOrderedMap[string, int]()
238238

239239
called := false
240-
om.Range(func(k string, v int) {
240+
om.Range(func(_ string, _ int) {
241241
called = true
242242
})
243243

@@ -278,7 +278,7 @@ func TestOrderedMap_RangeBreak(t *testing.T) {
278278

279279
var keys []string
280280

281-
om.RangeBreak(func(k string, v int) bool {
281+
om.RangeBreak(func(k string, _ int) bool {
282282
keys = append(keys, k)
283283
return k != "second" // Stop after second
284284
})
@@ -304,7 +304,7 @@ func TestOrderedMap_RangeBreak_NoBreak(t *testing.T) {
304304

305305
var keys []string
306306

307-
om.RangeBreak(func(k string, v int) bool {
307+
om.RangeBreak(func(k string, _ int) bool {
308308
keys = append(keys, k)
309309
return true // Never break
310310
})
@@ -554,7 +554,7 @@ func TestOrderedMap_Concurrent_RangeWhileModifying(t *testing.T) {
554554
defer wg.Done()
555555
for i := 0; i < 10; i++ {
556556
sum := 0
557-
om.Range(func(k, v int) {
557+
om.Range(func(_, v int) {
558558
sum += v
559559
})
560560
}

0 commit comments

Comments
 (0)