Details
-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:None
-
Message:
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Targeted languages:Flex, PL/I, RPG, Rust, Scala, Solidity, T-SQL
-
Covered Languages:C#, C, C++, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Python, Ruby, TypeScript, VB.Net
-
Irrelevant for Languages:ABAP, Cobol, HTML, Kotlin, PL/SQL, Swift, VB6, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:2min
-
Analysis Level:Syntactic Analysis
-
Analysis Scope:Main Sources, Test Sources
-
Common Rule:Yes
-
PVS-Studio:V588, V589, V3034, V3035, V3036
-
TSLint-SonarTS:no-misspelled-operator
Description
The use of operators pairs ( =+, =- or =! ) where the reversed, single operator was meant (+=, -= or !=) will compile and run, but not produce the expected results.
This rule raises an issue when =+, =-, or =! is used without any spacing between the two operators and when there is at least one whitespace character after.
Noncompliant Code Example
int target = -5; int num = 3; target =- num; // Noncompliant; target = -3. Is that really what's meant? target =+ num; // Noncompliant; target = 3
Compliant Solution
int target = -5; int num = 3; target = -num; // Compliant; intent to assign inverse value of num is clear target += num;
Attachments
Issue Links
- is implemented by
-
SONARFLEX-130 Rule: "=+" should not be used instead of "+="
-
- Open
-
-
SONARPLI-185 Rule: "=+" should not be used instead of "+="
-
- Open
-
-
SONARRPG-177 Rule: "=+" should not be used instead of "+="
-
- Open
-
-
SONARTSQL-115 Rule: "=+" should not be used instead of "+="
-
- Open
-
-
CPP-1113 Rule: Reversed operators should not be used
-
- Closed
-
-
SONARJAVA-2217 Rule S2757: "=+" should not be used instead of "+="
-
- Closed
-
-
SONARPHP-694 Rule S2757: "=+" should not be used instead of "+="
-
- Closed
-
-
SONARPY-204 Rule S2757: "=+" should not be used instead of "+="
-
- Closed
-
-
SONARSLANG-109 Rule S2757: "=+" should not be used instead of "+="
-
- Closed
-
-
SONARSLANG-231 [Scala] Enable Rule: S2757 "=+" should not be used instead of "+="
-
- Closed
-
-
SONARSLANG-310 [Apex] Enable Rule: S2757 "=+" should not be used instead of "+="
-
- Closed
-
-
SONARSLANG-430 [Go] Enable rule S2757 and S1110
-
- Closed
-
- links to
1.
|
C-family | RSPEC-3550 |
|
Active | Unassigned | |
2.
|
JavaScript: Non-existent operators '=+', '=-' and '=!' should not be used | RSPEC-3775 |
|
Active | Unassigned | |
3.
|
PHP | RSPEC-4321 |
|
Active | Unassigned | |
4.
|
Go | RSPEC-4559 |
|
Active | Unassigned | |
5.
|
Ruby | RSPEC-4788 |
|
Active | Unassigned | |
6.
|
Kotlin | RSPEC-4789 |
|
Active | Unassigned | |
7.
|
VB.Net | RSPEC-4878 |
|
Active | Unassigned | |
8.
|
Apex | RSPEC-5011 |
|
Active | Unassigned | |
9.
|
Python | RSPEC-5578 |
|
Active | Unassigned |