
## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule) --------- Co-authored-by: Zsolt Kolbay <121798625+zsolt-kolbay-sonarsource@users.noreply.github.com>
75 lines
1.2 KiB
Plaintext
75 lines
1.2 KiB
Plaintext
include::../why.adoc[]
|
||
|
||
include::../how.adoc[]
|
||
|
||
=== Code examples
|
||
|
||
==== Noncompliant code example
|
||
|
||
[source,javascript,diff-id=1,diff-type=noncompliant]
|
||
----
|
||
function seek(input) {
|
||
let target = 32; // Noncompliant
|
||
for (const i of input) {
|
||
if (i === target) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
----
|
||
|
||
==== Compliant solution
|
||
|
||
[source,javascript,diff-id=1,diff-type=compliant]
|
||
----
|
||
function seek(input) {
|
||
const target = 32;
|
||
for (const i of input) {
|
||
if (i === target) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
----
|
||
|
||
[source,javascript,diff-id=2,diff-type=noncompliant]
|
||
----
|
||
|
||
function getUrl(protocol, domain, path) {
|
||
let url; // Noncompliant
|
||
url = `${protocol}/${domain}/${path}`;
|
||
return url;
|
||
}
|
||
----
|
||
|
||
==== Compliant solution
|
||
|
||
[source,javascript,diff-id=2,diff-type=compliant]
|
||
----
|
||
function getUrl(protocol, domain, path) {
|
||
const url = `${protocol}/${domain}/${path}`;
|
||
return url;
|
||
}
|
||
----
|
||
|
||
== Resources
|
||
|
||
=== Documentation
|
||
|
||
* MDN - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const[const]
|
||
|
||
ifdef::env-github,rspecator-view[]
|
||
|
||
'''
|
||
== Implementation Specification
|
||
(visible only on this page)
|
||
|
||
=== Message
|
||
|
||
Make "xxx" "const".
|
||
|
||
|
||
endif::env-github,rspecator-view[]
|