Skip to content

Commit 9ed4428

Browse files
committed
next step for migration with last decisions
1 parent a020b60 commit 9ed4428

26 files changed

+87
-76
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

5-
<groupId>io.greencodeinitiative</groupId>
5+
<groupId>org.green-code-initiative</groupId>
66
<artifactId>creedengo-python-plugin</artifactId>
7-
<version>2.0.0-SNAPSHOT</version>
7+
<version>1.0.0-SNAPSHOT</version>
88
<packaging>sonar-plugin</packaging>
99

1010
<name>creedengo - Python language</name>
1111
<description>Provides rules to reduce the environmental footprint of your Python programs</description>
12-
<inceptionYear>2023</inceptionYear>
12+
<inceptionYear>2024</inceptionYear>
1313
<url>https://github.com/green-code-initiative/creedengo-python</url>
1414

1515
<organization>
@@ -61,7 +61,7 @@
6161
<mockito.version>5.14.1</mockito.version>
6262

6363
<!-- temporary version waiting for real automatic release in creedengo repository -->
64-
<ecocode-rules-specifications.version>1.6.4</ecocode-rules-specifications.version>
64+
<ecocode-rules-specifications.version>1.6.5</ecocode-rules-specifications.version>
6565

6666
</properties>
6767

@@ -173,7 +173,7 @@
173173
<extensions>true</extensions>
174174
<configuration>
175175
<pluginKey>creedengopython</pluginKey>
176-
<pluginClass>fr.greencodeinitiative.python.PythonPlugin</pluginClass>
176+
<pluginClass>org.greencodeinitiative.creedengo.python.PythonPlugin</pluginClass>
177177
<sonarLintSupported>true</sonarLintSupported>
178178
<pluginApiMinVersion>${sonarqube.version}</pluginApiMinVersion>
179179
<skipDependenciesPackaging>true</skipDependenciesPackaging>

src/main/java/fr/greencodeinitiative/python/PythonPlugin.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/PythonPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python;
18+
package org.greencodeinitiative.creedengo.python;
1919

2020
import org.sonar.api.Plugin;
2121

src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/PythonRuleRepository.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,9 +15,9 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python;
18+
package org.greencodeinitiative.creedengo.python;
1919

20-
import fr.greencodeinitiative.python.checks.*;
20+
import org.greencodeinitiative.creedengo.python.checks.*;
2121
import org.sonar.api.SonarRuntime;
2222
import org.sonar.api.server.rule.RulesDefinition;
2323
import org.sonar.plugins.python.api.PythonCustomRuleRepository;
@@ -44,9 +44,9 @@ public class PythonRuleRepository implements RulesDefinition, PythonCustomRuleRe
4444
);
4545

4646
public static final String LANGUAGE = "py";
47-
public static final String NAME = "ecoCode";
47+
public static final String NAME = "creedengo";
4848
public static final String RESOURCE_BASE_PATH = "io/ecocode/rules/python";
49-
public static final String REPOSITORY_KEY = "ecocode-python";
49+
public static final String REPOSITORY_KEY = "creedengo-python";
5050

5151
private final SonarRuntime sonarRuntime;
5252

src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidFullSQLRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020

2121
import org.sonar.check.Rule;
@@ -33,6 +33,7 @@
3333
import java.util.regex.Pattern;
3434

