From 5c0d987932dd03bbbf56fbaab82bf9ab9251099a Mon Sep 17 00:00:00 2001 From: jycr Date: Tue, 27 Jun 2023 09:21:54 +0200 Subject: [PATCH] green-code-initiative/ecoCode#92 improves code quality (reduce code duplication) --- .../src/main/rules/EC3/EC3.json | 2 ++ .../src/main/rules/EC34/EC34.json | 2 +- .../src/main/rules/EC66/EC66.json | 1 + .../java/checks/ArrayCopyCheck.java | 7 +------ .../java/checks/AvoidConcatenateStringsInLoop.java | 9 +-------- .../java/checks/AvoidFullSQLRequest.java | 9 ++------- .../java/checks/AvoidGettingSizeCollectionInLoop.java | 7 +------ .../java/checks/AvoidMultipleIfElseStatement.java | 7 +------ .../java/checks/AvoidRegexPatternNotStatic.java | 8 +------- .../java/checks/AvoidSQLRequestInLoop.java | 4 +--- .../java/checks/AvoidSetConstantInBatchUpdate.java | 7 ++----- .../checks/AvoidSpringRepositoryCallInLoopCheck.java | 7 +------ .../java/checks/AvoidStatementForDMLQueries.java | 2 +- .../java/checks/AvoidUsageOfStaticCollections.java | 8 +------- .../java/checks/AvoidUsingGlobalVariablesCheck.java | 8 +------- .../checks/FreeResourcesOfAutoCloseableInterface.java | 8 +------- .../java/checks/IncrementCheck.java | 8 +------- .../checks/InitializeBufferWithAppropriateSize.java | 8 +------- .../checks/NoFunctionCallWhenDeclaringForLoop.java | 4 +--- .../java/checks/OptimizeReadFileExceptions.java | 8 +------- .../checks/UnnecessarilyAssignValuesToVariables.java | 4 +--- .../java/checks/UseCorrectForLoop.java | 8 +------- .../php/checks/AvoidDoubleQuoteCheck.java | 9 +-------- .../php/checks/AvoidFullSQLRequestCheck.java | 10 +--------- .../checks/AvoidGettingSizeCollectionInLoopCheck.java | 10 +--------- .../php/checks/AvoidSQLRequestInLoopCheck.java | 9 +-------- ...TryCatchFinallyCheck_NOK_failsAllTryStatements.java | 9 +-------- .../php/checks/AvoidUsingGlobalVariablesCheck.java | 9 +-------- .../greencodeinitiative/php/checks/IncrementCheck.java | 9 +-------- .../php/checks/NoFunctionCallWhenDeclaringForLoop.java | 9 +-------- .../php/checks/UseOfMethodsForBasicOperations.java | 9 +-------- .../python/checks/AvoidDoubleQuoteCheck.java | 9 +-------- .../python/checks/AvoidFullSQLRequest.java | 10 +--------- .../python/checks/AvoidGettersAndSetters.java | 9 +-------- .../checks/AvoidGlobalVariableInFunctionCheck.java | 9 +-------- .../checks/AvoidListComprehensionInIterations.java | 9 +-------- .../python/checks/AvoidSQLRequestInLoop.java | 10 +--------- .../python/checks/AvoidTryCatchFinallyCheck.java | 9 +-------- .../checks/AvoidUnoptimizedVectorImagesCheck.java | 9 +-------- .../python/checks/DetectUnoptimizedImageFormat.java | 8 +------- .../checks/NoFunctionCallWhenDeclaringForLoop.java | 9 +-------- 41 files changed, 44 insertions(+), 266 deletions(-) diff --git a/ecocode-rules-specifications/src/main/rules/EC3/EC3.json b/ecocode-rules-specifications/src/main/rules/EC3/EC3.json index f511c1c2a..ab4738751 100644 --- a/ecocode-rules-specifications/src/main/rules/EC3/EC3.json +++ b/ecocode-rules-specifications/src/main/rules/EC3/EC3.json @@ -7,6 +7,8 @@ "constantCost": "5min" }, "tags": [ + "bad-practice", + "performance", "eco-design", "performance", "ecocode" diff --git a/ecocode-rules-specifications/src/main/rules/EC34/EC34.json b/ecocode-rules-specifications/src/main/rules/EC34/EC34.json index 4191cbb71..00bc65320 100644 --- a/ecocode-rules-specifications/src/main/rules/EC34/EC34.json +++ b/ecocode-rules-specifications/src/main/rules/EC34/EC34.json @@ -1,5 +1,5 @@ { - "title": "Avoid using try-catch-finally statement", + "title": "Avoid using try-catch statement", "type": "CODE_SMELL", "status": "ready", "remediation": { diff --git a/ecocode-rules-specifications/src/main/rules/EC66/EC66.json b/ecocode-rules-specifications/src/main/rules/EC66/EC66.json index 6ed6137dc..034168254 100644 --- a/ecocode-rules-specifications/src/main/rules/EC66/EC66.json +++ b/ecocode-rules-specifications/src/main/rules/EC66/EC66.json @@ -7,6 +7,7 @@ "constantCost": "5min" }, "tags": [ + "bad-practice", "eco-design", "performance", "ecocode" diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 5abd5201e..080fc83d1 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -6,7 +6,6 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree; @@ -37,11 +36,7 @@ * @author Aubay * @formatter:off */ -@Rule(key = "EC27", - name = "Developpement", - description = ArrayCopyCheck.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC27") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRPS0027") public class ArrayCopyCheck extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java index 996043b5a..90d68b852 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java @@ -2,10 +2,8 @@ import java.util.Arrays; import java.util.List; - import javax.annotation.Nonnull; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; @@ -15,12 +13,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC75", - name = "Developpement", - description = AvoidConcatenateStringsInLoop.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode", "memory"}) +@Rule(key = "EC75") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S75") public class AvoidConcatenateStringsInLoop extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index 3d9bcc22f..e8dd5d28b 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -6,7 +6,7 @@ import static java.util.Collections.singletonList; import static java.util.regex.Pattern.CASE_INSENSITIVE; import static java.util.regex.Pattern.compile; -import org.sonar.check.Priority; + import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.LiteralTree; @@ -14,12 +14,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC74", - name = "Developpement", - description = AvoidFullSQLRequest.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "sql", "eco-design", "ecocode", "network"}) +@Rule(key = "EC74") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S74") public class AvoidFullSQLRequest extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index 9f70e0ede..7112bb685 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -5,7 +5,6 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.semantic.MethodMatchers; @@ -18,11 +17,7 @@ import org.sonar.plugins.java.api.tree.WhileStatementTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC3", - name = "Developpement", - description = AvoidGettingSizeCollectionInLoop.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC3") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GSCIL") public class AvoidGettingSizeCollectionInLoop extends IssuableSubscriptionVisitor { protected static final String MESSAGERULE = "Avoid getting the size of the collection in the loop"; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 64a8fa037..9460642ab 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -3,7 +3,6 @@ import java.util.Arrays; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.BlockTree; @@ -12,11 +11,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC2", - name = "Developpement", - description = AvoidMultipleIfElseStatement.RULE_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC2") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "AMIES") public class AvoidMultipleIfElseStatement extends IssuableSubscriptionVisitor { protected static final String RULE_MESSAGE = "Using a switch statement instead of multiple if-else if possible"; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 4b6949cce..a4e8e2f7e 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -6,7 +6,6 @@ import javax.annotation.Nonnull; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.semantic.MethodMatchers; @@ -16,12 +15,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC77", - name = "Developpement", - description = AvoidRegexPatternNotStatic.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"performance", "regex", "eco-design", "ecocode", "memory"}) +@Rule(key = "EC77") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S77") public class AvoidRegexPatternNotStatic extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index 532b89c12..297895e08 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -3,7 +3,6 @@ import java.util.Arrays; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.semantic.MethodMatchers; @@ -14,8 +13,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC72", name = "Developpement", description = AvoidSQLRequestInLoop.MESSAGERULE, priority = Priority.MINOR, - tags = {"performance", "sql", "spring", "eco-design", "ecocode", "memory", "network"}) +@Rule(key = "EC72") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S72") public class AvoidSQLRequestInLoop extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index 9a692f82d..4a014c2a3 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -6,7 +6,7 @@ import static fr.greencodeinitiative.java.checks.ConstOrLiteralDeclare.isLiteral; import static java.util.Arrays.asList; -import org.sonar.check.Priority; + import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.semantic.MethodMatchers; @@ -21,10 +21,7 @@ import static org.sonar.plugins.java.api.tree.Tree.Kind.MEMBER_SELECT; import static org.sonar.plugins.java.api.tree.Tree.Kind.METHOD_INVOCATION; -@Rule(key = "EC78", name = "Developpement", - description = AvoidSetConstantInBatchUpdate.MESSAGERULE, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "sql", "performance", "memory"}) +@Rule(key = "EC78") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S78") public class AvoidSetConstantInBatchUpdate extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index 5730b69d9..6cf843392 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -3,7 +3,6 @@ import java.util.Arrays; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.semantic.MethodMatchers; @@ -12,11 +11,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC1", - name = "Developpement", - description = AvoidSpringRepositoryCallInLoopCheck.RULE_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "spring", "eco-design", "ecocode"}) +@Rule(key = "EC1") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRC1") public class AvoidSpringRepositoryCallInLoopCheck extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index efd76ca31..f273ae707 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -14,7 +14,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC5", tags={"performance", "sql", "eco-design", "ecocode"}) +@Rule(key = "EC5") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "SDMLQ1") public class AvoidStatementForDMLQueries extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index d4de0d49e..c6eba94b7 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -6,7 +6,6 @@ import javax.annotation.Nonnull; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.BaseTreeVisitor; @@ -14,12 +13,7 @@ import org.sonar.plugins.java.api.tree.VariableTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC76", - name = "Developpement", - description = AvoidUsageOfStaticCollections.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"cwe", "leak", "eco-design", "ecocode", "memory"}) +@Rule(key = "EC76") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S76") public class AvoidUsageOfStaticCollections extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java index e2f08c522..bdc4dee1b 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java @@ -4,7 +4,6 @@ import java.util.List; import com.google.re2j.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.Tree; @@ -12,12 +11,7 @@ import org.sonar.plugins.java.api.tree.VariableTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC4", - name = "Developpement", - description = "

