Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC75] Deprecation of rule EC75 for java #259

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#4](https://github.com/green-code-initiative/ecoCode-python/issues/4) Deprecate rule EC66 for Python because not applicable (see details inside issue)
- [#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
- [#259](https://github.com/green-code-initiative/ecoCode/pull/259) Deprecate rule EC75 for Java because not applicable since JDK8

## [1.4.2] - 2023-12-05

Expand Down
1 change: 1 addition & 0 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ This table lists rules proposed by the community but deprecated in ecoCode plugi
| 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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
*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
== Noncompliant Code Example

```java
[source,java]
----
public String concatenateStrings(String[] strings) {
String result = "";

Expand All @@ -22,11 +27,12 @@ public String concatenateStrings2() {
}
return result;
}
```
----

## Compliant Solution
== Compliant Solution

```java
[source,java]
----
public String concatenateStrings(String[] strings) {
StringBuilder result = new StringBuilder();

Expand All @@ -35,4 +41,4 @@ public String concatenateStrings(String[] strings) {
}
return result.toString();
}
```
----
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 @@ -30,6 +30,10 @@
import org.sonar.plugins.java.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;

/**
* @deprecated because not useless since JDK 8
*/
@Deprecated(forRemoval = true)
@Rule(key = "EC75")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S75")
public class AvoidConcatenateStringsInLoop 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
public class AvoidConcatenateStringsInLoopTest {

@Test
Expand Down