[quotes] Clarify that "avoid-escape" does not allow backticks #5147

Closed
feross opened this Issue Feb 4, 2016 · 5 comments

Projects

None yet

3 participants

@feross
Contributor
feross commented Feb 4, 2016

Using the latest eslint (2.0.0-rc.0).

Rules:

{
  "parserOptions": {
    "ecmaVersion": 6
  },
  "rules": {
    "quotes": [2, "single", "avoid-escape"]
  }
}

Code:

console.log(`hello 'hi'`)

Gives the following false-positive error:

  1:13  error  Strings must use singlequote  quotes

The ` string should be allowed, because it's being used to avoid quotes.

Changing the code to:

console.log("hello 'hi'")

causes the error to go away. This is inconsistent and contrary to what the docs say.

@eslintbot

@feross Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage label Feb 4, 2016
@feross feross referenced this issue in feross/standard Feb 4, 2016
Closed

Release proposal: standard v6 #399

25 of 25 tasks complete
@feross
Contributor
feross commented Feb 4, 2016

It's also worth noting that this worked correctly in 1.x.

@IanVS
Member
IanVS commented Feb 4, 2016

I believe the reason for this is that backticks are only allowed when they are not the chosen quote type if they add value (meaning, they are doing something that can't be done with normal quotes, see #3090 for the rationale/discussion). If you want to avoid escaping the single quotes, you should use double quotes.

The docs contain the line:

When using "single" or "double", template literals that don't contain a substitution, don't contain a line break, and aren't tagged templates are flagged as problems.

But perhaps it could probably be explained more clearly with regards to "avoid-escape".

@feross feross changed the title from `quotes` false positive to `quotes` false positive (eslint 2.0.0) Feb 4, 2016
@feross
Contributor
feross commented Feb 4, 2016

Ah, I see. Thanks for explaining. I agree with the rationale.

This was a breaking change for several packages that use standard because they were using backticks to avoid escaping. But we're going to release a new major version (6.0.0), so I think this is okay.

@feross feross closed this Feb 4, 2016
@IanVS IanVS reopened this Feb 4, 2016
@IanVS
Member
IanVS commented Feb 4, 2016

Let's keep this open so we remember to clarify in the docs that "avoid-escape" only applies to single quotes and double quotes.

@IanVS IanVS changed the title from `quotes` false positive (eslint 2.0.0) to [quotes] Clarify that "avoid-escape" does not allow backticks Feb 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment