Skip to content

Commit 479fdcd

Browse files
committed
chore: add forbidigo lint rules for modern Go test patterns
Add golangci-lint rules to enforce: - Using t.TempDir() instead of os.MkdirTemp in tests - Using t.Context() instead of context.Background()/TODO() in tests - No print statements in test code Assisted-By: cagent
1 parent 31ac13e commit 479fdcd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ linters:
33
default: none
44
enable:
55
- errcheck
6+
- forbidigo
67
- gocyclo
78
- govet
89
- ineffassign
@@ -16,6 +17,12 @@ linters:
1617
- unparam
1718
- unused
1819
settings:
20+
forbidigo:
21+
forbid:
22+
- pattern: '^os\.MkdirTemp$'
23+
msg: "use t.TempDir() instead"
24+
- pattern: '^context\.(Background|TODO)$'
25+
msg: "use t.Context() instead"
1926
gocritic:
2027
disabled-checks:
2128
- dupArg
@@ -44,6 +51,12 @@ linters:
4451
- builtin$
4552
- examples$
4653
- vendor$
54+
rules:
55+
# Scope test-specific forbidigo rules to test files only
56+
- path-except: '_test\.go$'
57+
linters:
58+
- forbidigo
59+
text: 'use t\.'
4760
formatters:
4861
enable:
4962
- gofumpt

0 commit comments

Comments
 (0)