diff --git a/CHANGELOG.md b/CHANGELOG.md index 06978243..bcf7430d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refuse rule proposition [Avoid returning a JPA Entity in a RestController](https://github.com/green-code-initiative/ecoCode/pull/138) for Java because of lack of arguments and measures - Refuse rule proposition [Avoid use of static in interface](https://github.com/green-code-initiative/ecoCode/pull/7) for Java because of lack of arguments and measures +- Deprecated java rules EC4, EC53, EC63 and EC75 - update RULES.md : close 2 old PRs and add to rework rules array ### Deleted diff --git a/RULES.md b/RULES.md index 95e6aae3..8fc29913 100644 --- a/RULES.md +++ b/RULES.md @@ -68,6 +68,7 @@ This table lists rules proposed by the community but they have to be reworked / | EC22 | Java | The use of methods for basic operations | We have to measure this rule for Java before accepting the implementation | [Github discussion - issue](https://github.com/green-code-initiative/ecoCode/issues/131)
[Github discussion - PR](https://github.com/green-code-initiative/ecoCode/pull/148) | | CRJVM204 | Java | Detect unoptimized file formats | We have to clarify and rework this rule for Java before accepting the implementation | [Github discussion - issue](https://github.com/green-code-initiative/ecoCode/issues/105)
[Github discussion - PR](https://github.com/green-code-initiative/ecoCode/pull/153) | | | Java | Avoid returning a JPA Entity in a RestController | We have to clarify and measure this rule for Java before accepting the implementation | [Github discussion - issue](https://github.com/green-code-initiative/ecoCode-challenge/issues/58)
[Github discussion - PR](https://github.com/green-code-initiative/ecoCode/pull/138) | +| 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) | | GRSP0007 | PHP | Prefer using foreach | We have to clarify and measure this rule for PHP before accepting the implementation | [Github discussion - PR](https://github.com/green-code-initiative/ecoCode/pull/5) | | GRSP0008 | PHP | Avoid using relative path | We have to clarify and measure this rule for PHP before accepting the implementation | [Github discussion - PR](https://github.com/green-code-initiative/ecoCode/pull/6) | @@ -77,18 +78,18 @@ This table lists rules proposed by the community but deprecated in ecoCode plugi | Rule key | Language | Name | Description | Invalidation | |----------|---------------------|----------------------------------------------------|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 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) | | EC66 | Python | Use single quote (') instead of quotation mark (") | Finally, not applicable for Python | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode-python/issues/4) | -| EC75 | Java | Concatenate Strings in loop | Optimizations on Java concatenation Strings are useless since JDK8 | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/246) | ## Refused / Deleted rules This table lists rules proposed by the community but refused or/and deleted in ecoCode plugins with the justification. -| Rule key | Language | Name | Description | Invalidation | -|----------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| CRDOM203 | HTML | HTML page must contain a doctype tag | The difference in performance is negligible, this rule is more related to the user experience. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/103) | -| CRPYT | Python | Use numpy array instead of standard list | The use of numpy library to perform array manipulation is more energy efficient than the use of the standard list functions. | [Github discussion with measures](https://github.com/green-code-initiative/ecoCode/issues/132) | +| Rule key | Language | Name | Description | Invalidation | +|----------|----------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| CRDOM203 | HTML | HTML page must contain a doctype tag | The difference in performance is negligible, this rule is more related to the user experience. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/103) | +| CRPYT | Python | Use numpy array instead of standard list | The use of numpy library to perform array manipulation is more energy efficient than the use of the standard list functions. | [Github discussion with measures](https://github.com/green-code-initiative/ecoCode/issues/132) | +| 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) | +| 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) | +| EC75 | Java | Concatenate Strings in loop | Optimizations on Java concatenation Strings are useless since JDK8 | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/246) | + diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml index be5d0377..187f901f 100644 --- a/ecocode-rules-specifications/pom.xml +++ b/ecocode-rules-specifications/pom.xml @@ -5,7 +5,7 @@ io.ecocode ecocode-parent - 1.4.8-SNAPSHOT + 1.5.0-SNAPSHOT ecocode-rules-specifications diff --git a/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc b/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc deleted file mode 100644 index 0aba43f6..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc +++ /dev/null @@ -1,41 +0,0 @@ -*This rule is deprecated because not applicable to Java, and will be removed soon.* - -== Why is this an issue? - -When calling a global variable, the interpretation engine must check that it exists in all the scopes, that it has a value, etc. Passing global variables as arguments gives them the status of local variables inside the function, thus saving computing time (CPU cycles). - -=== CASE 1 (Avoid as possible) - -You are back on the service code. You see that the `func1()` uses `globalVariabl1`. Okay, but whats its value by now ? How does it change ? Who mutates the `globalVariabl1` before it comes to this function ? What have been the sequence of all these mutations ? You would have no idea. It will be quite difficult to figure all this out. - -=== CASE 2 (Recommended) - -You are back to you code, and see that the `func0()` fetches something and then passes it to `func1(param1)` as a parameter. You clearly know what the data is, how does it gets here. - -=== Noncompliant Code Example - -[source,java] ----- -var aGlobal = new String('Hello'); - -function globalLength(){ - length = aGlobal.length; - console.log(length); -} - -globalLength(); ----- - -== Compliant Solution - -[source,java] ----- -var aGlobal = new String('Hello'); - -function someVarLength(str){ - length = str.length; - console.log(length); -} - -somVarLength(aGlobal); ----- diff --git a/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.json b/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.json deleted file mode 100644 index 0b963543..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "status": "deprecated" -} diff --git a/ecocode-rules-specifications/src/main/rules/EC63/EC63.json b/ecocode-rules-specifications/src/main/rules/EC63/EC63.json deleted file mode 100644 index dc918990..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC63/EC63.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "title": "Do not unnecessarily assign values to variables", - "type": "CODE_SMELL", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" - }, - "tags": [ - "eco-design", - "ecocode", - "memory" - ], - "defaultSeverity": "Minor" -} diff --git a/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc b/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc deleted file mode 100644 index b5f7ea88..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc +++ /dev/null @@ -1,23 +0,0 @@ -*This rule is deprecated because there are already Sonarqube native rules for the same things, and will be removed soon.* - -== Why is this an issue? - -Do not unnecessarily assign values to variables. It increases the use of RAM memory. - -== Noncompliant Code Example - -[source,java] ----- -String var1 = getValue(); -return var1; - -String var2 = "hello" -var2 = "world" //Non compliant cause never assigned ----- - -== Compliant Solution - -[source,java] ----- -return getValue(); ----- diff --git a/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.json b/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.json deleted file mode 100644 index 0b963543..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "status": "deprecated" -} diff --git a/ecocode-rules-specifications/src/main/rules/EC75/EC75.json b/ecocode-rules-specifications/src/main/rules/EC75/EC75.json deleted file mode 100644 index 42cef301..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC75/EC75.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "title": "Don't concatenate Strings in loop, use StringBuilder instead.", - "type": "CODE_SMELL", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "20min" - }, - "tags": [ - "performance", - "eco-design", - "ecocode", - "memory" - ], - "defaultSeverity": "Minor" -} diff --git a/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc b/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc deleted file mode 100644 index a0b7dad9..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc +++ /dev/null @@ -1,44 +0,0 @@ -*This rule is deprecated because not applicable to Java since JDK8, and will be removed soon.* - -== Why is this an issue? - -Don't concatenate Strings in loop. Use `StringBuilder instead. - -Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU. - -== Noncompliant Code Example - -[source,java] ----- -public String concatenateStrings(String[] strings) { - String result = ""; - - for (String string : strings) { - result += string; // Noncompliant - } - return result; -} - -public String concatenateStrings2() { - String result = ""; - - for (int i = 0; i < 1000; ++i) { - result += "another"; // Noncompliant - } - return result; -} ----- - -== Compliant Solution - -[source,java] ----- -public String concatenateStrings(String[] strings) { - StringBuilder result = new StringBuilder(); - - for (String string : strings) { - result.append(string); - } - return result.toString(); -} ----- diff --git a/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.json b/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.json deleted file mode 100644 index 0b963543..00000000 --- a/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "status": "deprecated" -} diff --git a/pom.xml b/pom.xml index 099348e0..19affc8a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-parent - 1.4.8-SNAPSHOT + 1.5.0-SNAPSHOT pom ecoCode Sonar Plugins Project