You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,21 +7,23 @@ A Go linter that checks goroutine context propagation.
7
7
8
8
## Overview
9
9
10
-
`goroutinectx` detects cases where a `context.Context` is available in function parameters but not properly passed to downstream calls that should receive it.
10
+
`goroutinectx` detects cases where a [`context.Context`](https://pkg.go.dev/context#Context) is available in function parameters but not properly passed to downstream calls that should receive it.
11
11
12
12
## Installation
13
13
14
-
This analyzer is designed to be used as a library with `go/analysis`. To use it, import the analyzer in your own tool:
14
+
This analyzer is designed to be used as a library with [`go/analysis`](https://pkg.go.dev/golang.org/x/tools/go/analysis). To use it, import the analyzer in your own tool:
15
15
16
16
```go
17
17
import"github.com/mpyw/goroutinectx"
18
18
19
19
funcmain() {
20
-
singlechecker.Main(goroutinectx.Analyzer)
20
+
singlechecker.Main(goroutinectx.Analyzer)// singlechecker from go/analysis
21
21
}
22
22
```
23
23
24
-
Or use it with `multichecker` alongside other analyzers.
24
+
See [`singlechecker`](https://pkg.go.dev/golang.org/x/tools/go/analysis/singlechecker) for details.
25
+
26
+
Or use it with [`multichecker`](https://pkg.go.dev/golang.org/x/tools/go/analysis/multichecker) alongside other analyzers.
This design ensures every goroutine explicitly acknowledges context propagation. If your goroutine doesn't need to use context directly but spawns nested goroutines that do, add `_ = ctx` to signal intentional propagation.
Treat additional types as context carriers (like `context.Context`). Useful for web frameworks that have their own context types.
223
+
Treat additional types as context carriers (like [`context.Context`](https://pkg.go.dev/context#Context)). Useful for web frameworks that have their own context types.
222
224
223
225
```bash
224
226
# Treat echo.Context as a context carrier
@@ -272,12 +274,12 @@ Also warns about unnecessary labels on functions that don't spawn and have no fu
272
274
## Design Principles
273
275
274
276
1.**Zero false positives** - Prefer missing issues over false alarms
275
-
2.**Type-safe analysis** - Uses `go/types` for accurate detection
277
+
2.**Type-safe analysis** - Uses [`go/types`](https://pkg.go.dev/go/types) for accurate detection
276
278
3.**Nested function support** - Correctly tracks context through closures
277
279
278
280
## Related Tools
279
281
280
-
-[contextcheck](https://github.com/kkHAIKE/contextcheck) - Detects `context.Background()`/`context.TODO()` usage and missing context parameters
282
+
-[contextcheck](https://github.com/kkHAIKE/contextcheck) - Detects [`context.Background`](https://pkg.go.dev/context#Background)/[`context.TODO`](https://pkg.go.dev/context#TODO) usage and missing context parameters
281
283
282
284
`goroutinectx` is complementary to `contextcheck`:
283
285
-`contextcheck` warns about creating new contexts when one should be propagated
0 commit comments