Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Update this method so that its implementation is not identical to "xxx".
-
Highlighting:
- primary: method signature
- secondary: original method
- message: "Original implementation."
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Targeted languages:Flex, Rust, Solidity, VB6
-
Covered Languages:C#, C, C++, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Python, Ruby, Scala, Swift, TypeScript, VB.Net
-
Irrelevant for Languages:ABAP, Cobol, CSS, HTML, PL/I, PL/SQL, RPG, T-SQL, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:15min
-
Analysis Level:Syntactic Analysis
-
Analysis Scope:Main Sources, Test Sources
-
Common Rule:Yes
-
ESLint-SonarJS:no-identical-functions
Description
When two methods have the same implementation, either it was a mistake - something else was intended - or the duplication was intentional, but may be confusing to maintainers. In the latter case, one implementation should invoke the other. Numerical and string literals are not taken into account.
Noncompliant Code Example
private final static String CODE = "bounteous"; public String calculateCode() { doTheThing(); return CODE; } public String getName() { // Noncompliant doTheThing(); return CODE; }
Compliant Solution
private final static String CODE = "bounteous"; public String getCode() { doTheThing(); return CODE; } public String getName() { return getCode(); }
Exceptions
Methods that are not accessors (getters and setters), with fewer than 2 statements are ignored.
Attachments
Issue Links
- is implemented by
-
SONARFLEX-140 Rule: Methods should not have identical implementations
-
- Open
-
-
SONARVBSIX-274 Rule: Methods should not have identical implementations
-
- Open
-
-
CPP-1891 Rule: Methods should not have identical implementations
-
- Closed
-
-
SONARJAVA-2405 Rule S4144: Methods should not have identical implementations
-
- Closed
-
-
SONARPHP-715 Rule S4144: Methods should not have identical implementations
-
- Closed
-
-
SONARPY-221 Rule S4144: Methods should not have identical implementations
-
- Closed
-
-
SONARSLANG-2 Rule S4144: Functions should not have identical implementations
-
- Closed
-
-
SONARSLANG-158 Enable in Ruby rule S4144 (DuplicatedFunctionImplementationCheck)
-
- Closed
-
-
SONARSLANG-227 [Scala] Enable Rule: S4144 Methods should not have identical implementations
-
- Closed
-
-
SONARSLANG-314 [Apex] Enable Rule: S4144 Methods should not have identical implementations
-
- Closed
-
-
SONARSWIFT-301 Rule: Methods should not have identical implementations
-
- Closed
-
-
SONARSLANG-423 [Go] Enable rules relying on functions
-
- Closed
-
-
SONARSLANG-174 S4144 (DuplicatedFunctionImplementationCheck) should not ignore literal values during syntactic equivalence evaluation
-
- Closed
-
- is related to
-
CPP-2510 S3923: Improve code equivalence checking in case of macro expansion
-
- Open
-
- links to
1.
|
C# | RSPEC-4203 |
|
Active | Unassigned | |
2.
|
VB.Net | RSPEC-4251 |
|
Active | Unassigned | |
3.
|
C-Family | RSPEC-4259 |
|
Active | Unassigned | |
4.
|
PHP | RSPEC-4319 |
|
Active | Unassigned | |
5.
|
JavaScript: Functions should not have identical implementations | RSPEC-4460 |
|
Active | Unassigned | |
6.
|
Go: Functions should not have identical implementations | RSPEC-4516 |
|
Active | Unassigned | |
7.
|
Swift: Functions should not have identical implementations | RSPEC-4615 |
|
Active | Unassigned | |
8.
|
Kotlin: Functions should not have identical implementations | RSPEC-4685 |
|
Active | Unassigned | |
9.
|
Ruby | RSPEC-4780 |
|
Active | Unassigned | |
10.
|
Scala | RSPEC-4935 |
|
Active | Unassigned | |
11.
|
Apex | RSPEC-5022 |
|
Active | Unassigned | |
12.
|
Python: Functions and methods should not have identical implementations | RSPEC-5585 |
|
Active | Unassigned |