Skip to content

Commit 20cae42

Browse files
authored
Merge branch 'main' into dependabot/maven/org.sonarsource.analyzer-commons-sonar-analyzer-commons-2.16.0.3141
2 parents 870287c + bc8e3df commit 20cae42

30 files changed

+130
-123
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

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14-
- [#43](https://github.com/green-code-initiative/creedengo-python/pull/43) Strong renaming plugin from `ecocode-python` to `creedengo-python` (and maven groupid from `io.ecocode` to `io.greencodeinitiative`)
15-
1614
### Deleted
1715

16+
## [2.0.0] - 2024-12-12
17+
18+
### Changed
19+
20+
- [#43](https://github.com/green-code-initiative/creedengo-python/pull/43) Strong renaming plugin from `ecocode-python` to `creedengo-python` (and maven groupid from `io.ecocode` to `org.green-code-initiative`)
21+
1822
## [1.5.0] - 2024-10-04
1923

2024
### Changed
@@ -101,7 +105,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
101105

102106
## Comparison list
103107

104-
[unreleased](https://github.com/green-code-initiative/creedengo-python/compare/1.5.0...HEAD)
108+
[unreleased](https://github.com/green-code-initiative/creedengo-python/compare/2.0.0...HEAD)
109+
[2.0.0](https://github.com/green-code-initiative/creedengo-python/compare/1.4.4...2.0.0)
105110
[1.5.0](https://github.com/green-code-initiative/creedengo-python/compare/1.4.4...1.5.0)
106111
[1.4.4](https://github.com/green-code-initiative/creedengo-python/compare/1.4.3...1.4.4)
107112
[1.4.3](https://github.com/green-code-initiative/creedengo-python/compare/1.4.2...1.4.3)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ _creedengo_ is a collective project aiming to reduce environmental footprint of
55
the project is to provide a list of static code analyzers to highlight code structures that may have a negative
66
ecological impact: energy and resources over-consumption, "fatware", shortening terminals' lifespan, etc.
77

8-
_ecoCode_ is based on evolving catalogs
9-
of [good practices](https://github.com/green-code-initiative/ecoCode/blob/main/docs/rules), for various technologies.
8+
_creedengo_ is based on evolving catalogs
9+
of [good practices](https://github.com/green-code-initiative/creedengo-rules-specifications/tree/main/docs/rules), for various technologies.
1010
This
1111
SonarQube plugin then implements these catalogs as rules for scanning your Python projects.
1212

@@ -69,17 +69,17 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
6969
| 1.4.+ | 9.4.+ LTS to 10.4.1 | 11 / 17 |
7070

7171
> Compatibility table of versions lower than 1.4.+ are available from the
72-
> main [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-plugins-version-compatibility).
72+
> main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
7373
7474
🤝 Contribution
7575
---------------
7676

77-
check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-contribution)
77+
check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-contribution)
7878

7979
🤓 Main contributors
8080
--------------------
8181

82-
check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-main-contributors)
82+
check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-main-contributors)
8383

8484
Links
8585
-----

RULES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Please read [RULES.md](https://github.com/green-code-initiative/ecoCode/blob/main/RULES.md) in `ecoCode` repository.
1+
Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `creedengo` repository.

pom.xml

Lines changed: 10 additions & 10 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>2.0.1-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>2.0.0</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>
@@ -221,7 +221,7 @@
221221
</excludes>
222222
</filter>
223223
<filter>
224-
<artifact>io.ecocode:ecocode-rules-specifications:*</artifact>
224+
<artifact>org.green-code-initiative:creedengo-rules-specifications:*</artifact>
225225
<excludes>
226226
<exclude>META-INF/**</exclude>
227227
</excludes>

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

0 commit comments

Comments
 (0)