From 8d25c52744a14692152be8a99f51485157a7abc8 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 16:36:36 +0100 Subject: [PATCH] delete test files because of PR #6 on ecoCode-java repo (deletion of deprecated java rules EC4, EC53, EC63 and EC75) --- CHANGELOG.md | 17 ---- .../checks/AvoidConcatenateStringsInLoop.java | 32 -------- .../AvoidUsingGlobalVariablesCheck.java | 21 ----- ...arilyAssignValuesToVariablesTestCheck.java | 78 ------------------- ...esToVariablesTestCheckWithEmptyReturn.java | 18 ----- .../java/checks/UseCorrectForLoopCheck.java | 24 ------ 6 files changed, 190 deletions(-) delete mode 100644 CHANGELOG.md delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 8ca0454..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,17 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -### Added - -### Changed - -- Rules elimination test for [Remove deprecated rules EC4, EC53, EC63 and EC75 for JAVA](https://github.com/green-code-initiative/ecoCode/pull/272) - -### Deleted - diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java deleted file mode 100644 index c5079eb..0000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -public class AvoidConcatenateStringsInLoop { - - public String concatenateStrings(String[] strings) { - String result1 = ""; - - for (String string : strings) { - result1 += string; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result1; - } - - public String concatenateStrings2() { - String result2 = ""; - - for (int i = 0; i < 1000; ++i) { - result2 += "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result2; - } - - public String concatenateStrings3() { - String result3 = ""; - - for (int i = 0; i < 1000; ++i) { - result3 = result3 + "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result3; - } - -} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java deleted file mode 100644 index 3dea9e3..0000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ /dev/null @@ -1,21 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -public class AvoidUsingGlobalVariablesCheck { - public static double price = 15.24; // Noncompliant {{Avoid using global variables}} - public static long pages = 1053; // Noncompliant {{Avoid using global variables}} - - public static void main(String[] args) { - double newPrice = AvoidUsingGlobalVariablesCheck.price; - long newPages = AvoidUsingGlobalVariablesCheck.pages; - System.out.println(newPrice); - System.out.println(newPages); - } - static{ // Noncompliant {{Avoid using global variables}} - int a = 4; - } - - public void printingA() { - System.out.println("a"); - } - -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java deleted file mode 100644 index b61a58e..0000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ /dev/null @@ -1,78 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -class UnnecessarilyAssignValuesToVariablesTestCheck { - UnnecessarilyAssignValuesToVariablesTestCheck(UnnecessarilyAssignValuesToVariablesTestCheck mc) { - } - - public int testSwitchCase() throws Exception { - int variableFor = 5; - int variableIf = 5; - int variableWhile = 5; - int variableExp = 5; - int variableReturn = 5; - int variableCLass = 5; - int[] intArray = {10, 20, 30, 40, 50}; - - Exception variableException = new Exception("message"); - int variableNotUse = 5; // Noncompliant {{The variable is declared but not really used}} - - - variableNotUse = 10; - for (variableFor = 0; variableFor < 5; ++variableFor) { - System.out.println(variableFor); - } - - for (int ia : intArray) { - System.out.println((char) ia); - } - - if (variableIf > 10) { - System.out.println(variableIf); - } - - while (variableWhile > 10) { - System.out.println(variableWhile); - } - - variableExp += 1; - variableNotUse = variableExp; - TestClass testClass = new TestClass(variableCLass); - if (testClass.isTrue()) { - throw variableException; - } - return variableReturn; - } - - private class TestClass { - TestClass(int i) { - ++i; - } - - public boolean isTrue() { - return true; - } - } - - - private int getIntValue() { - return 3; - } - - public int testNonCompliantReturn() { - int i = getIntValue(); // Noncompliant {{Immediately return this expression instead of assigning it to the temporary variable}} - return i; - } - - public int testCompliantReturn() { - return getIntValue(); - } - - public void testNonCompliantThrow() throws Exception { - Exception exception = new Exception("dummy"); // Noncompliant {{Immediately throw this expression instead of assigning it to the temporary variable}} - throw exception; - } - - public void testCompliantThrow() throws Exception { - throw new Exception("dummy"); - } -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java deleted file mode 100644 index 4dbb952..0000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java +++ /dev/null @@ -1,18 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -import java.util.ArrayList; - -class UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn { - UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn(UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn mc) { - } - - public void testSwitchCase() { - - ArrayList lst = new ArrayList(0); - if (lst == null) { - return; - } - System.out.println(lst); - } - -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java deleted file mode 100644 index fe5ee97..0000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java +++ /dev/null @@ -1,24 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -import java.util.Arrays; -import java.util.List; - -class UseCorrectForLoopCheck { - UseCorrectForLoopCheck(UseCorrectForLoopCheck mc) { - } - - private final Integer[] intArray = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - private final List intList = Arrays.asList(intArray); - - public void testForEachLoop() { - int dummy = 0; - for (Integer i : intArray) { - dummy += i; - } // Noncompliant {{Avoid the use of Foreach with Arrays}} - - for (Integer i : intList) { - dummy += i; - } - System.out.println(dummy); - } -} \ No newline at end of file