SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-151

Rule: Avoid use of constructor functions for side-effects

    Details

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

      Description

      • Title
        Avoid use of constructor functions for side-effects
      • Description
        Some people like to call constructor functions without assigning its result to any variable:
        var something = new MyConstructor();  //Compliant
        new MyConstructor();   //Non-Compliant, do we call a constructor to get a side effect ? If this is the case, this is definitely misleading.
        

        There is no advantage in this approach over simply calling MyConstructor since the object that the operator new creates isn't used anywhere. So such kind of syntax is misleading and should be avoided.

      • Violation message
        Replace the statement by a standard call to the MyConstructor() function
      • Default severity
        Major

      Part of Sonar war quality profile

      Origin: JSHint

        Issue Links

          Activity

          Hide
          Fabrice Bellingard added a comment -

          Manually tested.

          Show
          Fabrice Bellingard added a comment - Manually tested.
          Hide
          Evgeny Mandrikov added a comment -

          Integration tests were updated.

          Show
          Evgeny Mandrikov added a comment - Integration tests were updated.

            People

            • Assignee:
              Evgeny Mandrikov
              Reporter:
              Freddy Mallet
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: