59 lines
1.8 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
Jump statements, such as ``++return++``, ``++break++`` and ``++continue++``, are used to change the normal flow of execution in a program. They are useful because they allow for more complex and flexible code. However, it is important to use jump statements judiciously, as overuse or misuse can make code difficult to read and maintain.
2020-06-30 12:48:39 +02:00
Jump statements are redundant when they do not affect the program flow or behavior.
2020-06-30 12:48:39 +02:00
[source,javascript,diff-id=1,diff-type=noncompliant]
2020-06-30 12:48:39 +02:00
----
function redundantJump(x) {
if (x == 1) {
console.log("x == 1");
return; // Noncompliant: The function would return 'undefined' also without this 'return' statement
2020-06-30 12:48:39 +02:00
}
}
----
Remove any jump statements that are unnecessary or redundant.
2020-06-30 12:48:39 +02:00
[source,javascript,diff-id=1,diff-type=compliant]
2020-06-30 12:48:39 +02:00
----
function redundantJump(x) {
if (x == 1) {
console.log("x == 1");
}
}
----
=== Exceptions
2020-06-30 12:48:39 +02:00
* ``++break++`` and ``++return++`` inside ``++switch++`` statements are ignored, because they are often used for consistency.
* ``++continue++`` associated with a label is ignored, because it is usually used for clarity.
* Jump statements are ignored when they are the only statement inside a block.
== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue[MDN - `continue`]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break[MDN - `break`]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return[MDN - `return`]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]