Prefer local variables to globals

", - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC4") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "D4") public class AvoidUsingGlobalVariablesCheck extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index 0cacf32d0..fb41ba0f7 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -8,7 +8,6 @@ import javax.annotation.ParametersAreNonnullByDefault; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.JavaFileScannerContext; @@ -19,12 +18,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC79", - name = "Developpement", - description = FreeResourcesOfAutoCloseableInterface.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC79") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S79") public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionVisitor { private final Deque withinTry = new LinkedList<>(); diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 1ac657aa3..7b480b1c7 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -3,19 +3,13 @@ import java.util.Collections; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.Tree; import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC67", - name = "Developpement", - description = IncrementCheck.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC67") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S67") public class IncrementCheck extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index 0090a7ac5..bb3cc4dd6 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.NewClassTree; @@ -11,12 +10,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC32", - name = "Developpement", - description = InitializeBufferWithAppropriateSize.RULE_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC32") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0032") public class InitializeBufferWithAppropriateSize extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 6c8758aa0..1c7c47347 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.BaseTreeVisitor; @@ -21,8 +20,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC69", name = "Developpement", description = NoFunctionCallWhenDeclaringForLoop.MESSAGERULE, priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC69") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S69") public class NoFunctionCallWhenDeclaringForLoop extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 0ee8a79c7..9766d2009 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -6,7 +6,6 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.CatchTree; @@ -16,12 +15,7 @@ import org.sonar.plugins.java.api.tree.TryStatementTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC28", - name = "Developpement", - description = OptimizeReadFileExceptions.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "error-handling", "eco-design", "ecocode"}) +@Rule(key = "EC28") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0028") public class OptimizeReadFileExceptions extends IssuableSubscriptionVisitor { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java index d8a7e69da..8c6dde8f0 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java @@ -1,6 +1,5 @@ package fr.greencodeinitiative.java.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.JavaFileScanner; import org.sonar.plugins.java.api.JavaFileScannerContext; @@ -11,8 +10,7 @@ import javax.annotation.CheckForNull; import java.util.*; -@Rule(key = "EC63", name = "Developpement", description = "Do not unnecessarily assign values to variables", priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "memory"}) +@Rule(key = "EC63") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S63") public class UnnecessarilyAssignValuesToVariables extends BaseTreeVisitor implements JavaFileScanner { diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java index 5cbc68e2f..6da7c13c1 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java @@ -3,7 +3,6 @@ import java.util.Arrays; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.ForEachStatement; @@ -11,12 +10,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = "EC53", - name = "Developpement", - description = UseCorrectForLoop.MESSAGERULE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC53") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S53") public class UseCorrectForLoop extends IssuableSubscriptionVisitor { diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java index cc89b1600..67e6a7c47 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java @@ -7,23 +7,16 @@ import java.util.List; import java.util.Map; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.Tree; import org.sonar.plugins.php.api.tree.expression.LiteralTree; import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidDoubleQuoteCheck.RULE_KEY, - name = AvoidDoubleQuoteCheck.ERROR_MESSAGE, - description = AvoidDoubleQuoteCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC66") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S66") public class AvoidDoubleQuoteCheck extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC66"; public static final String ERROR_MESSAGE = "Avoid using double quote (\"), prefer using simple quote (')"; private static final Map> linesWithIssuesByFile = new HashMap<>(); diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java index c6fe2b28a..61c175d36 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.regex.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.Tree; import org.sonar.plugins.php.api.tree.Tree.Kind; @@ -12,17 +11,10 @@ import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidFullSQLRequestCheck.RULE_KEY, - name = AvoidFullSQLRequestCheck.ERROR_MESSAGE, - description = AvoidFullSQLRequestCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"sql", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC74") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S74") public class AvoidFullSQLRequestCheck extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC74"; - public static final String ERROR_MESSAGE = "Don't use the query SELECT * FROM"; private static final Pattern PATTERN = Pattern.compile("(?i).*select.*\\*.*from.*"); diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInLoopCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInLoopCheck.java index 7ef27ade9..de7fd1729 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInLoopCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInLoopCheck.java @@ -1,6 +1,5 @@ package fr.greencodeinitiative.php.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.SeparatedList; import org.sonar.plugins.php.api.tree.Tree; @@ -16,16 +15,9 @@ import java.util.List; import java.util.regex.Pattern; -@Rule( - key = AvoidGettingSizeCollectionInLoopCheck.RULE_KEY, - name = AvoidGettingSizeCollectionInLoopCheck.ERROR_MESSAGE, - description = AvoidGettingSizeCollectionInLoopCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "bad-practice", "performance"} -) +@Rule(key = "EC3") public class AvoidGettingSizeCollectionInLoopCheck extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC3"; public static final String ERROR_MESSAGE = "Avoid getting the size of the collection in the loop"; private static final Pattern PATTERN = Pattern.compile("\\b(?:count|sizeof|iterator_count)\\b"); diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java index 8a392fcb3..0badb8c2b 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.regex.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.Tree; import org.sonar.plugins.php.api.tree.Tree.Kind; @@ -18,16 +17,10 @@ import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidSQLRequestInLoopCheck.RULE_KEY, - name = AvoidSQLRequestInLoopCheck.ERROR_MESSAGE, - description = AvoidSQLRequestInLoopCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"sql", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC72") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S72") public class AvoidSQLRequestInLoopCheck extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC72"; public static final String ERROR_MESSAGE = "Avoid SQL request in loop"; private static final Pattern PATTERN = Pattern.compile("(mysql(i::|_)query\\s*\\(.*)|(oci_execute\\(.*)"); diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java index fa818f8c5..6aa9943a7 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java @@ -3,22 +3,15 @@ import java.util.Collections; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.Tree; import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.RULE_KEY, - name = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.ERROR_MESSAGE, - description = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"error-handling", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC34") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S34") public class AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC34"; public static final String ERROR_MESSAGE = "Avoid using try-catch"; @Override diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java index 7eecfdb2a..1b37a96e5 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java @@ -2,22 +2,15 @@ import java.util.regex.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.declaration.FunctionDeclarationTree; import org.sonar.plugins.php.api.visitors.PHPVisitorCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidUsingGlobalVariablesCheck.RULE_KEY, - name = AvoidUsingGlobalVariablesCheck.ERROR_MESSAGE, - description = AvoidUsingGlobalVariablesCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC4") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "D4") public class AvoidUsingGlobalVariablesCheck extends PHPVisitorCheck { - public static final String RULE_KEY = "EC4"; public static final String ERROR_MESSAGE = "Prefer local variables to globals"; private static final Pattern PATTERN = Pattern.compile("^.*(global \\$|\\$GLOBALS).*$", Pattern.CASE_INSENSITIVE); diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java index 79bd2cb4a..904cd404b 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java @@ -3,23 +3,16 @@ import java.util.Collections; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.Tree; import org.sonar.plugins.php.api.tree.Tree.Kind; import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = IncrementCheck.RULE_KEY, - name = IncrementCheck.ERROR_MESSAGE, - description = IncrementCheck.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC67") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S67") public class IncrementCheck extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC67"; public static final String ERROR_MESSAGE = "Remove the usage of $i++. prefer ++$i"; @Override diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java index 39ddca9a4..999d0cfe5 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.SeparatedList; import org.sonar.plugins.php.api.tree.Tree; @@ -14,16 +13,10 @@ import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = NoFunctionCallWhenDeclaringForLoop.RULE_KEY, - name = NoFunctionCallWhenDeclaringForLoop.ERROR_MESSAGE, - description = NoFunctionCallWhenDeclaringForLoop.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC69") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S69") public class NoFunctionCallWhenDeclaringForLoop extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC69"; public static final String ERROR_MESSAGE = "Do not call a function in for-type loop declaration"; @Override diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java index a1d03d769..1285fb4d7 100644 --- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java +++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java @@ -6,7 +6,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.php.api.tree.ScriptTree; import org.sonar.plugins.php.api.tree.Tree; @@ -18,16 +17,10 @@ import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = UseOfMethodsForBasicOperations.RULE_KEY, - name = UseOfMethodsForBasicOperations.ERROR_MESSAGE, - description = UseOfMethodsForBasicOperations.ERROR_MESSAGE, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC22") @DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "D2") public class UseOfMethodsForBasicOperations extends PHPSubscriptionCheck { - public static final String RULE_KEY = "EC22"; protected static final String ERROR_MESSAGE = "Use of methods for basic operations"; @Override diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidDoubleQuoteCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidDoubleQuoteCheck.java index 033c468d1..e6b191289 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidDoubleQuoteCheck.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidDoubleQuoteCheck.java @@ -1,20 +1,13 @@ package fr.greencodeinitiative.python.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; import org.sonar.plugins.python.api.tree.StringLiteral; import org.sonar.plugins.python.api.tree.Tree; -@Rule( - key = AvoidDoubleQuoteCheck.RULE_KEY, - name = AvoidDoubleQuoteCheck.MESSAGE_RULE, - description = AvoidDoubleQuoteCheck.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "bad-practice"}) +@Rule(key = "EC66") public class AvoidDoubleQuoteCheck extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC66"; public static final String MESSAGE_RULE = "Avoid using quotation mark (\"), prefer using simple quote (')"; @Override public void initialize(Context context) { diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java index 77c5f43be..8c6d4eedf 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.regex.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -16,17 +15,10 @@ import org.sonar.plugins.python.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidFullSQLRequest.RULE_KEY, - name = AvoidFullSQLRequest.MESSAGERULE, - description = AvoidFullSQLRequest.MESSAGERULE, - priority = Priority.MINOR, - tags = {"sql", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC74") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S74") public class AvoidFullSQLRequest extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC74"; - protected static final String MESSAGERULE = "Don't use the query SELECT * FROM"; // TODO DDC : create support to add in deployment th dependency com.google.re2j:re2j diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java index fc1dddca4..beb063de7 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java @@ -3,7 +3,6 @@ import java.util.List; import java.util.stream.Collectors; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -18,16 +17,10 @@ import org.sonar.plugins.python.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidGettersAndSetters.RULE_KEY, - name = AvoidGettersAndSetters.DESCRIPTION, - description = AvoidGettersAndSetters.DESCRIPTION, - priority = Priority.MINOR, - tags = {"convention", "eco-design", "ecocode"}) +@Rule(key = "EC7") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D7") public class AvoidGettersAndSetters extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC7"; public static final String DESCRIPTION = "Avoid creating getter and setter methods in classes"; @Override diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java index ab4302bbd..82bc46b74 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionCheck; @@ -62,16 +61,10 @@ import org.sonar.plugins.python.api.tree.YieldStatement; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidGlobalVariableInFunctionCheck.RULE_KEY, - name = "Do not call global variables directly inside functions", - description = AvoidGlobalVariableInFunctionCheck.DESCRIPTION, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC4") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D4") public class AvoidGlobalVariableInFunctionCheck extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC4"; public static final String DESCRIPTION = "Use local variable (function/class scope) instead of global variable (application scope)"; private List globalVariables; diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java index 5cb64346d..917d053c9 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java @@ -1,6 +1,5 @@ package fr.greencodeinitiative.python.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -18,15 +17,9 @@ import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_COMPREHENSION; import static org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT; -@Rule( - key = AvoidListComprehensionInIterations.RULE_KEY, - name = AvoidListComprehensionInIterations.DESCRIPTION, - description = AvoidListComprehensionInIterations.DESCRIPTION, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "performance"}) +@Rule(key = "EC404") public class AvoidListComprehensionInIterations extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC404"; public static final String DESCRIPTION = "Use generator comprehension instead of list comprehension in for loop declaration"; @Override diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java index 7a7c1187e..a2bb20786 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java @@ -6,7 +6,6 @@ import java.util.Objects; import java.util.Set; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -20,17 +19,10 @@ import org.sonar.plugins.python.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidSQLRequestInLoop.RULE_KEY, - name = "Avoid SQL request in loop", - description = AvoidSQLRequestInLoop.MESSAGE_RULE, - priority = Priority.MINOR, - tags = {"sql", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC72") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S72") public class AvoidSQLRequestInLoop extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC72"; - // TODO: Handle ORM lib private static final List SQL_LIBS = Arrays.asList("cx_Oracle", "mysql.connector", "psycopg2", "pymssql", "pyodbc", "sqlite3"); diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java index 43ae16492..be801c44d 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java @@ -1,6 +1,5 @@ package fr.greencodeinitiative.python.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -8,16 +7,10 @@ import org.sonar.plugins.python.api.tree.TryStatement; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = AvoidTryCatchFinallyCheck.RULE_KEY, - name = "Avoid using try-catch statement", - description = AvoidTryCatchFinallyCheck.DESCRIPTION, - priority = Priority.MINOR, - tags = {"error-handling", "performance", "eco-design", "ecocode"}) +@Rule(key = "EC34") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S34") public class AvoidTryCatchFinallyCheck extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC34"; public static final String DESCRIPTION = "Avoid the use of try-catch"; @Override diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java index 5819eeec0..f3a9c3686 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java @@ -3,21 +3,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; import org.sonar.plugins.python.api.tree.*; -@Rule( - key = AvoidUnoptimizedVectorImagesCheck.RULE_KEY, - name = AvoidUnoptimizedVectorImagesCheck.DESCRIPTION, - description = AvoidUnoptimizedVectorImagesCheck.DESCRIPTION, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode"}) +@Rule(key = "EC10") public class AvoidUnoptimizedVectorImagesCheck extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC10"; public static final String DESCRIPTION = "Avoid using unoptimized vector images"; private static final Pattern LAYERS_PATTERN = Pattern.compile(""); diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/DetectUnoptimizedImageFormat.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/DetectUnoptimizedImageFormat.java index 5cd3c48c7..a69599aed 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/DetectUnoptimizedImageFormat.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/DetectUnoptimizedImageFormat.java @@ -1,6 +1,5 @@ package fr.greencodeinitiative.python.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.SubscriptionContext; @@ -10,12 +9,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -@Rule( - key = DetectUnoptimizedImageFormat.RULE_KEY, - name = DetectUnoptimizedImageFormat.MESSAGERULE, - description = DetectUnoptimizedImageFormat.MESSAGEERROR, - priority = Priority.MINOR, - tags = {"eco-design", "ecocode", "performance", "user-experience"}) +@Rule(key = "EC203") public class DetectUnoptimizedImageFormat extends PythonSubscriptionCheck { protected static final String RULE_KEY = "EC203"; diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java index 5c7e09f05..b0bf30286 100644 --- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -1,22 +1,15 @@ package fr.greencodeinitiative.python.checks; -import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.python.api.PythonSubscriptionCheck; import org.sonar.plugins.python.api.tree.CallExpression; import org.sonar.plugins.python.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule( - key = NoFunctionCallWhenDeclaringForLoop.RULE_KEY, - name = NoFunctionCallWhenDeclaringForLoop.DESCRIPTION, - description = NoFunctionCallWhenDeclaringForLoop.DESCRIPTION, - priority = Priority.MINOR, - tags = {"performance", "eco-design", "ecocode"}) +@Rule(key = "EC69") @DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S69") public class NoFunctionCallWhenDeclaringForLoop extends PythonSubscriptionCheck { - public static final String RULE_KEY = "EC69"; public static final String DESCRIPTION = "Do not call a function when declaring a for-type loop"; @Override