Skip to content

Commit addbabd

Browse files
authored
Merge branch 'main' into t213
2 parents 2d9b910 + 9ed5fc0 commit addbabd

5 files changed

Lines changed: 62 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- [#12](https://github.com/green-code-initiative/ecoCode-java/issues/12) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature
13+
1214
### Changed
1315

1416
### Deleted
1517

1618
- Deprecated java rules EC4, EC53, EC63 and EC75
1719

20+
## [1.5.2] - 2024-01-23
21+
22+
### Changed
23+
24+
- [#9](https://github.com/green-code-initiative/ecoCode-java/issues/9) EC2 rule : correction no block statement use case
25+
26+
## [1.5.1] - 2024-01-23
27+
28+
### Changed
29+
30+
- [#7](https://github.com/green-code-initiative/ecoCode-java/issues/7) EC2 rule : correction NullPointer with interface
31+
1832
## [1.5.0] - 2024-01-06
1933

2034
### Added
@@ -26,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2640

2741
- Update ecocode-rules-specifications to 1.4.6
2842

29-
[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/v1.5.1...HEAD)
30-
[1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/v1.5.0...1.5.1)
43+
[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...HEAD)
44+
[1.5.2](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.1...1.5.2)
45+
[1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.0...1.5.1)
3146
[1.5.0](https://github.com/green-code-initiative/ecoCode-java/releases/tag/1.5.0)

pom.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@
6767
<google.re2j>1.7</google.re2j>
6868

6969
<!-- temporary version waiting for real automatic release in ecocode repository -->
70-
<<<<<<< HEAD
7170
<ecocode-rules-specifications.version>1.5.0</ecocode-rules-specifications.version>
72-
=======
73-
<ecocode-rules-specifications.version>1.6.0-SNAPSHOT</ecocode-rules-specifications.version>
74-
>>>>>>> 603fbcd (fix: :memo: Version et changes correction)
7571

7672
</properties>
7773

@@ -185,6 +181,7 @@
185181
<pluginApiMinVersion>${sonarqube.version}</pluginApiMinVersion>
186182
<skipDependenciesPackaging>true</skipDependenciesPackaging>
187183
<jreMinVersion>${java.version}</jreMinVersion>
184+
<requiredForLanguages>java</requiredForLanguages>
188185
<archive>
189186
<manifestEntries>
190187
<Implementation-Build>${buildNumber}</Implementation-Build>

src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ private void visitIfNode(IfStatementTree pIfTree, int pLevel) {
114114
// analyze condition variables and raise error if needed
115115
computeIfVariables(pIfTree, pLevel);
116116

117+
// return if there is no block
118+
if (!pIfTree.thenStatement().is(Kind.BLOCK))
119+
return;
120+
117121
// visit the content of if block
118122
visitNodeContent(((BlockTree)pIfTree.thenStatement()).body(), pLevel + 1);
119123

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java 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.java.checks;
19+
20+
class AvoidMultipleIfElseStatementNotBlock {
21+
22+
public boolean equals(Object obj) {
23+
if (this == obj)
24+
return true;
25+
}
26+
27+
}

src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,24 @@ void test() {
2727
.onFile("src/test/files/AvoidMultipleIfElseStatement.java")
2828
.withCheck(new AvoidMultipleIfElseStatement())
2929
.verifyIssues();
30+
CheckVerifier.newVerifier()
31+
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
32+
.withCheck(new AvoidMultipleIfElseStatement())
33+
.verifyNoIssues();
34+
}
35+
36+
@Test
37+
void testInterfaceMethodStatement() {
3038
CheckVerifier.newVerifier()
3139
.onFile("src/test/files/AvoidMultipleIfElseStatementInterface.java")
3240
.withCheck(new AvoidMultipleIfElseStatement())
3341
.verifyNoIssues();
42+
}
43+
44+
@Test
45+
void testNotBlockStatement() {
3446
CheckVerifier.newVerifier()
35-
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
47+
.onFile("src/test/files/AvoidMultipleIfElseStatementNotBlock.java")
3648
.withCheck(new AvoidMultipleIfElseStatement())
3749
.verifyNoIssues();
3850
}

0 commit comments

Comments
 (0)