2020-06-30 12:47:33 +02:00
include::../description.adoc[]
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:47:33 +02:00
----
function doSomething(a, b) { // "a" is unused
return compute(b);
}
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:47:33 +02:00
----
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:
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
----
$(["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.
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
Examples :
2020-06-30 14:49:38 +02:00
2020-06-30 12:47:33 +02:00
----
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; }
----
2021-01-27 13:42:22 +01:00
Further, when ``++arguments++`` is used in the function body, no parameter is reported as unused.
2020-06-30 12:47:33 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:47:33 +02:00
----
function doSomething(a, b, c) {
compute(arguments);
}
----
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[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]