3535
@Rule(key = "EC74")
36+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC74")
3637
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S74")
3738
public class AvoidFullSQLRequest extends PythonSubscriptionCheck {
3839

src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidGettersAndSetters.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import java.util.List;
2121
import java.util.stream.Collectors;
@@ -28,13 +28,13 @@
2828
import org.sonar.plugins.python.api.tree.FunctionDef;
2929
import org.sonar.plugins.python.api.tree.ParameterList;
3030
import org.sonar.plugins.python.api.tree.QualifiedExpression;
31-
import org.sonar.plugins.python.api.tree.ReturnStatement;
3231
import org.sonar.plugins.python.api.tree.Statement;
3332
import org.sonar.plugins.python.api.tree.StatementList;
3433
import org.sonar.plugins.python.api.tree.Tree;
3534
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3635

3736
@Rule(key = "EC7")
37+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC7")
3838
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D7")
3939
public class AvoidGettersAndSetters extends PythonSubscriptionCheck {
4040

@@ -62,36 +62,36 @@ private boolean isConstructorMethod(FunctionDef functionDef) {
6262
return functionDef.name() != null && "__init__".equals(functionDef.name().name());
6363
}
6464

65-
public void checkAllSetters(List<Statement> statements, FunctionDef functionDef, SubscriptionContext ctx) {
65+
private void checkAllSetters(List<Statement> statements, FunctionDef functionDef, SubscriptionContext ctx) {
6666
if (statements.size() == 1 && statements.get(0).is(Tree.Kind.ASSIGNMENT_STMT)) {
6767
AssignmentStatement assignmentStatement = (AssignmentStatement) statements.get(0);
6868
if (checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot((QualifiedExpression) assignmentStatement.children().get(0).children().get(0))) {
6969
// Check if assignedValue is a parameter of the function
7070
ParameterList parameters = functionDef.parameters();
71-
if (parameters != null && !parameters.all().stream().filter(p -> checkAssignementFromParameter(assignmentStatement, p)).collect(Collectors.toList()).isEmpty()) {
71+
if (parameters != null && !parameters.all().stream().filter(p -> checkAssignmentFromParameter(assignmentStatement, p)).collect(Collectors.toList()).isEmpty()) {
7272
ctx.addIssue(functionDef.defKeyword(), AvoidGettersAndSetters.DESCRIPTION);
7373
}
7474
}
7575
}
7676
}
7777

78-
public void checkAllGetters(List<Statement> statements, FunctionDef functionDef, SubscriptionContext ctx) {
78+
private void checkAllGetters(List<Statement> statements, FunctionDef functionDef, SubscriptionContext ctx) {
7979
Statement lastStatement = statements.get(statements.size() - 1);
8080
if (lastStatement.is(Tree.Kind.RETURN_STMT)) {
81-
List<Tree> returnStatementChildren = ((ReturnStatement) lastStatement).children();
81+
List<Tree> returnStatementChildren = lastStatement.children();
8282
if (returnStatementChildren.get(1).is(Tree.Kind.QUALIFIED_EXPR) &&
8383
checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot((QualifiedExpression) returnStatementChildren.get(1))) {
8484
ctx.addIssue(functionDef.defKeyword(), AvoidGettersAndSetters.DESCRIPTION);
8585
}
8686
}
8787
}
8888

89-
public boolean checkAssignementFromParameter(AssignmentStatement assignmentStatement, AnyParameter parameter) {
89+
private boolean checkAssignmentFromParameter(AssignmentStatement assignmentStatement, AnyParameter parameter) {
9090
String parameterToString = parameter.firstToken().value();
9191
return assignmentStatement.assignedValue().firstToken().value().equalsIgnoreCase(parameterToString);
9292
}
9393

94-
public boolean checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot(QualifiedExpression qualifiedExpression) {
94+
private boolean checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot(QualifiedExpression qualifiedExpression) {
9595
List<Tree> qualifedExpressionChildren = qualifiedExpression.children();
9696
return qualifedExpressionChildren.size() == 3 &&
9797
qualifedExpressionChildren.get(0).firstToken().value().equalsIgnoreCase("self") &&

src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidGlobalVariableInFunctionCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import java.util.ArrayList;
2121
import java.util.HashMap;
@@ -79,6 +79,7 @@
7979
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
8080

8181
@Rule(key = "EC4")
82+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC4")
8283
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D4")
8384
public class AvoidGlobalVariableInFunctionCheck extends PythonSubscriptionCheck {
8485

src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidListComprehensionInIterations.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import org.sonar.check.Rule;
2121
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
@@ -26,6 +26,7 @@
2626
import org.sonar.plugins.python.api.tree.ForStatement;
2727
import org.sonar.plugins.python.api.tree.Tree;
2828
import org.sonar.plugins.python.api.tree.RegularArgument;
29+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2930

3031
import java.util.Objects;
3132

@@ -35,6 +36,7 @@
3536
import static org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT;
3637

3738
@Rule(key = "EC404")
39+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC404")
3840
public class AvoidListComprehensionInIterations extends PythonSubscriptionCheck {
3941

4042
public static final String DESCRIPTION = "Use generator comprehension instead of list comprehension in for loop declaration";

src/main/java/fr/greencodeinitiative/python/checks/AvoidMultipleIfElseStatementCheck.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidMultipleIfElseStatementCheck.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import java.util.HashMap;
2121
import java.util.List;
@@ -31,6 +31,8 @@
3131
import org.sonar.plugins.python.api.tree.IfStatement;
3232
import org.sonar.plugins.python.api.tree.Statement;
3333
import org.sonar.plugins.python.api.tree.Tree;
34+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
35+
3436
import static org.sonar.plugins.python.api.tree.Tree.Kind.*;
3537

3638
/**
@@ -43,6 +45,7 @@
4345
* - IF and ELSEIF statements are considered as an IF statement
4446
*/
4547
@Rule(key = "EC2")
48+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC2")
4649
public class AvoidMultipleIfElseStatementCheck extends PythonSubscriptionCheck {
4750

4851
public static final String ERROR_MESSAGE = "Use a match-case statement instead of multiple if-else if possible";

src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidSQLRequestInLoop.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import java.util.Arrays;
2121
import java.util.HashSet;
@@ -37,6 +37,7 @@
3737
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3838

3939
@Rule(key = "EC72")
40+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC72")
4041
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S72")
4142
public class AvoidSQLRequestInLoop extends PythonSubscriptionCheck {
4243

src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchWithFileOpenedCheck.java renamed to src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidTryCatchWithFileOpenedCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* creedengo - Python language - Provides rules to reduce the environmental footprint of your Python programs
3-
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
3+
* Copyright © 2024 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package fr.greencodeinitiative.python.checks;
18+
package org.greencodeinitiative.creedengo.python.checks;
1919

2020
import org.sonar.check.Rule;
2121
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
@@ -27,8 +27,8 @@
2727
import static org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR;
2828

2929
@Rule(key = "EC35")
30+
@DeprecatedRuleKey(repositoryKey = "ecocode-python", ruleKey = "EC35")
3031
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S34")
31-
@DeprecatedRuleKey(ruleKey = "EC34")
3232
public class AvoidTryCatchWithFileOpenedCheck extends PythonSubscriptionCheck {
3333

3434
public static final String DESCRIPTION = "Avoid the use of try-catch with a file open in try block";

0 commit comments

Comments
 (0)