Skip to content

Commit 047796f

Browse files
committed
[ISSUE 21] keep EC69 depreciation
1 parent 934f381 commit 047796f

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

CHANGELOG.md

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

1414
### Changed
1515

16+
- [#22](https://github.com/green-code-initiative/ecoCode-python/issues/22) Depreciation of EC69 rule for python because not relevant (after analysis)
17+
1618
### Deleted
1719

20+
- [#22](https://github.com/green-code-initiative/ecoCode-python/issues/22) Delete deprecated EC66 rule for Python
21+
1822
## [1.4.3] - 2024-05-15
1923

2024
### Added
@@ -27,9 +31,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2731
- [#17](https://github.com/green-code-initiative/ecoCode-python/issues/17) EC7 - correction setter problem on constructor method
2832
- check Sonarqube 10.4.1 compatibility + update docker files and README.md / NOT OK with 10.5.x (issue created)
2933

30-
- [#4](https://github.com/green-code-initiative/ecoCode-python/issues/4) Deprecate rule EC66 for Python because not applicable (see details inside issue)
31-
- [#21](https://github.com/green-code-initiative/ecoCode-python/issues/21) Deletion of EC69 for python because not relevant (after analysis)
32-
3334
## [1.4.2] - 2024-01-11
3435

3536
### Changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* ecoCode - Python language - Provides rules to reduce the environmental footprint of your Python programs
3+
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package fr.greencodeinitiative.python.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
22+
import org.sonar.plugins.python.api.tree.CallExpression;
23+
import org.sonar.plugins.python.api.tree.Tree;
24+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
25+
26+
/**
27+
* @deprecated not applicable for Python
28+
* (check discussion inside issue https://github.com/green-code-initiative/ecoCode-python/issues/21)
29+
*/
30+
@Deprecated(forRemoval = true)
31+
@Rule(key = "EC69")
32+
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S69")
33+
public class NoFunctionCallWhenDeclaringForLoop extends PythonSubscriptionCheck {
34+
35+
public static final String DESCRIPTION = "Do not call a function when declaring a for-type loop";
36+
37+
@Override
38+
public void initialize(Context context) {
39+
context.registerSyntaxNodeConsumer(Tree.Kind.CALL_EXPR, ctx -> {
40+
CallExpression callExpression = (CallExpression) ctx.syntaxNode();
41+
if (callExpression.parent().getKind() == Tree.Kind.FOR_STMT) {
42+
ctx.addIssue(callExpression, NoFunctionCallWhenDeclaringForLoop.DESCRIPTION);
43+
}
44+
});
45+
}
46+
}

src/test/java/fr/greencodeinitiative/python/PythonRuleRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void testMetadata() {
7878

7979
@Test
8080
void testRegistredRules() {
81-
assertThat(repository.rules()).hasSize(12);
81+
assertThat(repository.rules()).hasSize(10);
8282
}
8383

8484
@Test
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* ecoCode - Python language - Provides rules to reduce the environmental footprint of your Python programs
3+
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package fr.greencodeinitiative.python.checks;
19+
20+
import org.junit.Test;
21+
import org.sonar.python.checks.utils.PythonCheckVerifier;
22+
23+
@Deprecated
24+
public class NoFunctionCallWhenDeclaringForLoopTest {
25+
@Test
26+
public void test() {
27+
PythonCheckVerifier.verify("src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.py", new NoFunctionCallWhenDeclaringForLoop());
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def my_function():
2+
return 6
3+
4+
for i in my_function(): # Noncompliant {{Do not call a function when declaring a for-type loop}}
5+
print("Test")
6+
my_function()
7+
pass
8+
9+
my_function()

0 commit comments

Comments
 (0)