Closed
Description
Some examples where it can be useful:
// check that some function call is not followed by a return.
m.Match(`foo(err); $x`).
Where(!m["x"].Matches(`return err`)).
Report(`foo(err) call not followed by return err`)
// Check that for loop contains expensive() call.
// We can't do `for { $*_; expensive(); $*_ } since it would only
// check that expensive() is called without any extra nesting.
// If call is done inside if statement or inside another block,
// it will not trigger.
m.Match(`for { $x }`).
Where(m["x"].Matches(`expensive()`).
Report(`expensive call inside a loop`)
// we want to check that $y contains $x[0] somewhere
// inside it's AST.
m.Match(`$x == nil && $y`).
Where(m["y"].Matches(`$x[0]`)).
Report(`suspicious $$; nil check may not be enough to access $x[0], check for len`)