SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-99

Rule: Each statement must end with a semicolon

    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
        Freddy Mallet added a comment - - edited

        Works well, could you just update the description of the rule as follows

        <p>In Javascript semicolons is an optional statement separator. But this can lead to some ambiguities and here is an example of ambiguous code that breaks in the absence of a semicolon :</p>
        
        <pre>
        // define a function
        var fn = function () {
            //...
        } // semicolon missing at this line
        
        // then execute some code inside a closure
        (function () {
            //...
        })();
        </pre>
        
        This will be interpreted as:
        
        <pre>
        var fn = function () {
            //...
        }(function () {
            //...
        })();
        </pre>
        
        <p>We end up passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. The second function will fail with a "... is not a function" error at runtime.</p>
        
        Show
        Freddy Mallet added a comment - - edited Works well, could you just update the description of the rule as follows <p>In Javascript semicolons is an optional statement separator. But this can lead to some ambiguities and here is an example of ambiguous code that breaks in the absence of a semicolon :</p> <pre> // define a function var fn = function () { //... } // semicolon missing at this line // then execute some code inside a closure (function () { //... })(); </pre> This will be interpreted as: <pre> var fn = function () { //... }(function () { //... })(); </pre> <p>We end up passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. The second function will fail with a "... is not a function" error at runtime.</p>
        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:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: