question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, May 15, 2016

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.

0reactions
jfmengelscommented, Jul 26, 2016

Still want to implement?

Yes 😃 I’ll try to take a stab at it tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
Proposed Rules - GovInfo
We propose to amend the general requirements for informed consent under § 50.20 to harmonize with the revised Common Rule at 45 CFR...
Read more >
Notice of Proposed Rule: Employee or Independent ...
The NPRM proposes to rescind a prior rule, Independent Contractor Status Under ... on this proposal by December 13, 2022 (the new deadline)....
Read more >
U.S. Labor Department Issues Proposed Rule on Independent ...
The U.S. Department of Labor (DOL) has issued a new proposed rule addressing the distinction between employees and independent contractors ...
Read more >
Resolution of Federal Tax Controversies by the Independent ...
This document contains proposed regulations relating to the IRS ... To meet Appeals' mission, new section 7803(e)(6)(A) provides that all ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found