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

Proposed new rule: wrong-quotes-for-template-string #6186

Closed
JamesMessinger opened this issue May 15, 2016 · 13 comments · Fixed by #6767
Closed

Proposed new rule: wrong-quotes-for-template-string #6186

JamesMessinger opened this issue May 15, 2016 · 13 comments · Fixed by #6767
Assignees
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@JamesMessinger
Copy link

JamesMessinger commented May 15, 2016

When does this rule warn? Please describe and show example code:
This rule would warn when a string appears to use ES6 template string variable substitution, but isn't using a backtick quotes. The goal is to eliminate an easy code mistake, such as the following:

This code would warn:

let name = "John Doe";             // <--- This is a normal string (not a template string)
let greeting = "Hello, ${name}";   // <--- This is ALSO a normal string, but the coder 
                                   //      probably meant for it to be a template string

This code would not warn:

let name = "John Doe";             // <--- This is a normal string (not a template string)
let greeting = `Hello, ${name}`;   // <--- This is a template string

Is this rule preventing an error or is it stylistic?
This rule aims to prevent a common ES6 coding mistake. It's easy to mistakenly use the wrong quotes (e.g. double-quotes instead of backticks) for a template string. When this happens, the code lints and runs perfectly fine, but at runtime, the string value will contain the raw "${name}" rather than the variable value "John Doe".

Why is this rule a candidate for inclusion instead of creating a custom rule?
This is a rule that would benefit everybody who is using ES6 template strings. It's not limited to a specific framework or platform.

Are you willing to create the rule yourself?
Maybe. Not sure how hard it would be.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 15, 2016
@nzakas
Copy link
Member

nzakas commented May 15, 2016

Duplicate of #5850

@nzakas nzakas added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 15, 2016
@JamesMessinger
Copy link
Author

Damn. I searched to make sure I wasn't creating a duplicate issue, but forgot to search closed issues.

So, since #5850 has been closed, does that mean this rule won't get implemented? Or is there still a chance? I know it's a bit anecdotal, but I've seen this mistake bite myself and some other devs on my team quite a few times.

@mysticatea
Copy link
Member

I will give 👍 for this.
There are 5 issues (#6143, #5408, #5376, #4286, #2170) about this in this repo, and my coworker also had this mistake before.
Plus, autofixing for this is usefull to me. I cannot modify both quotes by one step.

@nzakas
Copy link
Member

nzakas commented May 16, 2016

Okay, we need a champion and two more 👍

@BigstickCarpet if accepted, we will ask you to try to implement it yourself (see http://eslint.org/docs/developer-guide/contributing/new-rules#implementation-is-your-responsibility for details). The core team just doesn't have the time to implement every rule that is suggested.

@jfmengels
Copy link
Contributor

I'm willing to implement the rule if this gets accepted.

@ilyavolodin
Copy link
Member

I'll support this. Seems like a good rule to have. 👍

@nzakas
Copy link
Member

nzakas commented Jun 15, 2016

I'll give a 👍 but we still need a champion to shepherd this through the process.

@platinumazure
Copy link
Member

platinumazure commented Jul 19, 2016

I might be willing to implement this if we can find a champion.

@mysticatea
Copy link
Member

I'm a champion. (and we need one more 👍)

@nzakas
Copy link
Member

nzakas commented Jul 25, 2016

Looks like @michaelficarra have a 👍 On the issue, so marking as accepted.

@nzakas nzakas 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 Jul 25, 2016
@ljharb
Copy link
Sponsor Contributor

ljharb commented Jul 25, 2016

Hooray, glad this is finally going to be added :-D

@platinumazure
Copy link
Member

Ah, I didn't see @jfmengels' comment earlier. Still want to implement? I'm out of town for a week so I won't try to stake a claim here 😄

@jfmengels
Copy link
Contributor

Still want to implement?

Yes :) I'll try to take a stab at it tonight.

jfmengels added a commit to jfmengels/eslint that referenced this issue Jul 26, 2016
jfmengels added a commit to jfmengels/eslint that referenced this issue Jul 26, 2016
jfmengels added a commit to jfmengels/eslint that referenced this issue Aug 2, 2016
ilyavolodin pushed a commit that referenced this issue Aug 9, 2016
* New: wrong-quotes-for-template-string rule (fixes #6186)

* Review fixes

* Rename wrong-quotes-for-template-string to no-template-curly-in-string

* Simplify regex

* Update error message

* Use const instead of var

* Update docs
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants