Arseniy Zaostrovnykh 11c08de44a
Revert "RULEAPI-665: Remove security standards from the irrelevant language-specific rules" (#361)
This reverts commit 892bccde8ffcdf2a6d662d97ec469cd63de87878.
2021-09-17 13:50:03 +02:00

64 lines
1.7 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
----
function doSomething(a, b) { // "a" is unused
return compute(b);
}
----
== Compliant Solution
----
function doSomething(b) {
return compute(b);
}
----
== Exceptions
When writing function callbacks, some arguments might be required as part of the function signature, but not actually needed by the callback code. For instance, JQuery has the 'each' helper to iterate over arrays or objects, but using the counter 'i' should remain optional:
----
$(["first", "last"]).each(function (i, value) {
computeSomethingWithValue(value);
});
----
So only unused arguments listed at the end of the argument list will be flagged with issues because they could be omitted from the function signature. Unused arguments which are followed by an argument that _is_ used will be ignored.
Examples :
----
var myFirsCallBackFunction = function (p1, p2, p3, p4) { // p2 is ignored, but p4 is reported
return p1 + p3; }
var mySecondCallBackFunction = function (p1, p2, p3, p4) { // p1, p2 and p3 are ignored
return p4; }
var myThirdCallBackFunction = function (p1, p2, p3, p4) { // p1 is ignored but p3 and p4 are reported
return p2; }
----
Further, when ``++arguments++`` is used in the function body, no parameter is reported as unused.
----
function doSomething(a, b, c) {
compute(arguments);
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]