How to check for metavariable equality between mutiple patterns? #431
Replies: 1 comment 1 reply
-
Hi! Thanks for your continuous interest in ast-grep! I'm glad to see advanced usage of the tool! Multi Meta Variable currently is not checked currently, sadly. :( The main reason is that it is not clear to compare two sequences of nodes. For single meta variables like That said, for the specific lint rule, we can use safely use If we target this syntax, we can combine single meta var, rule:
all:
- pattern: pub use $B::$C;
- inside:
kind: source_file
has:
pattern: pub mod $A;
- has:
pattern: $A
stopBy: end |
Beta Was this translation helpful? Give feedback.
-
I am trying to write a automatic linting rule for this:
My plan was to find
foo
inpub use foo::Foo;
and check ifpub mod foo;
exists in the same file.Playground: https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InJ1c3QiLCJxdWVyeSI6IiIsImNvbmZpZyI6InJ1bGU6XG4gIGFsbDpcbiAgICAgLSBwYXR0ZXJuOiBwdWIgdXNlICQkJEE6OiRDO1xuICAgICAtIGluc2lkZTpcbiAgICAgICAgYWxsOlxuICAgICAgICAgIC0ga2luZDogc291cmNlX2ZpbGVcbiAgICAgICAgICAtIGhhczpcbiAgICAgICAgICAgICAgcGF0dGVybjogcHViIG1vZCAkJCRBOyIsInNvdXJjZSI6InB1YiBtb2QgZm9vO1xucHViIHVzZSBmb286OkZvbztcblxuXG5cbnB1YiBtb2QgZm9vO1xuXG5wdWIgdXNlIGFhYTo6QTtcblxuXG5cbnB1YiB1c2Ugd29vOjpXb287In0=
But I see that
$$$A
in both patterns are matched separately.How to go about this then?
Beta Was this translation helpful? Give feedback.
All reactions