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

Redundant pairs of parentheses should be removed

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove these useless parentheses.
    • Highlighting:
      Hide

      primary: the extra (
      2ndary: )

      Show
      primary: the extra ( 2ndary: )
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      Parentheses, UselessParenthesesCheck
    • Targeted languages:
      Flex, PL/I, RPG, VB6
    • Covered Languages:
      ABAP, C#, C, C++, Cobol, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, Python, Ruby, Swift, T-SQL, TypeScript, VB.Net
    • Irrelevant for Languages:
      HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • Checkstyle:
      UnnecessaryParentheses
    • ESLint:
      no-extra-parens
    • PMD:
      UnnecessaryParentheses, UselessParentheses
    • PVS-Studio:
      V3088
    • Pylint:
      C0325
    • SwiftLint:
      control_statement

      Description

      The use of parentheses, even those not required to enforce a desired order of operations, can clarify the intent behind a piece of code. But redundant pairs of parentheses could be misleading, and should be removed.

      Noncompliant Code Example

      int x = (y / 2 + 1);   //Compliant even if the parenthesis are ignored by the compiler
      
      if (a && ((x+y > 0))) {  // Noncompliant
        //...
      }
      
      return ((x + 1));  // Noncompliant
      

      Compliant Solution

      int x = (y / 2 + 1);
      
      if (a && (x+y > 0)) {
        //...
      }
      
      return (x + 1);
      

        Attachments

          Issue Links

          1.
          Python RSPEC-2759 Language-Specification Active Unassigned
          2.
          Swift RSPEC-2941 Language-Specification Active Unassigned
          3.
          JavaScript RSPEC-3701 Language-Specification Active Unassigned
          4.
          C# RSPEC-3920 Language-Specification Active Unassigned
          5.
          C-Family RSPEC-3930 Language-Specification Active Unassigned
          6.
          T-SQL RSPEC-4160 Language-Specification Active Unassigned
          7.
          PL/SQL RSPEC-4238 Language-Specification Active Unassigned
          8.
          ABAP RSPEC-4249 Language-Specification Active Unassigned
          9.
          COBOL RSPEC-4273 Language-Specification Active Unassigned
          10.
          PHP RSPEC-4310 Language-Specification Active Unassigned
          11.
          Go RSPEC-4549 Language-Specification Active Unassigned
          12.
          Kotlin RSPEC-4704 Language-Specification Active Unassigned
          13.
          Ruby RSPEC-4756 Language-Specification Active Unassigned
          14.
          Scala RSPEC-4941 Language-Specification Active Unassigned
          15.
          Apex RSPEC-5009 Language-Specification Active Unassigned
          16.
          VB.NET RSPEC-5219 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: