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.

Calculate leading/trailing comments

See original GitHub issue

Problem

Right now, leading and trailing comments are calculated in Espree and passed to ESLint. ESLint depends on these comments from things like configuration and determining if someone has opted-out of a rule (such as providing a comment in an empty block). That works well when using Espree, but if you’re using a different parser, it forces that parser to reimplement the same comment attachment strategy as Espree, which is a lot of work and not very easy. Case in point, we’re working on typescript-eslint-parser and are a bit stuck on getting the same leading/trailing comment information from Espree.

Solution

If we didn’t require parsers to provide leading/trailing comments, and instead calculated them inside of ESLint, we dramatically decrease the complexity of creating ESLint-compatible parsers. We could just require parsers to pass in the comments array, and we could figure out where the comments belong on-demand when a rule calls context.getComments(). This is probably a bit tricky, as we’d want to ensure we get the same results that Espree gives us right now, but ultimately, I think this would help the parser ecosystem tremendously and, as a side benefit, normalize ESLint behavior across parsers.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:50 (49 by maintainers)

github_iconTop GitHub Comments

2reactions
mikesherovcommented, Oct 30, 2016

@nzakas, we talked over the fact that the current leading and trailing behavior is currently pretty buggy, and that pursuing the simpler strategy might lead to breaks in userland that rely on the buggy behavior.

That’s why @kaicataldo is breaking it into two parts. First, we’re doing what the original intent of this issue is: get rid of leading/trailing Comments attach to nodes.

Once that’s been clarified a bit, we intend to use bigQuery to sample how userland uses these properties/functions, and will survey popular plugins so we have a bit of data to guide us on next steps that may be more drastic.

2reactions
JamesHenrycommented, Sep 8, 2016

Well if you don’t mind then I would love to take you up on that offer. I have about 7 other things I could be doing to keep the typescript-eslint-parser project motoring, and working on the comment attachment would naturally come at the expense of (some of) those.

If you don’t get chance to finish or want a second pair of eyes on something please let me know, and thanks a lot for offering!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leading and Trailing in Compiler Design | Example | PART 1.23
In this video, I have discussed leading and trailing calculation with the help of a grammar.To construct the operator precedence parsing ...
Read more >
What are LEADING and TRAILING operation of an ...
If production is of form A → αB. If a is in TRAILING (B), then a will be in TRAILING (A). Algorithm to...
Read more >
Understanding LEADING and TRAILING operations of an ...
I think this link will be a great help to find leading and trailing for every nonterminal involved in a given grammar.
Read more >
Computing leading and trailing sets for context-free grammar
Given an operator grammar, the function Leading (resp. Trailing ) of a non-terminal produces the set of terminals which could be (recursively) the...
Read more >
LEADING, TRAILING and Operator Precedence Table
Steps involved in the construction of the parser are as follows. 1. Ensure the Grammar satisfies the pre-requisite. 2. Compute the functions Leading...
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