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

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

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

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

This comment has been minimized.

Show comment
Hide comment
@eslintbot

eslintbot Feb 4, 2016

@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 commented Feb 4, 2016

@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 Feb 4, 2016

Closed

Release proposal: standard v6 #399

25 of 25 tasks complete
@feross

This comment has been minimized.

Show comment
Hide comment
@feross

feross Feb 4, 2016

Contributor

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

Contributor

feross commented Feb 4, 2016

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

@IanVS

This comment has been minimized.

Show comment
Hide comment
@IanVS

IanVS Feb 4, 2016

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@feross

feross Feb 4, 2016

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@IanVS

IanVS Feb 4, 2016

Member

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

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

ilyavolodin added a commit that referenced this issue Feb 5, 2016

Merge pull request #5163 from eslint/issue5147
Docs: `avoid-escape` does not allow backticks (fixes #5147)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.