-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
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.