This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 656
refactor(rome_analyze): add the visitor and queryable trait #2778
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3c334f6
to
8205e83
Compare
Deploying with
|
Latest commit: |
fc4f882
|
Status: | ✅ Deploy successful! |
Preview URL: | https://dbbdb1b0.tools-8rn.pages.dev |
Branch Preview URL: | https://refactor-analyze-visitor.tools-8rn.pages.dev |
8205e83
to
efa4a07
Compare
efa4a07
to
5bb829a
Compare
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
ematipico
reviewed
Jun 28, 2022
|
||
/// Quary type usable bi lint rules to match on specific [AstNode] types | ||
#[derive(Clone)] | ||
pub struct Ast<N>(pub N); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically just a "newtype" struct that wraps an AstNode
type N
to implement Queryable
on it, this is a common pattern in Rust to get around the orphan rule
507c3ee
to
704925e
Compare
xunilrj
approved these changes
Jun 28, 2022
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
5f66f71
to
fc4f882
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
This PR refactors the analysis infrastructure and introduces the concepts of
Visitor
andQueryable
. The general goal of these changes is to let the analyzer support not just the linting use case, but also provide the infrastructure for all kind of analysis we may need to perform on top of the syntax tree to support formatting, compiling and various IDE features.Visitor
is the main new building block for the analyzer: in fact the analyzer is nothing more than an executor running a collection of visitors over a given syntax tree. All visitors are executed simultaneously and receiveWalkEvent
as the syntax tree is traversed, and may use the opportunity to mutate their own state, as well as mutably access the sharedVisitorContext
object.This context holds a reference to the
RuleRegistry
through which the visitors may dispatchQueryMatch
objects to trigger the rules associated with a certainQueryable
type: for instancerome_analyze
defines aSyntaxVisitor
that dispatches anAst<T>
query match for each node it enters, which is the query type used by all currently existing lint rules as they all currently work on AST nodes.The PR also introduces a new
merge_node_visitors
macro that creates a single struct implementingVisitor
over a collection of type implementing theNodeVisitor
helper trait. Unlike the globalVisitor
, node visitors are transient: they get instantiated when the traversal enters the corresponding node and destroyed when the node is exited. They are intended as a building blocks for creating and managing the state of complex visitors by allowing the implementation to be split over multiple smaller components.Test Plan
TODO: Despite being more open-ended the components of this infrastructure are still tied together quite tightly, and this doesn't really allow writing tests for individual components. It should be possible to improve this by at least decoupling the emission of query matches by the visitors from the execution of rules matching on these queries