Skip to content

Commit

Permalink
[ISSUE 240] deprecation of EC53 rule for java
Browse files Browse the repository at this point in the history
  • Loading branch information
dedece35 committed Dec 11, 2023
1 parent e1ba914 commit 2020d7e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deleted

- [#240](https://github.com/green-code-initiative/ecoCode/issues/240) Deprecate rule EC53 for Java because of no good arguments and not enough green measures
- [#258](https://github.com/green-code-initiative/ecoCode/pull/258) Deprecate rule EC63 for Java because there are already 3 native Sonarqube rules that cover the same use cases

## [1.4.2] - 2023-12-05
Expand Down
2 changes: 1 addition & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Some are applicable for different technologies.
| EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 || 🚀 | 🚀 | 🚀 |
| ??? | Call a DOM element multiple times without caching (linter key : `@ecocode/no-multiple-access-dom-element`) | Access to the Document Object Model (DOM) is costly in terms of CPU resources (CPU cycles). Also, when you use the same DOM element from JavaScript multiple times, store its reference in a variable so that you do not go through the DOM again for the same element. | [cnumr best practices (3rd edition) BP_049](https://github.com/cnumr/best-practices/blob/main/chapters/BP_049_fr.md) | 🚫 | 🚫 || 🚫 | 🚫 |
| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚫 || 🚀 || 🚀 |
| EC53 | Using arrays in foreach loops | foreach deduplicates items in a list before starting the enumeration. It is therefore generally more economical to use a simple for loop when you have a good command of the collection. | [cnumr best practices (3rd edition) BP_053 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) || 🚀 | 🚀 | 🚫 | 🚀 |
| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | 🚀 | 🚀 || 🚀 |
| EC66 | Use single quote (') instead of quotation mark (") | The shape using the quotation marks allows the developer to insert variables that will be substituted at run time. But if the string does not have a variable, use quotes instead. Thus, language will not look for variables to subtituture, which will reduce the consumption of CPU cycles. | [cnumr best practices (3rd edition) BP_066 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 || 🚀 | 🚫 <br>[see](https://github.com/green-code-initiative/ecoCode-python/issues/4) | 🚀 |
| EC67 | Use the $i++ variable during an iteration | The $i++ form has the disadvantage of generating a tem-porary variable during incrementation, which is not the case with the ++$i form. | [cnumr best practices (3rd edition) BP_067 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) ||| 🚀 | 🚫 | 🚫 |
Expand Down Expand Up @@ -63,6 +62,7 @@ This table lists rules proposed by the community but deprecated in ecoCode plugi
|----------|---------------------|---------------------------------------------|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| EC4 | Java | Avoid using global variables | Global variables do not exist in Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/233) |
| EC34 | Java / Python / PHP | Using try...catch...finally calls | Implementation is too simple (only detection of presence of "try" statement) AND replaced by `EC35` rule | Github discussion with measures : [general/java](https://github.com/green-code-initiative/ecoCode/pull/128) / [python](https://github.com/green-code-initiative/ecoCode-python/pull/6) / [php](https://github.com/green-code-initiative/ecoCode-php/pull/10) |
| EC53 | Java | Using arrays in foreach loops | No good arguments and not enough green measures. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/240) |
| EC63 | Java | Unnecessarily assigning values to variables | There are already 3 native SonarQube rules for Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/pull/258) |

## Refused / Deleted rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
*This rule is deprecated because there aren't enough good arguments and not enough green measures / benchmarks, and will be removed soon.*

== Why is this an issue?

Using List instead of Arrays with Foreach save CPU cycles calculations and RAM consumption.

## Noncompliant Code Example
== Noncompliant Code Example

```java
[source,java]
----
private final Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for (Integer i : intArray) {
// ...
}
```
----

## Compliant Solution
== Compliant Solution

```java
[source,java]
----
private final List<Integer> intList = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
for (Integer i : intList) {
// ...
}
```
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "deprecated"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;

/**
* @deprecated there aren't enough good arguments and not enough green measures / benchmarks
* (check discussion on https://github.com/green-code-initiative/ecoCode/issues/240)
*/
@Deprecated(forRemoval = true)
@Rule(key = "EC53")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S53")
public class UseCorrectForLoop extends IssuableSubscriptionVisitor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

@Deprecated
class UseCorrectLoopCheckTest {

@Test
Expand Down

0 comments on commit 2020d7e

Please sign in to comment.