diff --git a/.golangci.yml b/.golangci.yml index 48898c457..7d75550fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,6 +8,7 @@ linters: - depguard - errcheck - errorlint + - forbidigo - gocritic - gocyclo - gomodguard @@ -38,6 +39,15 @@ linters: desc: use stdlib slices package - pkg: gopkg.in/yaml.v2 desc: compose-go uses yaml.v3 + forbidigo: + analyze-types: true + forbid: + - pattern: 'context\.Background' + pkg: '^context$' + msg: "in tests, use t.Context() instead of context.Background()" + - pattern: 'context\.TODO' + pkg: '^context$' + msg: "in tests, use t.Context() instead of context.TODO()" gocritic: disabled-checks: - paramTypeCombine @@ -74,6 +84,10 @@ linters: - third_party$ - builtin$ - examples$ + rules: + - path-except: '_test\.go' + linters: + - forbidigo issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/pkg/compose/kill_test.go b/pkg/compose/kill_test.go index a70228a65..f27606b7f 100644 --- a/pkg/compose/kill_test.go +++ b/pkg/compose/kill_test.go @@ -127,6 +127,7 @@ func containerLabels(service string, oneOff bool) map[string]string { } func anyCancellableContext() gomock.Matcher { + //nolint:forbidigo // This creates a context type for gomock matching, not for actual test usage ctxWithCancel, cancel := context.WithCancel(context.Background()) cancel() return gomock.AssignableToTypeOf(ctxWithCancel)