SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-132

Rule : Source should comply with the javascript strict mode

    Details

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

      Issue Links

        Activity

        Hide
        Evgeny Mandrikov added a comment - - edited

        Probably we should update WithStatementCheck (SONARPLUGINS-1813), which was implemented in version 1.0, to clearly specify that usage of with-statement not allowed in strict mode.

        Show
        Evgeny Mandrikov added a comment - - edited Probably we should update WithStatementCheck ( SONARPLUGINS-1813 ), which was implemented in version 1.0, to clearly specify that usage of with-statement not allowed in strict mode.
        Hide
        Fabrice Bellingard added a comment -

        Yes Evgeny, you can update the description of SONARPLUGINS-1813 by the following:

        The object of the 'with' statement can have properties that collide with local variables, which can drastically change the meaning of the program. For instance:

        with (foo) {
          var x = 3;
          return x;
        }
        

        , the local variable x could be clobbered by a property of foo - and perhaps it even has a setter, in which case assigning 3 could cause lots of other code to execute.

        Therefore, 'with' statement should never be used. Instead, the previous code should be refactored to make direct calls to the object (<code>foo.x</code> in the previous example).

        What's more, using the 'with' statement would produce an error in JavaScript strict mode code.

        Show
        Fabrice Bellingard added a comment - Yes Evgeny, you can update the description of SONARPLUGINS-1813 by the following: The object of the 'with' statement can have properties that collide with local variables, which can drastically change the meaning of the program. For instance: with (foo) { var x = 3; return x; } , the local variable x could be clobbered by a property of foo - and perhaps it even has a setter, in which case assigning 3 could cause lots of other code to execute. Therefore, 'with' statement should never be used. Instead, the previous code should be refactored to make direct calls to the object (<code>foo.x</code> in the previous example). What's more, using the 'with' statement would produce an error in JavaScript strict mode code.
        Hide
        Evgeny Mandrikov added a comment -

        Done.

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

        This ticket closed as "duplicate" since it was covered by others.

        Show
        Evgeny Mandrikov added a comment - This ticket closed as "duplicate" since it was covered by others.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: