question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: defer rule listener calls until after traversal is complete

See original GitHub issue

For a long time, rules have had a slight usability issue where the parent property of a node is only present after a node is traversed and its listeners have been invoked. This can lead to confusing issues (e.g. https://github.com/eslint/eslint/issues/9101) where a function call on a node can change behavior depending on whether the node has been traversed.

Previously, there has been discussion about adding the parent property during the scope analysis traversal (https://github.com/eslint/eslint-scope/issues/27). However, I realized there’s a much easier solution: We can just defer all rule listener calls until after traversal is complete.

The current traversal logic looks roughly like this (pseudocode):

for each node in the AST in traversal order:
    node.parent = parentNode
    for each rule listener that matches the node:
        invoke the listener on the node

We could change it to this:

for each node in the AST in traversal order:
    node.parent = parentNode
    for each rule listener that matches the node:
        push (listener, node) into a FIFO queue

for each (listener, node) pair in the queue:
    invoke the listener on the node

The effect is that all parent properties would be present for all rule listeners.

We would need to evaluate the performance effects of doing this. I suspect that most of the time spent traversing the AST is a result of enumerating the children of a node, so after all the nodes have already been enumerated in order, I don’t think invoking a function on a small fraction of the nodes will create a big performance problem. (Actually, this might allow us to move scope analysis into the same traversal too, since rules wouldn’t be able to observe the scope until the traversal is complete.)

Note that rules can observe the AST before traversal starts, so they would still be able to observe nodes without a parent property. (edit: actually, this can be avoided.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Sep 21, 2017

TSC Summary: This issue proposes updating traversal logic to call rule listeners after all nodes have a parent property. The issue was previously accepted by the TSC, but it was reverted because there was some compatibility impact (a plugin was relying on the fact that the AST is non-circular, and another plugin was relying on the parent property not existing in some cases).

TSC Question: Should we schedule this as a breaking change in v5.0.0?

0reactions
not-an-aardvarkcommented, Oct 13, 2017

In today’s TSC meeting, the TSC decided to accept this as a breaking change for 5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Parameters Proposal
In this example, the Node type argument to graph. New has a constraint NodeConstraint[Edge] . When we call graph. New with a Node...
Read more >
Spring for Apache Kafka
The listener container will defer the out-of-order commits until the missing acknowledgments are received. The consumer will be paused (no new records delivered) ......
Read more >
RFC 5245: Interactive Connectivity Establishment (ICE)
ICE makes use of the Session Traversal Utilities for NAT (STUN) protocol and its ... alive until ICE processing has completed, as described...
Read more >
draft-ietf-ice-rfc5245bis-00 - IETF Datatracker
Interactive Connectivity Establishment (ICE): A Protocol for Network Address Translator (NAT) Traversal (Internet-Draft, 2015)
Read more >
View - Android Developers
Other view subclasses offer more specialized listeners. ... Sets the id of a view after which this one is visited in accessibility traversal....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found