Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Remove these useless parentheses.
-
Highlighting:
-
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
- implements
-
SONARSWIFT-144 Rule: Useless parentheses around expressions should be removed to prevent any misunderstanding
-
- Closed
-
- is implemented by
-
SONARFLEX-102 Rule: Redundant pairs of parentheses should be removed
-
- Open
-
-
SONARPLI-163 Rule: Redundant pairs of parentheses should be removed
-
- Open
-
-
SONARRPG-163 Rule: Redundant pairs of parentheses should be removed
-
- Open
-
-
SONARVBSIX-238 Rule: Redundant pairs of parentheses should be removed
-
- Open
-
-
CPP-1772 Rule: Redundant parentheses should be removed
-
- Closed
-
-
SONARABAP-314 Rule: Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARCOBOL-1438 Rule: Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARPHP-687 Rule S1110: Redundant parentheses should be removed
-
- Closed
-
-
SONARPLSQL-597 Rule: Redundant parentheses should be removed
-
- Closed
-
-
SONARSLANG-73 Rule S1110: Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARSLANG-236 [Scala] Enable Rule: S1110 Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARSLANG-305 [Apex] Enable Rule: S1110 Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARTSQL-52 Rule: Redundant pairs of parentheses should be removed
-
- Closed
-
-
SONARSLANG-430 [Go] Enable rule S2757 and S1110
-
- Closed
-
- is related to
-
CPP-3263 S1110: Fix false-negative for nested parens in decltype(auto) and c-style cast
-
- Open
-
-
CPP-2801 S1110: Improve support of subscript operator and parenthesized references to variables
-
- Closed
-
-
CPP-2865 S1110: Fix false positive with comma operator
-
- Closed
-
-
CPP-3080 S1110: Fix false-negative on parenthesized literal
-
- Closed
-
-
CPP-3081 S1110: Fix false-positive on decltype(auto) and parenthized initializer
-
- Closed
-
- links to
1.
|
Python | RSPEC-2759 |
|
Active | Unassigned | |
2.
|
Swift | RSPEC-2941 |
|
Active | Unassigned | |
3.
|
JavaScript | RSPEC-3701 |
|
Active | Unassigned | |
4.
|
C# | RSPEC-3920 |
|
Active | Unassigned | |
5.
|
C-Family | RSPEC-3930 |
|
Active | Unassigned | |
6.
|
T-SQL | RSPEC-4160 |
|
Active | Unassigned | |
7.
|
PL/SQL | RSPEC-4238 |
|
Active | Unassigned | |
8.
|
ABAP | RSPEC-4249 |
|
Active | Unassigned | |
9.
|
COBOL | RSPEC-4273 |
|
Active | Unassigned | |
10.
|
PHP | RSPEC-4310 |
|
Active | Unassigned | |
11.
|
Go | RSPEC-4549 |
|
Active | Unassigned | |
12.
|
Kotlin | RSPEC-4704 |
|
Active | Unassigned | |
13.
|
Ruby | RSPEC-4756 |
|
Active | Unassigned | |
14.
|
Scala | RSPEC-4941 |
|
Active | Unassigned | |
15.
|
Apex | RSPEC-5009 |
|
Active | Unassigned | |
16.
|
VB.NET | RSPEC-5219 |
|
Active | Unassigned |