Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1764

Identical expressions should not be used on both sides of a binary operator

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      - Correct one of the identical sub-expressions on both sides of operator "XXX".
      - Correct one of the identical sub-expressions on both sides of equals.
      - Correct one of the identical argument sub-expressions.
      Show
      - Correct one of the identical sub-expressions on both sides of operator "XXX". - Correct one of the identical sub-expressions on both sides of equals. - Correct one of the identical argument sub-expressions.
    • Highlighting:
      • primary location: right operand
      • secondary location: equivalent left operand
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Flex, PL/I, VB6
    • Covered Languages:
      ABAP, C#, C, C++, Cobol, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, Python, RPG, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net
    • Irrelevant for Languages:
      HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • CERT:
      MSC12-C.
    • CPPCheck:
      comparisonFunctionIsAlwaysTrueOrFalse, duplicateExpression
    • ESLint:
      no-self-compare
    • ESLint-SonarJS:
      no-identical-expressions
    • FindBugs:
      SA_FIELD_SELF_COMPARISON, SA_LOCAL_SELF_COMPARISON, SA_FIELD_SELF_COMPUTATION, SA_LOCAL_SELF_COMPUTATION,RpC_REPEATED_CONDITIONAL_TEST
    • ReSharper:
      EqualExpressionComparison
    • TSLint-SonarTS:
      no-identical-expressions

      Description

      Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste error and therefore a bug, or it is simply wasted code, and should be simplified. In the case of bitwise operators and most binary mathematical operators, having the same value on both sides of an operator yields predictable results, and should be simplified.

      Exceptions

      This rule ignores *, +, and =.

      See

      • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
      • S1656 - Implements a check on =.

        Attachments

          Issue Links

          1.
          Java RSPEC-2079 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-2080 Language-Specification Active Unassigned
          3.
          COBOL RSPEC-2584 Language-Specification Active Unassigned
          4.
          JavaScript RSPEC-2686 Language-Specification Active Unassigned
          5.
          C# RSPEC-2739 Language-Specification Active Unassigned
          6.
          PHP RSPEC-2839 Language-Specification Active Unassigned
          7.
          RPG RSPEC-2917 Language-Specification Active Unassigned
          8.
          Swift RSPEC-3088 Language-Specification Active Unassigned
          9.
          VB.NET RSPEC-3712 Language-Specification Active Unassigned
          10.
          Python RSPEC-3820 Language-Specification Active Unassigned
          11.
          T-SQL RSPEC-4090 Language-Specification Active Unassigned
          12.
          PL/SQL RSPEC-4229 Language-Specification Active Unassigned
          13.
          Go RSPEC-4514 Language-Specification Active Unassigned
          14.
          Apex RSPEC-4979 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: