Details

    • Type: Language-Specification
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Remove this code after the "[return|break|continue|goto|throw]" statement.
    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity
    • Default Quality Profiles:
      Sonar way, Sonar way recommended
    • Legacy Key:
      UnreachableCode

      Description

      Jump statements (return, break and continue) and throw expressions move control flow out of the current code block. So any statements that come after a jump are dead code.

      Noncompliant Code Example

      function fun(a) {
        var i = 10;
        return i + a; 
        i++;             // Noncompliant; this is never executed
      }
      

      Compliant Solution

      function fun(int a) {
        var i = 10;
        return i + a;
      }
      

      Exceptions

      This rule ignores unreachable break statements in switch clauses.

      switch (x) {
        case 42:
           return 43;
           break;   // Compliant
        default:
          doSomething();
      }
      

      Hoisted variables declarations without initialization are always considered reachable.

      function bar() {
        return x = function() {
          x.foo = 42;
        }
        var x;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              pierre-yves.nicolas Pierre-Yves Nicolas
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: