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: quotes autofix produces syntax error with octal escape sequences #12118

Merged
merged 1 commit into from Aug 31, 2019
Merged

Fix: quotes autofix produces syntax error with octal escape sequences #12118

merged 1 commit into from Aug 31, 2019

Conversation

mdjermanovic
Copy link
Member

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.2.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 quotes: ["error", "backtick"]*/

var foo = '\1';

What did you expect to happen?

Given how prefer-template works in similar situations, to report a warning but without the auto-fix.

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

Fixed to:

/*eslint quotes: ["error", "backtick"]*/

var foo = `\1`;
3:12  error  Parsing error: Octal literal in template string

What changes did you make? (Give an overview)

Prevent fix to a template literal if the source string contains an octal escape sequence.

An alternative would be to not report that string at all.

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

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Aug 19, 2019
@platinumazure
Copy link
Member

Is there an equivalent escape sequence that is allowed in templates? (Ideally in octal but other radix is good too)

To be clear, I'm not trying to suggest a complicated fix. I'm trying to establish if there is no way for the user to fix the issue (in which case, best not to report at all), or if there is a way they could change the code to get the same value.

@mdjermanovic
Copy link
Member Author

I think there are only 'hex' (\xXX) and 'unicode' (\uXXXX or \u{...}) which is also hex notation, but there is no octal, unlike number literals which have 0oXX....

So, there is a way to manually fix, but the user would be forced to convert octal -> hex. On the other hand octal escapes shouldn't be used anyway, as far as I know it's a legacy feature and is forbidden in strict mode.

Re the auto-fix, it might be not even too complicated, but I guess that rules such as no-octal-escape, no-octal and even no-useless-escape don't have fixer although it wouldn't change behavior, because such literal might be a mistake rather than intention, and it could be better not to silently fix it.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 24, 2019
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

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 for contributing!

Copy link
Member

@platinumazure platinumazure 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!

@platinumazure
Copy link
Member

Marking as accepted based on this reproduction:

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 31, 2019
@platinumazure platinumazure merged commit e10eeba into eslint:master Aug 31, 2019
@platinumazure
Copy link
Member

Thanks for contributing to ESLint!

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

4 participants