-
Notifications
You must be signed in to change notification settings - Fork 7
/
noctx.go
36 lines (29 loc) · 763 Bytes
/
noctx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package noctx
import (
"fmt"
"github.com/sonatard/noctx/ngfunc"
"github.com/sonatard/noctx/reqwithoutctx"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/buildssa"
)
var Analyzer = &analysis.Analyzer{
Name: "noctx",
Doc: Doc,
Run: run,
RunDespiteErrors: false,
Requires: []*analysis.Analyzer{
buildssa.Analyzer,
},
ResultType: nil,
FactTypes: nil,
}
const Doc = "noctx finds sending http request without context.Context"
func run(pass *analysis.Pass) (interface{}, error) {
if _, err := ngfunc.Run(pass); err != nil {
return nil, fmt.Errorf("run: %w", err)
}
if _, err := reqwithoutctx.Run(pass); err != nil {
return nil, fmt.Errorf("run: %w", err)
}
return nil, nil
}