Skip to content

Commit

Permalink
Merge branch 'main' into t213
Browse files Browse the repository at this point in the history
  • Loading branch information
alograg authored Feb 2, 2024
2 parents 2d9b910 + 9ed5fc0 commit addbabd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

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

### Changed

### Deleted

- Deprecated java rules EC4, EC53, EC63 and EC75

## [1.5.2] - 2024-01-23

### Changed

- [#9](https://github.com/green-code-initiative/ecoCode-java/issues/9) EC2 rule : correction no block statement use case

## [1.5.1] - 2024-01-23

### Changed

- [#7](https://github.com/green-code-initiative/ecoCode-java/issues/7) EC2 rule : correction NullPointer with interface

## [1.5.0] - 2024-01-06

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

- Update ecocode-rules-specifications to 1.4.6

[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/v1.5.1...HEAD)
[1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/v1.5.0...1.5.1)
[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...HEAD)
[1.5.2](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.1...1.5.2)
[1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.0...1.5.1)
[1.5.0](https://github.com/green-code-initiative/ecoCode-java/releases/tag/1.5.0)
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@
<google.re2j>1.7</google.re2j>

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

</properties>

Expand Down Expand Up @@ -185,6 +181,7 @@
<pluginApiMinVersion>${sonarqube.version}</pluginApiMinVersion>
<skipDependenciesPackaging>true</skipDependenciesPackaging>
<jreMinVersion>${java.version}</jreMinVersion>
<requiredForLanguages>java</requiredForLanguages>
<archive>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private void visitIfNode(IfStatementTree pIfTree, int pLevel) {
// analyze condition variables and raise error if needed
computeIfVariables(pIfTree, pLevel);

// return if there is no block
if (!pIfTree.thenStatement().is(Kind.BLOCK))
return;

// visit the content of if block
visitNodeContent(((BlockTree)pIfTree.thenStatement()).body(), pLevel + 1);

Expand Down
27 changes: 27 additions & 0 deletions src/test/files/AvoidMultipleIfElseStatementNotBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java.checks;

class AvoidMultipleIfElseStatementNotBlock {

public boolean equals(Object obj) {
if (this == obj)
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ void test() {
.onFile("src/test/files/AvoidMultipleIfElseStatement.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyIssues();
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyNoIssues();
}

@Test
void testInterfaceMethodStatement() {
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidMultipleIfElseStatementInterface.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyNoIssues();
}

@Test
void testNotBlockStatement() {
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
.onFile("src/test/files/AvoidMultipleIfElseStatementNotBlock.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyNoIssues();
}
Expand Down

0 comments on commit addbabd

Please sign in to comment.