Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sub-match support #28

Closed
quasilyte opened this issue Dec 26, 2019 · 1 comment · Fixed by #363
Closed

Add sub-match support #28

quasilyte opened this issue Dec 26, 2019 · 1 comment · Fixed by #363
Labels
DSL May require DSL changes

Comments

@quasilyte
Copy link
Owner

quasilyte commented Dec 26, 2019

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`)
@quasilyte quasilyte added the DSL May require DSL changes label Jan 10, 2020
@quasilyte
Copy link
Owner Author

quasilyte/gogrep#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DSL May require DSL changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant