ruleguard,dsl: add Var.Node filters #124
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add the ability to assert the submatch node AST type.
A new
Var.Node.Is()
function accepts the type name string,like
Ident
(ast.Ident),Expr
(ast.Expr) and so on.For any unexpected arguments the rule compilation will fail.
We may add more node categories that are not declared in
go/ast
package for our convenience.Rationale: sometimes we need to check not only the types,
but also the "shape" of the match. For example, we may want
to enforce some func arguments to be literal strings.
Right now we can only do this by doing a regexp check
that may look like
<broken markdown>
but that's not reliable, nor efficient.What we can do is to add a negated
*ast.BasicLit
constraint,optionally with a type check if func signature accepts
interface{}
.Note that
m["s"].Const
is not identical here. It would acceptconst expressions like
"a" + "b"
as well.Not to be confused with an actual type. It's just a
syntactical check whether a matched node belongs to some
syntax category as defined by the
go/ast
package.Signed-off-by: Iskander Sharipov [email protected]