MCPcopy Index your code
hub / github.com/coder/coder / run

Function run

scripts/intxcheck/analyzer.go:43–96  ·  view source on GitHub ↗
(pass *analysis.Pass)

Source from the content-addressed store, hash-verified

41}
42
43func run(pass *analysis.Pass) (any, error) {
44 decls := make(map[types.Object]*ast.FuncDecl)
45 for _, file := range pass.Files {
46 for _, decl := range file.Decls {
47 funcDecl, ok := decl.(*ast.FuncDecl)
48 if !ok {
49 continue
50 }
51 obj := pass.TypesInfo.Defs[funcDecl.Name]
52 if obj == nil {
53 continue
54 }
55 decls[obj] = funcDecl
56 }
57 }
58
59 for _, file := range pass.Files {
60 suppressed := suppressedLines(pass.Fset, file)
61 ast.Inspect(file, func(n ast.Node) bool {
62 call, ok := n.(*ast.CallExpr)
63 if !ok {
64 return true
65 }
66
67 inTxSelector, ok := unparen(call.Fun).(*ast.SelectorExpr)
68 if !ok || inTxSelector.Sel.Name != "InTx" {
69 return true
70 }
71 if len(call.Args) == 0 {
72 return true
73 }
74
75 funcLit, ok := unparen(call.Args[0]).(*ast.FuncLit)
76 if !ok {
77 return true
78 }
79
80 outerStore, ok := newOuterStoreMatcher(pass, inTxSelector.X)
81 if !ok {
82 return true
83 }
84
85 ctx := txContext{
86 outerStore: outerStore,
87 txName: firstParamName(funcLit.Type),
88 }
89
90 inspectInTxBody(pass, funcLit.Body, ctx, decls, suppressed)
91 return true
92 })
93 }
94
95 return (*struct{})(nil), nil
96}
97
98func inspectInTxBody(pass *analysis.Pass, body *ast.BlockStmt, ctx txContext, decls map[types.Object]*ast.FuncDecl, suppressed map[int]bool) {
99 ctx = ctx.withAliases(pass, body)

Callers

nothing calls this directly

Calls 5

suppressedLinesFunction · 0.85
unparenFunction · 0.85
newOuterStoreMatcherFunction · 0.85
firstParamNameFunction · 0.85
inspectInTxBodyFunction · 0.85

Tested by

no test coverage detected