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: operator-assignment crash on adjacent division assignment #12844

Merged
merged 1 commit into from Feb 1, 2020

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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

[X] Bug fix

Tell us about your environment

  • ESLint Version: 7.0.0-alpha.0
  • Node Version: v12.14.0
  • npm Version: v6.13.4

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

default

Please show your full configuration:

Configuration
module.exports = {
    parserOptions: {
        ecmaVersion: 2015
    },
};

What did you do? Please include the actual source code causing the issue.

/*eslint operator-assignment: ["error", "never"]*/

foo/=bar

Online Demo Link (v6.8.0 actual)

What did you expect to happen?

Not to crash.

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

SyntaxError: Unterminated regular expression
...
at Espree.tokenize
at Object.tokenize
at Object.canTokensBeAdjacent

What changes did you make? (Give an overview)

astUtils.canTokensBeAdjacent passes source code / to Espree.tokenize, which throws on that seeing a lone slash as an unterminated regex literal.

I changed the operator-assignment rule to pass a token-like object instead of a source code made up of an operator only.

Is there anything you'd like reviewers to focus on?

astUtils.canTokensBeAdjacent should be also fixed to account for / on the left side and comments or regex literals on the right side, as these cannot be adjacent (it would turn everything into a // line comment). I'll work on that in another PR.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Jan 29, 2020
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.

LGTM, thanks!

Copy link
Member

@yeonjuan yeonjuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
I got it :). The newOperator was a string not a Token.

@kaicataldo kaicataldo merged commit dadc892 into master Feb 1, 2020
@kaicataldo kaicataldo deleted the operatorassignment-divisioncrash branch February 1, 2020 00:13
@kaicataldo
Copy link
Member

Thanks for contributing!

montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 1, 2020
@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 Aug 1, 2020
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 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants