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: prefer-template autofix produces syntax error with octal escapes #12085

Merged
merged 1 commit into from Aug 18, 2019

Conversation

@mdjermanovic
Copy link
Member

mdjermanovic commented Aug 10, 2019

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

[X] Bug fix

Tell us about your environment

  • ESLint Version: 6.1.0
  • Node Version: 10.16.0
  • npm Version: 6.9.0

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 prefer-template: "error"*/

"\0 \1" + foo
/*eslint prefer-template: "error"*/

"\08" + foo

What did you expect to happen?

Not a syntax error in autofix.

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

/*eslint prefer-template: "error"*/

`\0 \1${  foo}`

Parsing error: Octal literal in template string

/*eslint prefer-template: "error"*/

`\08${  foo}`

Parsing error: Octal literal in template string

What changes did you make? (Give an overview)

Made a new regex in astUtils, which fixes two bugs:

  • Octal escapes after a valid \0 were missed (e.g. "\0 \1"). This bug was probably inherited from no-octal-escape (fixed there in #12079)
  • Whether or not "\08" and "\09" are octal escapes (#12080) these two de facto produce parsing errors in template literals.

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

  • Regex and its performance.

I'll also fix the quotes rule in another PR when this gets merged.

@eslint eslint bot added the triage label Aug 10, 2019
@platinumazure platinumazure added bug evaluating rule and removed triage labels Aug 10, 2019
Copy link
Member

platinumazure left a comment

LGTM, but would like another set of eyes on this before merging. Thanks!

@platinumazure

This comment has been minimized.

Copy link
Member

platinumazure commented Aug 10, 2019

Reproduction:

Marking as accepted.

@platinumazure platinumazure added accepted and removed evaluating labels Aug 10, 2019
@platinumazure platinumazure requested a review from kaicataldo Aug 18, 2019
Copy link
Member

kaicataldo left a comment

LGTM. I actually didn't know about this restriction and had to go do some reading. Thanks for contributing and for the learning opportunity!

@kaicataldo kaicataldo merged commit 30ebf92 into eslint:master Aug 18, 2019
9 checks passed
9 checks passed
commit-message Commit message follows guidelines
Details
continuous-integration Build #20190810.1 succeeded
Details
continuous-integration (Test on Node.js 10 (Linux)) Test on Node.js 10 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Linux)) Test on Node.js 12 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Windows)) Test on Node.js 12 (Windows) succeeded
Details
continuous-integration (Test on Node.js 12 (macOS)) Test on Node.js 12 (macOS) succeeded
Details
continuous-integration (Test on Node.js 8 (Linux)) Test on Node.js 8 (Linux) succeeded
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
@eslint eslint bot locked and limited conversation to collaborators Feb 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.