49 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
Jump statements, such as ``++return++``, ``++break++`` and ``++continue++`` let you change the default flow of program execution, but jump statements that direct the control flow to the original direction are just a waste of keystrokes.
2020-06-30 12:48:39 +02:00
=== Noncompliant code example
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:39 +02:00
----
function redundantJump(x) {
if (x == 1) {
console.log("x == 1");
return; // Noncompliant
}
}
----
=== Compliant solution
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
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
2021-01-27 13:42:22 +01:00
``++break++`` and ``++return++`` inside ``++switch++`` statement are ignored, because they are often used for consistency. ``++continue++`` with label is also ignored, because label is usually used for clarity. Also a jump statement being a single statement in a block is ignored.
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[]