lostcancel

Imports

Imports #

_ "embed"
"fmt"
"go/ast"
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/ctrlflow"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/go/cfg"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

contextPackage var #

var contextPackage = "context"

debug const #

const debug = false

doc var #

go:embed doc.go

var doc string

Functions

isCall function #

func isCall(n ast.Node) bool

isContextWithCancel function #

isContextWithCancel reports whether n is one of the qualified identifiers context.With{Cancel,Timeout,Deadline}.

func isContextWithCancel(info *types.Info, n ast.Node) bool

lostCancelPath function #

lostCancelPath finds a path through the CFG, from stmt (which defines the 'cancel' variable v) to a return statement, that doesn't "use" v. If it finds one, it returns the return statement (which may be synthetic). sig is the function's type, if known.

func lostCancelPath(pass *analysis.Pass, g *cfg.CFG, v *types.Var, stmt ast.Node, sig *types.Signature) *ast.ReturnStmt

run function #

checkLostCancel reports a failure to the call the cancel function returned by context.WithCancel, either because the variable was assigned to the blank identifier, or because there exists a control-flow path from the call to a return statement and that path does not "use" the cancel function. Any reference to the variable counts as a use, even within a nested function literal. If the variable's scope is larger than the function containing the assignment, we assume that other uses exist. checkLostCancel analyzes a single named or literal function.

func run(pass *analysis.Pass) (interface{}, error)

runFunc function #

func runFunc(pass *analysis.Pass, node ast.Node)

tupleContains function #

func tupleContains(tuple *types.Tuple, v *types.Var) bool

Generated with Arrow