-
Notifications
You must be signed in to change notification settings - Fork 28
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
Example of how to write a rule with sibling nodes #9
Comments
Hey, you're right, I forgot to add this feature to the documentation, sorry about that. The rule you pointed to is indeed the one example in the repo about it. The idea is that you are allowed to declare local boolean variables, and then you can modify then within whatever matcher you wish. e.g. in your case, you could have However, as I wrote this, I realised you might run into another problem, which is that right now you must specify a top-level matcher, e.g. you can only declare variables after you matched a given node, which is unfortunate. In that case, you couldn't match both a class and a protocol at the top-level. I've filed #10 for that, and I'll look into it pretty soon. If that makes things clearer and you want to send a PR, that would be great 😃 otherwise, I'll add it to the docs before cutting a new version pretty soon. PS: sorry for the delay, for some reason I can't seem to get notifications for this repo. |
No worries about the delay, thanks for the thorough reply. The issue with top-level matchers was what I was seeing, so that makes sense. 👍 |
My use case is I want to warn when a Swift ImportDeclaration with a particular identifier is in a file that also contains a class that conforms to a particular protocol. I'm not sure how to declare that this rule should match an ImportDeclaration and ClassDeclaration that are siblings. I've tried a few things and none of them seem to work (syntax errors). Can you clarify if this is currently possible and maybe provide a small example? I could try to submit a PR with some docs if I got that far.
I see
Add support for sibling patterns through conditional variables
in the changelog and the closest I can find to something about this is this in a rule. It probably doesn't help that I'm not familiar with OCaml either 😄The text was updated successfully, but these errors were encountered: