Remove non-reachable code
Platform
| OS |
OS version |
Langage |
| All OS/Especially Javascript, PHP and languages other than JAVA and C# |
|
|
Rule short description
SonarQube as a code profiler has checks to list out unused variable, unused arguments etc but there are no rules to check for unused code. Intelligent editors of Java and .NET tackles this issue, but there is no way to detect this issue in Javascript and other scripting languages.
Rule complete description
Check for non-reachable code. Removing non-reachable code can lead to compiler optimization resulting in less CPU work, less memory usage and thus saving energy consumption
Also, leaving such unused code in the software results in maintainability issues for the support team. This results in increased efforts leading to increased usage of resources like device power consumption.
Optimized API: List Shallow Copy - Module copy
Platform
| OS |
OS version |
Langage |
| - |
- |
Python |
Main caracteristics
| ID |
Title |
Category |
Sub-category |
| EOPT001 |
List Shallow Copy - Module copy |
Environment |
Optimized API |
Severity / Remediation Cost
| Severity |
Remediation Cost |
| Minor |
Minor |
Rule short description
Using copy.copy(x) of module copy to perform a shallow copy of a list is not energy efficient.
Rule complete description
Text
Using copy.copy(x) of module copy to perform a shallow copy of a list is not energy efficient.
Prefer the usage of list.copy() which is more energy friendly.
HTML
<p>Using <code>copy.copy(x)</code> of <code>module copy</code> to perform a shallow
copy of a list is not energy efficient.</p>
<p>Prefer the usage of <code>list.copy()</code> which is more energy friendly.</p>
<h2>Noncompliant Code Example</h2>
<pre>
import copy
my_list = [1, 2, [3, 4], 5]
list_copy = copy.copy(my_list)
</pre>
<h2>Compliant Solution</h2>
<pre>
my_list = [1, 2, [3, 4], 5]
list_copy = my_list.copy()
</pre>
Implementation principle
- Inspect the import node to find
copy import
- Inspect the ARG_LIST node
- If the direct parent is CALL_EXPR tree and the function is
copy.copy()
- If the function is present, check the first argument
- If it is a list, report the line
Remove non-reachable code
Platform
Rule short description
SonarQube as a code profiler has checks to list out unused variable, unused arguments etc but there are no rules to check for unused code. Intelligent editors of Java and .NET tackles this issue, but there is no way to detect this issue in Javascript and other scripting languages.
Rule complete description
Check for non-reachable code. Removing non-reachable code can lead to compiler optimization resulting in less CPU work, less memory usage and thus saving energy consumption
Also, leaving such unused code in the software results in maintainability issues for the support team. This results in increased efforts leading to increased usage of resources like device power consumption.
Optimized API: List Shallow Copy - Module copy
Platform
Main caracteristics
Severity / Remediation Cost
Rule short description
Using
copy.copy(x)ofmodule copyto perform a shallow copy of a list is not energy efficient.Rule complete description
Text
Using
copy.copy(x)ofmodule copyto perform a shallow copy of a list is not energy efficient.Prefer the usage of
list.copy()which is more energy friendly.HTML
Implementation principle
copyimportcopy.copy()