42 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Template strings allow developers to embed variables or expressions in strings using template literals, instead of string concatenation. This is done by using expressions like ``++${variable} ++`` in a string between two back-ticks (``++`++``). However, when used in a regular string literal (between double or single quotes) the template will not be evaluated and will be used as a literal, which is probably not what was intended.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
console.log("Today is ${date}"); // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
console.log(`Today is ${date}`);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace the quotes (["|']) with back-ticks (`).
'''
== Comments And Links
(visible only on this page)
=== on 5 Dec 2016, 16:30:37 Elena Vilchik wrote:
\[~jeanchristophe.collet] WDYT about renaming to "Template literal placeholder syntax should not be used in regular strings"?
endif::env-github,rspecator-view[]