Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Hide
      Remove use of this comma operator.
      Remove use of all comma operators in this expression.
      Show
      Remove use of this comma operator. Remove use of all comma operators in this expression.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Flex
    • Covered Languages:
      C, C++, JavaScript, Objective-C, TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • CPPCheck:
      commaSeparatedReturn
    • ESLint:
      no-sequences
    • PC-Lint:
      505, 1505, 9008
    • TSLint:
      ban-comma-operator

      Description

      The comma operator takes two expressions, executes them from left to right and returns the result of the second one. Use of this operator is generally detrimental to the readability and reliability of code, and the same effect can be achieved by other means.

      Noncompliant Code Example

      i = a += 2, a + b;  // What's the value of i ?
      

      Compliant Solution

      a +=  2;
      i = a + b;
      

      Exceptions

      Use of comma operator is tolerated in initialization and increment expressions of for loops.

      for(i = 0, j = 5; i < 6; i++, j++) { ... }
      

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-2919 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-5373 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Anonymous
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: