2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2020-06-30 12:47:33 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2020-06-30 12:47:33 +02:00
|
|
|
|
2023-10-30 10:33:56 +01:00
|
|
|
To prevent generating some false-positives, literals having less than 10 characters are excluded as well as literals matching ``++/^\w*$/++``.
|
2023-10-11 11:41:24 +02:00
|
|
|
String literals inside import/export statements and JSX attributes are also ignored.
|
|
|
|
The same goes for statement-like string literals, e.g. `'use strict';`.
|
|
|
|
|
|
|
|
== How to fix it
|
|
|
|
|
|
|
|
include::../howtofix.adoc[]
|
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
With the default threshold of 3:
|
|
|
|
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
|
|
----
|
|
|
|
function run() {
|
|
|
|
prepare("action_to_launch"); // Noncompliant - "action_to_launch" is duplicated 3 times
|
|
|
|
execute("action_to_launch");
|
|
|
|
release("action_to_launch");
|
|
|
|
}
|
|
|
|
|
|
|
|
function printInQuotes(a, b) {
|
|
|
|
console.log("'" + a + "'" + b + "'"); // Compliant - literal "'" has less than 10 characters and is excluded
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
|
|
----
|
|
|
|
var ACTION_1 = "action_to_launch";
|
|
|
|
|
|
|
|
function run() {
|
|
|
|
prepare(ACTION_1); // Compliant
|
|
|
|
execute(ACTION_1);
|
|
|
|
release(ACTION_1);
|
|
|
|
}
|
|
|
|
----
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
include::../parameters.adoc[]
|
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|