Yassin Kammoun e864c4a697
Modify rule S1172: Match the behaviour of TypeScript compiler for JS/TS (#827)
Co-authored-by: vilchik.elena <elena.vilchik@sonarsource.com>
2022-02-18 08:15:47 +00:00

69 lines
1.1 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,javascript]
----
function doSomething(a, b) { // "a" is unused
return compute(b);
}
----
== Compliant Solution
[source,javascript]
----
function doSomething(b) {
return compute(b);
}
----
or
[source,javascript]
----
function doSomething(_a, b) {
return compute(b);
}
----
== Exceptions
When ``++arguments++`` is used in the function body, no parameter is reported as unused.
[source,javascript]
----
function doSomething(a, b, c) {
compute(arguments);
}
----
Also, the rule ignores all parameters whose name starts with an underscore (``++_++``).
This is a common practice to acknowledge the fact that some parameter is unused (e.g. in TypeScript compiler).
[source,javascript]
----
function doSomething(_a, b) {
return compute(b);
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]