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
WIP: react-hooks/exhaustive-deps #2637
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #2637 will not alter performanceComparing Summary
|
@Boshen pushed my latest code. Currently stuck by 2 things:
|
I think I need a completely different approach here. Instead I should iterate over all identifier references and traverse the tree upwards to detect whether I'm in a hook or not. This should remove most of traversal boilerplate I wrote |
This rule is pretty complicated, let's see whether @rzvxa can help. Feel free to ask questions. |
Hey mate, First off thanks for this impressive work. I was reading through the code when I got an idea that might make it easier to implement, Have you tried to create a custom visitor instead of using the If you add something like this: #[derive(Default)]
struct DependencyCollector<'a> {
deps: DependencyList<'a>,
}
impl<'a> Visit<'a> for DependencyCollector<'a> {
fn visit_identifier_reference(&mut self, ident: &IdentifierReference<'a>) {
self.deps.insert(/* dependency */);
}
/* .... */
} and use it like this: DependencyCollector::default().visit_statements(&body_expr.statements); instead of calling the I think it can result in what you want from visiting every identifier, I'm not sure which one is more performant though, Since one skips redundant checks but requires additional visits and the other one has a lot of redundant checks and no additional visit. |
Given the scope_id of the But we have to check Maybe it can be easier if you go for checking the |
How would this approach be different from: ctx.semantic().nodes().iter().for_each(|node| {
let AstKind::IdentifierReference(iref) = node.kind() else { return };
// do stuff
}) Will the visitor visit nodes that the iter above would not? |
I know there are some types missing from If there is nothing important missing in the Just to point out, We recently found out some types are missing a visit event in our Visit trait, So you can see even core stuff can be wrong when written by humans(since the visitor pattern is tedious and has a lot of boilerplate code). But feel free to use either one of these approaches since they should perform the same. |
I gotta be honest with you - I don't know Rust much and this may be too much for me. But I decided at least I can move things forwarding by creating the scaffolding and porting the tests
Related to #2174