SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-80

Rule: Do not use Internet Explorer's conditional comments

    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

      References: Google guidelines

      title

      Do not use Internet Explorer's conditional comments

      description

      Internet Explorer offers a way to change the JavaScript code at runtime using conditional comments (activated by a <code>@cc_on</code> statement found in a comment). Using this preprocessing feature decreases readability and maintainability, and can hinder automated tools. What's more, it is specific to Internet Explorer and won't work for other browsers.

      Most of the time, using those conditional comments can be easily avoided with some refactoring - using modern cross-browsers JavaScript frameworks and libraries.

      The following code snippet illustrates the use of conditional comments:

      /*@cc_on
         /*@if (@_jscript_version >= 5)
            ... // some JavaScript 5 code
         @else @*/
            ... // some "old" JavaScript code
         /*@end
      @*/
      

      message

      Refactor your code to avoid using Internet Explorer's conditional comments.

      severity

      Major

      in Sonar way?

      Yes

        Issue Links

          Activity

          Hide
          Fabrice Bellingard added a comment -

          Actually, I found out that "@cc_on" on single line comments may also activate the conditional comments (http://msdn.microsoft.com/en-us/library/ie/6s6fab9k%28v=vs.94%29.aspx).

          My bad, I updated the description of the rule (first sentence) to reflect this.

          Show
          Fabrice Bellingard added a comment - Actually, I found out that "@cc_on" on single line comments may also activate the conditional comments ( http://msdn.microsoft.com/en-us/library/ie/6s6fab9k%28v=vs.94%29.aspx ). My bad, I updated the description of the rule (first sentence) to reflect this.
          Hide
          Evgeny Mandrikov added a comment -

          Fixed.

          Show
          Evgeny Mandrikov added a comment - Fixed.
          Hide
          Fabrice Bellingard added a comment -

          Tested!

          Show
          Fabrice Bellingard added a comment - Tested!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: