Modify rule S1439: Adapt to LaYC (#2565)

This commit is contained in:
Yassin Kammoun 2023-07-20 11:46:15 +02:00 committed by GitHub
parent 2444f0a49e
commit ae719d7562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,10 @@
== Why is this an issue?
Labels allow specifying a target statement to jump to using the `break` or `continue` statements. It's possible to assign a label to any statement or block of statements. However using it with any statement can create a complex control flow path, making the code harder to understand and maintain.
Labels allow specifying a target statement to jump to using the `break` or `continue` statements. It's possible to assign a label to any statement or block of statements. However, using it with any statement can create a complex control flow path, making the code harder to understand and maintain.
[source,javascript,diff-id=1,diff-type=noncompliant]
----
myLabel: if (i % 2 == 0) { // Noncompliant
myLabel: if (i % 2 == 0) { // Noncompliant: Labeling an if statement
if (i == 12) {
console.log("12");
break myLabel;
@ -17,7 +17,7 @@ Instead of using a label with these nested `if` statements, this code block shou
[source,javascript,diff-id=1,diff-type=compliant]
----
if (i % 2 == 0) { // Compliant
if (i % 2 == 0) { // Compliant
if (i == 12) {
console.log("12");
} else {
@ -30,7 +30,7 @@ The rule considers that `while`, `do-while`, `for`, and `switch` statements don'
[source,javascript]
----
outerLoop: for (let i = 0; i < 10; i++) { // Compliant
outerLoop: for (let i = 0; i < 10; i++) { // Compliant
for (let j = 0; j < 10; j++) {
if (condition(i, j)) {
break outerLoop;
@ -44,7 +44,7 @@ outerLoop: for (let i = 0; i < 10; i++) { // Compliant
=== Documentation
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label[MDN web docs: Label]
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label[MDN - label]
=== Related rules