SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-93

Rule: Only while/do/for statements can be labelled

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Issue Links

        Activity

        Hide
        Evgeny Mandrikov added a comment -

        Freddy, could you please suggest description for this rule?

        Show
        Evgeny Mandrikov added a comment - Freddy, could you please suggest description for this rule?
        Hide
        Freddy Mallet added a comment - - edited

        Here is a proposal :

        <p>Any Javascript statement can be identified by a label but those labels are only useful on 'while', 'do-while' and 'for' statements. If such label is used on a different statement this is mistake.</p>
        
        <p>Here </p>
        
        <pre>
        var x = 0;  
        var z = 0  
        labelCancelLoops: while (true) {    //OK
            console.log("Outer loops: " + x);  
            wrongLabel : x += 1;            //NOK
            z = 1;  
            while (true) {  
                console.log("Inner loops: " + z);  
                z += 1;  
                if (z === 10 && x === 10) {  
                    break labelCancelLoops;
                } else if (z === 10) {  
                    break;  
                }  
            }  
        }
        </pre>
        
        Show
        Freddy Mallet added a comment - - edited Here is a proposal : <p>Any Javascript statement can be identified by a label but those labels are only useful on 'while', 'do-while' and 'for' statements. If such label is used on a different statement this is mistake.</p> <p>Here </p> <pre> var x = 0; var z = 0 labelCancelLoops: while (true) { //OK console.log("Outer loops: " + x); wrongLabel : x += 1; //NOK z = 1; while (true) { console.log("Inner loops: " + z); z += 1; if (z === 10 && x === 10) { break labelCancelLoops; } else if (z === 10) { break; } } } </pre>
        Hide
        Evgeny Mandrikov added a comment -

        Done.

        Show
        Evgeny Mandrikov added a comment - Done.
        Hide
        Freddy Mallet added a comment -

        Manually tested !

        Show
        Freddy Mallet added a comment - Manually tested !

          People

          • Assignee:
            Evgeny Mandrikov
            Reporter:
            Evgeny Mandrikov
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: