New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: getTokenAfter
was wrong
#8055
Conversation
@mysticatea, thanks for your PR! By analyzing the history of the files in this pull request, we identified @btmills, @not-an-aardvark and @nzakas to be potential reviewers. |
LGTM |
c9c5927
to
e3bd77f
Compare
LGTM |
getTokenAfter
was wronggetTokenAfter
was wrong
I updated this PR and this PR's description. |
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.
I would update the commit message to be more descriptive
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.
I agree with @gyandeeps about the commit message, but otherwise LGTM. Thanks!
I think we should land this before our next release - it would be nice not to release this in a patch afterwards since we know there's a bug and it hasn't been used out in the wild yet. |
I agree the commit message needs to be a bit more detailed. I don't mind if some of the details are in the commit message body (i.e., not in the first line shown in our release notes). |
I just ran into this issue. 😕 I'm blocked by this issue at the moment, so I'm going to merge it and update the commit message myself. |
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix (template)
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
I traversed tokens and comments by
token = sourceCode.getTokenAfter(token, { includeComments: true })
.What did you expect to happen?
What actually happened? Please include the actual, raw output from ESLint.
c
is lost).What changes did you make? (Give an overview)
This PR makes correct usage of indexMap (the map from locations to indices).
The map includes 2 kind of mapping; "token's locations to token's indices" and "comment's locations to token's indices". In the former case, it points itself index of each token. In the latter case, it points the next token's index of each comment. So it required additional checks in
utils.getFirstIndex
andutils.getLastIndex
.This PR fixes those, and adds tests for some edge cases.
Is there anything you'd like reviewers to focus on?
Nothing in particular.