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.

Leading comments incorrectly include comments inside previous token

See original GitHub issue

I recently contributed a rule that ended up having an issue regarding leading comments. The issue for the rule and the fix is here, but in looking at it, I started wondering if maybe this should be a fix in sourceCode.getComments rather than having to be guarded against in each individual rule.

I’m currently using ESLint v2.3.0, and the problem seems to be that comments inside a previous object literal or block get added to the following token’s leading comments array when there are no other expressions between the comment and the token. Example:

function foo() {
  var bar = {
    // comment
  };

  return bar;
}

Running sourceCode.getComments on the return expression’s node will include the comment inside the previous object literal, despite it actually being part of the previous token.

I’m assuming this is a bug - it definitely wasn’t what I was expecting to happen - can someone more knowledgable confirm?

In looking at things, it looks like maybe the change needs to happen in Espree…Happy to make a PR if this is accepted.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Mar 15, 2016

@ilyavolodin Thanks! I’ll try to get a PR together in the next day or two

1reaction
kaicataldocommented, Mar 13, 2016

PR opened for the Espree change. Will get to adding the tests on ESLint after that lands 👍

https://github.com/eslint/espree/pull/257

Read more comments on GitHub >

github_iconTop Results From Across the Web

JFlex match nested comments as one token - Stack Overflow
Unfortunately, this results in several COMMENT tokens for one comment, because I have to match nested comment starts and comment ends.
Read more >
NCL: NxsComment Class Reference
A vector of "embedded comments" in the NCL context is a collection of all comments that were encountered during a GetNextToken operation.
Read more >
What's wrong with comments that explain complex code?
If the code is straightforward overall, but contains one or two things that look excessively convoluted, unnecessary, or just plain wrong, but ...
Read more >
Modern Comments in Word - Microsoft Support
In the Comments pane, you can see a single list of all comments in your document, including resolved comments.
Read more >
Comments - IBM
A comment is a sequence of characters (on one or more lines) delimited by /* and */ . Within these delimiters any characters...
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