2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
This rule checks that all string literals use the same kind of quotes.
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-04-28 18:08:03 +02:00
|
|
|
|
|
|
|
Using the parameter default (forcing single quotes):
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2021-04-28 18:08:03 +02:00
|
|
|
----
|
|
|
|
var firstParameter = "something"; // Noncompliant
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2021-04-28 18:08:03 +02:00
|
|
|
----
|
2022-08-04 15:12:16 +02:00
|
|
|
var firstParameter = 'something';
|
2021-04-28 18:08:03 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2021-04-28 18:08:03 +02:00
|
|
|
|
|
|
|
Strings that contain quotes are ignored.
|
|
|
|
|
2022-08-04 15:12:16 +02:00
|
|
|
[source,javascript]
|
2021-04-28 18:08:03 +02:00
|
|
|
----
|
|
|
|
let heSaid = "Then he said 'What?'." // ignored
|
|
|
|
let sheSaid = '"Whatever!" she replied.' // ignored
|
|
|
|
----
|
|
|
|
|
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)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Use string literals quotes consistently
|
|
|
|
|
|
|
|
|
|
|
|
=== Parameters
|
|
|
|
|
|
|
|
.singleQuotes
|
|
|
|
****
|
|
|
|
|
|
|
|
----
|
|
|
|
true
|
|
|
|
----
|
|
|
|
|
|
|
|
Set to true to require single quotes, false for double quotes.
|
|
|
|
****
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== on 1 Nov 2016, 17:04:09 Elena Vilchik wrote:
|
|
|
|
\[~ann.campbell.2] Could you please add exceptions to this rule (they are both implemented already)?
|
|
|
|
|
|
|
|
* if string literal contains ``++'++`` (SONARJS-796)
|
|
|
|
* if string literal is part of JSX (SONARJS-681)
|
|
|
|
Thanks!
|
|
|
|
|
|
|
|
=== on 1 Nov 2016, 18:21:18 Ann Campbell wrote:
|
|
|
|
Done [~elena.vilchik]
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|