Skip to content

Commit 4705926

Browse files
authored
Merge pull request #46 from green-code-initiative/MIGRATION_DDC
next step for migration with last decisions
2 parents a020b60 + a82d48e commit 4705926

27 files changed

+115
-113
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,27 @@ jobs:
2525
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2626

2727
- name: Set up JDK 11
28-
uses: actions/setup-java@v3
28+
uses: actions/setup-java@v4
2929
with:
3030
distribution: 'temurin'
3131
java-version: 11
3232

33+
- name: Cache SonarQube packages
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.sonar/cache
37+
key: ${{ runner.os }}-sonar
38+
restore-keys: ${{ runner.os }}-sonar
39+
3340
- name: Cache Maven packages
3441
uses: actions/cache@v3
3542
with:
3643
path: ~/.m2
3744
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
3845
restore-keys: ${{ runner.os }}-m2
3946

40-
- name: Verify
41-
run: mvn -e -B verify
42-
43-
- name: Set up JDK 17
44-
uses: actions/setup-java@v3
45-
with:
46-
distribution: 'temurin'
47-
java-version: 17
48-
49-
- name: Cache SonarQube packages
50-
uses: actions/cache@v3
51-
with:
52-
path: ~/.sonar/cache
53-
key: ${{ runner.os }}-sonar
54-
restore-keys: ${{ runner.os }}-sonar
55-
56-
- name: SonarQube Scan
47+
- name: Build and analyze
5748
env:
58-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
5950
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60-
run: mvn -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_creedengo-python
51+
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_creedengo-python

pom.xml

Lines changed: 9 additions & 9 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>
@@ -60,16 +60,16 @@
6060

6161
<mockito.version>5.14.1</mockito.version>
6262

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

6666
</properties>
6767

6868
<dependencies>
6969
<dependency>
70-
<groupId>io.ecocode</groupId>
71-
<artifactId>ecocode-rules-specifications</artifactId>
72-
<version>${ecocode-rules-specifications.version}</version>
70+
<groupId>org.green-code-initiative</groupId>
71+
<artifactId>creedengo-rules-specifications</artifactId>
72+
<version>${creedengo-rules-specifications.version}</version>
7373
<classifier>python</classifier>
7474
</dependency>
7575

@@ -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: 6 additions & 6 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";
48-
public static final String RESOURCE_BASE_PATH = "io/ecocode/rules/python";
49-
public static final String REPOSITORY_KEY = "ecocode-python";
47+
public static final String NAME = "creedengo";
48+
public static final String RESOURCE_BASE_PATH = "org/green-code-initiative/rules/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: 4 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

2121
import org.sonar.check.Rule;
@@ -32,7 +32,8 @@
3232
import java.util.Map;
3333
import java.util.regex.Pattern;
3434

35-
@Rule(key = "EC74")
35+
@Rule(key = "GCI74")
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: 10 additions & 10 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

37-
@Rule(key = "EC7")
36+
@Rule(key = "GCI7")
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: 4 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 java.util.ArrayList;
2121
import java.util.HashMap;
@@ -78,7 +78,8 @@
7878
import org.sonar.plugins.python.api.tree.YieldStatement;
7979
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
8080

81-
@Rule(key = "EC4")
81+
@Rule(key = "GCI4")
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: 5 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;
@@ -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

@@ -34,7 +35,8 @@
3435
import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_COMPREHENSION;
3536
import static org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT;
3637

37-
@Rule(key = "EC404")
38+
@Rule(key = "GCI404")
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: 6 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 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
/**
@@ -42,7 +44,8 @@
4244
* - an "ELSE" statement is considered as a second IF statement using the same variables used on previous
4345
* - IF and ELSEIF statements are considered as an IF statement
4446
*/
45-
@Rule(key = "EC2")
47+
@Rule(key = "GCI2")
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: 4 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 java.util.Arrays;
2121
import java.util.HashSet;
@@ -36,7 +36,8 @@
3636
import org.sonar.plugins.python.api.tree.Tree;
3737
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3838

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

0 commit comments

Comments
 (0)