Skip to content
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

Merged
merged 1 commit into from Feb 17, 2017
Merged

Fix: getTokenAfter was wrong #8055

merged 1 commit into from Feb 17, 2017

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented Feb 9, 2017

What is the purpose of this pull request? (put an "X" next to item)

[X] Bug fix (template)

Tell us about your environment

  • ESLint Version: master
  • Node Version: 7.3.0
  • npm Version: 3.8.9

What parser (default, Babel-ESLint, etc.) are you using?

  • default

Please show your full configuration:

  • nothing

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 }).

(function(a, /*b,*/ c){})

What did you expect to happen?

  • It traverses 11 tokens.

What actually happened? Please include the actual, raw output from ESLint.

  • It traverses 10 tokens (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 and utils.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.

@mention-bot
Copy link

@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.

@eslintbot
Copy link

LGTM

@mysticatea mysticatea self-assigned this Feb 9, 2017
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features labels Feb 9, 2017
@eslintbot
Copy link

LGTM

@mysticatea mysticatea changed the title [WIP] Fix: getTokenAfter was wrong Fix: getTokenAfter was wrong Feb 13, 2017
@mysticatea
Copy link
Member Author

I updated this PR and this PR's description.
It's ready to review.

Copy link
Member

@gyandeeps gyandeeps left a 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

Copy link
Member

@kaicataldo kaicataldo left a 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!

@kaicataldo
Copy link
Member

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.

@platinumazure
Copy link
Member

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).

@not-an-aardvark
Copy link
Member

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.

@not-an-aardvark not-an-aardvark merged commit 7516303 into master Feb 17, 2017
@alberto alberto deleted the fix-get-token-after branch February 17, 2017 22:10
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants