Calculate leading/trailing comments
See original GitHub issueProblem
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:
- Created 7 years ago
- Reactions:2
- Comments:50 (49 by maintainers)
Top GitHub Comments
@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.
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!