59 lines
1.8 KiB
Plaintext

== 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.
Jump statements are redundant when they do not affect the program flow or behavior.
[source,javascript,diff-id=1,diff-type=noncompliant]
----
function redundantJump(x) {
if (x == 1) {
console.log("x == 1");
return; // Noncompliant: The function would return 'undefined' also without this 'return' statement
}
}
----
Remove any jump statements that are unnecessary or redundant.
[source,javascript,diff-id=1,diff-type=compliant]
----
function redundantJump(x) {
if (x == 1) {
console.log("x == 1");
}
}
----
=== Exceptions
* ``++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
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue[`continue`]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break[`break`]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return[`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[]