Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

52 lines
1.2 KiB
Plaintext

== Why is this an issue?
Template literals (previously named "template strings") are an elegant way to build a string without using the ``+`` operator to make strings concatenation more readable.
However, it's possible to build complex string literals by nesting together multiple template literals, and therefore lose readability and maintainability.
In such situations, it's preferable to move the nested template into a separate statement.
=== Noncompliant code example
[source,javascript]
----
let color = "red";
let count = 3;
let message = `I have ${color ? `${count} ${color}` : count} apples`; // Noncompliant; nested template strings not easy to read
----
=== Compliant solution
[source,javascript]
----
let color = "red";
let count = 3;
let apples = color ? `${count} ${color}` : count;
let message = `I have ${apples} apples`;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor this code to not use nested template literals.
'''
== Comments And Links
(visible only on this page)
=== on 3 May 2018, 16:53:51 Alexandre Gigleux wrote:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
endif::env-github,rspecator-view[]