diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9a4c5361d..96fd532cd 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -6,6 +6,8 @@ on:
paths-ignore:
- '*.md'
- '.github/**/*.yml'
+ tags:
+ - '[0-9]+.[0-9]+.[0-9]+'
pull_request:
types: [opened, synchronize, reopened]
jobs:
diff --git a/.github/workflows/manual_release.yml b/.github/workflows/manual_release.yml
index 787a4400a..90818a555 100644
--- a/.github/workflows/manual_release.yml
+++ b/.github/workflows/manual_release.yml
@@ -89,66 +89,3 @@ jobs:
asset_path: lib/ecocode-java-plugin-${{ needs.build.outputs.last_tag }}.jar
asset_name: ecocode-java-plugin-${{ needs.build.outputs.last_tag }}.jar
asset_content_type: application/zip
- upload-javascript:
- name: Upload JavaScript Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - JavaScript Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-javascript-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_name: ecocode-javascript-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_content_type: application/zip
- upload-php:
- name: Upload PHP Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - PHP Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-php-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_name: ecocode-php-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_content_type: application/zip
- upload-python:
- name: Upload Python Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - Python Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-python-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_name: ecocode-python-plugin-${{ needs.build.outputs.last_tag }}.jar
- asset_content_type: application/zip
diff --git a/.github/workflows/publish_to_maven_central.yml b/.github/workflows/publish_to_maven_central.yml
new file mode 100644
index 000000000..19de389e8
--- /dev/null
+++ b/.github/workflows/publish_to_maven_central.yml
@@ -0,0 +1,56 @@
+# This workflow will build a Java project with Maven and publish artifact to Maven Central (https://search.maven.org)
+#
+# After deploy to https://s01.oss.sonatype.org finished, manual steps is required :
+# - Go to: https://s01.oss.sonatype.org/#stagingRepositories
+# - Check upload and if all is right, "Close" corresponding Staging Repository
+# - "Release" corresponding Staging Repository
+# - Wait some hours and then check availability of release on Maven central: https://search.maven.org/search?q=g:io.ecocode
+#
+# Additional information:
+# - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-the-maven-central-repository
+# - https://blogs.itemis.com/en/github-actions-releasing-artifacts-into-maven-central
+
+name: Publish package to the Maven Central Repository
+
+on:
+ workflow_dispatch:
+
+jobs:
+ publish:
+ name: Deploy to Maven central
+ runs-on: ubuntu-latest
+
+ steps:
+ # Checks out a copy of project's repository.
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ # Sets up the Java JDK, and also configures the Maven `settings.xml` file to add authentication for the
+ # `ossrh` repository using the `OSSRH_USERNAME` and `OSSRH_TOKEN` environment variables.
+ - name: Set up Maven Central Repository
+ uses: actions/setup-java@v3
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ server-id: 'ossrh' # must match the serverId configured for the nexus-staging-maven-plugin in `pom.xml`
+ server-username: OSSRH_USERNAME
+ server-password: OSSRH_TOKEN
+ gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Substituted with the value stored in the referenced secret
+ gpg-passphrase: MAVEN_GPG_PASSPHRASE # Env var that holds the key's passphrase
+
+ - name: Cache Maven packages
+ uses: actions/cache@v1
+ with:
+ path: ~/.m2
+ key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
+ restore-keys: ${{ runner.os }}-m2
+
+ # Runs the Maven command to publish to the `ossrh` repository.
+ # The `OSSRH_USERNAME` environment variable will be set with the contents of your `OSSRH_USERNAME` secret,
+ # and the `OSSRH_TOKEN` environment variable will be set with the contents of your `OSSRH_TOKEN` secret.
+ - name: Publish package
+ run: mvn --batch-mode deploy -Pmaven-central-publishing
+ env:
+ OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
+ OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
+ MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
diff --git a/.github/workflows/stale_tag.yml b/.github/workflows/stale_tag.yml
new file mode 100644
index 000000000..4c7a9ff96
--- /dev/null
+++ b/.github/workflows/stale_tag.yml
@@ -0,0 +1,21 @@
+name: "Label stale PRs"
+on:
+ schedule:
+ - cron: "30 1 * * *"
+ workflow_dispatch:
+
+jobs:
+ stale:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/stale@v8.0.0
+ with:
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
+ days-before-issue-stale: -1 # We don't want to address issues
+ days-before-pr-stale: 30
+ days-before-issue-close: -1 # We don't want to close issues in this action
+ days-before-pr-close: -1 # We don't want to close PR in this action
+ stale-pr-label: stale
+ stale-pr-message: |
+ This PR has been automatically marked as stale because it has no activity for 30 days.
+ Please add a comment if you want to keep the issue open. Thank you for your contributions!
\ No newline at end of file
diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml
index 0d2f3d605..44ec92a15 100644
--- a/.github/workflows/tag_release.yml
+++ b/.github/workflows/tag_release.yml
@@ -69,66 +69,3 @@ jobs:
asset_path: lib/ecocode-java-plugin-${{ github.ref_name }}.jar
asset_name: ecocode-java-plugin-${{ github.ref_name }}.jar
asset_content_type: application/zip
- upload-javascript:
- name: Upload JavaScript Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - JavaScript Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-javascript-plugin-${{ github.ref_name }}.jar
- asset_name: ecocode-javascript-plugin-${{ github.ref_name }}.jar
- asset_content_type: application/zip
- upload-php:
- name: Upload PHP Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - PHP Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-php-plugin-${{ github.ref_name }}.jar
- asset_name: ecocode-php-plugin-${{ github.ref_name }}.jar
- asset_content_type: application/zip
- upload-python:
- name: Upload Python Plugin
- runs-on: ubuntu-latest
- needs: build
- steps:
- - name: Import plugin JAR files
- id: import_jar_files
- uses: actions/download-artifact@v3
- with:
- name: ecocode-plugins
- path: lib
- - name: Upload Release Asset - Python Plugin
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{needs.build.outputs.upload_url}}
- asset_path: lib/ecocode-python-plugin-${{ github.ref_name }}.jar
- asset_name: ecocode-python-plugin-${{ github.ref_name }}.jar
- asset_content_type: application/zip
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca102b523..96d824280 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,25 +7,86 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Changed
+
+- [#216](https://github.com/green-code-initiative/ecoCode/issues/216) Upgrade rule EC2 for Java : Multiple if-else statement improvment
+- [#106](https://github.com/green-code-initiative/ecoCode/issues/106) Upgrade RULES.md : rule EC67 not relevant neither for Python nor Rust
+- [#225](https://github.com/green-code-initiative/ecoCode/pull/225) Upgrade licence system and licence headers of Java files
+- [#140](https://github.com/green-code-initiative/ecoCode/issues/140) Upgrade rule EC3 for Python : no implementation possible for python
+- [#136](https://github.com/green-code-initiative/ecoCode/issues/136) Upgrade rule EC53 for Python : no implementation possible for python
+
+### Deleted
+
+## [1.4.0] - 2023-08-08
+
### Added
-- [171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
+- [#205](https://github.com/green-code-initiative/ecoCode/issues/205) compatibility with SonarQube 10.1
+- [#210](https://github.com/green-code-initiative/ecoCode/pull/210) Publish to Maven Central (module ecocode-rules-specifications)
-### Changed
+### Deleted
+
+- [#182](https://github.com/green-code-initiative/ecoCode/issues/182) Split repository : move Python module to new `ecoCode-python` repository
+- [#182](https://github.com/green-code-initiative/ecoCode/issues/182) Split repository : move Php module to new `ecoCode-php` repository
-- [166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
-- [167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
-- [173](https://github.com/green-code-initiative/ecoCode/issues/173) Update issue description of rule EC34 (try-catch)
+## [1.3.1] - 2023-07-19
+
+### Added
+
+- [#207](https://github.com/green-code-initiative/ecoCode/issues/207) Add release tag analyzis on SonarCloud
+
+### Changed
### Deleted
+- [#211](https://github.com/green-code-initiative/ecoCode/pull/211) Move JavaScript plugin to its dedicated repository
+
+## [1.3.0] - 2023-07-04
+
+### Added
+
+- [#108](https://github.com/green-code-initiative/ecoCode/issues/108) new Python rule EC66 : Use single quote (') instead of quotation mark (")
+- [#109](https://github.com/green-code-initiative/ecoCode/issues/109) new PHP rule EC3 : Getting the size of the collection in the loop. For further [RULES.md](./RULES.md) file
+- [#113](https://github.com/green-code-initiative/ecoCode/issues/113) new Python rule EC10 : Use unoptimized vector images
+- [#127](https://github.com/green-code-initiative/ecoCode/issues/127) new Python rule EC404 : Usage of generator comprehension instead of list comprehension in for loop declaration
+- [#190](https://github.com/green-code-initiative/ecoCode/pull/190) Add Python rule: Use unoptimized vector images
+- [#191](https://github.com/green-code-initiative/ecoCode/issues/191) Update rule tags for Java, Python, and PHP plugins
+- [#192](https://github.com/green-code-initiative/ecoCode/pull/192) new Python rule EC203 : Detect unoptimized file formats
+- Add JavaScript rules from [ecoCode ESLint plugin v0.2.0](https://github.com/green-code-initiative/ecoCode-linter/releases/tag/eslint-plugin%2F0.2.0)
+
+### Changed
+
+- [#19](https://github.com/green-code-initiative/ecoCode-common/issues/19) process changed for development environment installation : easier to initialize locally environment (check [`INSTALL.md`](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment) file)
+- [#187](https://github.com/green-code-initiative/ecoCode/issues/187) upgrade librairies to SonarQube 10.0.0
+- [#196](https://github.com/green-code-initiative/ecoCode/issues/196) updating PHP files to make them following the coding standards (PSR-12)
+- [#201](https://github.com/green-code-initiative/ecoCode/pull/201) Clean-up plugins and dependencies
+- technical : upgrade of maven plugins versions
+
+## [1.2.1] - 2023-04-18
+
+### Changed
+
+- [#180](https://github.com/green-code-initiative/ecoCode/pull/180) correction of SonarQube review for MarketPlace (sonar plugin)
+
+## [1.2.0] - 2023-04-14
+
+### Added
+
+- [#171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
+
+### Changed
+
+- [#161](https://github.com/green-code-initiative/ecoCode/pull/161) Remove unnecessary junit dependencies in pom.xml
+- [#166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
+- [#167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
+- [#173](https://github.com/green-code-initiative/ecoCode/issues/173) Update issue description of rule EC34 (try-catch)
+
## [1.1.0] - 2023-04-03
### Changed
- [#63](https://github.com/green-code-initiative/ecoCode/issues/63) Update plugins to be compliant for SonarQube MarketPlace integration ( PR [#79](https://github.com/green-code-initiative/ecoCode/pull/79) )
- [#88](https://github.com/green-code-initiative/ecoCode/pull/88) upgrade rules matrix with new ids + refactoring rules documentation (`RULES.md`)
- - _*WARNING*_ : since this plugin version, ids of plugin rules changed. In consequence, if you have already made some issue checks in your SonarQube instance, you will have to do them again (example : false-positive issues will appear again)
### Deleted
@@ -42,14 +103,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [#40](https://github.com/green-code-initiative/ecoCode/issues/40) Refactoring of package names (`cnumr` to `greencodeinitiative`)
+- [#55](https://github.com/green-code-initiative/ecoCode/issues/55) rename `eco-conception` tag of rules to `eco-design`
- [#58](https://github.com/green-code-initiative/ecoCode/issues/58) check and upgrade compatibility to SonarQube 9.9
- move common init scripts to `ecoCode-common` repository
- modifying documentation and move `CONTRIBUTING.md`, `CODE_STYLE.md` and `INSTALL.md` to common doc in `ecoCode-common` repository
- security / performance optimizations : correction of `sonarcloud.io` security hotspots (java / php, python) and move Pattern compilation to static attribute
+- [#64](https://github.com/green-code-initiative/ecoCode/issues/64) Python: ecoCode plugin with SonarQube, no code-smell detection
- [#65](https://github.com/green-code-initiative/ecoCode/issues/65) Create a test project to check new plugin rule in real environment
- [#71](https://github.com/green-code-initiative/ecoCode/issues/71) After an PHP analysis, no ecocode code smells appears in my Sonar project
-- [#64](https://github.com/green-code-initiative/ecoCode/issues/64) Python: ecoCode plugin with SonarQube, no code-smell detection
-- [#55](https://github.com/green-code-initiative/ecoCode/issues/55) rename `eco-conception` tag of rules to `eco-design`
- [#76](https://github.com/green-code-initiative/ecoCode/issues/76) correction of SonarQube plugins homepage link broken
- documentation upgrade
@@ -70,7 +131,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#33](https://github.com/green-code-initiative/ecoCode/issues/33) Update plugin description in code
- [#42](https://github.com/green-code-initiative/ecoCode/issues/42) Fix Crash SonarQube analysis because of some ClassCast Exceptions
- [#48](https://github.com/green-code-initiative/ecoCode/pull/48) correction SONAR issue info - delete public keyword on tests
-- Improve "build" Github actions to execute checks on branches from fork repositories
+- Improve "build" GitHub actions to execute checks on branches from fork repositories
## [0.2.1] - 2022-12-30
@@ -108,9 +169,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First official release of ecocode plugins : java plugin, php plugin and python plugin
-[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.1.0...HEAD
+[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.4.0...HEAD
+
+[1.4.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.3.1...v1.4.0
+
+[1.3.1]: https://github.com/green-code-initiative/ecoCode/compare/v1.3.0...v1.3.1
+
+[1.3.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.1...v1.3.0
+
+[1.2.1]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.0...v1.2.1
+
+[1.2.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.1.0...v1.2.0
-[1.0.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.0.0...v1.1.0
+[1.1.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/green-code-initiative/ecoCode/compare/v0.2.2...v1.0.0
diff --git a/Dockerfile b/Dockerfile
index e9dd8620f..d32d7b802 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,5 +5,5 @@ COPY . /usr/src/ecocode
WORKDIR /usr/src/ecocode
RUN ./tool_build.sh
-FROM sonarqube:9.9-community
+FROM sonarqube:10.1.0-community
COPY --from=builder /usr/src/ecocode/lib/* /opt/sonarqube/extensions/plugins/
diff --git a/INSTALL.md b/INSTALL.md
index 716f51d09..d459adc72 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -1,20 +1,19 @@
+# Install notes
+
- [Common installation notes / requirements](#common-installation-notes--requirements)
- [Special points for Standard plugins](#special-points-for-standard-plugins)
- [Project structure](#project-structure)
- [Plugin-specific guides](#plugin-specific-guides)
-Common installation notes / requirements
-========================================
+## Common installation notes / requirements
Please read common [INSTALL.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md)
in `ecoCode-common` repository. Please follow the specific guides below for additional information on installing the
desired plugins.
-Special points for Standard plugins
-=================================
+## Special points for Standard plugins
-Project structure
------------------
+### Project structure
Here is a preview of project tree :
@@ -23,21 +22,11 @@ ecoCode # Root directory
|
+--java-plugin # JAVA
|
-+--javascript-plugin # JavaScript
-|
-+--php-plugin # PHP
-|
-+--python-plugin # Python
-|
\--docker-compose.yml # Docker compose file
```
You will find more information about the pluginsβ architecture in their folders
-Plugin-specific guides
-----------------------
+### Plugin-specific guides
- [Java how-to](java-plugin/README.md)
-- [JavaScript how-to](javascript-plugin/README.md)
-- [Python how-to](python-plugin/README.md)
-- [PHP how-to](php-plugin/README.md)
diff --git a/README.md b/README.md
index eff1fbc1b..4942fbea7 100644
--- a/README.md
+++ b/README.md
@@ -20,9 +20,9 @@ refer to the contribution section.
4 technologies are supported by ecoCode right now:
- [Java](java-plugin/)
-- [JavaScript](javascript-plugin/)
-- [PHP](php-plugin/)
-- [Python](python-plugin/)
+- [JavaScript](https://github.com/green-code-initiative/ecoCode-javascript)
+- [PHP](https://github.com/green-code-initiative/ecoCode-php)
+- [Python](https://github.com/green-code-initiative/ecoCode-python)
![Screenshot](docs/resources/screenshot.PNG)
@@ -48,8 +48,6 @@ For example, youβll be able to access of all your `for` loop, to explore conte
To better understand AST structure, you can use the [AST Explorer](https://astexplorer.net/).
-JavaScript plugin works differently because it does not use AST. [More information here](javascript-plugin/README.md)
-
π Getting Started
------------------
@@ -78,22 +76,28 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
𧩠Plugins version compatibility
------------------
-| Plugins Version | SonarQube version |
-|------------------|----------------------------|
-| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 |
-| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 |
-| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 |
-| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 |
+| Plugins Version | SonarQube version |
+|------------------|-----------------------------|
+| 1.4.+ | SonarQube 9.4.+ LTS to 10.1 |
+| 1.3.+ | SonarQube 9.4.+ LTS to 10.0 |
+| 1.2.+ | SonarQube 9.4.+ LTS to 10.0 |
+| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 |
β Plugin Java part compatibility
------------------
| Plugins Version | Java version |
|------------------|--------------|
-| 0.1.+ | 11 / 17 |
-| 0.2.+ | 11 / 17 |
-| 1.0.+ | 11 / 17 |
+| 1.4.+ | 11 / 17 |
+| 1.3.+ | 11 / 17 |
+| 1.2.+ | 11 / 17 |
| 1.1.+ | 11 / 17 |
+| 1.0.+ | 11 / 17 |
+| 0.2.+ | 11 / 17 |
+| 0.1.+ | 11 / 17 |
π€ Contribution
---------------
@@ -117,13 +121,14 @@ Any question ? We are here for you !
first, create an issue, please.
Then, if no answer, contact ...
-- Jules Delecour
+- [Jules Delecour](https://www.linkedin.com/in/jules-delecour-498680118/)
- [Geoffrey LallouΓ©](https://github.com/glalloue)
-- Julien Hertout
+- [Julien Hertout](https://www.linkedin.com/in/julien-hertout-b1175449/)
- [Justin Berque](https://www.linkedin.com/in/justin-berque-444412140)
- [Olivier Le GoaΓ«r](https://olegoaer.perso.univ-pau.fr)
-- Maxime DUBOIS
-- [David DE CARVALHO](https://www.linkedin.com/in/%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-david%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-de-carvalho%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-8b395284/)
+- [Maxime DUBOIS](https://www.linkedin.com/in/maxime-dubois-%F0%9F%8C%B1-649a3a3/)
+- [David DE CARVALHO](https://www.linkedin.com/in/david%E2%80%8E-de-carvalho-8b395284/)
+- [Maxime MALGORN](https://www.linkedin.com/in/maximemalgorn/)
π§ Core Team Emeriti
--------------------
diff --git a/RULES.md b/RULES.md
index 7ef76d27a..dd5832c84 100644
--- a/RULES.md
+++ b/RULES.md
@@ -9,41 +9,46 @@ Some are applicable for different technologies.
- π Rule to implement
- π« Non applicable rule
-| Rule key | Name | Description | Reference/Validation | Java | Php | JS | Python | Rust |
-|--|--|--|--|--|--|--|--|--|
-| | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | π« | π« | π | π« | π« |
-| | Non-grouped similar CSS declarations | When multiple Document Object Model (DOM) elements have common CSS properties, declare them together in the same style sheet. This method reduces the weight of CSS. |[cnumr best practices (3rd edition) BP_025](https://github.com/cnumr/best-practices/blob/main/chapters/BP_025_fr.md) | π« | π« | π§ | π« | π« |
-| | CSS shorthand notations not used | Reduces the weight of the style sheet. | [cnumr best practices (3rd edition) BP_026](https://github.com/cnumr/best-practices/blob/main/chapters/BP_026_fr.md) | π« | π« | π« | π« | π« |
-| | CSS print not included | This style sheet reduces the number of pages printed. | [cnumr best practices (3rd edition) BP_027](https://github.com/cnumr/best-practices/blob/main/chapters/BP_027_fr.md) | π« | π« | π« | π« | π« |
-| | Non-standard fonts used | Prefer standard fonts, as they are already present on the user's computer, so they do not need to download them. This saves bandwidth, while speeding up the display of the site. | [cnumr best practices (3rd edition) BP_029](https://github.com/cnumr/best-practices/blob/main/chapters/BP_029_fr.md) | π« | π« | π« | π« | π« |
-| | Non-outsourced CSS and Javascript | If you include CSS or JavaScript code in the body of the HTML file, while the HTML file is used by several pages (or even the entire site), this code must be transferred for each page requested by the user, which increases the volume of data transmitted. | [cnumr best practices (3rd edition) BP_032](https://github.com/cnumr/best-practices/blob/main/chapters/BP_032_fr.md) | π« | π« | π | π« | π« |
-| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | π« | π« | π§ | π« | π« |
-| EC10 | Use unoptimized vector images | Less heavy SVG images using less bandwidth | [cnumr best practices (3rd edition) BP_036](https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md) | π§ | π | π | π§ | π |
-| | Using too many CSS/javascript animations | JavaScript/CSS animations can be very expensive in terms of CPU cycles and memory consumption. | [cnumr best practices (3rd edition) BP_039](https://github.com/cnumr/best-practices/blob/main/chapters/BP_039_fr.md) | π« | π« | π§ | π« | π« |
-| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | π« | π« | π§ | π« | π« |
-| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | π« | π« | π | π« | π« |
-| | Modify several CSS properties all at once | To limit the number of repaints/reflows, it is recommended not to modify properties one by one. | [cnumr best practices (3rd edition) BP_045](https://github.com/cnumr/best-practices/blob/main/chapters/BP_045_fr.md) | π« | π« | π | π« | π« |
-| EC34 | Using try...catch...finally calls | When an exception is thrown, a variable (the exception itself) is created in the catch block and destroyed at the end of the block. Creating this variable and destroying it consumes CPU cycles and RAM unnecessarily. That is why it is important not to use this construction and to prefer, as much as possible, a logical test. | [cnumr best practices (3rd edition) BP_047 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | β
| π |
-| EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | π | π |
-| ??? | Call a DOM element multiple times without caching (linter key : `@ecocode/no-multiple-access-dom-element`) | Access to the Document Object Model (DOM) is costly in terms of CPU resources (CPU cycles). Also, when you use the same DOM element from JavaScript multiple times, store its reference in a variable so that you do not go through the DOM again for the same element. | [cnumr best practices (3rd edition) BP_049](https://github.com/cnumr/best-practices/blob/main/chapters/BP_049_fr.md) | π« | π« | β
| π« | π« |
-| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
-| EC53 | Using arrays in foreach loops | foreach deduplicates items in a list before starting the enumeration. It is therefore generally more economical to use a simple for loop when you have a good command of the collection. | [cnumr best practices (3rd edition) BP_053 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| π | π | π | π |
-| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | π | π | β
| π |
-| EC63 | Unnecessarily assigning values to variables | Avoid declaring and using variables when it is not indis-thinkable. Indeed, each allocation corresponds to the RAM occupied. | [cnumr best practices (3rd edition) BP_063 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| π | π | π | π |
-| EC66 | Use single quote (') instead of quotation mark (") | The shape using the quotation marks allows the developer to insert variables that will be substituted at run time. But if the string does not have a variable, use quotes instead. Thus, language will not look for variables to subtituture, which will reduce the consumption of CPU cycles. | [cnumr best practices (3rd edition) BP_066 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | π | π |
-| EC67 | Use the $i++ variable during an iteration | The $i++ form has the disadvantage of generating a tem-porary variable during incrementation, which is not the case with the ++$i form. | [cnumr best practices (3rd edition) BP_067 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | π | π |
-| EC69 | Calling a function in the declaration of a for loop | Avoid calling the function each time the loop is iterated. | [cnumr best practices (3rd edition) BP_069 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
-| EC72 | Perform an SQL query inside a loop | Servers are optimized to process multiple selections, insertions, or changes in a single query or transaction. consume CPU cycles, RAM, and bandwidth unnecessarily. | [cnumr best practices (3rd edition) BP_072](https://github.com/cnumr/best-practices/blob/main/chapters/BP_072_fr.md) | β
| β
| π | β
| π |
-| EC74 | Write SELECT * FROM | The database server must resolve the fields based on the schema. If you are familiar with the diagram, it is strongly recommended to name the fields. | [cnumr best practices (3rd edition) BP_074 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
-| EC1 | Calling a Spring repository inside a loop | The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption. | | β
| π« | π« | π« | π« |
-| EC3 | Getting the size of the collection in the loop | When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. | | β
| π§ | π | π | π |
-| EC2 | Multiple if-else statement | Using too many conditional if-else statements will impact performance since JVM will have to compare the conditions. Prefer using a switch statement instead of multiple if-else if possible. Switch statement has a performance advantage over if β else. | | β
| π§ | π | π§ | π |
-| EC76 | Usage of static collections | Avoid usage of static collections. If you want to use static collections make them final and create for example a singleton if needed containing the collections. The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks. | | β
| π« | π« | π« | π« |
-| EC77 | Usage Pattern.compile() in a non-static context | Avoid using Pattern.compile() in a non-static context. This operation requires a non negligible amount of computational power, Using a single match saves CPU cycles and RAM consumption. | | β
| π« | π« | π« | π« |
-| EC75 | Concatenate Strings in loop | Don't concatenate Strings in loop. User StringBuilder instead. Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU. | | β
| π« | π« | π« | π« |
-| EC78 | Const parameter in batch update | Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily. | | β
| π« | π« | π« | π« |
-| EC79 | Free resources | try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources. | | β
| π« | π« | π« | π« |
-| EC32 | Initialize builder/buffer with the appropriate size | If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size. They will thus never have to be resized. This saves CPU cycles and therefore consumes less energy. | | β
| π« | π« | π« | π« |
-| EC28 | Optimize read file exceptions | | | β
| π« | π« | π« | π« |
-| EC5 | Usage of preparedStatement instead of Statement | SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption. | | β
| π« | π« | π« | π« |
-| EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | β
| π« | π« | π« | π« |
+| Rule key | Name | Description | Reference/Validation | Java | Php | JS | Python | Rust |
+|----------|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-----|----|--------|------|
+| | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | π« | π« | π | π« | π« |
+| | Non-grouped similar CSS declarations | When multiple Document Object Model (DOM) elements have common CSS properties, declare them together in the same style sheet. This method reduces the weight of CSS. | [cnumr best practices (3rd edition) BP_025](https://github.com/cnumr/best-practices/blob/main/chapters/BP_025_fr.md) | π« | π« | π§ | π« | π« |
+| | CSS shorthand notations not used | Reduces the weight of the style sheet. | [cnumr best practices (3rd edition) BP_026](https://github.com/cnumr/best-practices/blob/main/chapters/BP_026_fr.md) | π« | π« | π« | π« | π« |
+| | CSS print not included | This style sheet reduces the number of pages printed. | [cnumr best practices (3rd edition) BP_027](https://github.com/cnumr/best-practices/blob/main/chapters/BP_027_fr.md) | π« | π« | π« | π« | π« |
+| | Non-standard fonts used | Prefer standard fonts, as they are already present on the user's computer, so they do not need to download them. This saves bandwidth, while speeding up the display of the site. | [cnumr best practices (3rd edition) BP_029](https://github.com/cnumr/best-practices/blob/main/chapters/BP_029_fr.md) | π« | π« | π« | π« | π« |
+| | Non-outsourced CSS and Javascript | If you include CSS or JavaScript code in the body of the HTML file, while the HTML file is used by several pages (or even the entire site), this code must be transferred for each page requested by the user, which increases the volume of data transmitted. | [cnumr best practices (3rd edition) BP_032](https://github.com/cnumr/best-practices/blob/main/chapters/BP_032_fr.md) | π« | π« | π | π« | π« |
+| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | π« | π« | π§ | π« | π« |
+| EC10 | Use unoptimized vector images | Less heavy SVG images using less bandwidth | [cnumr best practices (3rd edition) BP_036](https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md) | π§ | π | π | β
| π |
+| | Using too many CSS/javascript animations | JavaScript/CSS animations can be very expensive in terms of CPU cycles and memory consumption. | [cnumr best practices (3rd edition) BP_039](https://github.com/cnumr/best-practices/blob/main/chapters/BP_039_fr.md) | π« | π« | π§ | π« | π« |
+| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | π« | π« | π§ | π« | π« |
+| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | π« | π« | π | π« | π« |
+| | Modify several CSS properties all at once | To limit the number of repaints/reflows, it is recommended not to modify properties one by one. (linter key : `@ecocode/no-multiple-style-changes`) | [cnumr best practices (3rd edition) BP_045](https://github.com/cnumr/best-practices/blob/main/chapters/BP_045_fr.md) | π« | π« | β
| π« | π« |
+| EC34 | Using try...catch...finally calls | When an exception is thrown, a variable (the exception itself) is created in the catch block and destroyed at the end of the block. Creating this variable and destroying it consumes CPU cycles and RAM unnecessarily. That is why it is important not to use this construction and to prefer, as much as possible, a logical test. | [cnumr best practices (3rd edition) BP_047 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | β
| π |
+| EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | π | π |
+| ??? | Call a DOM element multiple times without caching (linter key : `@ecocode/no-multiple-access-dom-element`) | Access to the Document Object Model (DOM) is costly in terms of CPU resources (CPU cycles). Also, when you use the same DOM element from JavaScript multiple times, store its reference in a variable so that you do not go through the DOM again for the same element. | [cnumr best practices (3rd edition) BP_049](https://github.com/cnumr/best-practices/blob/main/chapters/BP_049_fr.md) | π« | π« | β
| π« | π« |
+| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
+| EC53 | Using arrays in foreach loops | foreach deduplicates items in a list before starting the enumeration. It is therefore generally more economical to use a simple for loop when you have a good command of the collection. | [cnumr best practices (3rd edition) BP_053 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| π | π | π« | π |
+| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | π | π | β
| π |
+| EC63 | Unnecessarily assigning values to variables | Avoid declaring and using variables when it is not indis-thinkable. Indeed, each allocation corresponds to the RAM occupied. | [cnumr best practices (3rd edition) BP_063 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| π | π | π | π |
+| EC66 | Use single quote (') instead of quotation mark (") | The shape using the quotation marks allows the developer to insert variables that will be substituted at run time. But if the string does not have a variable, use quotes instead. Thus, language will not look for variables to subtituture, which will reduce the consumption of CPU cycles. | [cnumr best practices (3rd edition) BP_066 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π | β
| π | β
| π |
+| EC67 | Use the $i++ variable during an iteration | The $i++ form has the disadvantage of generating a tem-porary variable during incrementation, which is not the case with the ++$i form. | [cnumr best practices (3rd edition) BP_067 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | π« | π« |
+| EC69 | Calling a function in the declaration of a for loop | Avoid calling the function each time the loop is iterated. | [cnumr best practices (3rd edition) BP_069 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
+| EC72 | Perform an SQL query inside a loop | Servers are optimized to process multiple selections, insertions, or changes in a single query or transaction. consume CPU cycles, RAM, and bandwidth unnecessarily. | [cnumr best practices (3rd edition) BP_072](https://github.com/cnumr/best-practices/blob/main/chapters/BP_072_fr.md) | β
| β
| π | β
| π |
+| EC74 | Write SELECT * FROM | The database server must resolve the fields based on the schema. If you are familiar with the diagram, it is strongly recommended to name the fields. | [cnumr best practices (3rd edition) BP_074 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | β
| β
| π | β
| π |
+| EC1 | Calling a Spring repository inside a loop | The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption. | | β
| π« | π« | π« | π« |
+| EC3 | Getting the size of the collection in the loop | When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. | | β
| β
| π | π« | π |
+| EC2 | Multiple if-else statement | Using too many conditional if-else statements will impact performance since JVM will have to compare the conditions. Prefer using a switch statement instead of multiple if-else if possible, or refactor your code to reduce conditonnal statements on the same variable. Switch statement has a performance advantage over if β else. | | β
| β
| π | π§ | π |
+| EC76 | Usage of static collections | Avoid usage of static collections. If you want to use static collections make them final and create for example a singleton if needed containing the collections. The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks. | | β
| π« | π« | π« | π« |
+| EC77 | Usage Pattern.compile() in a non-static context | Avoid using Pattern.compile() in a non-static context. This operation requires a non negligible amount of computational power, Using a single match saves CPU cycles and RAM consumption. | | β
| π« | π« | π« | π« |
+| EC75 | Concatenate Strings in loop | Don't concatenate Strings in loop. User StringBuilder instead. Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU. | | β
| π« | π« | π« | π« |
+| EC78 | Const parameter in batch update | Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily. | | β
| π« | π« | π« | π« |
+| EC79 | Free resources | try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources. | | β
| π« | π« | π« | π« |
+| EC32 | Initialize builder/buffer with the appropriate size | If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size. They will thus never have to be resized. This saves CPU cycles and therefore consumes less energy. | | β
| π« | π« | π« | π« |
+| EC28 | Optimize read file exceptions | | | β
| π« | π« | π« | π« |
+| EC5 | Usage of preparedStatement instead of Statement | SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption. | | β
| π« | π« | π« | π« |
+| EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | β
| π« | π« | π« | π« |
+| EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | π« | π« | π« | β
| π« |
+| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | π | π | π | β
| π |
+| | Avoid high accuracy geolocation | Avoid using high accuracy geolocation in web applications (linter key : `@ecocode/avoid-high-accuracy-geolocation`) | | π« | π« | β
| π« | π« |
+| | No import all from library | Should not import all from library (linter key : `@ecocode/no-import-all-from-library`) | | π« | π« | β
| π« | π« |
+| | Prefer collections with pagination | Prefer API collections with pagination (linter key : `@ecocode/prefer-collections-with-pagination`) | | π« | π« | β
| π« | π« |
diff --git a/TODOs_DDC.md b/TODOs_DDC.md
new file mode 100644
index 000000000..712180f52
--- /dev/null
+++ b/TODOs_DDC.md
@@ -0,0 +1,16 @@
+TODOS dev DDC
+===
+
+actions vues en sΓ©ance weekly-meeting :
+
+- ecoCode-android : nettoyer packages (suite au release)
+- teams : nettoyer anciennes Γ©quipes
+
+actions vues perso :
+
+- nettoyer le MIGRATION_TODOs.md
+- mΓ©nage dans les branches de dev (local et remote)
+- JYC : suppression dΓ©pendance analyser-commons ==> check si bien tout nettoyΓ© (version dans pom, rΓ©fΓ©rence dans code)
+- voir les rules dΓ©sativΓ©es chez PJ, crΓ©er des issues et corriger (`avoidMultipleIfElse`) :
+ - voir pourquoi dΓ©sactivΓ©es car ralaient trop
+ - retester le EC2
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index bc48387aa..224b2fe21 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,7 +1,7 @@
version: "3.3"
services:
sonar:
- image: sonarqube:9.9-community
+ image: sonarqube:10.1.0-community
container_name: sonar_ecocode
ports:
- "9000:9000"
@@ -16,17 +16,8 @@ services:
SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
volumes:
- type: bind
- source: ./java-plugin/target/ecocode-java-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.1.1-SNAPSHOT.jar
- - type: bind
- source: ./javascript-plugin/target/ecocode-javascript-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.1.1-SNAPSHOT.jar
- - type: bind
- source: ./php-plugin/target/ecocode-php-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.1.1-SNAPSHOT.jar
- - type: bind
- source: ./python-plugin/target/ecocode-python-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.1.1-SNAPSHOT.jar
+ source: ./java-plugin/target/ecocode-java-plugin-1.4.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.4.1-SNAPSHOT.jar
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"
diff --git a/ecocode-rules-specifications/README.md b/ecocode-rules-specifications/README.md
new file mode 100644
index 000000000..1ee24ba52
--- /dev/null
+++ b/ecocode-rules-specifications/README.md
@@ -0,0 +1,15 @@
+# ecoCode rules specification repository
+
+## Description
+
+This project contains the specifications of the ecoCode rules.
+
+All the existing rules can be found in the [rules folder](src/main/rules).
+
+## Description language
+
+The description of the rules uses the ASCIIDOC format (with [Markdown compatibility](https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/#markdown-compatibility)) in order to allow the inclusion of other pages (this feature is not available in standard with Markdown).
+
+See:
+* [AsciiDoc Syntax Quick Reference](https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/)
+* [Compare AsciiDoc to Markdown](https://docs.asciidoctor.org/asciidoc/latest/asciidoc-vs-markdown/)
diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml
new file mode 100644
index 000000000..81977d3d7
--- /dev/null
+++ b/ecocode-rules-specifications/pom.xml
@@ -0,0 +1,238 @@
+
+
+ 4.0.0
+
+
+ io.ecocode
+ ecocode-parent
+ 1.4.1-SNAPSHOT
+
+
+ ecocode-rules-specifications
+
+ ecoCode Rules Specifications repository
+ Repository that contains the specifications of every static-analysis rules available in ecoCode plugins.
+ https://github.com/green-code-initiative/ecoCode/tree/main/ecocode-rules-specifications
+
+
+
+ org.sonarsource.sonarqube
+ sonar-plugin-api
+ provided
+
+
+ org.sonarsource.analyzer-commons
+ sonar-analyzer-commons
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
+
+
+ org.assertj
+ assertj-core
+ test
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+
+
+ prepare-agent
+
+ prepare-agent
+
+
+
+ report
+
+ report
+
+
+
+
+
+
+ org.asciidoctor
+ asciidoctor-maven-plugin
+ 2.2.4
+
+
+ convert-to-html
+ generate-resources
+
+ process-asciidoc
+
+
+ ${project.basedir}/src/main/rules
+ ${project.build.directory}/rules
+
+ coderay
+ style
+
+ true
+ false
+ true
+
+
+ ERROR
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.1.0
+
+
+ process-resources
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 3.6.0
+
+
+ assembly-java
+ prepare-package
+
+ single
+
+
+
+ ${project.basedir}/src/main/assembly/java.xml
+
+
+
+
+ assembly-php
+ prepare-package
+
+ single
+
+
+
+ ${project.basedir}/src/main/assembly/php.xml
+
+
+
+
+ assembly-python
+ prepare-package
+
+ single
+
+
+
+ ${project.basedir}/src/main/assembly/python.xml
+
+
+
+
+ assembly-js
+ prepare-package
+
+ single
+
+
+
+ ${project.basedir}/src/main/assembly/js.xml
+
+
+
+
+ assembly-ts
+ prepare-package
+
+ single
+
+
+
+ ${project.basedir}/src/main/assembly/ts.xml
+
+
+
+
+
+ true
+
+
+
+
+
diff --git a/ecocode-rules-specifications/src/main/assembly/java.xml b/ecocode-rules-specifications/src/main/assembly/java.xml
new file mode 100644
index 000000000..dc9d8bd3c
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/assembly/java.xml
@@ -0,0 +1,18 @@
+
+ java
+
+ jar
+
+ false
+
+
+ ${project.build.outputDirectory}
+
+ io/ecocode/rules/java/*.*
+
+
+
+
+
diff --git a/ecocode-rules-specifications/src/main/assembly/js.xml b/ecocode-rules-specifications/src/main/assembly/js.xml
new file mode 100644
index 000000000..d5d72ca1e
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/assembly/js.xml
@@ -0,0 +1,18 @@
+
+ js
+
+ jar
+
+ false
+
+
+ ${project.build.outputDirectory}
+
+ io/ecocode/rules/js/*.*
+
+
+
+
+
diff --git a/ecocode-rules-specifications/src/main/assembly/php.xml b/ecocode-rules-specifications/src/main/assembly/php.xml
new file mode 100644
index 000000000..83eb07521
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/assembly/php.xml
@@ -0,0 +1,18 @@
+
+ php
+
+ jar
+
+ false
+
+
+ ${project.build.outputDirectory}
+
+ io/ecocode/rules/php/*.*
+
+
+
+
+
diff --git a/ecocode-rules-specifications/src/main/assembly/python.xml b/ecocode-rules-specifications/src/main/assembly/python.xml
new file mode 100644
index 000000000..7c294fd24
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/assembly/python.xml
@@ -0,0 +1,18 @@
+
+ python
+
+ jar
+
+ false
+
+
+ ${project.build.outputDirectory}
+
+ io/ecocode/rules/python/*.*
+
+
+
+
+
diff --git a/ecocode-rules-specifications/src/main/assembly/ts.xml b/ecocode-rules-specifications/src/main/assembly/ts.xml
new file mode 100644
index 000000000..ec0100661
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/assembly/ts.xml
@@ -0,0 +1,18 @@
+
+ ts
+
+ jar
+
+ false
+
+
+ ${project.build.outputDirectory}
+
+ io/ecocode/rules/ts/*.*
+
+
+
+
+
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.json b/ecocode-rules-specifications/src/main/rules/EC1/EC1.json
similarity index 94%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.json
rename to ecocode-rules-specifications/src/main/rules/EC1/EC1.json
index d8da6723c..5b583dcfe 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.json
+++ b/ecocode-rules-specifications/src/main/rules/EC1/EC1.json
@@ -7,10 +7,10 @@
"constantCost": "50min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "spring",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc b/ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc
new file mode 100644
index 000000000..91ae3f7f0
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc
@@ -0,0 +1,23 @@
+The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption.
+
+## Noncompliant Code Example
+
+```java
+private final List ids = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+List employees = new ArrayList<>();
+
+for (Integer id: ids) {
+ Optional employee = employeeRepository.findById(id); // Noncompliant
+ if (employee.isPresent()) {
+ employees.add(employee.get());
+ }
+}
+```
+
+## Compliant Solution
+
+```java
+private final List ids = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+List employees = employeeRepository.findAllById(ids);
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC10/EC10.json b/ecocode-rules-specifications/src/main/rules/EC10/EC10.json
new file mode 100644
index 000000000..ec7fbffd9
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC10/EC10.json
@@ -0,0 +1,14 @@
+{
+ "title": "Avoid using unoptimized vector images",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "60min"
+ },
+ "tags": [
+ "eco-design",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC10/python/EC10.asciidoc b/ecocode-rules-specifications/src/main/rules/EC10/python/EC10.asciidoc
new file mode 100644
index 000000000..cf2483171
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC10/python/EC10.asciidoc
@@ -0,0 +1,39 @@
+SVG images generated by common drawing softwares contains unnecessary data: calc layer, metadata, namespaces and comments.
+
+## Noncompliant Code Example
+
+```xml
+
+
+
+
+
+
+```
+
+## Compliant Solution
+
+```xml
+
+
+
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC11/EC11.json b/ecocode-rules-specifications/src/main/rules/EC11/EC11.json
new file mode 100644
index 000000000..878a34665
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC11/EC11.json
@@ -0,0 +1,19 @@
+{
+ "title": "Disallow multiple access of same DOM element.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Major",
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC11/js/EC11.asciidoc b/ecocode-rules-specifications/src/main/rules/EC11/js/EC11.asciidoc
new file mode 100644
index 000000000..b5a2a8649
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC11/js/EC11.asciidoc
@@ -0,0 +1,20 @@
+## Rule details
+
+This rule aims to reduce DOM access assigning its object to variable when access multiple time. It saves CPU cycles.
+
+## Examples
+
+Examples of **incorrect** code for this rule:
+
+```js
+var el1 = document.getElementById("block1").test1;
+var el2 = document.getElementById("block1").test2;
+```
+
+Examples of **correct** code for this rule:
+
+```js
+var blockElement = document.getElementById("block1");
+var el1 = blockElement.test1;
+var el2 = blockElement.test2;
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC12/EC12.json b/ecocode-rules-specifications/src/main/rules/EC12/EC12.json
new file mode 100644
index 000000000..67c6010cf
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC12/EC12.json
@@ -0,0 +1,19 @@
+{
+ "title": "Disallow multiple style changes at once.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "10min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Major",
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC12/js/EC12.asciidoc b/ecocode-rules-specifications/src/main/rules/EC12/js/EC12.asciidoc
new file mode 100644
index 000000000..5bd836997
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC12/js/EC12.asciidoc
@@ -0,0 +1,33 @@
+## Rule Details
+
+This rule aims to disallow batching multiple style changes at once.
+
+To limit the number of repaint/reflow, it is advised to batch style modifications by adding a class containing all style changes that will generate a unique reflow.
+
+## Examples
+
+Examples of **non-compliant** code for this rule:
+
+```html
+
+```
+
+Examples of **compliant** code for this rule:
+
+```html
+
+
+
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC13/EC13.json b/ecocode-rules-specifications/src/main/rules/EC13/EC13.json
new file mode 100644
index 000000000..6ff60b4fa
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC13/EC13.json
@@ -0,0 +1,19 @@
+{
+ "title": "Prefer API collections with pagination.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "30min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor",
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC13/ts/EC13.asciidoc b/ecocode-rules-specifications/src/main/rules/EC13/ts/EC13.asciidoc
new file mode 100644
index 000000000..abc58bf6c
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC13/ts/EC13.asciidoc
@@ -0,0 +1,31 @@
+## Rule details
+
+This rule aims to reduce the size and thus the network weight of API returns that may contain many elements. This rule is built for the https://nestjs.com[NestJS framework] but can work with a controller `@Controller()` and a decorated method `@Get()`.
+
+## Examples
+
+Examples of **non-compliant** code for this rule:
+
+```typescript
+@Controller()
+class Test {
+ @Get()
+ public find(): Promise {}
+}
+```
+
+Examples of **compliant** code for this rule:
+
+```typescript
+interface Pagination {
+ items: string[];
+ currentPage: number;
+ totalPages: number;
+}
+
+@Controller()
+class Test {
+ @Get()
+ public find(): Promise {}
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.json b/ecocode-rules-specifications/src/main/rules/EC2/EC2.json
similarity index 95%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.json
rename to ecocode-rules-specifications/src/main/rules/EC2/EC2.json
index c4f0f80ab..d48945c08 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.json
+++ b/ecocode-rules-specifications/src/main/rules/EC2/EC2.json
@@ -9,8 +9,7 @@
"tags": [
"eco-design",
"performance",
- "bug",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc b/ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc
new file mode 100644
index 000000000..df00a5933
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc
@@ -0,0 +1,55 @@
+If we are using too many conditional IF, ELSEIF or ELSE statements it will impact performance.
+We can think of using a switch statement instead of multiple if-else if possible, or refactor code
+to reduce number of IF, ELSEIF and ELSE statements. Sometimes called "complexity cyclomatic".
+Switch statement has a performance advantage over if β else.
+
+## Functional rules
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at the same level - WARNINGs :
+- IF and ELSEIF statements use explicitly variable names !
+- ELSE statements use implicity variable names !
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at differents hierarchical levels
+- we can assume that if one variable is used three times or more, we should :
+- use a SWITCH statement instead
+- or refactor the code if possible
+
+## Non-compliant Code Example
+
+NON compliant, because `nb` is used 4 times :
+- 2 explicit times in IF statements
+- 2 implicit times in ELSE statements
+
+```java
+int index = 1;
+int nb = 2;
+...
+if (nb == 0) {
+ nb = index;
+} else if (nb == 1) {
+ nb = index * 2;
+} else if (nb == 2) {
+ nb = index * 3;
+} else {
+ nb = -1;
+}
+return nb;
+```
+
+## Compliant Code Example
+
+SWITCH statement solution + refactor solution
+
+```java
+int index = 1;
+int nb = 2;
+...
+switch (nb) {
+ case 0:
+ case 1:
+ case 2:
+ nb = index * (nb + 1);
+ break;
+ default:
+ nb = -1;
+}
+return nb;
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC2/php/EC2.asciidoc b/ecocode-rules-specifications/src/main/rules/EC2/php/EC2.asciidoc
new file mode 100644
index 000000000..eae2c2817
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC2/php/EC2.asciidoc
@@ -0,0 +1,55 @@
+If we are using too many conditional IF, ELSEIF or ELSE statements it will impact performance.
+We can think of using a switch statement instead of multiple if-else if possible, or refactor code
+to reduce number of IF, ELSEIF and ELSE statements. Sometimes called "complexity cyclomatic".
+Switch statement has a performance advantage over if β else.
+
+## Functional rules
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at the same level - WARNINGs :
+- IF and ELSEIF statements use explicitly variable names !
+- ELSE statements use implicity variable names !
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at differents hierarchical levels
+- we can assume that if one variable is used three times or more, we should :
+- use a SWITCH statement instead
+- or refactor the code if possible
+
+## Non-compliant Code Example
+
+NON compliant, because `$nb` is used 4 times :
+- 2 explicit times in IF statements
+- 2 implicit times in ELSE statements
+
+```php
+$index = 1;
+$nb = 2;
+...
+if ($nb == 0) {
+ $nb = $index;
+} elseif ($nb == 1) {
+ $nb = $index * 2;
+} elseif ($nb == 2) {
+ $nb = $index * 3;
+} else {
+ $nb = -1;
+}
+return $nb;
+```
+
+## Compliant Code Example
+
+SWITCH statement solution + refactor solution
+
+```php
+$index = 1;
+$nb = 2;
+...
+switch ($nb) {
+ case 0:
+ case 1:
+ case 2:
+ $nb = $index * ($nb + 1);
+ break;
+ default:
+ $nb = -1;
+}
+return $nb;
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC2/python/EC2.asciidoc b/ecocode-rules-specifications/src/main/rules/EC2/python/EC2.asciidoc
new file mode 100644
index 000000000..e2688d834
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC2/python/EC2.asciidoc
@@ -0,0 +1,54 @@
+If we are using too many conditional IF, ELSEIF or ELSE statements it will impact performance.
+We can think of using a switch statement instead of multiple if-else if possible, or refactor code
+to reduce number of IF, ELSEIF and ELSE statements. Sometimes called "complexity cyclomatic".
+MATCH-CASE statement has a performance advantage over if β else.
+
+## Functional rules
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at the same level - WARNINGs :
+- IF and ELSEIF statements use explicitly variable names !
+- ELSE statements use implicity variable names !
+- one variable must be used maximum twice in IF / ELSEIF / ELSE statements at differents hierarchical levels
+- we can assume that if one variable is used three times or more, we should :
+- use a MATCH-CASE statement instead
+- or refactor the code if possible
+
+## Non-compliant Code Example
+
+Non-compliant, because `nb` is used 4 times :
+- 2 explicit times in IF statements
+- 2 implicit times in ELSE statements
+
+```python
+index = 1
+nb = 2
+...
+if nb == 0:
+ nb = index
+elif nb == 1:
+ nb = index * 2
+elif nb == 2:
+ nb = index * 3
+else:
+ nb = -1
+return nb
+```
+
+## Compliant Code Example
+
+MATCH-CASE statement solution + refactor solution
+
+```python
+index = 1
+nb = 2
+...
+match nb:
+ case 0:
+ nb = index * (nb + 1)
+ case 1:
+ nb = index * (nb + 1)
+ case 2:
+ nb = index * (nb + 1)
+ case _:
+ nb = -1
+return nb
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC203/EC203.json b/ecocode-rules-specifications/src/main/rules/EC203/EC203.json
new file mode 100644
index 000000000..3f46aefd8
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC203/EC203.json
@@ -0,0 +1,16 @@
+{
+ "title": "Detect unoptimized image format",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "60min"
+ },
+ "tags": [
+ "performance",
+ "user-experience",
+ "eco-design",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc b/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc
new file mode 100644
index 000000000..85d38acb6
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc
@@ -0,0 +1,78 @@
+If possible, the utilisation of svg image format (or ` ` html tag) is recommended over other image format.
+
+Because SVGs are generally smaller than other image format, theyβre less taxing on your server despite needing to render on load.
+
+When to use SVG :
+
+- Your image is used for decorative website graphics, logos, icons, graphs and diagrams, and other simple images.
+- You image require animation.
+- You image need to be responsive and scale without lack of quality.
+
+Some advantages of using SVG:
+
+- SVGs are scalable and will render pixel-perfect at any resolution whereas JPEGs, PNGs and GIFs will not.
+- SVGs are vector images and therefore are usually much smaller in file-size than bitmap-based images.
+- SVGs can be embedded into the HTML which means they can be cached, edited directly using CSS and indexed for greater accessibility.
+- SVGs can be animated directly or by using CSS or JavaScript making it easy for web designers to add interactivity to a site.
+
+## Noncompliant Code Example
+
+```
+img_jpg = "image.jpg"
+```
+
+## Compliant Solution
+
+```
+img_svg = "image.svg"
+```
+
+## Noncompliant Code Example
+
+```
+public void foo() {
+ // ...
+ image_format = testImage("image.jpg")
+ // ...
+}
+```
+
+## Compliant Solution
+
+```
+public void foo() {
+ // ...
+ image_format = testImage("image.svg")
+ // ...
+}
+```
+
+## Noncompliant Code Example
+
+```
+public void foo() {
+ // ...
+ return ' '
+ // ...
+}
+```
+
+## Compliant Solution
+
+```
+public void foo() {
+ // ...
+ return ' '
+ // ...
+}
+```
+
+Or
+
+```
+ public void foo() {
+ // ...
+ return (' ')
+ // ...
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC22/EC22.json b/ecocode-rules-specifications/src/main/rules/EC22/EC22.json
new file mode 100644
index 000000000..9d3ed8c36
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC22/EC22.json
@@ -0,0 +1,15 @@
+{
+ "title": "Use of methods for basic operations",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC22/php/EC22.asciidoc b/ecocode-rules-specifications/src/main/rules/EC22/php/EC22.asciidoc
new file mode 100644
index 000000000..c42338993
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC22/php/EC22.asciidoc
@@ -0,0 +1,13 @@
+Use of methods for basic operations
+
+## Noncompliant Code Example
+
+```php
+$min = min($a, $b); // Noncompliant
+```
+
+## Compliant Solution
+
+```php
+$min = $a < $b ? $a : $b;
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.json b/ecocode-rules-specifications/src/main/rules/EC27/EC27.json
similarity index 95%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.json
rename to ecocode-rules-specifications/src/main/rules/EC27/EC27.json
index 13530377d..eaa045e90 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.json
+++ b/ecocode-rules-specifications/src/main/rules/EC27/EC27.json
@@ -7,10 +7,9 @@
"constantCost": "20min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc b/ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc
new file mode 100644
index 000000000..455e0a137
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc
@@ -0,0 +1,28 @@
+Using `System.arraycopy` to copy arrays
+
+Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms.
+
+For example, an array copy is potentially a non-performance source if it is poorly designed. Indeed, the use of a single copy loop can be twice as consuming as dedicated methods.
+Loops must be optimized to reduce processing time and make full use of hardware and processor mechanisms and optimizations.
+In the case of table copying (table), use the native `System.arraycopy`.
+We can also use `copyOf` or `clone` that are slightly less efficient.
+The looping method will be outlawed.
+
+## Noncompliant Code Example
+
+```java
+int len = array.length;
+boolean[] copy = new boolean[array.length];
+for (int i = 0; i < len; i++) {
+ copy[i] = array[i]; // Noncompliant
+}
+return copy;
+```
+
+## Compliant Solution
+
+```java
+int[] copy = new int[array.length];
+System.arraycopy(array, 0, copy, 0, array.length);
+return copy;
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.json b/ecocode-rules-specifications/src/main/rules/EC28/EC28.json
similarity index 86%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.json
rename to ecocode-rules-specifications/src/main/rules/EC28/EC28.json
index 80cf37817..c85d2ee51 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.json
+++ b/ecocode-rules-specifications/src/main/rules/EC28/EC28.json
@@ -7,8 +7,9 @@
"constantCost": "5min"
},
"tags": [
+ "performance",
+ "error-handling",
"eco-design",
- "bug",
"ecocode"
],
"defaultSeverity": "Minor"
diff --git a/ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc b/ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc
new file mode 100644
index 000000000..841ee9f8c
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc
@@ -0,0 +1,30 @@
+Optimize read file exception
+
+## Noncompliant Code Example
+
+```java
+public void readPreferences(String filename) {
+ //...
+ InputStream in = null;
+ try {
+ in = new FileInputStream(filename);
+ } catch (FileNotFoundException e) {
+ logger.log(e);
+ }
+ in.read(...);
+ //...
+}
+```
+
+## Compliant Solution
+
+```java
+public void readPreferences(String filename) throws IllegalArgumentException, FileNotFoundException, IOException {
+ if (filename == null) {
+ throw new IllegalArgumentException ("filename is null");
+ }
+ //...
+ InputStream in = new FileInputStream(filename);
+ //...
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.json b/ecocode-rules-specifications/src/main/rules/EC3/EC3.json
similarity index 93%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.json
rename to ecocode-rules-specifications/src/main/rules/EC3/EC3.json
index a8b365948..33916b15e 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.json
+++ b/ecocode-rules-specifications/src/main/rules/EC3/EC3.json
@@ -7,10 +7,10 @@
"constantCost": "5min"
},
"tags": [
+ "bad-practice",
"eco-design",
"performance",
- "bug",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc b/ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc
new file mode 100644
index 000000000..49fcb223e
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc
@@ -0,0 +1,22 @@
+When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. The example provided below illustrates what should be avoided.
+
+## Noncompliant Code Example
+
+```java
+List objList = getData();
+
+for (int i = 0; i < objList.size(); i++) { // Noncompliant
+ // execute code
+}
+```
+
+## Compliant Solution
+
+```java
+List objList = getData();
+
+int size = objList.size();
+for (int i = 0; i < size; i++) {
+ // execute code
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC3/php/EC3.asciidoc b/ecocode-rules-specifications/src/main/rules/EC3/php/EC3.asciidoc
new file mode 100644
index 000000000..9c4d5bb81
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC3/php/EC3.asciidoc
@@ -0,0 +1,96 @@
+When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power.
+
+NB : note that we are using the `count()` method to get the size of an array but it would work the same with the `sizeof()` and `iterator_count()` methods.
+
+## Noncompliant Code Example
+
+```php
+$array = array('orange', 'banana', 'apple', 'carrot', 'collard', 'pea');
+
+// FOR STATEMENTS / Right operand
+for ($i = 0; $i < count($array); ++$i) {
+ var_dump($array[$i]);
+}
+
+// FOR STATEMENTS / Left operand
+for ($i = 0; count($array) > $i; ++$i) {
+ var_dump($array[$i]);
+}
+
+// WHILE STATEMENTS / Right operand
+$i = 0;
+while($i < count($array)) {
+ var_dump($array[$i]);
+ ++$i;
+}
+
+// WHILE STATEMENTS / Left operand
+$i = 0;
+while(count($array) > $i) {
+ var_dump($array[$i]);
+ ++$i;
+}
+
+// DO WHILE STATEMENTS / Right operand
+$i = 0;
+do {
+ var_dump($array[$i]);
+ ++$i;
+} while ($i < count($array));
+
+// DO WHILE STATEMENTS / Left operand
+$i = 0;
+do {
+ var_dump($array[$i]);
+ ++$i;
+} while (count($array) > $i);
+```
+
+## Compliant Solution
+
+```php
+$array = array('orange', 'banana', 'apple', 'carrot', 'collard', 'pea');
+// FOR STATEMENTS / Right operand
+$size = sizeof($array);
+for ($i = 0; $i < $size; ++$i) {
+ var_dump($array[$i]);
+}
+
+// FOR STATEMENTS / Left operand
+$size = sizeof($array);
+for ($i = 0; $size > $i; ++$i) {
+ var_dump($array[$i]);
+}
+
+// WHILE STATEMENTS / Right operand
+$i = 0;
+$size = count($array);
+while($i < $size) {
+ var_dump($array[$i]);
+ ++$i;
+}
+
+// WHILE STATEMENTS / Left operand
+$i = 0;
+$size = count($array);
+while($size > $i) {
+ var_dump($array[$i]);
+ ++$i;
+}
+
+// DO WHILE STATEMENTS / Right operand
+$i = 0;
+$size = count($array);
+do {
+ var_dump($array[$i]);
+ ++$i;
+} while ($i < $size);
+
+// DO WHILE STATEMENTS / Left operand
+$i = 0;
+$size = count($array);
+do {
+ var_dump($array[$i]);
+ ++$i;
+} while ($size > $i);
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.json b/ecocode-rules-specifications/src/main/rules/EC32/EC32.json
similarity index 96%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.json
rename to ecocode-rules-specifications/src/main/rules/EC32/EC32.json
index 9a76c4c9e..95e1d7b33 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.json
+++ b/ecocode-rules-specifications/src/main/rules/EC32/EC32.json
@@ -7,10 +7,9 @@
"constantCost": "5min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc b/ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc
new file mode 100644
index 000000000..00c2ac907
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc
@@ -0,0 +1,21 @@
+If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size.
+They will thus never have to be resized.
+This saves CPU cycles and therefore consumes less energy.
+
+## Noncompliant Code Example
+
+```java
+StringBuilder sb = new StringBuilder(); // Noncompliant
+for (int i = 0; i < 100; i++) {
+ sb.append(...);
+}
+```
+
+## Compliant Solution
+
+```java
+StringBuilder sb = new StringBuilder(100);
+for (int i = 0; i < 100; i++) {
+ sb.append(...);
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC34/EC34.json b/ecocode-rules-specifications/src/main/rules/EC34/EC34.json
new file mode 100644
index 000000000..00bc65320
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC34/EC34.json
@@ -0,0 +1,15 @@
+{
+ "title": "Avoid using try-catch statement",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC34/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC34/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..5b56c3789
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC34/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),515.855638,516.9188409999999
+Transfer (B),1579453,1579457
+Storage (B),637549804,637549804
diff --git a/ecocode-rules-specifications/src/main/rules/EC34/php/EC34.asciidoc b/ecocode-rules-specifications/src/main/rules/EC34/php/EC34.asciidoc
new file mode 100644
index 000000000..f7b2ab71d
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC34/php/EC34.asciidoc
@@ -0,0 +1,45 @@
+Inside complex code parts (for exemple multiple loops, complex data constructions...), avoid using try...catch...finally.
+
+When an exception is thrown, a variable (the exception itself) is created in a catch block and it's destruction consumes unnecessary CPU cycles and RAM. Prefer using logical tests in this cases.
+
+## Noncompliant Code Example
+
+```php
+try
+{
+ $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
+}
+catch(Exception $ex)
+{
+ $msg = "Error opening $imgFile for Product $row['Identifier']";
+ throw new Exception($msg);
+}
+```
+
+## Compliant Solution
+
+```php
+//try
+if (file_exists($imgFile)) {
+ $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0);
+}
+
+//catch
+if (!$picture) {
+ $msg = "Error opening $imgFile for Product $row['Identifier']";
+ print $msg;
+}
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52622382871_f19da08db4_o.png[ETSdiff percent comparison]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
diff --git a/ecocode-rules-specifications/src/main/rules/EC34/python/EC34.asciidoc b/ecocode-rules-specifications/src/main/rules/EC34/python/EC34.asciidoc
new file mode 100644
index 000000000..14b3c3c5b
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC34/python/EC34.asciidoc
@@ -0,0 +1,25 @@
+Inside complex code parts (for example multiple loops, complex data constructions...), avoid using try...catch...finally.
+
+When an exception is thrown, a variable (the exception itself) is created in a catch block, and it's destruction consumes unnecessary CPU cycles and RAM. Prefer using logical tests in this cases.
+
+## Noncompliant Code Example
+
+```python
+try:
+ f = open(path)
+ print(fh.read())
+except:
+ print('No such file '+path
+finally:
+ f.close()
+```
+
+## Compliant Solution
+
+```python
+if os.path.isfile(path):
+ fh = open(path, 'r')
+ print(fh.read())
+ fh.close
+```
+
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.json b/ecocode-rules-specifications/src/main/rules/EC4/EC4.json
similarity index 95%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.json
rename to ecocode-rules-specifications/src/main/rules/EC4/EC4.json
index 292eca846..0cf5108bd 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.json
+++ b/ecocode-rules-specifications/src/main/rules/EC4/EC4.json
@@ -7,10 +7,9 @@
"constantCost": "5min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc b/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc
new file mode 100644
index 000000000..f8763b4ed
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc
@@ -0,0 +1,37 @@
+Prefer local variables as parameters
+
+When calling a global variable, the interpretation engine must check that it exists in all the scopes, that it has a value, etc. Passing global variables as arguments gives them the status of local variables inside the function, thus saving computing time (CPU cycles).
+
+## CASE 1 (Avoid as possible)
+
+You are back on the service code. You see that the `func1()` uses `globalVariabl1`. Okay, but whats its value by now ? How does it change ? Who mutates the `globalVariabl1` before it comes to this function ? What have been the sequence of all these mutations ? You would have no idea. It will be quite difficult to figure all this out.
+
+## CASE 2 (Recommended)
+
+You are back to you code, and see that the `func0()` fetches something and then passes it to `func1(param1)` as a parameter. You clearly know what the data is, how does it gets here.
+
+## Noncompliant Code Example
+
+```java
+var aGlobal = new String('Hello');
+
+function globalLength(){
+ length = aGlobal.length;
+ console.log(length);
+}
+
+globalLength();
+```
+
+## Compliant Solution
+
+```java
+var aGlobal = new String('Hello');
+
+function someVarLength(str){
+ length = str.length;
+ console.log(length);
+}
+
+somVarLength(aGlobal);
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC4/php/EC4.asciidoc b/ecocode-rules-specifications/src/main/rules/EC4/php/EC4.asciidoc
new file mode 100644
index 000000000..94021a9e6
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC4/php/EC4.asciidoc
@@ -0,0 +1,29 @@
+Prefer local variables as parameters
+
+When calling a global variable, the interpretation engine must check that it exists in all the scopes, that it has a value, etc. Passing global variables as arguments gives them the status of local variables inside the function, thus saving computing time (CPU cycles).
+
+## Noncompliant Code Example
+
+```php
+var aGlobal = new String('Hello');
+
+function globalLength(){
+ length = aGlobal.length;
+ console.log(length);
+}
+
+globalLength();
+```
+
+## Compliant Solution
+
+```php
+var aGlobal = new String('Hello');
+
+function someVarLength(str){
+ length = str.length;
+ console.log(length);
+}
+
+somVarLength(aGlobal);
+```
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC4.html b/ecocode-rules-specifications/src/main/rules/EC4/python/EC4.asciidoc
similarity index 55%
rename from python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC4.html
rename to ecocode-rules-specifications/src/main/rules/EC4/python/EC4.asciidoc
index c92e7e5be..b777840a9 100644
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC4.html
+++ b/ecocode-rules-specifications/src/main/rules/EC4/python/EC4.asciidoc
@@ -1,20 +1,24 @@
-When function calls global variables, a lot a CPU cycles is consumed.
-Noncompliant Code Example
-
+When function calls global variables, a lot a CPU cycles is consumed.
+
+## Noncompliant Code Example
+
+```python
global_var = 'foo'
def print_global_var_details():
print(len(global_var)) # Noncompliant
print('Global var : ', global_var) # Noncompliant
print('Global var : ' + global_var) # Noncompliant
print_global_var_details()
-
-Compliant Solution
-
+```
+
+## Compliant Solution
+
+```python
global_var = 'foo';
def print_var_details(local_var) {
- print(len(local_var));
- print('Var : ', local_var)
- print('Var : ' + local_var)
+ print(len(local_var));
+ print('Var : ', local_var)
+ print('Var : ' + local_var)
}
print_length(global_var);
-
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC404/EC404.json b/ecocode-rules-specifications/src/main/rules/EC404/EC404.json
new file mode 100644
index 000000000..c04d919d3
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC404/EC404.json
@@ -0,0 +1,15 @@
+{
+ "title": "Use generator comprehension instead of list comprehension in for loop declaration",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "performance",
+ "eco-design",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC404/python/EC404.asciidoc b/ecocode-rules-specifications/src/main/rules/EC404/python/EC404.asciidoc
new file mode 100644
index 000000000..4a0738f9f
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC404/python/EC404.asciidoc
@@ -0,0 +1,20 @@
+Use generator comprehension instead of list comprehension in for loop declaration.
+
+Python generators resemble lazy lists from other programming languages: when iterated over, they compute their values on the fly. They lack some list behaviors (indexing, len method, ...) but are memory-efficient, as they do not store each of their values in memory, unlike lists. Thus, when declared in a for-loop declaration, list comprehensions can be safely replaced with generator comprehensions.
+
+For more details on list comprehensions vs generator comprehensions, see https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions[Python documentation].
+
+## Noncompliant Code Example
+
+```python
+for var in [var2 for var2 in range(100)]:
+ ...
+
+```
+
+## Compliant Solution
+
+```python
+for var in (var2 for var2 in range(100)):
+ ...
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.json b/ecocode-rules-specifications/src/main/rules/EC5/EC5.json
similarity index 95%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.json
rename to ecocode-rules-specifications/src/main/rules/EC5/EC5.json
index 1095573a9..6629e0943 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.json
+++ b/ecocode-rules-specifications/src/main/rules/EC5/EC5.json
@@ -7,10 +7,10 @@
"constantCost": "10min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "sql",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc b/ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc
new file mode 100644
index 000000000..229a3503d
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc
@@ -0,0 +1,22 @@
+Use `PreparedStatement` instead of `Statement`, because SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption.
+
+## Noncompliant Code Example
+
+```java
+public void select() {
+ Statement statement = connection.createStatement();
+ statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'John DOE')"); // Noncompliant
+}
+```
+
+## Compliant Solution
+
+```java
+public void select() {
+ PreparedStatement statement = connection.prepareStatement(INSERT INTO persons(id, name) VALUES(?, ?));
+
+ statement.setInt(1, 2);
+ statement.setString(2, "John DOE");
+ statement.executeQuery();
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.json b/ecocode-rules-specifications/src/main/rules/EC53/EC53.json
similarity index 96%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.json
rename to ecocode-rules-specifications/src/main/rules/EC53/EC53.json
index f6411338f..3b1f7e72b 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.json
+++ b/ecocode-rules-specifications/src/main/rules/EC53/EC53.json
@@ -7,9 +7,8 @@
"constantCost": "5min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
diff --git a/ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc b/ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc
new file mode 100644
index 000000000..924efda63
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc
@@ -0,0 +1,21 @@
+Using List instead of Arrays with Foreach save CPU cycles calculations and RAM consumption.
+
+## Noncompliant Code Example
+
+```java
+private final Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+for (Integer i : intArray) {
+ // ...
+}
+```
+
+## Compliant Solution
+
+```java
+private final List intList = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
+
+for (Integer i : intList) {
+ // ...
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.json b/ecocode-rules-specifications/src/main/rules/EC63/EC63.json
similarity index 86%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.json
rename to ecocode-rules-specifications/src/main/rules/EC63/EC63.json
index b09e15020..dc9189905 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.json
+++ b/ecocode-rules-specifications/src/main/rules/EC63/EC63.json
@@ -8,9 +8,8 @@
},
"tags": [
"eco-design",
- "memory",
- "bug",
- "ecocode"
+ "ecocode",
+ "memory"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc b/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc
new file mode 100644
index 000000000..9d3ca796d
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc
@@ -0,0 +1,17 @@
+Do not unnecessarily assign values to variables. It increases the use of RAM memory.
+
+## Noncompliant Code Example
+
+```java
+String var1 = getValue();
+return var1;
+
+String var2 = "hello"
+var2 = "world" //Non compliant cause never assigned
+```
+
+## Compliant Solution
+
+```java
+return getValue();
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC66/EC66.json b/ecocode-rules-specifications/src/main/rules/EC66/EC66.json
new file mode 100644
index 000000000..034168254
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC66/EC66.json
@@ -0,0 +1,16 @@
+{
+ "title": "Avoid using double quote (\"), prefer using simple quote (')",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "bad-practice",
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC66/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC66/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..4765a99fe
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC66/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),3.041966,1.2651545000000002
+Transfer (B),68520884,68588123
+Storage (B),637548795,637548795
diff --git a/ecocode-rules-specifications/src/main/rules/EC66/php/EC66.asciidoc b/ecocode-rules-specifications/src/main/rules/EC66/php/EC66.asciidoc
new file mode 100644
index 000000000..8af551481
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC66/php/EC66.asciidoc
@@ -0,0 +1,30 @@
+PHP allows declaring a string with simple or double quotes. Using double quotes allows developers to insert variables which will be substituted during execution. When the string has no variables, using single quotes prevents PHP from searching for non-existent variables. It will save CPU cycles consumption and RAM usage.
+
+## Noncompliant Code Example
+
+```php
+myFunction("name", "age", "IsStudent");
+ $lastName = "Hugo";
+ $concatenatedString = "$lastName is a student";
+```
+
+## Compliant Solution
+
+```php
+myFunction('name', 'age', 'IsStudent');
+ $lastName = 'Hugo';
+ $concatenatedString = $lastName . 'is a student';
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52621866212_de15608a41_o.png[ETSdiff percent comparison]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
diff --git a/ecocode-rules-specifications/src/main/rules/EC66/python/EC66.asciidoc b/ecocode-rules-specifications/src/main/rules/EC66/python/EC66.asciidoc
new file mode 100644
index 000000000..09e0eda41
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC66/python/EC66.asciidoc
@@ -0,0 +1,31 @@
+The shape using the quotation marks (") allows the developer to insert variables that will be substituted at run time.
+
+But if the string does not have a variable, use quotes (') instead.
+
+Thus, language will not look for variables to substitute, which will reduce the consumption of CPU cycles.
+
+## Noncompliant Code Example
+
+```python
+# in variables
+firstname = "Andrea" # Noncompliant {{Avoid using quotation mark ("), prefer using simple quote (')}}
+
+# in functions
+def my_function(name, age):
+ print(name + 'is' + age + ' yo.')
+
+my_function("Robert", 12) # Noncompliant {{Avoid using quotation mark ("), prefer using simple quote (')}}
+```
+
+## Compliant Solution
+
+```python
+# in variables
+firstname = 'Andrea'
+
+# in functions
+def my_function(name, age):
+ print(name + 'is' + age + ' yo.')
+
+my_function('Robert', 12)
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.json b/ecocode-rules-specifications/src/main/rules/EC67/EC67.json
similarity index 96%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.json
rename to ecocode-rules-specifications/src/main/rules/EC67/EC67.json
index a13d7e7cd..824d66d16 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.json
+++ b/ecocode-rules-specifications/src/main/rules/EC67/EC67.json
@@ -7,9 +7,8 @@
"constantCost": "5min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
diff --git a/ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc b/ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc
new file mode 100644
index 000000000..a0c7b961a
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc
@@ -0,0 +1,13 @@
+The form `$i++` creates a temporary variable whereas `++$i` does not. It save CPU cycles.
+
+## Noncompliant Code Example
+
+```java
+i++ // Noncompliant
+```
+
+## Compliant Solution
+
+```java
+++i
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC67/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC67/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..c79e54fc0
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC67/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),1.8163645000000002,0.2613885000000001
+Transfer (B),11265758,11290494
+Storage (B),637548673,637548673
diff --git a/ecocode-rules-specifications/src/main/rules/EC67/php/EC67.asciidoc b/ecocode-rules-specifications/src/main/rules/EC67/php/EC67.asciidoc
new file mode 100644
index 000000000..9a025ea99
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC67/php/EC67.asciidoc
@@ -0,0 +1,26 @@
+The form `$i++` creates a temporary variable whereas `++$i` does not. It save CPU cycles.
+
+## Noncompliant Code Example
+
+```php
+$i++
+```
+
+## Compliant Solution
+
+```php
+++$i
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52622379586_f84c767111_o.png[ETSdiff percent comparison]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.json b/ecocode-rules-specifications/src/main/rules/EC69/EC69.json
similarity index 96%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.json
rename to ecocode-rules-specifications/src/main/rules/EC69/EC69.json
index f00a9b99b..b66f24ee0 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.json
+++ b/ecocode-rules-specifications/src/main/rules/EC69/EC69.json
@@ -7,10 +7,9 @@
"constantCost": "5min"
},
"tags": [
- "eco-design",
"performance",
- "bug",
+ "eco-design",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc b/ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc
new file mode 100644
index 000000000..e32cd94db
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc
@@ -0,0 +1,24 @@
+Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.
+
+## Noncompliant Code Example
+
+```java
+public void foo() {
+ for (int i = 0; i < getMyValue(); i++) { // Noncompliant
+ System.out.println(i);
+ boolean b = getMyValue() > 6;
+ }
+}
+```
+
+## Compliant Solution
+
+```java
+public void foo() {
+ int myValue = getMyValue();
+ for (int i = 0; i < myValue; i++) {
+ System.out.println(i);
+ boolean b = getMyValue() > 6;
+ }
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC69/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC69/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..227f4def5
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC69/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),144.635057,144.58341249999998
+Transfer (B),50000,50004
+Storage (B),637549590,637549590
diff --git a/ecocode-rules-specifications/src/main/rules/EC69/php/EC69.asciidoc b/ecocode-rules-specifications/src/main/rules/EC69/php/EC69.asciidoc
new file mode 100644
index 000000000..0da3cde83
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC69/php/EC69.asciidoc
@@ -0,0 +1,38 @@
+Do not call a function when declaring a for-type loop in order to avoid function calls each iteration. It saves CPU cycles.
+
+## Noncompliant Code Example
+
+```php
+for ($i = 0; $i <= foo(); $i++) { // Noncompliant
+ // ......
+}
+```
+
+## Compliant Solution
+
+```php
+$maxI = foo();
+for ($i = 0; $i <= $maxI; $i++) {
+ .....
+}
+
+ OR
+
+for ($i = 0, $maxI = foo(); $i <= $maxI; $i++) {
+ .....
+}
+}
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52622634654_bf3c3d9ba8_o.png[ETSdiff percent comparison]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
diff --git a/ecocode-rules-specifications/src/main/rules/EC69/python/EC69.asciidoc b/ecocode-rules-specifications/src/main/rules/EC69/python/EC69.asciidoc
new file mode 100644
index 000000000..3d73ce30a
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC69/python/EC69.asciidoc
@@ -0,0 +1,17 @@
+Do not call a function when declaring a for-type loop in order to avoid function calls each iteration. It saves CPU cycles.
+
+## Noncompliant Code Example
+
+```python
+for i in my_function(): # Noncompliant
+ ......
+```
+
+## Compliant Solution
+
+```python
+limit = my_function()
+for i in limit:
+ ......
+```
+
diff --git a/ecocode-rules-specifications/src/main/rules/EC7/EC7.json b/ecocode-rules-specifications/src/main/rules/EC7/EC7.json
new file mode 100644
index 000000000..46c194d56
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC7/EC7.json
@@ -0,0 +1,15 @@
+{
+ "title": "Avoid creating getter and setter methods in classes",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC7.html b/ecocode-rules-specifications/src/main/rules/EC7/python/EC7.asciidoc
similarity index 75%
rename from python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC7.html
rename to ecocode-rules-specifications/src/main/rules/EC7/python/EC7.asciidoc
index 181906af2..4ca4240e5 100644
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC7.html
+++ b/ecocode-rules-specifications/src/main/rules/EC7/python/EC7.asciidoc
@@ -1,6 +1,8 @@
-Avoid Getters and Setters in class, It increase unless RAM memory usage.
-Noncompliant Code Example
-
+Avoid using getters and setters in a class, as they increase unnecessary RAM memory usage.
+
+## Noncompliant Code Example
+
+```python
class Client():
def __init__(self, age):
@@ -15,10 +17,11 @@ Noncompliant Code Example
client = Client(25)
client.get_age() # Getter inutile
client.set_age(25) # Setter inutile
+```
-
-Compliant Solution
-
+## Compliant Solution
+
+```python
class Client():
def __init__(self, age):
@@ -33,4 +36,5 @@ Compliant Solution
client = Client(25)
client.age # RΓ©cupΓ©rer l'attribut age
client.age = 26 # Modifier l'attribut age
-
+```
+
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.json b/ecocode-rules-specifications/src/main/rules/EC72/EC72.json
similarity index 86%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.json
rename to ecocode-rules-specifications/src/main/rules/EC72/EC72.json
index 3cbb604ed..5fdf8c909 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.json
+++ b/ecocode-rules-specifications/src/main/rules/EC72/EC72.json
@@ -7,13 +7,13 @@
"constantCost": "10min"
},
"tags": [
- "eco-design",
"performance",
- "memory",
- "network",
"sql",
- "bug",
- "ecocode"
+ "spring",
+ "eco-design",
+ "ecocode",
+ "memory",
+ "network"
],
"defaultSeverity": "Minor"
}
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc b/ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc
new file mode 100644
index 000000000..7032eb960
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc
@@ -0,0 +1,50 @@
+Executing SQL queries in loop induced unnecessary calculation by the CPU, RAM usage and network transfer.
+
+## Noncompliant Code Example
+
+```java
+public void foo() {
+ // ...
+ String baseQuery = "SELECT name FROM users where id = ";
+
+ for (int i = 0; i < 20; i++) {
+
+ String query = baseQuery.concat("" + i);
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery(query); // Noncompliant
+
+ // iterate through the java resultset
+ while (rs.next()) {
+ String name = rs.getString("name");
+ System.out.println(name);
+ }
+ st.close();
+ }
+ // ...
+}
+```
+
+## Compliant Solution
+
+```java
+public void foo() {
+ // ...
+ String query = "SELECT name FROM users where id in (0 ";
+ for (int i = 1; i < 20; i++) {
+
+ query = baseQuery.concat("," + i);
+ }
+
+ query = baseQuery.concat(")");
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery(query); // compliant
+
+ // iterate through the java resultset
+ while (rs.next()) {
+ String name = rs.getString("name");
+ System.out.println(name);
+ }
+ st.close();
+ // ...
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC72/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..b006091ac
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),73.907586,82.15627099999998
+Transfer (B),49526,221836
+Storage (B),637549572,637549572
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/php/2GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC72/php/2GB.etsdiff.csv
new file mode 100644
index 000000000..73f5bac22
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/php/2GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),159.4871645,169.746055
+Transfer (B),50385,228225
+Storage (B),1178614788,1178614788
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/php/4GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC72/php/4GB.etsdiff.csv
new file mode 100644
index 000000000..4c253ef72
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/php/4GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),395.7629349999999,404.37447649999996
+Transfer (B),51597,238884
+Storage (B),2357214212,2357214212
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/php/8GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC72/php/8GB.etsdiff.csv
new file mode 100644
index 000000000..2a518e5eb
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/php/8GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),992.128585,1005.4625534999999
+Transfer (B),52189,249499
+Storage (B),4685052932,4685052932
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/php/EC72.asciidoc b/ecocode-rules-specifications/src/main/rules/EC72/php/EC72.asciidoc
new file mode 100644
index 000000000..12fe0d7b7
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/php/EC72.asciidoc
@@ -0,0 +1,91 @@
+Executing SQL queries in loop induced unnecessary network transfert, calculation by the cpu and RAM usage.
+
+## Noncompliant Code Example
+
+```php
+public function foo() {
+ ...
+ $baseQuery = "SELECT name FROM users where id = ";
+
+ for ($i = 0; $i < 20; ++$i) {
+
+ $query = $baseQuery . $i;
+ $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
+ mysql_select_db($dbname) or die("Could not open the db '$dbname'");
+ $result = mysql_query($this->Query);// Noncompliant
+
+ // iterate through the result
+ ...
+ mysql_close($connection);
+ }
+ ...
+}
+```
+
+## Compliant Solution
+
+```php
+public function foo() {
+ ...
+ $query = "SELECT name FROM users where id in (";
+
+ for ($i = 0; $i < 20; ++$i) {
+ $query .= ',' . $i;
+ }
+ $query .= ')';
+
+ $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
+ mysql_select_db($dbname) or die("Could not open the db '$dbname'");
+ $result = mysql_query($this->Query); // compliant
+
+ // iterate through the result
+ ...
+ mysql_close($connection);
+}
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52622813465_9c453a43b1_w.jpg[ETSdiff percent comparison" style="padding: 1rem;]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
+
+## Case for a 2GB database:
+
+image::https://live.staticflickr.com/65535/52622862388_720fd219ba_o.png[ETSdiff percent comparison" style="padding: 1rem;]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::2GB.etsdiff.csv[]
+|===
+
+## Case for a 4GB database:
+
+image::https://live.staticflickr.com/65535/52622814395_f8aab7a5c0_o.png[ETSdiff percent comparison" style="padding: 1rem;]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::4GB.etsdiff.csv[]
+|===
+
+## Case for a 8GB database:
+
+image::https://live.staticflickr.com/65535/52622635779_f1c5d9660e_o.png[ETSdiff percent comparison" style="padding: 1rem;]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::8GB.etsdiff.csv[]
+|===
diff --git a/ecocode-rules-specifications/src/main/rules/EC72/python/EC72.asciidoc b/ecocode-rules-specifications/src/main/rules/EC72/python/EC72.asciidoc
new file mode 100644
index 000000000..ae85dfe3e
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC72/python/EC72.asciidoc
@@ -0,0 +1,23 @@
+Executing SQL queries in loop induced unnecessary calculation by the CPU, RAM usage and network transfer.
+
+## Noncompliant Code Example
+
+```python
+def foo():
+ ...
+ results = []
+ for id in range(20):
+ results.append(cursor.execute("SELECT name FROM users where id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
+ ...
+```
+
+## Compliant Solution
+
+```python
+def foo():
+ ...
+ ids = range(20)
+ results = cursor.execute("SELECT name FROM users where id IN ({0})".format(', '.join("?" * len(ids))), ids).fetchmany() # Compliant
+ ...
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.json b/ecocode-rules-specifications/src/main/rules/EC74/EC74.json
similarity index 96%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.json
rename to ecocode-rules-specifications/src/main/rules/EC74/EC74.json
index 64ba5a125..7a4eea182 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.json
+++ b/ecocode-rules-specifications/src/main/rules/EC74/EC74.json
@@ -11,8 +11,7 @@
"performance",
"network",
"sql",
- "bug",
"ecocode"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc b/ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc
new file mode 100644
index 000000000..4f1299b18
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc
@@ -0,0 +1,21 @@
+Database servers have to resolve schema fields when using asterisk symbol (`*`). Knowing and using the schema saves CPU cycles and network transfer.
+
+## Noncompliant Code Example
+
+```java
+public void foo() {
+ // ...
+ String baseQuery = "SELECT * FROM users"; // Noncompliant
+ // ...
+}
+```
+
+## Compliant Solution
+
+```java
+public void foo() {
+ // ...
+ String query = "SELECT id, name, address FROM users";
+ // ...
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC74/php/1GB.etsdiff.csv b/ecocode-rules-specifications/src/main/rules/EC74/php/1GB.etsdiff.csv
new file mode 100644
index 000000000..06710e417
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC74/php/1GB.etsdiff.csv
@@ -0,0 +1,3 @@
+Energy (J),0.040610499999999994,0.065223
+Transfer (B),779232,2697937
+Storage (B),637548827,637548827
diff --git a/ecocode-rules-specifications/src/main/rules/EC74/php/EC74.asciidoc b/ecocode-rules-specifications/src/main/rules/EC74/php/EC74.asciidoc
new file mode 100644
index 000000000..ffb380dd5
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC74/php/EC74.asciidoc
@@ -0,0 +1,34 @@
+Database servers have to resolve schema fields when using asterisk symbol (`*`). Knowing and using the schema saves CPU cycles and network transfer.
+
+## Noncompliant Code Example
+
+```php
+public function foo() {
+ ...
+ $baseQuery = "SELECT * FROM users"; // Noncompliant
+ ...
+}
+```
+
+## Compliant Solution
+
+```php
+public function foo() {
+ ...
+ $baseQuery = "SELECT id,name, address FROM users ";
+ ...
+}
+```
+
+include::../../etsdiff-methodology.asciidoc[]
+
+## Case for a 1GB database:
+
+image::https://live.staticflickr.com/65535/52622636584_52938fcf7e_o.png[ETSdiff percent comparison]
+
+[format=csv,cols="1h,1,1"]
+|===
+Source of impacts,Compliant,Non-compliant
+
+include::1GB.etsdiff.csv[]
+|===
diff --git a/ecocode-rules-specifications/src/main/rules/EC74/python/EC74.asciidoc b/ecocode-rules-specifications/src/main/rules/EC74/python/EC74.asciidoc
new file mode 100644
index 000000000..3b9b41c0f
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC74/python/EC74.asciidoc
@@ -0,0 +1,21 @@
+Database servers have to resolve schema fields when using asterisk symbol (`*`). Knowing and using the schema saves CPU cycles and network transfer.
+
+## Noncompliant Code Example
+
+```python
+public void foo() {
+ ...
+ String baseQuery = "SELECT * FROM users"; // Noncompliant
+ ...
+}
+```
+
+## Compliant Solution
+
+```python
+public void foo() {
+ ...
+ String query = "SELECT id, name, address FROM users ";
+ ...
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.json b/ecocode-rules-specifications/src/main/rules/EC75/EC75.json
similarity index 88%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.json
rename to ecocode-rules-specifications/src/main/rules/EC75/EC75.json
index 1f4c21348..42cef3012 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.json
+++ b/ecocode-rules-specifications/src/main/rules/EC75/EC75.json
@@ -7,11 +7,10 @@
"constantCost": "20min"
},
"tags": [
- "eco-design",
"performance",
- "memory",
- "bug",
- "ecocode"
+ "eco-design",
+ "ecocode",
+ "memory"
],
"defaultSeverity": "Minor"
}
diff --git a/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc b/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc
new file mode 100644
index 000000000..6cbc5ed2a
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc
@@ -0,0 +1,38 @@
+Don't concatenate Strings in loop. Use `StringBuilder instead.
+
+Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU.
+
+## Noncompliant Code Example
+
+```java
+public String concatenateStrings(String[] strings) {
+ String result = "";
+
+ for (String string : strings) {
+ result += string; // Noncompliant
+ }
+ return result;
+}
+
+public String concatenateStrings2() {
+ String result = "";
+
+ for (int i = 0; i < 1000; ++i) {
+ result += "another"; // Noncompliant
+ }
+ return result;
+}
+```
+
+## Compliant Solution
+
+```java
+public String concatenateStrings(String[] strings) {
+ StringBuilder result = new StringBuilder();
+
+ for (String string : strings) {
+ result.append(string);
+ }
+ return result.toString();
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.json b/ecocode-rules-specifications/src/main/rules/EC76/EC76.json
similarity index 82%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.json
rename to ecocode-rules-specifications/src/main/rules/EC76/EC76.json
index 246fb1b85..95b8bc483 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.json
+++ b/ecocode-rules-specifications/src/main/rules/EC76/EC76.json
@@ -7,10 +7,11 @@
"constantCost": "20min"
},
"tags": [
+ "cwe",
+ "leak",
"eco-design",
- "memory",
- "bug",
- "ecocode"
+ "ecocode",
+ "memory"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc b/ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc
new file mode 100644
index 000000000..f21e5298c
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc
@@ -0,0 +1,36 @@
+Avoid usage of static collections.
+
+If you want to use static collections make them final and create for example a singleton if needed containing the collections.
+
+The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks.
+
+## Noncompliant Code Example
+
+```java
+/**
+ * Not compliant
+ */
+public class AvoidUsageOfStaticCollections {
+ public static final List<> LIST = new ArrayList<>();
+ public static final Set<> SET = new HashSet<>();
+ public static final Map<> MAP = new HashMap<>();
+}
+```
+
+## Compliant Solution
+
+```java
+/**
+ * Compliant
+ */
+public class GoodUsageOfStaticCollections {
+ public static volatile GoodUsageOfStaticCollections INSTANCE = new GoodUsageOfStaticCollections();
+
+ public final List<> LIST = new ArrayList<>();
+ public final Set<> SET = new HashSet<>();
+ public final Map<> MAP = new HashMap<>();
+
+ private GoodUsageOfStaticCollections() {
+ }
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.json b/ecocode-rules-specifications/src/main/rules/EC77/EC77.json
similarity index 87%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.json
rename to ecocode-rules-specifications/src/main/rules/EC77/EC77.json
index fa21f3110..2aa53debd 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.json
+++ b/ecocode-rules-specifications/src/main/rules/EC77/EC77.json
@@ -7,11 +7,11 @@
"constantCost": "20min"
},
"tags": [
- "eco-design",
"performance",
- "memory",
- "bug",
- "ecocode"
+ "regex",
+ "eco-design",
+ "ecocode",
+ "memory"
],
"defaultSeverity": "Minor"
}
diff --git a/ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc b/ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc
new file mode 100644
index 000000000..188b8f648
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc
@@ -0,0 +1,53 @@
+Avoid using `Pattern.compile()` in a non-static context.
+This operation requires a significant amount of computational power, Using a single match saves CPU cycles and RAM consumption.
+
+## Noncompliant Code Example
+
+```java
+public class AvoidRegexPatternNotStatic {
+ public boolean foo() {
+ final Pattern pattern = Pattern.compile("foo"); // Noncompliant
+ return pattern.matcher("foo").find();
+ }
+}
+```
+
+## Compliant Solution NΒ°1
+
+```java
+public class ValidRegexPattern {
+ private static final Pattern pattern = Pattern.compile("foo"); // Compliant
+
+ public boolean foo() {
+ return pattern.matcher("foo").find();
+ }
+}
+```
+
+## Compliant Solution NΒ°2
+
+```java
+public class ValidRegexPattern2 {
+ private final Pattern pattern = Pattern.compile("foo"); // Compliant
+
+ public boolean foo() {
+ return pattern.matcher("foo").find();
+ }
+}
+```
+
+## Compliant Solution NΒ°3
+
+```java
+public class ValidRegexPattern3 {
+ private final Pattern pattern;
+
+ public ValidRegexPattern3() {
+ pattern = Pattern.compile("foo"); // Compliant
+ }
+
+ public boolean foo() {
+ return pattern.matcher("foo").find();
+ }
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.json b/ecocode-rules-specifications/src/main/rules/EC78/EC78.json
similarity index 88%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.json
rename to ecocode-rules-specifications/src/main/rules/EC78/EC78.json
index eb97c43c2..6525cb823 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.json
+++ b/ecocode-rules-specifications/src/main/rules/EC78/EC78.json
@@ -8,11 +8,10 @@
},
"tags": [
"eco-design",
- "performance",
- "memory",
+ "ecocode",
"sql",
- "bug",
- "ecocode"
+ "performance",
+ "memory"
],
"defaultSeverity": "Minor"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc b/ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc
new file mode 100644
index 000000000..3153a8742
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc
@@ -0,0 +1,34 @@
+Don't set a constant parameter in batch update. Instead, put it in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily.
+
+## Noncompliant Code Example
+
+```java
+public void foo() {
+ // ...
+ String query = "insert into mytable values(?,?,?)";
+ // ...
+ for(DummyClass o : list) {
+ stmt.setInt(1, 123); // Noncompliant
+ stmt.setString(2, o.getName());
+ stmt.setDouble(3, o.getPrice());
+ stmt.addBatch();
+ }
+ // ...
+}
+```
+
+## Compliant Solution
+
+```java
+public void foo() {
+ // ...
+ String query = "insert into mytable values(123,?,?)";
+ // ...
+ for(DummyClass o : list) {
+ stmt.setString(1, o.getName());
+ stmt.setDouble(2, o.getPrice());
+ stmt.addBatch();
+ }
+ // ...
+}
+```
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.json b/ecocode-rules-specifications/src/main/rules/EC79/EC79.json
similarity index 92%
rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.json
rename to ecocode-rules-specifications/src/main/rules/EC79/EC79.json
index 9d74b48fe..968adfe0c 100644
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.json
+++ b/ecocode-rules-specifications/src/main/rules/EC79/EC79.json
@@ -7,8 +7,8 @@
"constantCost": "15min"
},
"tags": [
+ "performance",
"eco-design",
- "bug",
"ecocode"
],
"defaultSeverity": "Minor"
diff --git a/ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc b/ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc
new file mode 100644
index 000000000..ef8bc2156
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc
@@ -0,0 +1,28 @@
+Use `try-with-resources` statement for any object that implements the `AutoCloseable` interface, it save computer resources.
+
+## Noncompliant Code Example
+
+```java
+private static void printFileJava7() throws IOException {
+ FileInputStream input = new FileInputStream("file.txt");
+ int data = input.read();
+ while(data != -1){
+ System.out.print((char) data);
+ data = input.read();
+ }
+}
+```
+
+## Compliant Solution
+
+```java
+private static void printFileJava7() throws IOException {
+ try(FileInputStream input = new FileInputStream("file.txt")) {
+ int data = input.read();
+ while(data != -1){
+ System.out.print((char) data);
+ data = input.read();
+ }
+ }
+}
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC8/EC8.json b/ecocode-rules-specifications/src/main/rules/EC8/EC8.json
new file mode 100644
index 000000000..232f1ce0a
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC8/EC8.json
@@ -0,0 +1,19 @@
+{
+ "title": "Avoid using high accuracy geolocation in web applications.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Major",
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC8/js/EC8.asciidoc b/ecocode-rules-specifications/src/main/rules/EC8/js/EC8.asciidoc
new file mode 100644
index 000000000..7528b2bb2
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC8/js/EC8.asciidoc
@@ -0,0 +1,43 @@
+## Rule details
+
+This rule aims at reducing CPU consumption by telling the device to use a less accurate yet more eco-friendly geolocation, when geolocation API is used.
+
+## Examples
+
+Examples of **non-compliant** code for this rule:
+
+```js
+var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 };
+function success(pos) {
+ console.log(pos.coords);
+}
+
+function error(err) {
+ console.warn(err);
+}
+
+navigator.geolocation.getCurrentPosition(success, error, options);
+```
+
+Examples of **compliant** code for this rule:
+
+```js
+// enableHighAccuracy is false by default, so not declaring it is correct
+function success(pos) {
+ console.log(pos);
+}
+navigator.geolocation.getCurrentPosition(success);
+```
+
+```js
+var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 };
+function success(pos) {
+ console.log(pos.coords);
+}
+
+function error(err) {
+ console.warn(err);
+}
+
+navigator.geolocation.getCurrentPosition(success, error, options);
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC9/EC9.json b/ecocode-rules-specifications/src/main/rules/EC9/EC9.json
new file mode 100644
index 000000000..99e524b50
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC9/EC9.json
@@ -0,0 +1,19 @@
+{
+ "title": "Should not import all from library",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Major",
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC9/js/EC9.asciidoc b/ecocode-rules-specifications/src/main/rules/EC9/js/EC9.asciidoc
new file mode 100644
index 000000000..c6be22d50
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC9/js/EC9.asciidoc
@@ -0,0 +1,69 @@
+## Rule details
+
+This rule aims to reduce weight of programs by using only needed modules. Many libraries export only one module by default, but some of them are exporting ES modules or submodules. We should use them to select more precisly needed modules and avoid unnecessarily overloading files weight.
+
+*Example with the well-known https://lodash.com/[lodash] library, if you only need
+`isEmpty` method.*
+
+
+|===
+|Full lodash library |Only `isEmpty` method
+
+a|index.js - 531.46 KB
+
+* node_modules/lodash - 531.35 KB
+** lodash.js - 531.35 KB
+
+a|index.js - 24.42 KB
+
+* node_modules/lodash - 24.31 KB
+** isEmpty - 1.95 KB
+** _nodeUtil.js - 995 B
+** isArrayLike.js - 830 B
+** ...
+
+|===
+
+## Options
+
+You can externally add your own libraries to be checked. To add your own libraries you need to modify your .eslintrc.js by adding the following rule configuration:
+
+```js
+module.exports = {
+ ...yourConf,
+ rules: {
+ "no-import-all-from-library": [
+ "warn",
+ {
+ notAllowedLibraries: ["some-lib"], // will check for -> import someLib from "some-lib"
+ importByNamespaceNotAllowedLibraries: ["some-other-lib"], // will check for -> import * as someOtherLib from "some-other-lib"
+ },
+ ],
+ },
+};
+```
+
+## Examples
+
+Examples of **non-compliant** code for this rule:
+
+```js
+// Example with lodash
+import lodash from "lodash";
+import { isEmpty } from "lodash";
+import * as lodash from "lodash";
+
+// Example with underscore
+import _ from "underscore";
+```
+
+Examples of **compliant** code for this rule:
+
+```js
+// Example with lodash (uses submodules)
+import isEmpty from "lodash/isEmpty";
+import intersect from "lodash/intersect";
+
+// Example with underscore (uses esm modules)
+import map from "underscore/modules/map.js";
+```
diff --git a/ecocode-rules-specifications/src/main/rules/etsdiff-methodology.asciidoc b/ecocode-rules-specifications/src/main/rules/etsdiff-methodology.asciidoc
new file mode 100644
index 000000000..3239fa7d4
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/etsdiff-methodology.asciidoc
@@ -0,0 +1,11 @@
+## The three sources of impacts of a code identified are:
+
+- Energy: measured in joules (J)
+- Transfer: measured in Bytes (B)
+- Storage: measured in Bytes (B)
+
+The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
+
+The _ETSdiff_ tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
+
+The results generated by _ETSdiff_ must help define the interest of the rule reported by _SonarQube_ in the context of the code analyzed.
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 6e5e11f38..f5f780e25 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocode
ecocode-parent
- 1.1.1-SNAPSHOT
+ 1.4.1-SNAPSHOT
ecocode-java-plugin
@@ -16,38 +16,24 @@
https://github.com/green-code-initiative/ecoCode/tree/main/java-plugin
+
+ ${project.groupId}
+ ecocode-rules-specifications
+ ${project.version}
+ java
+
org.sonarsource.java
sonar-java-plugin
sonar-plugin
+ provided
org.sonarsource.sonarqube
sonar-plugin-api
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api-impl
-
-
-
- org.sonarsource.analyzer-commons
- sonar-analyzer-commons
-
-
-
- org.apache.commons
- commons-lang3
- 3.11
-
-
-
- com.google.guava
- guava
- 31.0.1-jre
+ provided
@@ -70,14 +56,14 @@
- org.junit.jupiter
- junit-jupiter-migrationsupport
+ org.assertj
+ assertj-core
test
- org.assertj
- assertj-core
+ org.mockito
+ mockito-junit-jupiter
test
@@ -95,48 +81,13 @@
fr.greencodeinitiative.java.JavaPlugin
true
${sonarqube.version}
-
-
-
- java
${java.version}
+
org.apache.maven.plugins
maven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- commons-*:*
-
- META-INF/**
-
-
-
- org.*:*
-
- META-INF/**
- org/sonar/api/batch/sensor/**
- javax/annotation/**
-
-
-
- com.*:*
-
- META-INF/**
-
-
-
-
-
-
org.jacoco
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java
index 1d92303b1..b66e81cfa 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java
@@ -1,26 +1,44 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
+import java.util.Collections;
import java.util.List;
+import fr.greencodeinitiative.java.checks.ArrayCopyCheck;
+import fr.greencodeinitiative.java.checks.AvoidConcatenateStringsInLoop;
+import fr.greencodeinitiative.java.checks.AvoidFullSQLRequest;
+import fr.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop;
+import fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement;
+import fr.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic;
+import fr.greencodeinitiative.java.checks.AvoidSQLRequestInLoop;
+import fr.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate;
+import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopCheck;
+import fr.greencodeinitiative.java.checks.AvoidStatementForDMLQueries;
+import fr.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections;
+import fr.greencodeinitiative.java.checks.AvoidUsingGlobalVariablesCheck;
+import fr.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface;
+import fr.greencodeinitiative.java.checks.IncrementCheck;
+import fr.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize;
+import fr.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop;
+import fr.greencodeinitiative.java.checks.OptimizeReadFileExceptions;
+import fr.greencodeinitiative.java.checks.UnnecessarilyAssignValuesToVariables;
+import fr.greencodeinitiative.java.checks.UseCorrectForLoop;
import org.sonar.plugins.java.api.CheckRegistrar;
import org.sonar.plugins.java.api.JavaCheck;
import org.sonarsource.api.sonarlint.SonarLintSide;
@@ -33,6 +51,27 @@
*/
@SonarLintSide
public class JavaCheckRegistrar implements CheckRegistrar {
+ private static final List> ANNOTATED_RULE_CLASSES = List.of(
+ ArrayCopyCheck.class,
+ IncrementCheck.class,
+ AvoidConcatenateStringsInLoop.class,
+ AvoidUsageOfStaticCollections.class,
+ AvoidGettingSizeCollectionInLoop.class,
+ AvoidRegexPatternNotStatic.class,
+ NoFunctionCallWhenDeclaringForLoop.class,
+ AvoidStatementForDMLQueries.class,
+ AvoidSpringRepositoryCallInLoopCheck.class,
+ AvoidSQLRequestInLoop.class,
+ AvoidFullSQLRequest.class,
+ UseCorrectForLoop.class,
+ UnnecessarilyAssignValuesToVariables.class,
+ OptimizeReadFileExceptions.class,
+ InitializeBufferWithAppropriateSize.class,
+ AvoidUsingGlobalVariablesCheck.class,
+ AvoidSetConstantInBatchUpdate.class,
+ FreeResourcesOfAutoCloseableInterface.class,
+ AvoidMultipleIfElseStatement.class
+ );
/**
* Register the classes that will be used to instantiate checks during analysis.
@@ -47,13 +86,13 @@ public void register(RegistrarContext registrarContext) {
* Lists all the main checks provided by the plugin
*/
public static List> checkClasses() {
- return RulesList.getJavaChecks();
+ return ANNOTATED_RULE_CLASSES;
}
/**
* Lists all the test checks provided by the plugin
*/
public static List> testCheckClasses() {
- return RulesList.getJavaTestChecks();
+ return Collections.emptyList();
}
}
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java
index 1e40808d8..ff070c1b1 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java
@@ -1,29 +1,24 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
import org.sonar.api.Plugin;
-/**
- * Entry point of your plugin containing your custom rules
- */
public class JavaPlugin implements Plugin {
@Override
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
index 9b6d698d5..958edc829 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
@@ -1,35 +1,26 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Objects;
-import java.util.Set;
-import org.sonar.api.SonarEdition;
-import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
-import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.utils.Version;
import org.sonarsource.analyzer.commons.RuleMetadataLoader;
/**
@@ -37,36 +28,29 @@
* That allows to list the rules in the page "Rules".
*/
public class JavaRulesDefinition implements RulesDefinition {
+ private static final String RESOURCE_BASE_PATH = "io/ecocode/rules/java";
- // don't change that because the path is hard coded in CheckVerifier
- private static final String RESOURCE_BASE_PATH = "fr/greencodeinitiative/l10n/java/rules/java";
+ private static final String NAME = "ecoCode";
+ private static final String LANGUAGE = "java";
+ static final String REPOSITORY_KEY = "ecocode-java";
+ private final SonarRuntime sonarRuntime;
- // Add the rule keys of the rules which need to be considered as template-rules
- private static final Set RULE_TEMPLATES_KEY = Collections.emptySet();
- public static final String NAME = "ecoCode";
- public static final String LANGUAGE = "java";
- public static final String REPOSITORY_KEY = "ecocode-java";
+ public JavaRulesDefinition(SonarRuntime sonarRuntime) {
+ this.sonarRuntime = sonarRuntime;
+ }
@Override
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME);
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 8), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
-
RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, sonarRuntime);
- ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(RulesList.getChecks()));
-
- setTemplates(repository);
-
+ ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(JavaCheckRegistrar.checkClasses()));
repository.done();
}
- private static void setTemplates(NewRepository repository) {
- RULE_TEMPLATES_KEY.stream()
- .map(repository::rule)
- .filter(Objects::nonNull)
- .forEach(rule -> rule.setTemplate(true));
+ public String repositoryKey() {
+ return REPOSITORY_KEY;
}
}
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java
deleted file mode 100644
index d6a5cdbf4..000000000
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.java;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import fr.greencodeinitiative.java.checks.ArrayCopyCheck;
-import fr.greencodeinitiative.java.checks.AvoidConcatenateStringsInLoop;
-import fr.greencodeinitiative.java.checks.AvoidFullSQLRequest;
-import fr.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop;
-import fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement;
-import fr.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic;
-import fr.greencodeinitiative.java.checks.AvoidSQLRequestInLoop;
-import fr.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate;
-import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopCheck;
-import fr.greencodeinitiative.java.checks.AvoidStatementForDMLQueries;
-import fr.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections;
-import fr.greencodeinitiative.java.checks.AvoidUsingGlobalVariablesCheck;
-import fr.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface;
-import fr.greencodeinitiative.java.checks.IncrementCheck;
-import fr.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize;
-import fr.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop;
-import fr.greencodeinitiative.java.checks.OptimizeReadFileExceptions;
-import fr.greencodeinitiative.java.checks.UnnecessarilyAssignValuesToVariables;
-import fr.greencodeinitiative.java.checks.UseCorrectForLoop;
-import org.sonar.plugins.java.api.JavaCheck;
-
-public final class RulesList {
-
- private RulesList() {
- }
-
- public static List> getChecks() {
- List> checks = new ArrayList<>();
- checks.addAll(getJavaChecks());
- checks.addAll(getJavaTestChecks());
- return Collections.unmodifiableList(checks);
- }
-
- public static List> getJavaChecks() {
- return Collections.unmodifiableList(Arrays.asList(
- ArrayCopyCheck.class,
- IncrementCheck.class,
- AvoidConcatenateStringsInLoop.class,
- AvoidUsageOfStaticCollections.class,
- AvoidGettingSizeCollectionInLoop.class,
- AvoidRegexPatternNotStatic.class,
- NoFunctionCallWhenDeclaringForLoop.class,
- AvoidStatementForDMLQueries.class,
- AvoidSpringRepositoryCallInLoopCheck.class,
- AvoidSQLRequestInLoop.class,
- AvoidFullSQLRequest.class,
- UseCorrectForLoop.class,
- UnnecessarilyAssignValuesToVariables.class,
- OptimizeReadFileExceptions.class,
- InitializeBufferWithAppropriateSize.class,
- AvoidUsingGlobalVariablesCheck.class,
- AvoidSetConstantInBatchUpdate.class,
- FreeResourcesOfAutoCloseableInterface.class,
- AvoidMultipleIfElseStatement.class
- ));
- }
-
- public static List> getJavaTestChecks() {
- return Collections.emptyList();
- }
-}
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java
index 409303d70..b594af9d4 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.ArrayList;
@@ -6,7 +23,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree;
@@ -37,11 +53,7 @@
* @author Aubay
* @formatter:off
*/
-@Rule(key = "EC27",
- name = "Developpement",
- description = ArrayCopyCheck.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC27")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRPS0027")
public class ArrayCopyCheck extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java
index d95335862..99b732c50 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java
@@ -1,11 +1,26 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
import java.util.List;
-
import javax.annotation.Nonnull;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.AssignmentExpressionTree;
@@ -15,12 +30,7 @@
import org.sonar.plugins.java.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC75",
- name = "Developpement",
- description = AvoidConcatenateStringsInLoop.MESSAGE_RULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC75")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S75")
public class AvoidConcatenateStringsInLoop extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java
index c73516662..88ff715c4 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.List;
@@ -6,7 +23,7 @@
import static java.util.Collections.singletonList;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static java.util.regex.Pattern.compile;
-import org.sonar.check.Priority;
+
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.LiteralTree;
@@ -14,12 +31,7 @@
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC74",
- name = "Developpement",
- description = AvoidFullSQLRequest.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC74")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S74")
public class AvoidFullSQLRequest extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java
index 7317617c0..c81d79534 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
@@ -5,7 +22,6 @@
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -18,11 +34,7 @@
import org.sonar.plugins.java.api.tree.WhileStatementTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC3",
- name = "Developpement",
- description = AvoidGettingSizeCollectionInLoop.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC3")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GSCIL")
public class AvoidGettingSizeCollectionInLoop extends IssuableSubscriptionVisitor {
protected static final String MESSAGERULE = "Avoid getting the size of the collection in the loop";
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
index 5b584c342..383365309 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
@@ -1,72 +1,346 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
-import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
+import org.sonar.plugins.java.api.tree.BinaryExpressionTree;
import org.sonar.plugins.java.api.tree.BlockTree;
+import org.sonar.plugins.java.api.tree.ExpressionTree;
+import org.sonar.plugins.java.api.tree.IdentifierTree;
import org.sonar.plugins.java.api.tree.IfStatementTree;
+import org.sonar.plugins.java.api.tree.MethodTree;
import org.sonar.plugins.java.api.tree.StatementTree;
import org.sonar.plugins.java.api.tree.Tree;
+import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC2",
- name = "Developpement",
- description = AvoidMultipleIfElseStatement.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug"})
+/**
+ * FUNCTIONAL DESCRIPTION : please see ASCIIDOC description file of this rule (inside `ecocode-rules-spcifications`)
+ * TECHNICAL CHOICES :
+ * - Kind.IF_STATEMENT, Kind.ELSE_STATEMENT, Kind.ELSEIF_STATEMENT not used because it isn't possible
+ * to keep parent references to check later if variables already used or not in parent tree
+ * - only one way to keep parent history : manually go throw the all tree and thus, start at method declaration
+ * - an "ELSE" statement is considered as a second IF statement using the same variables used on previous
+ * - IF and ELSEIF statements are considered as an IF statement
+ */
+@Rule(key = "EC2")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "AMIES")
public class AvoidMultipleIfElseStatement extends IssuableSubscriptionVisitor {
- protected static final String RULE_MESSAGE = "Using a switch statement instead of multiple if-else if possible";
- private void checkIfStatement(Tree tree) {
- int sizeBody = 0;
- int idx = 0;
- int countIfStatement = 0;
+ public static final String ERROR_MESSAGE = "Use a switch statement instead of multiple if-else if possible";
- Tree parentNode = tree.parent();
+ public static final int NB_MAX_VARIABLE_USAGE = 2;
- if (!(parentNode instanceof BlockTree))
+ // data structure for following usage of variable inside all the AST tree
+ private VariablesPerLevelDataStructure variablesStruct = new VariablesPerLevelDataStructure();
+
+ // only visit each method to keep data of all conditional tree
+ // with IF, ELSE or ELSEIF statements, we can't keep all data of conditional tree
+ @Override
+ public List nodesToVisit() {
+ return List.of(Kind.METHOD);
+ }
+
+ @Override
+ public void visitNode(@SuppressWarnings("NullableProblems") Tree pTree) {
+
+ MethodTree method = (MethodTree)pTree;
+
+ // reinit data structure before each method analysis
+ variablesStruct = new VariablesPerLevelDataStructure();
+
+ // starting visit
+ visitNodeContent(method.block().body(), 0);
+
+ }
+
+ /**
+ * Visit all content of a node for one level (with its statements list)
+ *
+ * @param pLstStatements statements list of current node
+ * @param pLevel level of current node
+ */
+ private void visitNodeContent(List pLstStatements, int pLevel) {
+ if (pLstStatements == null || pLstStatements.isEmpty()) {
return;
- BlockTree node = (BlockTree) parentNode;
- sizeBody = node.body().toArray().length;
- while (idx < sizeBody) {
- if (node.body().get(idx) instanceof IfStatementTree)
- ++countIfStatement;
- ++idx;
- }
- if (countIfStatement > 1)
- reportIssue(tree, RULE_MESSAGE);
+ }
+
+ for (StatementTree statement : pLstStatements) {
+ if (statement.is(Kind.BLOCK)) {
+ // the current node is a block : visit block content
+ visitNodeContent(((BlockTree)statement).body(), pLevel);
+ } else if (statement.is(Kind.IF_STATEMENT)) {
+ visitIfNode((IfStatementTree) statement, pLevel);
+ }
+ }
}
- private void checkElseIfStatement(Tree tree) {
- IfStatementTree node = (IfStatementTree) tree;
- int count = 0;
- StatementTree statementTree;
-
- while (true) {
- if (count >= 2)
- reportIssue(tree, RULE_MESSAGE);
- statementTree = node.elseStatement();
- if (statementTree instanceof IfStatementTree) {
- ++count;
- node = (IfStatementTree) statementTree;
- } else {
- break;
+ /**
+ * Visit an IF type node
+ * @param pIfTree the current node (Tree type)
+ * @param pLevel the level of node
+ */
+ private void visitIfNode(IfStatementTree pIfTree, int pLevel) {
+
+ if (pIfTree == null) return;
+
+ // init current if structure with cleaning child levels
+ variablesStruct.reinitVariableUsageForLevel(pLevel + 1);
+ // init current if structure with cleaning for ELSE process checking
+ variablesStruct.reinitVariableUsageForLevelForCurrentIfStruct(pLevel);
+
+ // analyze condition variables and raise error if needed
+ computeIfVariables(pIfTree, pLevel);
+
+ // visit the content of if block
+ visitNodeContent(((BlockTree)pIfTree.thenStatement()).body(), pLevel + 1);
+
+ // analyze ELSE clause et ELSE IF clauses
+ if (pIfTree.elseStatement() != null) {
+ if (pIfTree.elseStatement().is(Kind.BLOCK)) { // ELSE clause content
+ visitElseNode((BlockTree) pIfTree.elseStatement(), pLevel);
+ } else if (pIfTree.elseStatement().is(Kind.IF_STATEMENT)) { // ELSE IF clause
+ visitIfNode((IfStatementTree) pIfTree.elseStatement(), pLevel);
}
}
}
- @Override
- public List nodesToVisit() {
- return Arrays.asList(Tree.Kind.IF_STATEMENT);
+ /**
+ * Analyze and compute variables usage for IF AST structure
+ * @param pIfTree IF node
+ * @param pLevel the level of IF node
+ */
+ private void computeIfVariables(IfStatementTree pIfTree, int pLevel) {
+
+ if (pIfTree.condition() == null) return;
+
+ // analysing content of conditions of IF node
+ ExpressionTree expr = pIfTree.condition();
+ if (expr instanceof BinaryExpressionTree) {
+ computeConditionVariables((BinaryExpressionTree) expr, pLevel);
+ }
+
}
- @Override
- public void visitNode(Tree tree) {
- checkIfStatement(tree);
- checkElseIfStatement(tree);
+ /**
+ * Analyze and compute variables usage for Expression structure
+ * @param pBinExprTree binary expression to analyze
+ * @param pLevel The level of binary expression
+ */
+ private void computeConditionVariables(BinaryExpressionTree pBinExprTree, int pLevel) {
+
+ // if multiple conditions, continue with each part of complex expression
+ if (pBinExprTree.is(Kind.CONDITIONAL_AND) || pBinExprTree.is(Kind.CONDITIONAL_OR)) {
+ if (pBinExprTree.leftOperand() instanceof BinaryExpressionTree) {
+ computeConditionVariables((BinaryExpressionTree) pBinExprTree.leftOperand(), pLevel);
+ }
+ if (pBinExprTree.rightOperand() instanceof BinaryExpressionTree) {
+ computeConditionVariables((BinaryExpressionTree) pBinExprTree.rightOperand(), pLevel);
+ }
+ } else if (pBinExprTree.is(Kind.EQUAL_TO)
+ || pBinExprTree.is(Kind.NOT_EQUAL_TO)
+ || pBinExprTree.is(Kind.GREATER_THAN)
+ || pBinExprTree.is(Kind.GREATER_THAN_OR_EQUAL_TO)
+ || pBinExprTree.is(Kind.LESS_THAN_OR_EQUAL_TO)
+ || pBinExprTree.is(Kind.LESS_THAN)
+ ) {
+ // continue analysis with variables if some key-words are found
+ if (pBinExprTree.leftOperand().is(Kind.IDENTIFIER)) {
+ computeVariables((IdentifierTree) pBinExprTree.leftOperand(), pLevel);
+ }
+ if (pBinExprTree.rightOperand().is(Kind.IDENTIFIER)) {
+ computeVariables((IdentifierTree) pBinExprTree.rightOperand(), pLevel);
+ }
+ }
+ }
+
+ /**
+ * Analyze and compute variables usage for Variable AST structure
+ * @param pVarIdTree The Variable AST structure
+ * @param pLevel the level of structure
+ */
+ private void computeVariables(IdentifierTree pVarIdTree, int pLevel) {
+ if (pVarIdTree.is(Kind.IDENTIFIER)) {
+ // increment the variable counter to list of all variables
+ int nbUsed = variablesStruct.incrementVariableUsageForLevel(pVarIdTree.name(), pLevel);
+
+ // increment variable counter to list of variables already declared for current if or elseif struture
+ variablesStruct.incrementVariableUsageForLevelForCurrentIfStruct(pVarIdTree.name(), pLevel);
+
+ // raise an error if maximum
+ if (nbUsed > NB_MAX_VARIABLE_USAGE) {
+ reportIssue(pVarIdTree, ERROR_MESSAGE);
+ }
+ }
+ }
+
+ /**
+ * Analyze and compute variables usage for ELSE AST structure
+ * @param pElseTree ELSE node
+ * @param pLevel the level of ELSE node
+ */
+ private void visitElseNode(BlockTree pElseTree, int pLevel) {
+
+ if (pElseTree == null) { return; }
+
+ // analyze variables and raise error if needed
+ computeElseVariables(pElseTree, pLevel);
+
+ // go to next child level
+ visitNodeContent(pElseTree.body(), pLevel + 1);
}
+
+ /**
+ * Analyze and compute variables usage for ELSE AST structure
+ * @param pElseTree ELSE node
+ * @param pLevel the level of ELSE node
+ */
+ private void computeElseVariables(StatementTree pElseTree, int pLevel) {
+
+ for (Map.Entry entry : variablesStruct.getVariablesForCurrentIfStruct(pLevel).entrySet()) {
+ String variableName = entry.getKey();
+
+ // increment usage of all variables in the same level of ELSE staetement
+ int nbUsed = variablesStruct.incrementVariableUsageForLevel(variableName, pLevel);
+
+ // increment variable counter to list of variables already declared for current if or elseif struture
+ variablesStruct.incrementVariableUsageForLevelForCurrentIfStruct(variableName, pLevel);
+
+ // raise an error if maximum
+ if (nbUsed > NB_MAX_VARIABLE_USAGE) {
+ reportIssue(pElseTree, ERROR_MESSAGE);
+ }
+ }
+ }
+
+ /**
+ * Complex data structure representing variables counters per AST level (cumulative counts with parent levels)
+ * Map> ==>
+ * - Key : index of Level (0 = first level)
+ * - Value : Map
+ * - Key : name of variable in the current or parent level
+ * - Value : number of usage of this variable in an IF statement in current level or one of parent levels
+ *
+ */
+ private static class VariablesPerLevelDataStructure {
+
+ // global map variable counters per level
+ private final Map> mapVariablesPerLevel;
+
+ // map variable counters per level for current If / ElseIf structure
+ // purpose : used by compute variables Else process (because Else structure is particular :
+ // we don't know previous variables and we need previous If / ElseIf structure to know variables)
+ private final Map> mapVariablesPerLevelForCurrentIfStruct;
+
+ public VariablesPerLevelDataStructure() {
+ mapVariablesPerLevel = new HashMap<>(10);
+ mapVariablesPerLevelForCurrentIfStruct = new HashMap<>(10);
+ }
+
+ /**
+ * increment variable counters on global map
+ */
+ public int incrementVariableUsageForLevel(String variableName, int pLevel) {
+ return internalIncrementVariableUsage(mapVariablesPerLevel, variableName, pLevel);
+ }
+
+ /**
+ * increment variable counters on input map
+ */
+ private int internalIncrementVariableUsage(Map> pDataMap, String variableName, int pLevel) {
+
+ // get variable usage map for current level and init if null
+ Map variablesMap = pDataMap.computeIfAbsent(pLevel, k -> new HashMap<>(5));
+
+ // get usage from parent if needed
+ Integer nbUsed = variablesMap.get(variableName);
+ if (nbUsed == null) {
+ Integer nbParentUsed = internalGetVariableUsageOfNearestParent(pDataMap, variableName, pLevel - 1);
+ nbUsed = nbParentUsed == null ? 0 : nbParentUsed;
+ }
+
+ // increment usage for current level
+ nbUsed++;
+ variablesMap.put(variableName, nbUsed);
+
+ return nbUsed;
+ }
+
+ /**
+ * get usage of a variable in top tree (nearest top parent)
+ */
+ private Integer internalGetVariableUsageOfNearestParent(Map> pDataMap, String variableName, int pLevel) {
+
+ Integer nbParentUsed = null;
+ for (int i = pLevel; i >= 0 && nbParentUsed == null; i--) {
+ Map variablesParentLevelMap = pDataMap.get(i);
+ nbParentUsed = variablesParentLevelMap.get(variableName);
+ }
+
+ return nbParentUsed;
+ }
+
+ /**
+ * reinitialization of variable usages for input level and global map
+ */
+ public void reinitVariableUsageForLevel(int pLevel) {
+ internalReinitVariableUsageForLevelForCurrentIfStruct(mapVariablesPerLevel, pLevel);
+ }
+
+ /**
+ * reinitialization of variable usages in input level in input map
+ */
+ private void internalReinitVariableUsageForLevelForCurrentIfStruct(Map> pDataMap, int pLevel) {
+ if (pDataMap.get(pLevel) == null) { return; }
+
+ // cleaning of current If Structure beginning at level specified
+ for (int i = pLevel; i < pDataMap.size(); i++) {
+ pDataMap.remove(i);
+ }
+
+ }
+
+ /**
+ * reinitialization of variable usages for input level on if/elseif map
+ */
+ public void reinitVariableUsageForLevelForCurrentIfStruct(int pLevel) {
+ internalReinitVariableUsageForLevelForCurrentIfStruct(mapVariablesPerLevelForCurrentIfStruct, pLevel);
+ }
+
+ /**
+ * increment variable counters on if/elseif map
+ */
+ public void incrementVariableUsageForLevelForCurrentIfStruct(String variableName, int pLevel) {
+ internalIncrementVariableUsage(mapVariablesPerLevelForCurrentIfStruct, variableName, pLevel);
+ }
+
+ /**
+ * get usage of a variable in a level on if/elseif map
+ */
+ public Map getVariablesForCurrentIfStruct(int pLevel) {
+ return mapVariablesPerLevelForCurrentIfStruct.get(pLevel);
+ }
+
+ }
+
}
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
index 1020168d8..2561a6c0f 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collections;
@@ -6,7 +23,6 @@
import javax.annotation.Nonnull;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -16,12 +32,7 @@
import org.sonar.plugins.java.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC77",
- name = "Developpement",
- description = AvoidRegexPatternNotStatic.MESSAGE_RULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC77")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S77")
public class AvoidRegexPatternNotStatic extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java
index efea9cce8..7c4ff5623 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java
@@ -1,9 +1,25 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
import java.util.List;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -14,8 +30,7 @@
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC72", name = "Developpement", description = AvoidSQLRequestInLoop.MESSAGERULE, priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC72")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S72")
public class AvoidSQLRequestInLoop extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java
index 21f332e27..4fe31abda 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java
@@ -1,12 +1,30 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.stream.Stream;
-import static fr.greencodeinitiative.java.checks.ConstOrLiteralDeclare.isLiteral;
+import fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare;
+import static fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare.isLiteral;
import static java.util.Arrays.asList;
-import org.sonar.check.Priority;
+
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -21,10 +39,7 @@
import static org.sonar.plugins.java.api.tree.Tree.Kind.MEMBER_SELECT;
import static org.sonar.plugins.java.api.tree.Tree.Kind.METHOD_INVOCATION;
-@Rule(key = "EC78", name = "Developpement",
- description = AvoidSetConstantInBatchUpdate.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC78")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S78")
public class AvoidSetConstantInBatchUpdate extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
index 2322acfaf..e95d75e98 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
@@ -1,9 +1,25 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
import java.util.List;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -12,11 +28,7 @@
import org.sonar.plugins.java.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC1",
- name = "Developpement",
- description = AvoidSpringRepositoryCallInLoopCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC1")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRC1")
public class AvoidSpringRepositoryCallInLoopCheck extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
index f273ae707..04e7b619e 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collections;
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
index 0dc3ce960..18a7fb7f9 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collections;
@@ -6,7 +23,6 @@
import javax.annotation.Nonnull;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
@@ -14,12 +30,7 @@
import org.sonar.plugins.java.api.tree.VariableTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC76",
- name = "Developpement",
- description = AvoidUsageOfStaticCollections.MESSAGE_RULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC76")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S76")
public class AvoidUsageOfStaticCollections extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java
index 1e86ba874..98bb254b4 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java
@@ -1,10 +1,26 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
import java.util.List;
import com.google.re2j.Pattern;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.Tree;
@@ -12,12 +28,7 @@
import org.sonar.plugins.java.api.tree.VariableTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC4",
- name = "Developpement",
- description = "Prefer local variables to globals
",
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC4")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "D4")
public class AvoidUsingGlobalVariablesCheck extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
index d36cc9805..47cbc2eb1 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.ArrayList;
@@ -8,7 +25,6 @@
import javax.annotation.ParametersAreNonnullByDefault;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -19,12 +35,7 @@
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC79",
- name = "Developpement",
- description = FreeResourcesOfAutoCloseableInterface.MESSAGE_RULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC79")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S79")
public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionVisitor {
private final Deque withinTry = new LinkedList<>();
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java
index 41a54c1ca..00c3094dd 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java
@@ -1,21 +1,32 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collections;
import java.util.List;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC67",
- name = "Developpement",
- description = IncrementCheck.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC67")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S67")
public class IncrementCheck extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
index d5ee088b3..44caa8722 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
@@ -1,9 +1,25 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collections;
import java.util.List;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.NewClassTree;
@@ -11,12 +27,7 @@
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC32",
- name = "Developpement",
- description = InitializeBufferWithAppropriateSize.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC32")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0032")
public class InitializeBufferWithAppropriateSize extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 91c88106c..d4088bd22 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.ArrayList;
@@ -7,7 +24,6 @@
import java.util.List;
import java.util.Map;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
@@ -21,8 +37,7 @@
import org.sonar.plugins.java.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC69", name = "Developpement", description = NoFunctionCallWhenDeclaringForLoop.MESSAGERULE, priority = Priority.MINOR, tags = {
- "bug"})
+@Rule(key = "EC69")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S69")
public class NoFunctionCallWhenDeclaringForLoop extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java
index d94f57676..2362404be 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
@@ -6,7 +23,6 @@
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.CatchTree;
@@ -16,12 +32,7 @@
import org.sonar.plugins.java.api.tree.TryStatementTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC28",
- name = "Developpement",
- description = OptimizeReadFileExceptions.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC28")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0028")
public class OptimizeReadFileExceptions extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java
index 3069393db..f5544d2e5 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java
@@ -1,41 +1,33 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.CheckForNull;
-
-import org.apache.commons.lang3.StringUtils;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
-import org.sonar.plugins.java.api.tree.AssignmentExpressionTree;
-import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
-import org.sonar.plugins.java.api.tree.BinaryExpressionTree;
-import org.sonar.plugins.java.api.tree.BlockTree;
-import org.sonar.plugins.java.api.tree.ExpressionTree;
-import org.sonar.plugins.java.api.tree.ForEachStatement;
-import org.sonar.plugins.java.api.tree.IdentifierTree;
-import org.sonar.plugins.java.api.tree.IfStatementTree;
-import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
-import org.sonar.plugins.java.api.tree.MethodInvocationTree;
-import org.sonar.plugins.java.api.tree.NewClassTree;
-import org.sonar.plugins.java.api.tree.ReturnStatementTree;
-import org.sonar.plugins.java.api.tree.StatementTree;
-import org.sonar.plugins.java.api.tree.ThrowStatementTree;
-import org.sonar.plugins.java.api.tree.Tree;
+import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.tree.Tree.Kind;
-import org.sonar.plugins.java.api.tree.TypeCastTree;
-import org.sonar.plugins.java.api.tree.UnaryExpressionTree;
-import org.sonar.plugins.java.api.tree.VariableTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(key = "EC63", name = "Developpement", description = "Do not unnecessarily assign values to variables", priority = Priority.MINOR, tags = {
- "bug"})
+import javax.annotation.CheckForNull;
+import java.util.*;
+
+@Rule(key = "EC63")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S63")
public class UnnecessarilyAssignValuesToVariables extends BaseTreeVisitor implements JavaFileScanner {
@@ -191,7 +183,7 @@ private void checkImmediatelyReturnedVariable(BlockTree tree) {
String lastStatementIdentifier = getReturnOrThrowIdentifier(lastStatement);
if (lastStatementIdentifier != null) {
String identifier = variableTree.simpleName().name();
- if (StringUtils.equals(lastStatementIdentifier, identifier)) {
+ if (lastStatementIdentifier.equals(identifier)) {
context.reportIssue(this, variableTree.initializer(), errorMessage);
}
}
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java
index 767f3449b..05e46a4ab 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java
@@ -1,9 +1,25 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
import java.util.List;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.ForEachStatement;
@@ -11,12 +27,7 @@
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-@Rule(
- key = "EC53",
- name = "Developpement",
- description = UseCorrectForLoop.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug"})
+@Rule(key = "EC53")
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S53")
public class UseCorrectForLoop extends IssuableSubscriptionVisitor {
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java
similarity index 85%
rename from java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java
rename to java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java
index 8a5b459a0..db01a76bc 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java
@@ -1,4 +1,21 @@
-package fr.greencodeinitiative.java.checks;
+/*
+ * 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 .
+ */
+package fr.greencodeinitiative.java.checks.enums;
import java.math.BigDecimal;
import java.util.Set;
@@ -18,7 +35,7 @@
import static org.sonar.plugins.java.api.tree.Tree.Kind.TYPE_CAST;
import org.sonar.plugins.java.api.tree.TypeCastTree;
-enum ConstOrLiteralDeclare {
+public enum ConstOrLiteralDeclare {
BOOLEAN {
@Override
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/package-info.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/package-info.java
deleted file mode 100644
index 03dc1c94a..000000000
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.java.checks;
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/package-info.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/package-info.java
deleted file mode 100644
index 5f3b0c8b2..000000000
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.java;
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java
index 2cb531718..2b709d790 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java
@@ -1,21 +1,19 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java.utils;
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java
index 78f6e4df6..b9b81c526 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java
@@ -1,21 +1,19 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java.utils;
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/package-info.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/package-info.java
deleted file mode 100644
index f88cc6249..000000000
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.java.utils;
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html
deleted file mode 100644
index c7bc959b3..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html
+++ /dev/null
@@ -1,20 +0,0 @@
-The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption.
-Noncompliant Code Example
-
- private final List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
-
- List<Employee> employees = new ArrayList<>();
-
- for (Integer id: ids) {
- Optional<Employee> employee = employeeRepository.findById(id); // Noncompliant
- if (employee.isPresent()) {
- employees.add(employee.get());
- }
- }
-
-
-Compliant Solution
-
- private final List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- List<Employee> employees = employeeRepository.findAllById(ids);
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html
deleted file mode 100644
index 7e5fcc2a0..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html
+++ /dev/null
@@ -1,31 +0,0 @@
-If we are using too many conditional if-else statements it will impact performance since JVM will have to compare the conditions. We can think of using a switch statement instead of multiple if-else if possible. Switch statement has a performance advantage over if β else.
-
-Non-compliant Code Example
-
- int index = 1;
- int nb = 2;
-
- if (nb > index) {
- nb = nb + index;
- } else {
- nb = nb - 1;
- }
- if (nb != index + 1) {
- nb = nb + index;
- } else {
- nb = nb - 1;
- }
-
-
-
-Compliant Code Example
-
- int index = 1;
- int nb = 2;
-
- if (nb > index) {
- nb = nb + index;
- } else {
- nb = nb - 1;
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html
deleted file mode 100644
index 8bfb72e6b..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html
+++ /dev/null
@@ -1,24 +0,0 @@
-Using System.arraycopy to copy arrays
-
- Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms.
- For example, an array copy is potentially a non-performance source if it is poorly designed. Indeed, the use of a single copy loop can be twice as consuming as dedicated methods.
- Loops must be optimized to reduce processing time and make full use of hardware and processor mechanisms and optimizations.
- In the case of table copying (table), the native System.arraycopy.
- We can also use copyOf or clone that are slightly less efficient.
- The looping method will be outlawed.
-
-Noncompliant Code Example
-
- int len = array.length;
- boolean[] copy = new boolean[array.length];
- for (int i = 0; i < len; i++) {
- copy[i] = array[i]; // Noncompliant
- }
- return copy;
-
-Compliant Solution
-
- int[] copy = new int[array.length];
- System.arraycopy(array, 0, copy, 0, array.length);
- return copy;
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html
deleted file mode 100644
index d37bcef22..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html
+++ /dev/null
@@ -1,29 +0,0 @@
-Optimize read file exception
-Noncompliant Code Example
-
- public void readPreferences(String filename) {
- //...
- InputStream in = null;
- try {
- in = new FileInputStream(filename);
- } catch (FileNotFoundException e) {
- logger.log(e);
- }
- in.read(...);
- //...
- }
-
-
-Compliant Solution
-
- public void readPreferences(String filename)
- throws IllegalArgumentException,
- FileNotFoundException, IOException {
- if (filename == null) {
- throw new IllegalArgumentException ("filename is null");
- } //if
- //...
- InputStream in = new FileInputStream(filename);
- //...
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html
deleted file mode 100644
index b347d7141..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html
+++ /dev/null
@@ -1,19 +0,0 @@
-When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. The example provided below illustrates what should be avoided.
-Noncompliant Code Example
-
- List<String> objList = getData();
-
- for (int i = 0; i < objList.size(); i++) { // Noncompliant
- // execute code
- }
-
-
-Compliant Solution
-
- List<String> objList = getData();
-
- int size = objList.size();
- for (int i = 0; i < size; i++) {
- // execute code
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html
deleted file mode 100644
index 253090269..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html
+++ /dev/null
@@ -1,19 +0,0 @@
-
- If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size.
- They will thus never have to be resized.
- This saves CPU cycles and therefore consumes less energy.
-
-Noncompliant Code Example
-
- StringBuilder sb = new StringBuilder(); // Noncompliant
- for (int i = 0; i < 100; i++) {
- sb.append(...);
- }
-
-Compliant Solution
-
- StringBuilder sb = new StringBuilder(100);
- for (int i = 0; i < 100; i++) {
- sb.append(...);
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html
deleted file mode 100644
index e95fd679d..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html
+++ /dev/null
@@ -1,34 +0,0 @@
-
- Prefer local variables as parameters
-
-When calling a global variable, the interpretation engine must check that it exists in all the scopes, that it has a value, etc. Passing global variables as arguments gives them the status of local variables inside the function, thus saving computing time (CPU cycles).
-
-
-CASE 1 (Avoid as possible):
-You are back on the service code. You see that the func1() uses globalVariabl1. Okay, but whats its value by now ? How does it change ? Who mutates the globalVariabl1 before it comes to this function ? What have been the sequence of all these mutations ? You would have no idea. It will be quite difficult to figure all this out.
-
-CASE 2 (Recommended):
-You are back to you code, and see that the func0() fetches something and then passes it to func1(param1) as a parameter. You clearly know what the data is, how does it gets here.
-
-Noncompliant Code Example
-
- var aGlobal = new String('Hello');
-
- function globalLength(){
- length = aGlobal.length;
- console.log(length);
- }
-
- globalLength();
-
-Compliant Solution
-
- var aGlobal = new String('Hello');
-
- function someVarLength(str){
- length = str.length;
- console.log(length);
- }
-
- somVarLength(aGlobal);
-
\ No newline at end of file
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html
deleted file mode 100644
index 3fd5bb834..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html
+++ /dev/null
@@ -1,18 +0,0 @@
-Use PreparedStatement
instead of Statement
, because SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption.
-Noncompliant Code Example
-
- public void select() {
- Statement statement = connection.createStatement();
- statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant
- }
-
-Compliant Solution
-
- public void select() {
- PreparedStatement statement = connection.prepareStatement(INSERT INTO persons(id, name) VALUES(?, ?));
-
- statement.setInt(1, 2);
- statement.setString(2, "Toto");
- statement.executeQuery();
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html
deleted file mode 100644
index b1d548c92..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html
+++ /dev/null
@@ -1,18 +0,0 @@
-Using List instead of Arrays with Foreach save CPU cycles calculations and RAM consumption.
-Noncompliant Code Example
-
- private final Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-
- for (Integer i : intArray) {
- ...
- }
-
-
-Compliant Solution
-
- private final List<Integer> intList = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
-
- for (Integer i : intList) {
- ...
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html
deleted file mode 100644
index be6d491d4..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html
+++ /dev/null
@@ -1,12 +0,0 @@
-Do not unnecessarily assign values to variables. It increases the use of RAM memory.
-Noncompliant Code Example
-
-String var1 = getValue();
-return var1;
-
-String var2 = "hello"
-var2 = "world" //Non compliant cause never assigned
-
-
-Compliant Solution
-return getValue();
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html
deleted file mode 100644
index 3c55323e5..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html
+++ /dev/null
@@ -1,7 +0,0 @@
-The form $i++ creates a temporary variable whereas ++$i does not. It save CPU cycles.
-Noncompliant Code Example
-
-i++ // Noncompliant
-
-Compliant Solution
-++i
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html
deleted file mode 100644
index 5d8c46aa1..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html
+++ /dev/null
@@ -1,23 +0,0 @@
-Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.
-Noncompliant Code Example
-
- public void foo() {
- for (int i = 0; i < getMyValue(); i++) { // Noncompliant
- System.out.println(i);
- boolean b = getMyValue() > 6;
- }
- }
-
-
-Compliant Solution
-
-
- public void foo() {
- int myValue = getMyValue();
- for (int i = 0; i < myValue; i++) {
- System.out.println(i);
- boolean b = getMyValue() > 6;
- }
- }
-
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html
deleted file mode 100644
index 4bb67e113..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html
+++ /dev/null
@@ -1,49 +0,0 @@
-Executing SQL queries in loop induced unnecessary calculation by the cpu, RAM usage and network transfert.
-Noncompliant Code Example
-
- public void foo() {
- ...
- String baseQuery = "SELECT name FROM users where id = ";
-
- for (int i = 0; i < 20; i++) {
-
- String query = baseQuery.concat("" + i);
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery(query); // Noncompliant
-
- // iterate through the java resultset
- while (rs.next()) {
- String name = rs.getString("name");
- System.out.println(name);
- }
- st.close();
- }
- ...
- }
-
-
-Compliant Solution
-
-
- public void foo() {
- ...
- String query = "SELECT name FROM users where id in (0 ";
- for (int i = 1; i < 20; i++) {
-
- query = baseQuery.concat("," + i);
- }
-
- query = baseQuery.concat(")");
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery(query); // compliant
-
- // iterate through the java resultset
- while (rs.next()) {
- String name = rs.getString("name");
- System.out.println(name);
- }
- st.close();
- ...
- }
-
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html
deleted file mode 100644
index d3f65bcf6..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html
+++ /dev/null
@@ -1,21 +0,0 @@
-Databases servers have to solve fields regarding the schema. Knowing and using the schema save CPU cycles and network transfer.
-Noncompliant Code Example
-
- public void foo() {
- ...
- String baseQuery = "SELECT * FROM users"; // Noncompliant
-
- ...
- }
-
-
-Compliant Solution
-
-
- public void foo() {
- ...
- String query = "SELECT id,name, adress FROM users ";
- ...
- }
-
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html
deleted file mode 100644
index 67c1c1ccf..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html
+++ /dev/null
@@ -1,41 +0,0 @@
-
- Don't concatenate Strings in loop. User StringBuilder instead.
- Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU.
-
-
-Noncompliant Code Example
-
-
- public String concatenateStrings(String[] strings) {
- String result = "";
-
- for (String string : strings) {
- result += string; // Noncompliant
- }
- return result;
- }
-
- public String concatenateStrings2() {
- String result = "";
-
- for (int i = 0; i < 1000; ++i) {
- result += "another"; // Noncompliant
- }
- return result;
- }
-
-
-
-Compliant Solution
-
-
- public String concatenateStrings(String[] strings) {
- StringBuilder result = new StringBuilder();
-
- for (String string : strings) {
- result.append(string);
- }
- return result.toString();
- }
-
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html
deleted file mode 100644
index 608b0285b..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html
+++ /dev/null
@@ -1,38 +0,0 @@
-
- Avoid usage of static collections.
- If you want to use static collections make them final and create for example a singleton if needed containing the collections.
- The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks.
-
-
-Noncompliant Code Example
-
-
- /**
- * Not compliant
- */
- public class AvoidUsageOfStaticCollections {
- public static final List<> LIST = new ArrayList<>();
- public static final Set<> SET = new HashSet<>();
- public static final Map<> MAP = new HashMap<>();
- }
-
-
-
-Compliant Solution
-
-
- /**
- * Compliant
- */
- public class GoodUsageOfStaticCollections {
- public static volatile GoodUsageOfStaticCollections INSTANCE = new GoodUsageOfStaticCollections();
-
- public final List<> LIST = new ArrayList<>();
- public final Set<> SET = new HashSet<>();
- public final Map<> MAP = new HashMap<>();
-
- private GoodUsageOfStaticCollections() {
- }
- }
-
-
\ No newline at end of file
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html
deleted file mode 100644
index 8de04cef2..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html
+++ /dev/null
@@ -1,67 +0,0 @@
-
- Avoid using Pattern.compile() in a non-static context.
- This operation requires a non negligible amount of computational power, Using a single match saves CPU cycles and RAM consumption.
-
-
-Noncompliant Code Example
-
-
- public class AvoidRegexPatternNotStatic {
-
- public boolean foo() {
- final Pattern pattern = Pattern.compile("foo"); // Noncompliant
- return pattern.matcher("foo").find();
- }
-
- }
-
-
-
-Compliant Solution NΒ°1
-
-
- public class ValidRegexPattern {
-
- private static final Pattern pattern = Pattern.compile("foo"); // Compliant
-
- public boolean foo() {
- return pattern.matcher("foo").find();
- }
-
- }
-
-
-
-Compliant Solution NΒ°2
-
-
- public class ValidRegexPattern2 {
-
- private final Pattern pattern = Pattern.compile("foo"); // Compliant
-
- public boolean foo() {
- return pattern.matcher("foo").find();
- }
-
- }
-
-
-
-Compliant Solution NΒ°3
-
-
- public class ValidRegexPattern3 {
-
- private final Pattern pattern;
-
- public ValidRegexPattern3() {
- pattern = Pattern.compile("foo"); // Compliant
- }
-
- public boolean foo() {
- return pattern.matcher("foo").find();
- }
-
- }
-
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html
deleted file mode 100644
index 2b0c687b0..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html
+++ /dev/null
@@ -1,30 +0,0 @@
-Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily.
-Noncompliant Code Example
-
- public void foo() {
- ...
- String query = "insert into mytable values(?,?,?)";
- ...
- for(DummyClass o : list) {
- stmt.setInt(1, 123); // Noncompliant
- stmt.setString(2, o.getName());
- stmt.setDouble(3, o.getPrice());
- stmt.addBatch();
- }
- ...
- }
-
-Compliant Solution
-
- public void foo() {
- ...
- String query = "insert into mytable values(123,?,?)";
- ...
- for(DummyClass o : list) {
- stmt.setString(1, o.getName());
- stmt.setDouble(2, o.getPrice());
- stmt.addBatch();
- }
- ...
- }
-
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html
deleted file mode 100644
index f8801ef21..000000000
--- a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html
+++ /dev/null
@@ -1,24 +0,0 @@
-try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources.
-Noncompliant Code Example
-
- private static void printFileJava7() throws IOException {
- FileInputStream input = new FileInputStream("file.txt");
- int data = input.read();
- while(data != -1){
- System.out.print((char) data);
- data = input.read();
- }
- }
-
-Compliant Solution
-
- private static void printFileJava7() throws IOException {
- try(FileInputStream input = new FileInputStream("file.txt")) {
- int data = input.read();
- while(data != -1){
- System.out.print((char) data);
- data = input.read();
- }
- }
- }
-
diff --git a/java-plugin/src/test/files/ArrayCopyCheck.java b/java-plugin/src/test/files/ArrayCopyCheck.java
index d18890515..09c780eaa 100644
--- a/java-plugin/src/test/files/ArrayCopyCheck.java
+++ b/java-plugin/src/test/files/ArrayCopyCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
diff --git a/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java b/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java
index b6b36b2f1..4e2a5877a 100644
--- a/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java
+++ b/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.utils;
public class AvoidConcatenateStringsInLoop {
diff --git a/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java b/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java
index 4a0994727..b388252af 100644
--- a/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java
+++ b/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.regex.Pattern;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
index 18d38b49b..46963cd7f 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
index dec9e0f8a..3c74c86dc 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
index 840ace8cc..5f2bcd2e7 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
index 719f620c2..544e08e7d 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
index 32c74e128..f47570c9b 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
index 7329fba97..57668687e 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
index ca913f17d..10c752f40 100644
--- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
+++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Collection;
diff --git a/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java b/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java
index 88e40ad0c..435218fa6 100644
--- a/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java
+++ b/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java
@@ -1,38 +1,283 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
class AvoidMultipleIfElseStatementCheck {
- AvoidMultipleIfElseStatementCheck(AvoidMultipleIfElseStatementCheck mc) {
+
+// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// //
+// // NON COMPLIANT use cases
+// //
+// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // NON COMPLIANT
+ // USE CASE : Non compliant use case to check if following is NON OK :
+ // - two uses of the same variable
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements()
+ {
+ int nb1 = 0;
+
+ if (nb1 == 1) {
+ nb1 = 2;
+ } else {
+ if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 1;
+ }
+ }
+
+ return nb1;
}
- public void methodWithMultipleIfElseIf() {
+ // NON COMPLIANT
+ // USE CASE : non compliant use case to check if a variable is not used max twice on several IF / ELSE statements
+ // at the same level
+ public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed()
+ {
int nb1 = 0;
- int nb2 = 10;
+ int nb2 = 0;
+ int nb3 = 0;
- if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}}
+ if (nb3 == 1
+ && nb3 == 2
+ && nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
nb1 = 1;
- } else if (nb1 == nb2) {
- //
- } else if (nb2 == nb1) {
- //
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb2 = 2;
+ }
+
+ if (nb2 == 2) {
+ nb1 = 3;
} else {
- //
+ nb1 = 4;
}
- nb1 = nb2;
+
+ return nb1;
}
- public void methodWithMultipleIfElse() {
+ // NON COMPLIANT
+ // USE CASE : NON compliant use case to check if following is NOT COMPLIANT :
+ // one variable is used maximum in two IF / ELSE / ELSEIF statements
+ public int shouldBeNotCompliantBecauseVariablesIsUsedMoreThanTwice()
+ {
int nb1 = 0;
- int nb2 = 10;
- if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}}
- nb1 = 1;
+ if (nb1 == 1) {
+ nb1 = 2;
} else {
- //
+ nb1 = 3;
}
- if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}}
- nb1 = 1;
+
+ if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 4;
+ }
+
+ return nb1;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : NON compliant use case to check if following is NOT OK :
+ // - same variable used maximum twice : no compliant because 2 IFs and 1 ELSE
+ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtDifferentsLevels()
+ {
+ int nb1 = 0;
+
+ if (nb1 == 1) {
+ if (nb1 == 2) {
+ nb1 = 1;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 3;
+ }
} else {
- //
+ nb1 = 2;
}
+
+ return nb1;
+ }
+
+
+ // NON COMPLIANT
+ // USE CASE : non compliant use case to check if following is NOT OK :
+ // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatements()
+ {
+ int nb1 = 0;
+
+ if (nb1 == 1) {
+ nb1 = 2;
+ } else {
+ if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 1;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 3;
+ }
+ }
+
+ return nb1;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : non compliant use case to check if following is NOT OK :
+ // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario2()
+ {
+ int nb1 = 0;
+
+ if (nb1 == 1) {
+ if (nb1 == 3) {
+ nb1 = 4;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 5;
+ }
+ } else {
+ if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 1;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 3;
+ }
+ }
+
+ return nb1;
}
-}
\ No newline at end of file
+
+
+ // NON COMPLIANT
+ // USE CASE : non compliant use case to check if following is NOT OK :
+ // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario3()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+
+ if (nb1 == 1) {
+ if (nb1 == 3) {
+ nb1 = 4;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 5;
+ }
+ } else if (nb2 == 2) {
+ if (nb1 == 4) {
+ nb1 = 5;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 6;
+ }
+ }
+
+ return nb1;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : non compliant use case to check if following is NOT OK :
+ // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario4()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+
+ if (nb1 == 1) {
+ if (nb2 == 3) {
+ nb1 = 4;
+ } else {
+ nb1 = 5;
+ }
+ } else if (nb2 == 2) {
+ if (nb1 == 3) {
+ nb1 = 4;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 5;
+ }
+ }
+
+ return nb1;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : NON compliant use case to check if following is NOT OK :
+ // - the same variable must used maximum twice
+ // - usage of the same variable on different levels of IF / ELSE statements
+ public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements()
+ {
+ int nb1 = 0;
+
+ if (nb1 == 1) {
+ nb1 = 2;
+ } else {
+ if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 1;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 4;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb1 = 5;
+ }
+ }
+ }
+
+ return nb1;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : NON compliant use case to check if following is NOT OK :
+ // - more than twice uses of the same variable
+ // - usage of the same variable on different kind of test statements (IF and ELSEIF)
+ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NOT Compliant
+ {
+ int nb1 = 0;
+ int nb2 = 10;
+
+ if (nb1 == 1) {
+ nb2 = 1;
+ } else if (nb1 == nb2) {
+ nb2 = 2;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb2 = 4;
+ }
+
+ return nb2;
+ }
+
+ // NON COMPLIANT
+ // USE CASE : NON compliant use case to check if following is NOT OK :
+ // - more than twice uses of the same variable
+ // - usage of the same variable on different kind of test statements (IF and ELSEIF)
+ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Compliant
+ {
+ int nb1 = 0;
+ int nb2 = 10;
+ int nb3 = 11;
+
+ if (nb1 == 1) {
+ nb2 = 1;
+ } else if (nb1 == nb2) {
+ nb2 = 2;
+ } else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb2 = 3;
+ } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+ nb2 = 4;
+ }
+
+ return nb2;
+ }
+
+}
diff --git a/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
index 60d10293c..a56e9e599 100644
--- a/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
+++ b/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
@@ -1,31 +1,211 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
-class AvoidMultipleIfElseStatementNoIssueCheck {
- AvoidMultipleIfElseStatementNoIssueCheck(AvoidMultipleIfElseStatementNoIssueCheck mc) {
+class AvoidMultipleIfElseStatementCheckNoIssue {
+
+ // inital RULES : please see HTML description file of this rule (resources directory)
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // COMPLIANT use cases
+ //
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // COMPLIANT
+ // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements
+ // at the same level AND no problem with several IF staments at the same level using different variables
+ public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+ int nb3 = 0;
+
+ if (nb3 != 1 && nb1 > 1) {
+ nb1 = 1;
+ } else {
+ nb2 = 2;
+ }
+
+ if (nb2 == 2) {
+ nb1 = 3;
+ } else {
+ nb1 = 4;
+ }
+
+ return nb1;
}
- public void methodWithOneIfElseIf() {
+ // COMPLIANT
+ // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements
+ // at the same level AND no problem with several IF staments at the same level using different variables
+ public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsedAtDiffLevels()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+ int nb3 = 0;
+
+ if (nb1 < 1) {
+ if (nb2 == 2) {
+ nb3 = 3;
+ } else {
+ nb3 = 4;
+ }
+ } else {
+ nb2 = 2;
+ }
+
+ if (nb3 >= 1) {
+ if (nb2 == 2) {
+ nb1 = 3;
+ } else {
+ nb1 = 4;
+ }
+ } else {
+ nb1 = 2;
+ }
+
+ return nb1;
+ }
+
+ // COMPLIANT
+ // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements
+ // at the same level AND no problem with several IF staments at the same level using different variables
+ public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDiffVariablesUsedAtDiffLevelsScenario2()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+ int nb3 = 0;
+
+ if (nb1 <= 1) {
+ if (nb2 == 2) {
+ if (nb3 == 2) {
+ nb3 = 3;
+ } else {
+ nb3 = 4;
+ }
+ } else {
+ nb3 = 4;
+ }
+ } else {
+ nb2 = 2;
+ }
+
+ if (nb3 == 1) {
+ if (nb2 == 2) {
+ nb1 = 3;
+ } else {
+ nb1 = 4;
+ }
+ } else {
+ nb1 = 2;
+ }
+
+ return nb1;
+ }
+
+ // COMPLIANT
+ // USE CASE : compliant use case to check if one variable is used maximum twice in different IF statements
+ public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfStatements()
+ {
int nb1 = 0;
- int nb2 = 10;
if (nb1 == 1) {
nb1 = 1;
- } else if (nb1 == nb2) {
- //
+ }
+
+ if (nb1 == 2) {
+ nb1 = 3;
+ }
+
+ return nb1;
+ }
+
+ // COMPLIANT
+ // USE CASE : compliant use case to check if following is OK :
+ // - two uses of the same variable
+ // - usage of the same variable on different levels of IF statements
+ public int shouldBeCompliantBecauseSereralVariablesUsedMaximumTwiceInComposedElseStatements()
+ {
+ int nb1 = 0;
+ int nb2 = 0;
+ int nb3 = 0;
+
+ if (nb1 == 1) {
+ nb1 = 2;
} else {
- //
+ if (nb2 == 2) {
+ nb1 = 1;
+ } else {
+ if (nb3 == 4) {
+ nb1 = 3;
+ } else {
+ nb1 = 6;
+ }
+ }
}
- nb1 = nb2;
+
+ return nb1;
}
- public void methodWithOneIfElse() {
+ // COMPLIANT
+ // USE CASE : compliant use case to check if following is OK :
+ // - two uses of the same variable
+ // - usage of the same variable on different kind of test statements (IF and ELSEIF)
+ public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfOrElseIfStatements() // Compliant
+ {
int nb1 = 0;
int nb2 = 10;
if (nb1 == 1) {
- nb1 = 1;
+ nb2 = 1;
+ } else if (nb1 == nb2) {
+ nb2 = 2;
+ }
+
+ return nb2;
+ }
+
+ // COMPLIANT
+ // USE CASE : compliant use case to check if following is OK :
+ // - two uses of the same variable
+ // - usage of the same variable on different kind of test statements (IF and ELSEIF)
+ public int shouldBeCompliantBecauseSeveralVariablesUsedMaximumTwiceInIfOrElseIfStatements() // Compliant
+ {
+ int nb1 = 0;
+ int nb2 = 10;
+ int nb3 = 3;
+ int nb4 = 1;
+ int nb5 = 2;
+
+ if (nb1 == 1) {
+ nb2 = 1;
+ } else if (nb3 == nb2) {
+ nb2 = 2;
+ } else if (nb4 == nb5) {
+ nb2 = 4;
} else {
- //
+ nb2 = 3;
}
+
+ return nb2;
}
-}
\ No newline at end of file
+
+}
diff --git a/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java b/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java
index 0474e4520..b5e19c6e3 100644
--- a/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java
+++ b/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.regex.Pattern;
diff --git a/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java b/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java
index 4981d0b4c..753a717a6 100644
--- a/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java
+++ b/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.sql.Connection;
diff --git a/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
index 122a48b4d..03f5e86ab 100644
--- a/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
+++ b/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.math.BigDecimal;
diff --git a/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
index c4aec153c..d2ae74e8a 100644
--- a/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
+++ b/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/java-plugin/src/test/files/AvoidStatementForDMLQueries.java b/java-plugin/src/test/files/AvoidStatementForDMLQueries.java
index 70ba4ed5e..5059b0933 100644
--- a/java-plugin/src/test/files/AvoidStatementForDMLQueries.java
+++ b/java-plugin/src/test/files/AvoidStatementForDMLQueries.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.sql.Connection;
diff --git a/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java b/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java
index ac1b9f0dc..353099720 100644
--- a/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java
+++ b/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.*;
diff --git a/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java b/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java
index 362510eff..557d6fc92 100644
--- a/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java
+++ b/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
public class Openclass {
public static double price = 15.24; // Noncompliant {{Avoid using global variables}}
public static long pages = 1053; // Noncompliant {{Avoid using global variables}}
diff --git a/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java
index e2ca15225..e1eaab59e 100644
--- a/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java
+++ b/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.io.*;
diff --git a/java-plugin/src/test/files/GoodUsageOfStaticCollections.java b/java-plugin/src/test/files/GoodUsageOfStaticCollections.java
index 8f8e55c71..6d2d3c202 100644
--- a/java-plugin/src/test/files/GoodUsageOfStaticCollections.java
+++ b/java-plugin/src/test/files/GoodUsageOfStaticCollections.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.*;
diff --git a/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java b/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java
index b4218d0d7..c11c1ab6a 100644
--- a/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java
+++ b/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.utils;
public class GoodWayConcatenateStringsLoop {
diff --git a/java-plugin/src/test/files/IncrementCheck.java b/java-plugin/src/test/files/IncrementCheck.java
index 6a6d1b536..54b20bf90 100644
--- a/java-plugin/src/test/files/IncrementCheck.java
+++ b/java-plugin/src/test/files/IncrementCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
class MyClass {
MyClass(MyClass mc) {
}
diff --git a/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java b/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java
index 1b391c106..b5852a195 100644
--- a/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java
+++ b/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.sql.Connection;
diff --git a/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
index 8b92a39a8..da72a3efd 100644
--- a/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
+++ b/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
class NoFunctionCallWhenDeclaringForLoop {
NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) {
}
diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java
index 6e7a6e29c..e9fd260cb 100644
--- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java
+++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java
index 2e1054925..689dc1878 100644
--- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java
+++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java
index e76f64a01..92dc15019 100644
--- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java
+++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java
index 89ca97340..5914e0fa5 100644
--- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java
+++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java
index b4c3388dd..6d8b553e2 100644
--- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java
+++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java
index b61a58ec7..17eb069a5 100644
--- a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java
+++ b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
class UnnecessarilyAssignValuesToVariablesTestCheck {
diff --git a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java
index f732e4945..f70c4c410 100644
--- a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java
+++ b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
class UnnecessarilyAssignValuesToVariablesTestCheck {
diff --git a/java-plugin/src/test/files/UseCorrectForLoopCheck.java b/java-plugin/src/test/files/UseCorrectForLoopCheck.java
index dfdde5d16..350ed6ebb 100644
--- a/java-plugin/src/test/files/UseCorrectForLoopCheck.java
+++ b/java-plugin/src/test/files/UseCorrectForLoopCheck.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.Arrays;
diff --git a/java-plugin/src/test/files/ValidRegexPattern.java b/java-plugin/src/test/files/ValidRegexPattern.java
index 5ed3652f4..aacb701e5 100644
--- a/java-plugin/src/test/files/ValidRegexPattern.java
+++ b/java-plugin/src/test/files/ValidRegexPattern.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.regex.Pattern;
diff --git a/java-plugin/src/test/files/ValidRegexPattern2.java b/java-plugin/src/test/files/ValidRegexPattern2.java
index d6d9efd71..a674b9bc4 100644
--- a/java-plugin/src/test/files/ValidRegexPattern2.java
+++ b/java-plugin/src/test/files/ValidRegexPattern2.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.regex.Pattern;
diff --git a/java-plugin/src/test/files/ValidRegexPattern3.java b/java-plugin/src/test/files/ValidRegexPattern3.java
index e19073454..086769384 100644
--- a/java-plugin/src/test/files/ValidRegexPattern3.java
+++ b/java-plugin/src/test/files/ValidRegexPattern3.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import java.util.regex.Pattern;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java
index 3225b1a56..db1383ae5 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java
@@ -1,28 +1,27 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
-import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.java.api.CheckRegistrar;
+import static org.assertj.core.api.Assertions.assertThat;
+
class JavaCheckRegistrarTest {
@Test
@@ -35,4 +34,5 @@ void checkNumberRules() {
assertThat(context.checkClasses()).hasSize(19);
assertThat(context.testCheckClasses()).isEmpty();
}
+
}
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
index 53eaad42e..0f2167d37 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
@@ -1,65 +1,43 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.sonar.api.Plugin;
-import org.sonar.api.SonarEdition;
-import org.sonar.api.SonarProduct;
-import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
-import org.sonar.api.utils.Version;
-class JavaPluginTest {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
- @Test
- void testName() {
- Plugin.Context context = new Plugin.Context(new MockedSonarRuntime());
+class JavaPluginTest {
+ private Plugin.Context context;
+ @BeforeEach
+ void init() {
+ SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+ context = new Plugin.Context(sonarRuntime);
new JavaPlugin().define(context);
-
- assertThat(context.getExtensions()).hasSize(2);
}
- private static class MockedSonarRuntime implements SonarRuntime {
-
- @Override
- public Version getApiVersion() {
- return Version.create(9, 9);
- }
-
- @Override
- public SonarProduct getProduct() {
- return SonarProduct.SONARQUBE;
- }
-
- @Override
- public SonarQubeSide getSonarQubeSide() {
- return SonarQubeSide.SCANNER;
- }
-
- @Override
- public SonarEdition getEdition() {
- return SonarEdition.COMMUNITY;
- }
+ @Test
+ void test() {
+ assertThat(context.getExtensions()).hasSize(2);
}
}
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java
index 45bd537e2..2c6551436 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java
@@ -1,21 +1,19 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java;
@@ -23,36 +21,69 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.debt.DebtRemediationFunction.Type;
import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinition.Param;
-import org.sonar.api.server.rule.RulesDefinition.Repository;
import org.sonar.api.server.rule.RulesDefinition.Rule;
+import org.sonar.api.utils.Version;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
class JavaRulesDefinitionTest {
private RulesDefinition.Repository repository;
+ private RulesDefinition.Context context;
@BeforeEach
void init() {
- final JavaRulesDefinition rulesDefinition = new JavaRulesDefinition();
- final RulesDefinition.Context context = new RulesDefinition.Context();
+ // TODO: Remove this check after Git repo split
+ /*
+ On an IDE (like IntelliJ), if the developer runs the unit tests without building/generating the Maven goals on the
+ "ecocode-rules-specifications" module before, the unit tests will not see the generated HTML descriptions (from ASCIIDOC files).
+ The developer must therefore configure his IDE to build the `ecocode-rules-specifications` module before launching the Tests.
+
+ When the `java-plugin` submodule is in a specific Git repository, `ecocode-rules-specifications` will be fetched from a classic
+ external Maven dependency. There will therefore no longer be any need to perform this specific configuration.
+ */
+ if (JavaRulesDefinition.class.getResource("/io/ecocode/rules/java/EC4.json") == null) {
+ String message = "'ecocode-rules-specification' resources corrupted. Please check build of 'ecocode-rules-specification' module";
+ if (System.getProperties().keySet().stream().anyMatch(k -> k.toString().startsWith("idea."))) {
+ message += "\n\nOn 'IntelliJ IDEA':" +
+ "\n1. go to settings :" +
+ "\n > Build, Execution, Deployment > Build Tools > Maven > Runner" +
+ "\n2. check option:" +
+ "\n > Delegate IDE build/run actions to Maven" +
+ "\n3. Click on menu: " +
+ "\n > Build > Build Project"
+ ;
+ }
+ fail(message);
+ }
+
+ final SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+ doReturn(Version.create(0, 0)).when(sonarRuntime).getApiVersion();
+ JavaRulesDefinition rulesDefinition = new JavaRulesDefinition(sonarRuntime);
+ RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
- repository = context.repository(JavaRulesDefinition.REPOSITORY_KEY);
+ repository = context.repository(rulesDefinition.repositoryKey());
}
@Test
- void test() {
- assertThat(repository.name()).isEqualTo(JavaRulesDefinition.NAME);
- assertThat(repository.language()).isEqualTo(JavaRulesDefinition.LANGUAGE);
- assertThat(repository.rules()).hasSize(RulesList.getChecks().size());
- assertThat(repository.rules().stream().filter(Rule::template)).isEmpty();
+ @DisplayName("Test repository metadata")
+ void testMetadata() {
+ assertThat(repository.name()).isEqualTo("ecoCode");
+ assertThat(repository.language()).isEqualTo("java");
+ assertThat(repository.key()).isEqualTo("ecocode-java");
+ assertThat(repository.rules()).hasSize(19);
+ }
- assertRuleProperties(repository);
- assertAllRuleParametersHaveDescription(repository);
+ @Test
+ void testRegistredRules() {
+ assertThat(repository.rules()).hasSize(19);
}
@Test
@@ -65,7 +96,8 @@ void testRuleKeyPrefix() {
assertions.assertAll();
}
- private static void assertRuleProperties(Repository repository) {
+ @Test
+ void assertRuleProperties() {
Rule rule = repository.rule("EC67");
assertThat(rule).isNotNull();
assertThat(rule.name()).isEqualTo("Use ++i instead of i++");
@@ -73,12 +105,13 @@ private static void assertRuleProperties(Repository repository) {
assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
}
- private static void assertAllRuleParametersHaveDescription(Repository repository) {
- for (Rule rule : repository.rules()) {
- for (Param param : rule.params()) {
- assertThat(param.description()).as("description for " + param.key()).isNotEmpty();
- }
- }
+ @Test
+ void testAllRuleParametersHaveDescription() {
+ SoftAssertions assertions = new SoftAssertions();
+ repository.rules().stream()
+ .flatMap(rule -> rule.params().stream())
+ .forEach(param -> assertions.assertThat(param.description()).as("description for " + param.key()).isNotEmpty());
+ assertions.assertAll();
}
}
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java
index e83a49e2f..5f0b12767 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java
index d5e3e6fcb..00027474c 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java
index 516f31fec..25ead7c4d 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java
index 4a0bad7f8..8083c1db6 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java
index 84a7e5f32..568757e7c 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java
index a3c8ba912..5350cc127 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java
index 54f5f4a53..5abed41fd 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java
index 73a7e58d3..8c138fde7 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
index ce5dfc36e..2ea1887bd 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import fr.greencodeinitiative.java.utils.FilesUtils;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java
index 1a8803440..40c5a51b6 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java
index e72d271de..a9b8a2d84 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java
index c8dbeb26a..f9e270e6c 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
index 2736a12e3..9a9ca4929 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java
index 4044341cd..e9d5b98ef 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java
index 5096eee2f..deef83e80 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
index f2876bb1d..ef3c983fe 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java
index 5dffac408..b3ef8c89e 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java
index efcb2aa1b..09336e24a 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java
index f6add5776..815d097a1 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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 .
+ */
package fr.greencodeinitiative.java.checks;
import org.junit.jupiter.api.Test;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java
index 37be25da4..ed06d4cef 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java
@@ -1,21 +1,19 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java.utils;
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java
index c0eee7c3c..9e6d9328a 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java
@@ -1,21 +1,19 @@
/*
- * SonarQube Java
- * Copyright (C) 2012-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
+ * 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 Lesser 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 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
- * Lesser General Public License for more details.
+ * 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 Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
package fr.greencodeinitiative.java.utils;
diff --git a/javascript-plugin/README.md b/javascript-plugin/README.md
deleted file mode 100644
index b6095a6ea..000000000
--- a/javascript-plugin/README.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# ecoCode JavaScript plugin
-
-This plugin behaves differently from the others in the ecoCode project. Since version 8.9 of SonarQube, it is no longer
-possible to use an AST to implement a
-rule, [as explained here](https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/javascript-custom-rules).
-In compliance with the SonarSource decision, the ecoCode project uses ESLint to implement the custom rules.
-
-Thus, the plugin does not implement any rules. Its purpose is to import the result of the ESLint analysis of the
-project made with the ecoCode linter, with the complete documentation of each rule. In this context, the rules are
-considered by SonarQube as external: they do not appear in the list of rules but are reported as real rules during the
-analysis ([click to learn more](https://docs.sonarqube.org/latest/analyzing-source-code/importing-external-issues/importing-third-party-issues/)).
-
-π Getting Started
-------------------
-
-The installation is not much more complicated than another ecoCode plugin. In addition to the Sonar plugin, you will
-need to install the ESLint plugin in your JavaScript/TypeScript project to be analyzed:
-
-- Install the SonarQube plugin as described in the [ecoCode README](../README.md#-getting-started).
-- Install the ESLint plugin into your project as described
- in [ESLint project README](https://github.com/green-code-initiative/ecoCode-linter/blob/main/eslint-plugin/README.md#installation).\
- This guide also explains how to configure ESLint to import results into SonarQube.
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
deleted file mode 100644
index 8412187ea..000000000
--- a/javascript-plugin/pom.xml
+++ /dev/null
@@ -1,152 +0,0 @@
-
-
- 4.0.0
-
-
- io.ecocode
- ecocode-parent
- 1.1.1-SNAPSHOT
-
-
- ecocode-javascript-plugin
- sonar-plugin
-
- ecoCode - JavaScript language
- Provides rules to reduce the environmental footprint of your JavaScript programs
- https://github.com/green-code-initiative/ecoCode/tree/main/javascript-plugin
-
-
-
-
- org.sonarsource.javascript
- sonar-javascript-plugin
- sonar-plugin
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api-impl
-
-
-
- org.sonarsource.analyzer-commons
- sonar-analyzer-commons
-
-
-
-
-
- junit
- junit
- test
-
-
-
- org.assertj
- assertj-core
- test
-
-
-
-
-
-
-
- org.sonarsource.sonar-packaging-maven-plugin
- sonar-packaging-maven-plugin
- true
-
- ecocodejavascript
- ${project.name}
- fr.greencodeinitiative.javascript.JavaScriptPlugin
- true
- ${sonarqube.version}
- javascript
- ${java.version}
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- commons-*:*
-
- META-INF/**
-
-
-
- org.*:*
-
- META-INF/**
- org/sonar/api/batch/sensor/**
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-bundle
- package
-
- copy
-
-
-
-
- ${project.groupId}
- ${project.artifactId}
- ${project.version}
- jar
- true
-
-
- ../lib
-
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
-
- file
- false
-
-
-
- prepare-agent
-
- prepare-agent
-
-
-
- report
- test
-
- report
-
-
-
-
-
-
-
diff --git a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java b/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java
deleted file mode 100644
index 6959ea2e1..000000000
--- a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package fr.greencodeinitiative.javascript;
-
-import org.sonar.api.Plugin;
-
-public class JavaScriptPlugin implements Plugin {
-
- @Override
- public void define(Context context) {
- context.addExtension(JavaScriptRulesDefinition.class);
- }
-
-}
diff --git a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java b/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java
deleted file mode 100644
index e5fbae09d..000000000
--- a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package fr.greencodeinitiative.javascript;
-
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonarsource.analyzer.commons.ExternalRuleLoader;
-
-public class JavaScriptRulesDefinition implements RulesDefinition {
-
- private static final String LANGUAGE = "js";
-
- /*
- As we integrate our rules using SonarJS, these values should remain to "eslint_repo" and "ESLint" in order to import them correctly
- see: https://github.com/green-code-initiative/ecoCode/pull/79#discussion_r1137797583
- */
- private static final String LINTER_KEY = "eslint_repo";
- private static final String LINTER_NAME = "ESLint";
- private static final String METADATA_PATH = "fr/greencodeinitiative/l10n/javascript/rules.json";
-
- @Override
- public void define(Context context) {
- new ExternalRuleLoader(LINTER_KEY, LINTER_NAME, METADATA_PATH, LANGUAGE)
- .createExternalRuleRepository(context);
- }
-
-}
diff --git a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json b/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json
deleted file mode 100644
index 5beda43e8..000000000
--- a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json
+++ /dev/null
@@ -1,14 +0,0 @@
-[
- {
- "key": "@ecocode/no-multiple-access-dom-element",
- "type": "CODE_SMELL",
- "name": "Disallow multiple access of same DOM element",
- "description": "\n\nRule details \nThis rule aims to reduce DOM access assigning its object to variable when access multiple time. It saves CPU cycles.
\nExamples \nExamples of incorrect code for this rule:
\nvar el1 = document.getElementById("block1").test1;\nvar el2 = document.getElementById("block1").test2;\n
\nExamples of correct code for this rule:
\nvar blockElement = document.getElementById("block1");\nvar el1 = blockElement.test1;\nvar el2 = blockElement.test2;\n
\nClick here to access the rule details. ",
- "constantDebtMinutes": 5,
- "severity": "MINOR",
- "tags": [
- "eco-design",
- "ecocode"
- ]
- }
-]
diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
deleted file mode 100644
index a558e0626..000000000
--- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package fr.greencodeinitiative.javascript;
-
-import org.junit.Test;
-import org.sonar.api.*;
-import org.sonar.api.utils.Version;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class JavaScriptPluginTest {
-
- @Test
- public void extensions() {
- Plugin.Context context = new Plugin.Context(new MockedSonarRuntime());
- new JavaScriptPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(1);
- }
-
- private static class MockedSonarRuntime implements SonarRuntime {
-
- @Override
- public Version getApiVersion() {
- return Version.create(9, 9);
- }
-
- @Override
- public SonarProduct getProduct() {
- return SonarProduct.SONARQUBE;
- }
-
- @Override
- public SonarQubeSide getSonarQubeSide() {
- return SonarQubeSide.SCANNER;
- }
-
- @Override
- public SonarEdition getEdition() {
- return SonarEdition.COMMUNITY;
- }
- }
-
-}
diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java
deleted file mode 100644
index 60bdc8510..000000000
--- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package fr.greencodeinitiative.javascript;
-
-import org.junit.Test;
-import org.sonar.api.server.rule.RulesDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class JavaScriptRulesDefinitionTest {
-
- @Test
- public void createExternalRepository() {
- RulesDefinition.Context context = new RulesDefinition.Context();
- new JavaScriptRulesDefinition().define(context);
- assertThat(context.repositories()).hasSize(1);
-
- RulesDefinition.Repository repository = context.repositories().get(0);
- assertThat(repository.isExternal()).isTrue();
- assertThat(repository.language()).isEqualTo("js");
- assertThat(repository.key()).isEqualTo("external_eslint_repo");
- }
-
-}
diff --git a/php-plugin/README.md b/php-plugin/README.md
deleted file mode 100644
index d7c7e9847..000000000
--- a/php-plugin/README.md
+++ /dev/null
@@ -1 +0,0 @@
-https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/php-custom-rules
\ No newline at end of file
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
deleted file mode 100644
index a79f181ef..000000000
--- a/php-plugin/pom.xml
+++ /dev/null
@@ -1,161 +0,0 @@
-
-
- 4.0.0
-
-
- io.ecocode
- ecocode-parent
- 1.1.1-SNAPSHOT
-
-
- ecocode-php-plugin
- sonar-plugin
-
- ecoCode - PHP language
- Provides rules to reduce the environmental footprint of your PHP programs
- https://github.com/green-code-initiative/ecoCode/tree/main/php-plugin
-
-
-
-
- org.sonarsource.php
- sonar-php-plugin
- sonar-plugin
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api-impl
-
-
-
-
-
-
-
-
-
-
- junit
- junit
- test
-
-
-
- org.assertj
- assertj-core
- test
-
-
-
-
-
-
-
- org.sonarsource.sonar-packaging-maven-plugin
- sonar-packaging-maven-plugin
- true
-
- ecocodephp
- ${project.name}
- fr.greencodeinitiative.php.PHPPlugin
- true
- ${sonarqube.version}
- php
- ${java.version}
- php:${sonarphp.version}
- ${sonarqube.version}
- ${java.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-bundle
- package
-
- copy
-
-
-
-
- ${project.groupId}
- ${project.artifactId}
- ${project.version}
- jar
- true
-
-
- ../lib
-
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
-
- file
- false
-
-
-
- prepare-agent
-
- prepare-agent
-
-
-
- report
- test
-
- report
-
-
-
-
-
-
-
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/PHPPlugin.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/PHPPlugin.java
deleted file mode 100644
index c9bd1ce55..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/PHPPlugin.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SonarQube PHP Custom Rules Example
- * Copyright (C) 2016-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php;
-
-import org.sonar.api.Plugin;
-
-/**
- * Extension point to define a Sonar Plugin.
- */
-public class PHPPlugin implements Plugin {
-
- @Override
- public void define(Context context) {
- context.addExtension(PhpRuleRepository.class);
- }
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java
deleted file mode 100644
index bebb9e605..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.ImmutableList;
-import fr.greencodeinitiative.php.checks.AvoidDoubleQuoteCheck;
-import fr.greencodeinitiative.php.checks.AvoidFullSQLRequestCheck;
-import fr.greencodeinitiative.php.checks.AvoidSQLRequestInLoopCheck;
-import fr.greencodeinitiative.php.checks.AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements;
-import fr.greencodeinitiative.php.checks.AvoidUsingGlobalVariablesCheck;
-import fr.greencodeinitiative.php.checks.IncrementCheck;
-import fr.greencodeinitiative.php.checks.NoFunctionCallWhenDeclaringForLoop;
-import fr.greencodeinitiative.php.checks.UseOfMethodsForBasicOperations;
-import org.sonar.api.rules.RuleType;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
-import org.sonar.plugins.php.api.visitors.PHPCustomRuleRepository;
-
-public class PhpRuleRepository implements RulesDefinition, PHPCustomRuleRepository {
-
- public static final String LANGUAGE = "php";
- public static final String NAME = "ecoCode";
- public static final String RESOURCE_BASE_PATH = "/fr/greencodeinitiative/l10n/php/rules/custom/";
- public static final String REPOSITORY_KEY = "ecocode-php";
-
- @Override
- public void define(Context context) {
- NewRepository repository = context.createRepository(repositoryKey(), LANGUAGE).setName(NAME);
-
- new RulesDefinitionAnnotationLoader().load(repository, checkClasses().toArray(new Class[] {}));
-
- // technical debt
- Map remediationCosts = new HashMap<>();
- remediationCosts.put(AvoidSQLRequestInLoopCheck.RULE_KEY, "10min");
- remediationCosts.put(AvoidFullSQLRequestCheck.RULE_KEY, "20min");
- repository.rules().forEach(rule -> {
- rule.setType(RuleType.CODE_SMELL);
- String debt = remediationCosts.get(rule.key());
-
- // TODO DDC : create support to use org.apache.commons.lang.StringUtils
-// if (StringUtils.isBlank(debt)) {
- if (debt == null || debt.trim().equals("")) {
- // default debt to 5min for issue correction
- rule.setDebtRemediationFunction(
- rule.debtRemediationFunctions().constantPerIssue("5min"));
- } else {
- rule.setDebtRemediationFunction(
- rule.debtRemediationFunctions().constantPerIssue(debt));
- }
- });
-
- // HTML description
- repository.rules().forEach(rule ->
- rule.setHtmlDescription(loadResource(RESOURCE_BASE_PATH + rule.key() + ".html")));
-
- repository.done();
- }
-
- @Override
- public String repositoryKey() {
- return REPOSITORY_KEY;
- }
-
- @Override
- public List> checkClasses() {
- return ImmutableList.of(
- AvoidDoubleQuoteCheck.class,
- AvoidFullSQLRequestCheck.class,
- AvoidSQLRequestInLoopCheck.class,
- AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.class,
- AvoidUsingGlobalVariablesCheck.class,
- IncrementCheck.class,
- NoFunctionCallWhenDeclaringForLoop.class,
- UseOfMethodsForBasicOperations.class
- );
- }
-
- private String loadResource(String path) {
- URL resource = getClass().getResource(path);
- if (resource == null) {
- throw new IllegalStateException("Resource not found: " + path);
- }
- ByteArrayOutputStream result = new ByteArrayOutputStream();
- try (InputStream in = resource.openStream()) {
- byte[] buffer = new byte[1024];
- for (int len = in.read(buffer); len != -1; len = in.read(buffer)) {
- result.write(buffer, 0, len);
- }
- return new String(result.toByteArray(), StandardCharsets.UTF_8);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to read resource: " + path, e);
- }
- }
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java
deleted file mode 100644
index 2fe45079c..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheck.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.expression.LiteralTree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidDoubleQuoteCheck.RULE_KEY,
- name = AvoidDoubleQuoteCheck.ERROR_MESSAGE,
- description = AvoidDoubleQuoteCheck.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S66")
-public class AvoidDoubleQuoteCheck extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC66";
- public static final String ERROR_MESSAGE = "Avoid using double quote (\"), prefer using simple quote (')";
- private static final Map> linesWithIssuesByFile = new HashMap<>();
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(Tree.Kind.REGULAR_STRING_LITERAL);
- }
-
- @Override
- public void visitNode(Tree tree) {
- LiteralTree method = (LiteralTree) tree;
- checkIssue(method);
- }
-
- public void checkIssue(LiteralTree literalTree) {
- if (lineAlreadyHasThisIssue(literalTree)) return;
- if (literalTree.value().indexOf("\"") == 0 && literalTree.value().lastIndexOf("\"") == literalTree.value().length() - 1) {
- repport(literalTree);
- }
- }
-
- private void repport(LiteralTree literalTree) {
- if (literalTree.token() != null) {
-
- final String classname = context().getPhpFile().toString();
- final int line = literalTree.token().line();
- linesWithIssuesByFile.computeIfAbsent(classname, k -> new ArrayList<>());
- linesWithIssuesByFile.get(classname).add(line);
- }
- context().newIssue(this, literalTree, ERROR_MESSAGE);
-
- }
-
- private boolean lineAlreadyHasThisIssue(LiteralTree literalTree) {
- if (literalTree.token() != null) {
- final String filename = context().getPhpFile().toString();
- final int line = literalTree.token().line();
-
- return linesWithIssuesByFile.containsKey(filename)
- && linesWithIssuesByFile.get(filename).contains(line);
- }
-
- return false;
- }
-
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java
deleted file mode 100644
index fdc016916..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheck.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.Tree.Kind;
-import org.sonar.plugins.php.api.tree.expression.LiteralTree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidFullSQLRequestCheck.RULE_KEY,
- name = AvoidFullSQLRequestCheck.ERROR_MESSAGE,
- description = AvoidFullSQLRequestCheck.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S74")
-public class AvoidFullSQLRequestCheck extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC74";
-
- public static final String ERROR_MESSAGE = "Don't use the query SELECT * FROM";
-
- private static final Pattern PATTERN = Pattern.compile("(?i).*select.*\\*.*from.*");
-
- @Override
- public List nodesToVisit() {
- return Arrays.asList(Kind.REGULAR_STRING_LITERAL);
- }
-
- @Override
- public void visitNode(Tree tree) {
-
- LiteralTree literal = (LiteralTree) tree;
- if (PATTERN.matcher(literal.value()).matches()) {
- context().newIssue(this, tree, ERROR_MESSAGE);
- }
- }
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java
deleted file mode 100644
index 358f43008..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheck.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.Tree.Kind;
-import org.sonar.plugins.php.api.tree.statement.BlockTree;
-import org.sonar.plugins.php.api.tree.statement.DoWhileStatementTree;
-import org.sonar.plugins.php.api.tree.statement.ExpressionStatementTree;
-import org.sonar.plugins.php.api.tree.statement.ForEachStatementTree;
-import org.sonar.plugins.php.api.tree.statement.ForStatementTree;
-import org.sonar.plugins.php.api.tree.statement.IfStatementTree;
-import org.sonar.plugins.php.api.tree.statement.StatementTree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidSQLRequestInLoopCheck.RULE_KEY,
- name = AvoidSQLRequestInLoopCheck.ERROR_MESSAGE,
- description = AvoidSQLRequestInLoopCheck.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S72")
-public class AvoidSQLRequestInLoopCheck extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC72";
- public static final String ERROR_MESSAGE = "Avoid SQL request in loop";
- private static final Pattern PATTERN = Pattern.compile("(mysql(i::|_)query\\s*\\(.*)|(oci_execute\\(.*)");
-
- @Override
- public List nodesToVisit() {
- return Arrays.asList(Kind.FOR_STATEMENT, Kind.FOREACH_STATEMENT, Kind.DO_WHILE_STATEMENT);
- }
-
- @Override
- public void visitNode(Tree tree) {
- if (tree.is(Kind.FOR_STATEMENT)) {
- StatementTree stTree = ((ForStatementTree) tree).statements().get(0);
- if (stTree.is(Kind.BLOCK)) {
- visitBlockNode((BlockTree) stTree);
- }
- }
-
- if (tree.is(Kind.FOREACH_STATEMENT)) {
- StatementTree stTree = ((ForEachStatementTree) tree).statements().get(0);
- if (stTree.is(Kind.BLOCK)) {
- visitBlockNode((BlockTree) stTree);
- }
- }
-
- if (tree.is(Kind.DO_WHILE_STATEMENT)) {
- StatementTree stTree = ((DoWhileStatementTree) tree).statement();
- if (stTree.is(Kind.BLOCK)) {
- visitBlockNode((BlockTree) stTree);
- }
- }
- }
-
- private void visitBlockNode(BlockTree block) {
- block.statements().forEach(this::visiteChildNode);
- }
-
- private void visiteChildNode(Tree tree) {
- if (tree.is(Kind.EXPRESSION_STATEMENT)) {
- ExpressionStatementTree expressionStatementTree = (ExpressionStatementTree) tree;
- String expression = expressionStatementTree.expression().toString();
- verifyIfThereIsAError(expression, expressionStatementTree);
- }
-
- if (tree.is(Kind.IF_STATEMENT)) {
- StatementTree statementTree = ((IfStatementTree) tree).statements().get(0);
- if (statementTree.is(Kind.BLOCK)) {
- visitBlockNode((BlockTree) statementTree);
- } else {
- visiteChildNode(statementTree);
- }
- }
- }
-
- private void verifyIfThereIsAError(String expression, ExpressionStatementTree expressionStatementTree) {
- if (PATTERN.matcher(expression).find())
- context().newIssue(this, expressionStatementTree, ERROR_MESSAGE);
- }
-
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java
deleted file mode 100644
index bced0aa40..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.RULE_KEY,
- name = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.ERROR_MESSAGE,
- description = AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S34")
-public class AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC34";
- public static final String ERROR_MESSAGE = "Avoid using try-catch";
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(Tree.Kind.TRY_STATEMENT);
- }
-
- @Override
- public void visitNode(Tree tree) {
- context().newIssue(this, tree, ERROR_MESSAGE);
- }
-
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java
deleted file mode 100644
index 76607760d..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheck.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.regex.Pattern;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.declaration.FunctionDeclarationTree;
-import org.sonar.plugins.php.api.visitors.PHPVisitorCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidUsingGlobalVariablesCheck.RULE_KEY,
- name = AvoidUsingGlobalVariablesCheck.ERROR_MESSAGE,
- description = AvoidUsingGlobalVariablesCheck.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "D4")
-public class AvoidUsingGlobalVariablesCheck extends PHPVisitorCheck {
-
- public static final String RULE_KEY = "EC4";
- public static final String ERROR_MESSAGE = "Prefer local variables to globals";
-
- private static final Pattern PATTERN = Pattern.compile("^.*(global \\$|\\$GLOBALS).*$", Pattern.CASE_INSENSITIVE);
-
- @Override
- public void visitFunctionDeclaration(FunctionDeclarationTree tree) {
- if (PATTERN.matcher(tree.body().toString()).matches()) {
- context().newIssue(this, tree, String.format(ERROR_MESSAGE, tree.body().toString()));
- }
- }
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java
deleted file mode 100644
index ba2c09e57..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/IncrementCheck.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * SonarQube PHP Custom Rules Example
- * Copyright (C) 2016-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php.checks;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.Tree.Kind;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = IncrementCheck.RULE_KEY,
- name = IncrementCheck.ERROR_MESSAGE,
- description = IncrementCheck.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S67")
-public class IncrementCheck extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC67";
- public static final String ERROR_MESSAGE = "Remove the usage of $i++. prefer ++$i";
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(Kind.POSTFIX_INCREMENT);
- }
-
- @Override
- public void visitNode(Tree tree) {
- context().newIssue(this, tree, ERROR_MESSAGE);
- }
-
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java
deleted file mode 100644
index 4381c8a12..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.SeparatedList;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.Tree.Kind;
-import org.sonar.plugins.php.api.tree.expression.BinaryExpressionTree;
-import org.sonar.plugins.php.api.tree.expression.ExpressionTree;
-import org.sonar.plugins.php.api.tree.statement.ForStatementTree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = NoFunctionCallWhenDeclaringForLoop.RULE_KEY,
- name = NoFunctionCallWhenDeclaringForLoop.ERROR_MESSAGE,
- description = NoFunctionCallWhenDeclaringForLoop.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "S69")
-public class NoFunctionCallWhenDeclaringForLoop extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC69";
- public static final String ERROR_MESSAGE = "Do not call a function in for-type loop declaration";
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(Kind.FOR_STATEMENT);
- }
-
- @Override
- public void visitNode(Tree tree) {
- ForStatementTree method = (ForStatementTree) tree;
- checkExpressionsTree(method.update());
- checkExpressionsTree(method.condition());
- }
-
- public void checkExpressionsTree(SeparatedList treeSeparatedList) {
- treeSeparatedList.forEach(this::checkBothSideExpression);
- }
-
- public void checkBothSideExpression(ExpressionTree expressionTree) {
- if (expressionTree.getKind().getAssociatedInterface() == BinaryExpressionTree.class) {
- BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) expressionTree;
- isFunctionCall(binaryExpressionTree.leftOperand());
- isFunctionCall(binaryExpressionTree.rightOperand());
- } else
- isFunctionCall(expressionTree);
- }
-
- public void isFunctionCall(ExpressionTree expressionTree) {
- if (expressionTree.getKind() == Tree.Kind.FUNCTION_CALL)
- context().newIssue(this, expressionTree, ERROR_MESSAGE);
- }
-}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java
deleted file mode 100644
index 4af8d8d9e..000000000
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperations.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.stream.Collectors;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.ScriptTree;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.declaration.ClassDeclarationTree;
-import org.sonar.plugins.php.api.tree.declaration.ClassMemberTree;
-import org.sonar.plugins.php.api.tree.declaration.MethodDeclarationTree;
-import org.sonar.plugins.php.api.tree.expression.FunctionCallTree;
-import org.sonar.plugins.php.api.tree.statement.StatementTree;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = UseOfMethodsForBasicOperations.RULE_KEY,
- name = UseOfMethodsForBasicOperations.ERROR_MESSAGE,
- description = UseOfMethodsForBasicOperations.ERROR_MESSAGE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-php", ruleKey = "D2")
-public class UseOfMethodsForBasicOperations extends PHPSubscriptionCheck {
-
- public static final String RULE_KEY = "EC22";
- protected static final String ERROR_MESSAGE = "Use of methods for basic operations";
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(Tree.Kind.FUNCTION_CALL);
- }
-
- @Override
- public void visitNode(Tree tree) {
- AtomicBoolean contains = new AtomicBoolean(false);
-
- final FunctionCallTree functionTree = ((FunctionCallTree) tree);
- final String functionName = functionTree.callee().toString();
-
- final List parents = this.getAllParent(tree, new ArrayList<>());
-
- parents.forEach(parent -> {
- if (parent.is(Tree.Kind.SCRIPT)) {
-
- final ScriptTree specific = (ScriptTree) parent;
- final List trees = specific.statements();
-
- trees.forEach(statement -> {
-
- if (statement.is(Tree.Kind.CLASS_DECLARATION)) {
-
- final List methodDeclarations = ((ClassDeclarationTree) statement).members()
- .stream()
- .filter(member -> member.is(Tree.Kind.METHOD_DECLARATION))
- .map(MethodDeclarationTree.class::cast)
- .filter(declarationTree -> this.isFunctionDeclared(declarationTree, functionName))
- .collect(Collectors.toList());
-
- if (methodDeclarations != null && !methodDeclarations.isEmpty()) {
- contains.set(true);
- }
- }
- });
- }
- });
-
- if (!contains.get()) {
- context().newIssue(this, tree, ERROR_MESSAGE);
- }
- }
-
- public boolean isFunctionDeclared(final MethodDeclarationTree method, final String name) {
- if (method == null) {
- return false;
- }
-
- return method.name().text()
- .trim()
- .equals(name.trim());
- }
-
- public List getAllParent(final Tree tree, final List list) {
- if (tree == null)
- return list;
-
- final Tree parent = tree.getParent();
-
- if (parent == null)
- return list;
-
- list.add(parent);
-
- return this.getAllParent(parent, list);
- }
-}
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC22.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC22.html
deleted file mode 100644
index f5d6da36f..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC22.html
+++ /dev/null
@@ -1,9 +0,0 @@
-Use of methods for basic operations
-Noncompliant Code Example
-
- $min = min($a, $b); // Noncompliant
-
-Compliant Solution
-
- $min = ($a < $b) ? $a : $b;
-
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC34.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC34.html
deleted file mode 100644
index 5b8bd83c2..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC34.html
+++ /dev/null
@@ -1,109 +0,0 @@
-Inside complex code parts (for exemple multiple loops, complex data constructions...), avoid using try...catch...finally.
-When an exception is thrown, a variable (the exception itself) is created in a catch block and it's destruction consumes unnecessary CPU cycles and RAM. Prefer using logical tests in this cases.
-Noncompliant Code Example
-
-try
-{
- $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
-}
-catch(Exception $ex)
-{
- $msg = "Error opening $imgFile for Product $row['Identifier']";
- throw new Exception($msg);
-}
-
-
-Compliant Solution
-
-//try
-if (file_exists($imgFile)) {
- $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0);
-}
-
-//catch
-if (!$picture) {
- $msg = "Error opening $imgFile for Product $row['Identifier']";
- print $msg;
-}
-
-The three sources of impacts of a code identified are:
-- Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-Case for a 1GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC4.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC4.html
deleted file mode 100644
index 6e9687fa7..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC4.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
- Prefer local variables as parameters
-
-When calling a global variable, the interpretation engine must check that it exists in all the scopes, that it has a value, etc. Passing global variables as arguments gives them the status of local variables inside the function, thus saving computing time (CPU cycles).
-
-Noncompliant Code Example
-
- var aGlobal = new String('Hello');
-
- function globalLength(){
- length = aGlobal.length;
- console.log(length);
- }
-
- globalLength();
-
-Compliant Solution
-
- var aGlobal = new String('Hello');
-
- function someVarLength(str){
- length = str.length;
- console.log(length);
- }
-
- somVarLength(aGlobal);
-
\ No newline at end of file
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC66.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC66.html
deleted file mode 100644
index 5e06ebef7..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC66.html
+++ /dev/null
@@ -1,94 +0,0 @@
-PHP allows declaring a string with simple or double quotes. Using double quotes allows developers to insert variables which will be substituted during execution. When the string has no variables, using simple quotes avoid PHP to search inexisting variables. It will save CPU cycles consumption and RAM usage.
-Noncompliant Code Example
-
-myFunction("name", "age", "IsStudent");
- $lastName = "Hugo";
- $concatenatedString = "$lastName is a student";
-
-Compliant Solution
-
-myFunction('name', 'age', 'IsStudent');
- $lastName = 'Hugo';
- $concatenatedString = $lastName . 'is a student';
-
-The three sources of impacts of a code identified are:
-- Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-Case for a 1GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC67.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC67.html
deleted file mode 100644
index 6e087ebf4..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC67.html
+++ /dev/null
@@ -1,88 +0,0 @@
-The form $i++ creates a temporary variable whereas ++$i does not. It save CPU cycles.
-Noncompliant Code Example
-
-$i++
-
-Compliant Solution
-++$i
-The three sources of impacts of a code identified are:
-- Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-Case for a 1GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC69.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC69.html
deleted file mode 100644
index 655f6cab1..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC69.html
+++ /dev/null
@@ -1,104 +0,0 @@
-Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.
-Noncompliant Code Example
-
-for ($i = 0; $i <= foo(); $i++) { // Noncompliant
- // ......
-}
-
-Compliant Solution
-
-$maxI = foo();
-for ($i = 0; $i <= $maxI; $i++) {
- .....
-}
-
- OR
-
-for ($i = 0, $maxI = foo(); $i <= $maxI; $i++) {
- .....
-}
-}
-
-The three sources of impacts of a code identified are:
-- Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-
-Case for a 1GB database:
-
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC72.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC72.html
deleted file mode 100644
index 7973ec509..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC72.html
+++ /dev/null
@@ -1,349 +0,0 @@
-Executing SQL queries in loop induced unnecessary network transfert, calculation by the cpu and RAM usage.
-Noncompliant Code Example
-
- public function foo() {
- ...
- $baseQuery = "SELECT name FROM users where id = ";
-
- for ($i = 0; $i < 20; ++$i) {
-
- $query = $baseQuery . $i;
- $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
- mysql_select_db($dbname) or die("Could not open the db '$dbname'");
- $result = mysql_query($this->Query);// Noncompliant
-
- // iterate through the result
- ...
- mysql_close($connection);
- }
- ...
- }
-
-
-Compliant Solution
-
-
- public function foo() {
- ...
- $query = "SELECT name FROM users where id in (";
-
- for ($i = 0; $i < 20; ++$i) {
- $query .= ',' . $i;
- }
- $query .= ')';
-
- $connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
- mysql_select_db($dbname) or die("Could not open the db '$dbname'");
- $result = mysql_query($this->Query); // compliant
-
- // iterate through the result
- ...
- mysql_close($connection);
- }
-
-
-
- The three sources of impacts of a code identified are:
- - Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-
-Case for a 1GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Case for a 2GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Case for a 4GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Case for a 8GB database:
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC74.html b/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC74.html
deleted file mode 100644
index 3b1edba30..000000000
--- a/php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC74.html
+++ /dev/null
@@ -1,101 +0,0 @@
-Databases servers have to solve fields regarding the schema. Knowing and using the schema save CPU cycles and network transfer.
-Noncompliant Code Example
-
- public function foo() {
- ...
- $baseQuery = "SELECT * FROM users"; // Noncompliant
-
- ...
- }
-
-Compliant Solution
-
- public function foo() {
- ...
- $baseQuery = "SELECT id,name, adress FROM users ";
- ...
- }
-
-The three sources of impacts of a code identified are:
-- Energy (measured in joules)
- - Transfer (measured in Bytes)
- - Storage (measured in Bytes)
- The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
- The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
- The results generated by ETSdiff must help define the interest of the rule reported by Sonarqube in the context of the code analyzed.
-
-
-Case for a 1GB database:
-
-
-
-
-Total:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java
deleted file mode 100644
index 3c89dab5a..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
-import org.sonar.api.Plugin;
-import org.sonar.api.SonarEdition;
-import org.sonar.api.SonarQubeSide;
-import org.sonar.api.SonarRuntime;
-import org.sonar.api.internal.PluginContextImpl;
-import org.sonar.api.internal.SonarRuntimeImpl;
-import org.sonar.api.utils.Version;
-
-public class PhpPluginTest {
- @Test
- public void test() {
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 9), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
- Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(sonarRuntime).build();
- new PHPPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(1);
- }
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java
deleted file mode 100644
index f2345716d..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import org.assertj.core.api.SoftAssertions;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.rule.RulesDefinition;
-
-public class PhpRuleRepositoryTest {
-
- private PhpRuleRepository phpRuleRepository;
- private RulesDefinition.Context context;
-
- @Before
- public void init() {
- phpRuleRepository = new PhpRuleRepository();
- context = new RulesDefinition.Context();
- phpRuleRepository.define(context);
- }
-
- @Test
- public void test() {
- assertThat(phpRuleRepository.repositoryKey()).isEqualTo(PhpRuleRepository.REPOSITORY_KEY);
- assertThat(context.repositories()).hasSize(1).extracting("key").containsExactly(phpRuleRepository.repositoryKey());
- assertThat(context.repositories().get(0).rules()).hasSize(8);
- assertThat(phpRuleRepository.checkClasses()).hasSize(8);
- }
-
- /**
- * Check all rule keys must be prefixed by 'EC'
- */
- @Test()
- public void testRuleKeyPrefix() {
- RulesDefinition.Repository repository = context.repository(PhpRuleRepository.REPOSITORY_KEY);
- SoftAssertions assertions = new SoftAssertions();
- repository.rules().forEach(
- rule -> assertions.assertThat(rule.key()).startsWith("EC")
- );
- assertions.assertAll();
- }
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheckTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheckTest.java
deleted file mode 100644
index 1bd7f2ddb..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidDoubleQuoteCheckTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class AvoidDoubleQuoteCheckTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new AvoidDoubleQuoteCheck(), new PhpTestFile(new File("src/test/resources/checks/avoidDoubleQuote.php")));
- }
-
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheckTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheckTest.java
deleted file mode 100644
index de90bec78..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidFullSQLRequestCheckTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class AvoidFullSQLRequestCheckTest {
-
- @Test
- public void test() {
- PHPCheckTest.check(new AvoidFullSQLRequestCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidFullSQLRequest.php")));
- }
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheckTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheckTest.java
deleted file mode 100644
index e124b8547..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidSQLRequestInLoopCheckTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class AvoidSQLRequestInLoopCheckTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new AvoidSQLRequestInLoopCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidSQLRequestInLoop.php")));
- }
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheckNOKfailsAllTryStatementsTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheckNOKfailsAllTryStatementsTest.java
deleted file mode 100644
index 7a14288ce..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidTryCatchFinallyCheckNOKfailsAllTryStatementsTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class AvoidTryCatchFinallyCheckNOKfailsAllTryStatementsTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new AvoidTryCatchFinallyCheck_NOK_failsAllTryStatements(), new PhpTestFile(new File("src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php")));
- }
-
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheckTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheckTest.java
deleted file mode 100644
index 4b8bda378..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidUsingGlobalVariablesCheckTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SonarQube PHP Custom Rules Example
- * Copyright (C) 2016-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-/**
- * Test class to test the check implementation.
- */
-public class AvoidUsingGlobalVariablesCheckTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new AvoidUsingGlobalVariablesCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidUsingGlobalVariablesCheck.php")));
- }
-
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/IncrementCheckTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/IncrementCheckTest.java
deleted file mode 100644
index 777531563..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/IncrementCheckTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SonarQube PHP Custom Rules Example
- * Copyright (C) 2016-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-/**
- * Test class to test the check implementation.
- */
-public class IncrementCheckTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new IncrementCheck(), new PhpTestFile(new File("src/test/resources/checks/incrementCheck.php")));
- }
-
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoopTest.java
deleted file mode 100644
index 2f47ad768..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/NoFunctionCallWhenDeclaringForLoopTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class NoFunctionCallWhenDeclaringForLoopTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new NoFunctionCallWhenDeclaringForLoop(), new PhpTestFile(new File("src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.php")));
- }
-}
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperationsTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperationsTest.java
deleted file mode 100644
index ba878b1b6..000000000
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/UseOfMethodsForBasicOperationsTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package fr.greencodeinitiative.php.checks;
-
-import java.io.File;
-
-import org.junit.Test;
-import org.sonar.plugins.php.api.tests.PHPCheckTest;
-import org.sonar.plugins.php.api.tests.PhpTestFile;
-
-public class UseOfMethodsForBasicOperationsTest {
-
- @Test
- public void test() throws Exception {
- PHPCheckTest.check(new UseOfMethodsForBasicOperations(), new PhpTestFile(new File("src/test/resources/checks/useOfMethodsForBasicOperations.php")));
- }
-}
diff --git a/php-plugin/src/test/resources/checks/AvoidFullSQLRequest.php b/php-plugin/src/test/resources/checks/AvoidFullSQLRequest.php
deleted file mode 100644
index f32480b78..000000000
--- a/php-plugin/src/test/resources/checks/AvoidFullSQLRequest.php
+++ /dev/null
@@ -1,24 +0,0 @@
-SqlCall("SeLeCt * FrOm table"); // NOK {{Don't use the query SELECT * FROM}}
- OtherClass->SqlCall("SeLeCt DiStInCt * FrOm table"); // NOK {{Don't use the query SELECT * FROM}}
- OtherClass->SqlCall("SeLeCt name FrOm table");
- }
-
- public function PasseAsVariable()
- {
- $sqlQuery1 = "SeLeCt * FrOm table"; // NOK {{Don't use the query SELECT * FROM}}
- $sqlQuery2 = "SeLeCt DiStInCt * FrOm table"; // NOK {{Don't use the query SELECT * FROM}}
- $sqlQuery3 = "SeLeCt name FrOm table";
- OtherClass->SqlCall($sqlQuery1);
- OtherClass->SqlCall($sqlQuery2);
- }
-}
\ No newline at end of file
diff --git a/php-plugin/src/test/resources/checks/AvoidSQLRequestInLoop.php b/php-plugin/src/test/resources/checks/AvoidSQLRequestInLoop.php
deleted file mode 100644
index 8a1fb1293..000000000
--- a/php-plugin/src/test/resources/checks/AvoidSQLRequestInLoop.php
+++ /dev/null
@@ -1,74 +0,0 @@
-Init();
- $this->NoLoop();
- $this->ForLoop($expectedNbOfRequest, $someCondition);
- $this->ForEachLoop($arrayOfQuery, $someCondition);
- $this->WhileLoop($expectedNbOfRequest, $someCondition);
- }
- private function Init()
- {
- $this->Connection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
- mysql_select_db($dbname) or die("Could not open the db '$dbname'");
- }
-
- private function NoLoop()
- {
- $result = mysql_query($this->Query);
- // display result or work with it
- }
-
- private function ForLoop($expectedNbOfRequest, $someCondition)
- {
- for($index = 0; $expectedNbOfRequest > $index; ++$index){
- $result = mysql_query($this->Query); // NOK {{Avoid SQL request in loop}}
- // display result or work with it
- if($someCondition)
- {
- $result = mysql_query($OtherQuery); // NOK {{Avoid SQL request in loop}}
- $result = mysql_query($OtherQuery); // NOK {{Avoid SQL request in loop}}
- }
- }
- }
-
- private function ForEachLoop($arrayOfQuery, $someCondition)
- {
- foreach($arrayOfQuery as $query){
- $result = mysql_query($Query); // NOK {{Avoid SQL request in loop}}
- // display result or work with it
- if($someCondition)
- $result = mysql_query($OtherQuery); // NOK {{Avoid SQL request in loop}}
- }
- }
-
- private function WhileLoop($expectedNbOfRequest, $someCondition)
- {
- $nbOfRequest = 0;
- do{
- $result = mysql_query($this->Query); // NOK {{Avoid SQL request in loop}}
- // display result or work with it
- if($someCondition)
- $result = mysql_query($OtherQuery); // NOK {{Avoid SQL request in loop}}
- ++$nbOfRequest;
- }while($expectedNbOfRequest > $nbOfRequest);
- }
-
- private function EmptyLoop()
- {
- for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
- }
-}
\ No newline at end of file
diff --git a/php-plugin/src/test/resources/checks/AvoidUsingGlobalVariablesCheck.php b/php-plugin/src/test/resources/checks/AvoidUsingGlobalVariablesCheck.php
deleted file mode 100644
index 2f5d4eadb..000000000
--- a/php-plugin/src/test/resources/checks/AvoidUsingGlobalVariablesCheck.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
diff --git a/php-plugin/src/test/resources/checks/avoidDoubleQuote.php b/php-plugin/src/test/resources/checks/avoidDoubleQuote.php
deleted file mode 100644
index dd9b9da96..000000000
--- a/php-plugin/src/test/resources/checks/avoidDoubleQuote.php
+++ /dev/null
@@ -1,35 +0,0 @@
-';
- echo $age;
-
- $lastName = 'Hadrien';
- $age = 18;
-
- echo $lastName;
- echo " ";// NOK {{Avoid using double quote ("), prefer using simple quote (')}}
- echo $age;
-
- $identite = $lastName .' '. $name;
- echo $identite;
-
- myFunction($name, $age, $isStudent);
-
- myFunction("name", "age", "isStudent"); // NOK {{Avoid using double quote ("), prefer using simple quote (')}}
-
- myFunction('name', 'age', 'isStudent');
-
- myFunction("name", 'age', "isStudent"); // NOK {{Avoid using double quote ("), prefer using simple quote (')}}
-
-?>
\ No newline at end of file
diff --git a/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php b/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php
deleted file mode 100644
index 22a44564c..000000000
--- a/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
-getMessage()." catch in\n";
- throw $e;
-} finally {
- echo $e->getMessage()." finally \n";
- throw new \Exception("Bye");
-}
-
-//FAILS with this RULE
-/*try {
- throw new \Exception("Hello");
-} catch(\Exception $e) {
- echo $e->getMessage()." catch in\n";
- throw $e;
-}*/
-?>
diff --git a/php-plugin/src/test/resources/checks/incrementCheck.php b/php-plugin/src/test/resources/checks/incrementCheck.php
deleted file mode 100644
index 8aced9e59..000000000
--- a/php-plugin/src/test/resources/checks/incrementCheck.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
\ No newline at end of file
diff --git a/php-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.php b/php-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.php
deleted file mode 100644
index 6ecdf83a2..000000000
--- a/php-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.php
+++ /dev/null
@@ -1,49 +0,0 @@
-
- 10) {
- break;
- }
- echo $i;
-}
-
-/* exemple 3 */
-
-$i = 1;
-for (; ; ) {
- if ($i > 10) {
- break;
- }
- echo $i;
- $i++;
-}
-
-/* exemple 4 */
-
-for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++); // NOK {{Do not call a function in for-type loop declaration}}
-
-
-function somewhat_calcMax()
-{
- return 500;
-}
-
-
-for ($i = 0; $i <= somewhat_calcMax(); $i++) { // NOK {{Do not call a function in for-type loop declaration}}
- somewhat_doSomethingWith($i);
-}
-
-$maxI = somewhat_calcMax();
-for ($i = 0; $i <= $maxI; $i++) {
- somewhat_doSomethingWith($i);
-}
-
-?>
diff --git a/php-plugin/src/test/resources/checks/useOfMethodsForBasicOperations.php b/php-plugin/src/test/resources/checks/useOfMethodsForBasicOperations.php
deleted file mode 100644
index daf07b62a..000000000
--- a/php-plugin/src/test/resources/checks/useOfMethodsForBasicOperations.php
+++ /dev/null
@@ -1,18 +0,0 @@
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 83d26a01e..f30d9ec81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,11 +4,12 @@
io.ecocode
ecocode-parent
- 1.1.1-SNAPSHOT
+ 1.4.1-SNAPSHOT
pom
ecoCode Sonar Plugins Project
Provides rules to reduce the environmental footprint of your programs
+ 2023
https://github.com/green-code-initiative/ecocode
green-code-initiative
@@ -22,11 +23,64 @@
+
+
+
+ Gilles Grousset
+ zippy1978@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ Maxime Malgorn
+ utarwyn@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ Geoffrey LallouΓ©
+ glalloue@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ David DE CARVALHO
+ dedece35@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ Olivier Le GoaΓ«r
+ olegoaer@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ Julien Hertout
+ jhertout@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ Jules Delecour
+ jules-delecour-dav@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+ DUBOIS Maxime
+ mdubois81@users.noreply.github.com
+ green-code-initiative
+ https://github.com/green-code-initiative
+
+
+
- python-plugin
+ ecocode-rules-specifications
java-plugin
- javascript-plugin
- php-plugin
@@ -50,26 +104,20 @@
${encoding}
${encoding}
- 9.4.0.54424
- 7.15.0.30507
-
green-code-initiative
https://sonarcloud.io
-
- 0.8.8
+ 9.4.0.54424
+ 7.19.0.31550
+
+ 2.5.0.1358
- 9.7.1.62043
- 2.1.0.1111
- 3.19.0.10254
- 3.25.0.9077
- 9.13.0.20537
1.21.0.505
true
- 3.4.1
- 4.13.2
+
5.9.1
3.23.1
+ 5.3.1
1.7
@@ -92,12 +140,6 @@
${sonar-analyzer-commons.version}
-
- org.sonarsource.sonarqube
- sonar-plugin-api-impl
- ${sonar-plugin-api-impl.version}
-
-
com.google.re2j
@@ -114,33 +156,6 @@
provided
-
-
- org.sonarsource.javascript
- sonar-javascript-plugin
- ${sonarjavascript.version}
- sonar-plugin
- provided
-
-
-
-
- org.sonarsource.php
- sonar-php-plugin
- ${sonarphp.version}
- sonar-plugin
- provided
-
-
-
-
- org.sonarsource.python
- sonar-python-plugin
- ${sonar.python.version}
- sonar-plugin
- provided
-
-
org.sonarsource.java
@@ -156,13 +171,6 @@
test
-
- org.junit.jupiter
- junit-jupiter-migrationsupport
- ${junit.jupiter.version}
- test
-
-
org.assertj
assertj-core
@@ -171,16 +179,9 @@
- junit
- junit
- ${junit.version}
- test
-
-
-
- org.sonarsource.python
- python-checks-testkit
- ${sonar.python.version}
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito.version}
test
@@ -193,12 +194,12 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.10.1
+ 3.11.0
org.apache.maven.plugins
maven-dependency-plugin
- 3.3.0
+ 3.6.0
org.sonarsource.sonar-packaging-maven-plugin
@@ -208,14 +209,154 @@
org.apache.maven.plugins
maven-shade-plugin
- ${maven-shade-plugin.version}
+ 3.5.0
+
+
+
+ package
+
+ shade
+
+
+
+
+ commons-*:*
+
+ META-INF/**
+
+
+
+ org.*:*
+
+ META-INF/**
+ org/sonar/api/batch/sensor/**
+ javax/annotation/**
+
+
+
+ com.*:*
+
+ META-INF/**
+
+
+
+ junit:*
+
+ META-INF/**
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.2
org.jacoco
jacoco-maven-plugin
- ${jacoco.version}
+ 0.8.10
+
+
+ com.mycila
+ license-maven-plugin
+ 4.1
+
+
+ Green Code Initiative
+ https://www.ecocode.io
+
+
+
+ com/mycila/maven/plugin/license/templates/GPL-3.txt
+
+ **/*.java
+
+
+
+
+
+
+ validate
+
+ check
+
+ validate
+
+
+
+
+
+
+
+ maven-central-publishing
+
+
+
+
+ ossrh
+ https://s01.oss.sonatype.org/content/repositories/snapshots
+
+
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.6.13
+ true
+
+ ossrh
+ https://s01.oss.sonatype.org/
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 3.1.0
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+ --pinentry-mode
+ loopback
+
+
+
+
+
+
+
+
+
diff --git a/python-plugin/README.md b/python-plugin/README.md
deleted file mode 100644
index 4e77f52dc..000000000
--- a/python-plugin/README.md
+++ /dev/null
@@ -1 +0,0 @@
-https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/python-custom-rules
\ No newline at end of file
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
deleted file mode 100644
index bfef526ff..000000000
--- a/python-plugin/pom.xml
+++ /dev/null
@@ -1,157 +0,0 @@
-
-
- 4.0.0
-
-
- io.ecocode
- ecocode-parent
- 1.1.1-SNAPSHOT
-
-
- ecocode-python-plugin
- sonar-plugin
-
- ecoCode - Python language
- Provides rules to reduce the environmental footprint of your Python programs
- https://github.com/green-code-initiative/ecoCode/tree/main/python-plugin
-
-
-
-
- org.sonarsource.python
- sonar-python-plugin
- sonar-plugin
-
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api
-
-
- org.sonarsource.sonarqube
- sonar-plugin-api-impl
-
-
-
-
-
-
-
-
-
- org.sonarsource.python
- python-checks-testkit
- test
-
-
-
- junit
- junit
- test
-
-
-
-
-
-
-
- org.sonarsource.sonar-packaging-maven-plugin
- sonar-packaging-maven-plugin
- true
-
- ecocodepython
- ${project.name}
- fr.greencodeinitiative.python.PythonPlugin
- true
- python:${sonar.python.version}
- ${sonarqube.version}
- ${java.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-bundle
- package
-
- copy
-
-
-
-
- ${project.groupId}
- ${project.artifactId}
- ${project.version}
- jar
- true
-
-
- ../lib
-
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
-
-
- file
- false
-
-
-
- prepare-agent
-
- prepare-agent
-
-
-
- report
- test
-
- report
-
-
-
-
-
-
-
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonPlugin.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonPlugin.java
deleted file mode 100644
index 73678cb08..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonPlugin.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.python;
-
-import org.sonar.api.Plugin;
-
-public class PythonPlugin implements Plugin {
-
- @Override
- public void define(Context context) {
- context.addExtension(PythonRuleRepository.class);
- }
-
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
deleted file mode 100644
index 93de44ffb..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.python;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import fr.greencodeinitiative.python.checks.AvoidFullSQLRequest;
-import fr.greencodeinitiative.python.checks.AvoidGettersAndSetters;
-import fr.greencodeinitiative.python.checks.AvoidGlobalVariableInFunctionCheck;
-import fr.greencodeinitiative.python.checks.AvoidSQLRequestInLoop;
-import fr.greencodeinitiative.python.checks.AvoidTryCatchFinallyCheck;
-import fr.greencodeinitiative.python.checks.NoFunctionCallWhenDeclaringForLoop;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.rules.RuleType;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
-import org.sonar.plugins.python.api.PythonCustomRuleRepository;
-
-public class PythonRuleRepository implements RulesDefinition, PythonCustomRuleRepository {
-
- public static final String LANGUAGE = "py";
- public static final String NAME = "ecoCode";
- public static final String RESOURCE_BASE_PATH = "/fr/greencodeinitiative/l10n/python/rules/python/";
- public static final String REPOSITORY_KEY = "ecocode-python";
-
- @Override
- public void define(Context context) {
- NewRepository repository = context.createRepository(repositoryKey(), LANGUAGE).setName(NAME);
-
- new RulesDefinitionAnnotationLoader().load(repository, checkClasses().toArray(new Class[] {}));
-
- // technical debt
- Map remediationCosts = new HashMap<>();
- remediationCosts.put(AvoidSQLRequestInLoop.RULE_KEY, "10min");
- remediationCosts.put(AvoidFullSQLRequest.RULE_KEY, "20min");
- repository.rules().forEach(rule -> {
- rule.setType(RuleType.CODE_SMELL);
- String debt = remediationCosts.get(rule.key());
-
- // TODO DDC : create support to use org.apache.commons.lang.StringUtils
-// if (StringUtils.isBlank(debt)) {
- if (debt == null || debt.trim().equals("")) {
- // default debt to 5min for issue correction
- rule.setDebtRemediationFunction(
- rule.debtRemediationFunctions().constantPerIssue("5min"));
- } else {
- rule.setDebtRemediationFunction(
- rule.debtRemediationFunctions().constantPerIssue(debt));
- }
- });
-
- // HTML description
- repository.rules().forEach(rule ->
- rule.setHtmlDescription(loadResource(RESOURCE_BASE_PATH + rule.key() + ".html")));
-
- repository.done();
- }
-
- @Override
- public String repositoryKey() {
- return REPOSITORY_KEY;
- }
-
- @Override
- public List checkClasses() {
- return Arrays.asList(
- AvoidGettersAndSetters.class,
- AvoidGlobalVariableInFunctionCheck.class,
- AvoidSQLRequestInLoop.class,
- AvoidTryCatchFinallyCheck.class,
- NoFunctionCallWhenDeclaringForLoop.class,
- AvoidFullSQLRequest.class
- );
- }
-
- private String loadResource(String path) {
- URL resource = getClass().getResource(path);
- if (resource == null) {
- throw new IllegalStateException("Resource not found: " + path);
- }
- ByteArrayOutputStream result = new ByteArrayOutputStream();
- try (InputStream in = resource.openStream()) {
- byte[] buffer = new byte[1024];
- for (int len = in.read(buffer); len != -1; len = in.read(buffer)) {
- result.write(buffer, 0, len);
- }
- return new String(result.toByteArray(), StandardCharsets.UTF_8);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to read resource: " + path, e);
- }
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java
deleted file mode 100644
index 39e700245..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.tree.StringElement;
-import org.sonar.plugins.python.api.tree.StringLiteral;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidFullSQLRequest.RULE_KEY,
- name = AvoidFullSQLRequest.MESSAGERULE,
- description = AvoidFullSQLRequest.MESSAGERULE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S74")
-public class AvoidFullSQLRequest extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC74";
-
- protected static final String MESSAGERULE = "Don't use the query SELECT * FROM";
-
- // TODO DDC : create support to add in deployment th dependency com.google.re2j:re2j
- // and replace "import java.util.regex.Pattern" by "import com.google.re2j.Pattern"
- private static final Pattern PATTERN = Pattern.compile("(?i).*select.*\\*.*from.*");
- private static final Map> linesWithIssuesByFile = new HashMap<>();
-
-
- @Override
- public void initialize(Context context) {
- context.registerSyntaxNodeConsumer(Tree.Kind.STRING_LITERAL, this::visitNodeString);
- }
-
- public void visitNodeString(SubscriptionContext ctx) {
- StringLiteral stringLiteral = (StringLiteral) ctx.syntaxNode();
- stringLiteral.stringElements().forEach(stringElement -> checkIssue(stringElement, ctx));
- }
-
- public void checkIssue(StringElement stringElement, SubscriptionContext ctx) {
- if (lineAlreadyHasThisIssue(stringElement, ctx)) return;
- if (PATTERN.matcher(stringElement.value()).matches()) {
- repport(stringElement, ctx);
- }
- }
-
- private void repport(StringElement stringElement, SubscriptionContext ctx) {
- if (stringElement.firstToken() != null) {
- final String classname = ctx.pythonFile().fileName();
- final int line = stringElement.firstToken().line();
- linesWithIssuesByFile.computeIfAbsent(classname, k -> new ArrayList<>());
- linesWithIssuesByFile.get(classname).add(line);
- }
- ctx.addIssue(stringElement, MESSAGERULE);
- }
-
- private boolean lineAlreadyHasThisIssue(StringElement stringElement, SubscriptionContext ctx) {
- if (stringElement.firstToken() != null) {
- final String filename = ctx.pythonFile().fileName();
- final int line = stringElement.firstToken().line();
-
- return linesWithIssuesByFile.containsKey(filename)
- && linesWithIssuesByFile.get(filename).contains(line);
- }
-
- return false;
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java
deleted file mode 100644
index b3aeccde1..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSetters.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.tree.AnyParameter;
-import org.sonar.plugins.python.api.tree.AssignmentStatement;
-import org.sonar.plugins.python.api.tree.FunctionDef;
-import org.sonar.plugins.python.api.tree.ParameterList;
-import org.sonar.plugins.python.api.tree.QualifiedExpression;
-import org.sonar.plugins.python.api.tree.ReturnStatement;
-import org.sonar.plugins.python.api.tree.Statement;
-import org.sonar.plugins.python.api.tree.StatementList;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidGettersAndSetters.RULE_KEY,
- name = AvoidGettersAndSetters.DESCRIPTION,
- description = AvoidGettersAndSetters.DESCRIPTION,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D7")
-public class AvoidGettersAndSetters extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC7";
- public static final String DESCRIPTION = "Avoid creating getter and setter methods in classes";
-
- @Override
- public void initialize(Context context) {
- context.registerSyntaxNodeConsumer(Tree.Kind.FUNCDEF, ctx -> {
- FunctionDef functionDef = (FunctionDef) ctx.syntaxNode();
- StatementList statementList = functionDef.body();
- List statements = statementList.statements();
- if (functionDef.parent().parent().is(Tree.Kind.CLASSDEF)) {
- checkAllGetters(statements, functionDef, ctx);
- checkAllSetters(statements, functionDef, ctx);
- }
- });
- }
-
- public void checkAllSetters(List statements, FunctionDef functionDef, SubscriptionContext ctx) {
- if (statements.size() == 1 && statements.get(0).is(Tree.Kind.ASSIGNMENT_STMT)) {
- AssignmentStatement assignmentStatement = (AssignmentStatement) statements.get(0);
- if (checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot((QualifiedExpression) assignmentStatement.children().get(0).children().get(0))) {
- // Check if assignedValue is a parameter of the function
- ParameterList parameters = functionDef.parameters();
- if (parameters != null && !parameters.all().stream().filter(p -> checkAssignementFromParameter(assignmentStatement, p)).collect(Collectors.toList()).isEmpty()) {
- ctx.addIssue(functionDef.defKeyword(), AvoidGettersAndSetters.DESCRIPTION);
- }
- }
- }
- }
-
- public void checkAllGetters(List statements, FunctionDef functionDef, SubscriptionContext ctx) {
- Statement lastStatement = statements.get(statements.size() - 1);
- if (lastStatement.is(Tree.Kind.RETURN_STMT)) {
- List returnStatementChildren = ((ReturnStatement) lastStatement).children();
- if (returnStatementChildren.get(1).is(Tree.Kind.QUALIFIED_EXPR) &&
- checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot((QualifiedExpression) returnStatementChildren.get(1))) {
- ctx.addIssue(functionDef.defKeyword(), AvoidGettersAndSetters.DESCRIPTION);
- }
- }
- }
-
- public boolean checkAssignementFromParameter(AssignmentStatement assignmentStatement, AnyParameter parameter) {
- String parameterToString = parameter.firstToken().value();
- return assignmentStatement.assignedValue().firstToken().value().equalsIgnoreCase(parameterToString);
- }
-
- public boolean checkIfStatementIsQualifiedExpressionAndStartsWithSelfDot(QualifiedExpression qualifiedExpression) {
- List qualifedExpressionChildren = qualifiedExpression.children();
- return qualifedExpressionChildren.size() == 3 &&
- qualifedExpressionChildren.get(0).firstToken().value().equalsIgnoreCase("self") &&
- qualifedExpressionChildren.get(1).firstToken().value().equalsIgnoreCase(".");
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java
deleted file mode 100644
index ef712ec35..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheck.java
+++ /dev/null
@@ -1,327 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.symbols.Symbol;
-import org.sonar.plugins.python.api.tree.AnnotatedAssignment;
-import org.sonar.plugins.python.api.tree.ArgList;
-import org.sonar.plugins.python.api.tree.AssertStatement;
-import org.sonar.plugins.python.api.tree.AssignmentExpression;
-import org.sonar.plugins.python.api.tree.AssignmentStatement;
-import org.sonar.plugins.python.api.tree.AwaitExpression;
-import org.sonar.plugins.python.api.tree.BinaryExpression;
-import org.sonar.plugins.python.api.tree.CallExpression;
-import org.sonar.plugins.python.api.tree.CompoundAssignmentStatement;
-import org.sonar.plugins.python.api.tree.ComprehensionExpression;
-import org.sonar.plugins.python.api.tree.ComprehensionFor;
-import org.sonar.plugins.python.api.tree.ComprehensionIf;
-import org.sonar.plugins.python.api.tree.ConditionalExpression;
-import org.sonar.plugins.python.api.tree.DictCompExpression;
-import org.sonar.plugins.python.api.tree.DictionaryLiteral;
-import org.sonar.plugins.python.api.tree.ElseClause;
-import org.sonar.plugins.python.api.tree.ExceptClause;
-import org.sonar.plugins.python.api.tree.ExecStatement;
-import org.sonar.plugins.python.api.tree.ExpressionList;
-import org.sonar.plugins.python.api.tree.ExpressionStatement;
-import org.sonar.plugins.python.api.tree.FileInput;
-import org.sonar.plugins.python.api.tree.FinallyClause;
-import org.sonar.plugins.python.api.tree.ForStatement;
-import org.sonar.plugins.python.api.tree.FunctionDef;
-import org.sonar.plugins.python.api.tree.IfStatement;
-import org.sonar.plugins.python.api.tree.KeyValuePair;
-import org.sonar.plugins.python.api.tree.LambdaExpression;
-import org.sonar.plugins.python.api.tree.ListLiteral;
-import org.sonar.plugins.python.api.tree.Name;
-import org.sonar.plugins.python.api.tree.Parameter;
-import org.sonar.plugins.python.api.tree.ParameterList;
-import org.sonar.plugins.python.api.tree.ParenthesizedExpression;
-import org.sonar.plugins.python.api.tree.PrintStatement;
-import org.sonar.plugins.python.api.tree.RaiseStatement;
-import org.sonar.plugins.python.api.tree.RegularArgument;
-import org.sonar.plugins.python.api.tree.ReprExpression;
-import org.sonar.plugins.python.api.tree.ReturnStatement;
-import org.sonar.plugins.python.api.tree.SetLiteral;
-import org.sonar.plugins.python.api.tree.StatementList;
-import org.sonar.plugins.python.api.tree.SubscriptionExpression;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonar.plugins.python.api.tree.TryStatement;
-import org.sonar.plugins.python.api.tree.Tuple;
-import org.sonar.plugins.python.api.tree.TupleParameter;
-import org.sonar.plugins.python.api.tree.UnaryExpression;
-import org.sonar.plugins.python.api.tree.UnpackingExpression;
-import org.sonar.plugins.python.api.tree.WhileStatement;
-import org.sonar.plugins.python.api.tree.YieldExpression;
-import org.sonar.plugins.python.api.tree.YieldStatement;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidGlobalVariableInFunctionCheck.RULE_KEY,
- name = "Do not call global variables directly inside functions",
- description = AvoidGlobalVariableInFunctionCheck.DESCRIPTION,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "D4")
-public class AvoidGlobalVariableInFunctionCheck extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC4";
- public static final String DESCRIPTION = "Use local variable (function/class scope) instead of global variable (application scope)";
-
- private List globalVariables;
- private List definedLocalVariables;
- private Map usedLocalVariables;
-
- @Override
- public void initialize(SubscriptionCheck.Context context) {
- globalVariables = new ArrayList<>();
- context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, this::visitFileInput);
- context.registerSyntaxNodeConsumer(Tree.Kind.FUNCDEF, this::visitFuncDef);
- }
-
- public void visitFileInput(SubscriptionContext ctx) {
- FileInput fileInput = (FileInput) ctx.syntaxNode();
- fileInput.globalVariables().stream().filter(v -> v.is(Symbol.Kind.OTHER)).forEach(v -> this.globalVariables.add(v.name()));
- }
-
- void visitFuncDef(SubscriptionContext ctx) {
- this.definedLocalVariables = new ArrayList<>();
- this.usedLocalVariables = new HashMap<>();
-
- FunctionDef functionDef = (FunctionDef) ctx.syntaxNode();
-
- ParameterList parameterList = functionDef.parameters();
- if (parameterList != null) {
- parameterList.nonTuple().forEach(p -> extractVariablesFromExpression(p, true));
- }
-
- functionDef.body().statements()
- .forEach(s -> extractVariablesFromExpression(s, false));
-
- this.usedLocalVariables.entrySet().stream()
- .filter(e -> !this.definedLocalVariables.contains(e.getValue()) && this.globalVariables.contains(e.getValue()))
- .forEach(e -> ctx.addIssue(e.getKey(), DESCRIPTION));
- }
-
- void extractVariablesFromExpression(Tree element, boolean isAssigned) {
- if (element == null) {
- return;
- }
-
- switch (element.getKind()) {
- case REGULAR_ARGUMENT:
- extractVariablesFromExpression(((RegularArgument) element).expression(), isAssigned);
- break;
- case ARG_LIST:
- ((ArgList) element).arguments().forEach(a -> extractVariablesFromExpression(a, isAssigned));
- break;
- case ANNOTATED_ASSIGNMENT:
- AnnotatedAssignment annotatedAssignment = (AnnotatedAssignment) element;
- extractVariablesFromExpression(annotatedAssignment.variable(), true);
- extractVariablesFromExpression(annotatedAssignment.assignedValue(), false);
- break;
- case ASSERT_STMT:
- AssertStatement assertStatement = (AssertStatement) element;
- extractVariablesFromExpression(assertStatement.condition(), false);
- extractVariablesFromExpression(assertStatement.message(), false);
- break;
- case ASSIGNMENT_STMT:
- AssignmentStatement assignmentStatement = (AssignmentStatement) element;
- assignmentStatement.lhsExpressions().forEach(e -> extractVariablesFromExpression(e, true));
- extractVariablesFromExpression(assignmentStatement.assignedValue(), false);
- break;
- case CALL_EXPR:
- extractVariablesFromExpression(((CallExpression) element).argumentList(), isAssigned);
- break;
- case CONDITIONAL_EXPR:
- ConditionalExpression conditionalExpression = (ConditionalExpression) element;
- extractVariablesFromExpression(conditionalExpression.trueExpression(), isAssigned);
- extractVariablesFromExpression(conditionalExpression.falseExpression(), false);
- extractVariablesFromExpression(conditionalExpression.condition(), isAssigned);
- break;
- case COMPOUND_ASSIGNMENT:
- CompoundAssignmentStatement compoundAssignmentStatement = (CompoundAssignmentStatement) element;
- extractVariablesFromExpression(compoundAssignmentStatement.lhsExpression(), true);
- extractVariablesFromExpression(compoundAssignmentStatement.rhsExpression(), false);
- break;
- case DICTIONARY_LITERAL:
- ((DictionaryLiteral) element).elements().forEach(e -> extractVariablesFromExpression(e, false));
- break;
- case ELSE_CLAUSE:
- extractVariablesFromExpression(((ElseClause) element).body(), isAssigned);
- break;
- case EXCEPT_CLAUSE:
- extractVariablesFromExpression(((ExceptClause) element).body(), isAssigned);
- break;
- case EXEC_STMT:
- ExecStatement execStatement = (ExecStatement) element;
- extractVariablesFromExpression(execStatement.expression(), isAssigned);
- extractVariablesFromExpression(execStatement.globalsExpression(), isAssigned);
- extractVariablesFromExpression(execStatement.localsExpression(), isAssigned);
- break;
- case EXPRESSION_LIST:
- ((ExpressionList) element).expressions().forEach(e -> extractVariablesFromExpression(e, isAssigned));
- break;
- case EXPRESSION_STMT:
- ((ExpressionStatement) element).expressions().forEach(e -> extractVariablesFromExpression(e, isAssigned));
- break;
- case FILE_INPUT:
- extractVariablesFromExpression(((FileInput) element).statements(), isAssigned);
- break;
- case FINALLY_CLAUSE:
- extractVariablesFromExpression(((FinallyClause) element).body(), isAssigned);
- break;
- case FOR_STMT:
- ForStatement forStatement = ((ForStatement) element);
- forStatement.expressions().forEach(e -> extractVariablesFromExpression(e, true));
- forStatement.testExpressions().forEach(e -> extractVariablesFromExpression(e, false));
- extractVariablesFromExpression(forStatement.body(), isAssigned);
- extractVariablesFromExpression(forStatement.elseClause(), isAssigned);
- break;
- case IF_STMT:
- IfStatement ifStatement = (IfStatement) element;
- extractVariablesFromExpression(ifStatement.condition(), false);
- extractVariablesFromExpression(ifStatement.body(), isAssigned);
- extractVariablesFromExpression(ifStatement.elseBranch(), isAssigned);
- ifStatement.elifBranches().forEach(b -> extractVariablesFromExpression(b, isAssigned));
- break;
- case LAMBDA:
- extractVariablesFromExpression(((LambdaExpression) element).expression(), isAssigned);
- break;
- case LIST_LITERAL:
- extractVariablesFromExpression(((ListLiteral) element).elements(), false);
- break;
- case NAME:
- if (isAssigned) {
- this.definedLocalVariables.add(((Name) element).name());
- } else {
- this.usedLocalVariables.put(element, ((Name) element).name());
- }
- break;
- case PRINT_STMT:
- ((PrintStatement) element).expressions().forEach(e -> extractVariablesFromExpression(e, false));
- break;
- case RAISE_STMT:
- RaiseStatement raiseStatement = (RaiseStatement) element;
- extractVariablesFromExpression(raiseStatement.fromExpression(), false);
- raiseStatement.expressions().forEach(e -> extractVariablesFromExpression(e, false));
- break;
- case REPR:
- extractVariablesFromExpression(((ReprExpression) element).expressionList(), isAssigned);
- break;
- case RETURN_STMT:
- ((ReturnStatement) element).expressions().forEach(e -> extractVariablesFromExpression(e, false));
- break;
- case SET_LITERAL:
- ((SetLiteral) element).elements().forEach(e -> extractVariablesFromExpression(e, false));
- break;
- case STATEMENT_LIST:
- ((StatementList) element).statements().forEach(s -> extractVariablesFromExpression(s, isAssigned));
- break;
- case TRY_STMT:
- TryStatement tryStatement = (TryStatement) element;
- extractVariablesFromExpression(tryStatement.body(), isAssigned);
- tryStatement.exceptClauses().forEach(c -> extractVariablesFromExpression(c, isAssigned));
- extractVariablesFromExpression(tryStatement.elseClause(), isAssigned);
- extractVariablesFromExpression(tryStatement.finallyClause(), isAssigned);
- break;
- case PARAMETER:
- Parameter parameter = (Parameter) element;
- extractVariablesFromExpression(parameter.name(), true);
- extractVariablesFromExpression(parameter.defaultValue(), false);
- break;
- case TUPLE_PARAMETER:
- ((TupleParameter) element).parameters().forEach(p -> extractVariablesFromExpression(p, isAssigned));
- break;
- case PARAMETER_LIST:
- ((ParameterList) element).all().forEach(a -> extractVariablesFromExpression(a, true));
- break;
- case WHILE_STMT:
- WhileStatement whileStatement = (WhileStatement) element;
- extractVariablesFromExpression(whileStatement.condition(), false);
- extractVariablesFromExpression(whileStatement.body(), isAssigned);
- extractVariablesFromExpression(whileStatement.elseClause(), isAssigned);
- break;
- case YIELD_EXPR:
- ((YieldExpression) element).expressions().forEach(e -> extractVariablesFromExpression(e, isAssigned));
- break;
- case YIELD_STMT:
- extractVariablesFromExpression(((YieldStatement) element).yieldExpression(), isAssigned);
- break;
- case PARENTHESIZED:
- extractVariablesFromExpression(((ParenthesizedExpression) element).expression(), isAssigned);
- break;
- case UNPACKING_EXPR:
- extractVariablesFromExpression(((UnpackingExpression) element).expression(), isAssigned);
- break;
- case AWAIT:
- extractVariablesFromExpression(((AwaitExpression) element).expression(), false);
- break;
- case TUPLE:
- ((Tuple) element).elements().forEach(e -> extractVariablesFromExpression(e, isAssigned));
- break;
- case DICT_COMPREHENSION:
- extractVariablesFromExpression(((DictCompExpression) element).comprehensionFor(), false);
- break;
- case LIST_COMPREHENSION:
- case SET_COMPREHENSION:
- case GENERATOR_EXPR:
- extractVariablesFromExpression(((ComprehensionExpression) element).resultExpression(), false);
- extractVariablesFromExpression(((ComprehensionExpression) element).comprehensionFor(), true);
- break;
- case COMP_FOR:
- extractVariablesFromExpression(((ComprehensionFor) element).loopExpression(), true);
- extractVariablesFromExpression(((ComprehensionFor) element).iterable(), false);
- break;
- case COMP_IF:
- extractVariablesFromExpression(((ComprehensionIf) element).condition(), false);
- break;
- case SUBSCRIPTION:
- extractVariablesFromExpression(((SubscriptionExpression) element).object(), false);
- extractVariablesFromExpression(((SubscriptionExpression) element).subscripts(), false);
- break;
- case PLUS:
- case MINUS:
- case MULTIPLICATION:
- case DIVISION:
- case FLOOR_DIVISION:
- case MODULO:
- case MATRIX_MULTIPLICATION:
- case SHIFT_EXPR:
- case BITWISE_AND:
- case BITWISE_OR:
- case BITWISE_XOR:
- case AND:
- case OR:
- case COMPARISON:
- case POWER:
- BinaryExpression binaryExpression = (BinaryExpression) element;
- extractVariablesFromExpression(binaryExpression.leftOperand(), false);
- extractVariablesFromExpression(binaryExpression.rightOperand(), false);
- break;
- case UNARY_PLUS:
- case UNARY_MINUS:
- case BITWISE_COMPLEMENT:
- case NOT:
- extractVariablesFromExpression(((UnaryExpression) element).expression(), false);
- break;
- case ASSIGNMENT_EXPRESSION:
- AssignmentExpression assignmentExpression = (AssignmentExpression) element;
- extractVariablesFromExpression(assignmentExpression.lhsName(), true);
- extractVariablesFromExpression(assignmentExpression.expression(), false);
- break;
- case KEY_VALUE_PAIR:
- KeyValuePair keyValuePair = (KeyValuePair) element;
- extractVariablesFromExpression(keyValuePair.key(), true);
- extractVariablesFromExpression(keyValuePair.value(), false);
- break;
- default:
- }
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java
deleted file mode 100644
index 97877cf22..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoop.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.symbols.Symbol;
-import org.sonar.plugins.python.api.tree.AliasedName;
-import org.sonar.plugins.python.api.tree.BaseTreeVisitor;
-import org.sonar.plugins.python.api.tree.CallExpression;
-import org.sonar.plugins.python.api.tree.FileInput;
-import org.sonar.plugins.python.api.tree.Name;
-import org.sonar.plugins.python.api.tree.QualifiedExpression;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidSQLRequestInLoop.RULE_KEY,
- name = "Avoid SQL request in loop",
- description = AvoidSQLRequestInLoop.MESSAGE_RULE,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S72")
-public class AvoidSQLRequestInLoop extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC72";
-
- // TODO: Handle ORM lib
- private static final List SQL_LIBS = Arrays.asList("cx_Oracle", "mysql.connector", "psycopg2", "pymssql", "pyodbc", "sqlite3");
-
- protected static final String MESSAGE_RULE = "Avoid performing SQL queries within a loop";
-
- private boolean isUsingSqlLib = false;
-
- @Override
- public void initialize(Context context) {
- context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, this::visitFile);
- context.registerSyntaxNodeConsumer(Tree.Kind.CALL_EXPR, this::checkCallExpression);
- }
-
- private void visitFile(SubscriptionContext ctx) {
- FileInput tree = (FileInput) ctx.syntaxNode();
- SymbolsFromImport visitor = new SymbolsFromImport();
- tree.accept(visitor);
- visitor.symbols.stream()
- .filter(Objects::nonNull)
- .map(Symbol::fullyQualifiedName)
- .filter(Objects::nonNull)
- .forEach(qualifiedName -> {
- if (SQL_LIBS.contains(qualifiedName)) {
- isUsingSqlLib = true;
- }
- });
- }
-
- private static class SymbolsFromImport extends BaseTreeVisitor {
- private final Set symbols = new HashSet<>();
-
- @Override
- public void visitAliasedName(AliasedName aliasedName) {
- List names = aliasedName.dottedName().names();
- symbols.add(names.get(names.size() - 1).symbol());
- }
- }
-
- private void checkCallExpression(SubscriptionContext context) {
- CallExpression expression = (CallExpression) context.syntaxNode();
-
- if (expression.callee().is(Tree.Kind.QUALIFIED_EXPR)) {
- String name = ((QualifiedExpression) expression.callee()).name().name();
- if (isUsingSqlLib && "execute".equals(name) && hasLoopParent(expression)) {
- context.addIssue(expression, AvoidSQLRequestInLoop.MESSAGE_RULE);
- }
- }
- }
-
- private boolean hasLoopParent(Tree tree) {
- for (Tree parent = tree.parent(); parent != null; parent = parent.parent()) {
- Tree.Kind kind = parent.getKind();
- if (kind == Tree.Kind.FOR_STMT || kind == Tree.Kind.WHILE_STMT) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java
deleted file mode 100644
index 2d70e97f3..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonar.plugins.python.api.tree.TryStatement;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = AvoidTryCatchFinallyCheck.RULE_KEY,
- name = "Avoid using try-catch-finally statement",
- description = AvoidTryCatchFinallyCheck.DESCRIPTION,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S34")
-public class AvoidTryCatchFinallyCheck extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC34";
- public static final String DESCRIPTION = "Avoid the use of try-catch";
-
- @Override
- public void initialize(Context context) {
- context.registerSyntaxNodeConsumer(Tree.Kind.TRY_STMT, this::visitNode);
- }
-
- public void visitNode(SubscriptionContext ctx) {
- TryStatement tryStatement = (TryStatement) ctx.syntaxNode();
- ctx.addIssue(tryStatement.tryKeyword(), DESCRIPTION);
-
- }
-
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java
deleted file mode 100644
index 906a43253..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.sonar.check.Priority;
-import org.sonar.check.Rule;
-import org.sonar.plugins.python.api.PythonSubscriptionCheck;
-import org.sonar.plugins.python.api.tree.CallExpression;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
-@Rule(
- key = NoFunctionCallWhenDeclaringForLoop.RULE_KEY,
- name = NoFunctionCallWhenDeclaringForLoop.DESCRIPTION,
- description = NoFunctionCallWhenDeclaringForLoop.DESCRIPTION,
- priority = Priority.MINOR,
- tags = {"bug", "eco-design", "ecocode"})
-@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S69")
-public class NoFunctionCallWhenDeclaringForLoop extends PythonSubscriptionCheck {
-
- public static final String RULE_KEY = "EC69";
- public static final String DESCRIPTION = "Do not call a function when declaring a for-type loop";
-
- @Override
- public void initialize(Context context) {
- context.registerSyntaxNodeConsumer(Tree.Kind.CALL_EXPR, ctx -> {
- CallExpression callExpression = (CallExpression) ctx.syntaxNode();
- if (callExpression.parent().getKind() == Tree.Kind.FOR_STMT) {
- ctx.addIssue(callExpression, NoFunctionCallWhenDeclaringForLoop.DESCRIPTION);
- }
- });
- }
-}
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/package-info.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/package-info.java
deleted file mode 100644
index 63be179f7..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package fr.greencodeinitiative.python.checks;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/package-info.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/package-info.java
deleted file mode 100644
index 58299e2f7..000000000
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-@ParametersAreNonnullByDefault
-package fr.greencodeinitiative.python;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC34.html b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC34.html
deleted file mode 100644
index e72e14b5b..000000000
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC34.html
+++ /dev/null
@@ -1,21 +0,0 @@
-Inside complex code parts (for exemple multiple loops, complex data constructions...), avoid using try...catch...finally.
-
When an exception is thrown, a variable (the exception itself) is created in a catch block and it's destruction consumes unnecessary CPU cycles and RAM. Prefer using logical tests in this cases.
-
-Noncompliant Code Example
-
-try:
- f = open(path)
- print(fh.read())
-except:
- print('No such file '+path
-finally:
- f.close()
-
-
-Compliant Solution
-
-if os.path.isfile(path):
- fh = open(path, 'r')
- print(fh.read())
- fh.close
-
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC69.html b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC69.html
deleted file mode 100644
index 6d2b10475..000000000
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC69.html
+++ /dev/null
@@ -1,13 +0,0 @@
-Do not call a function when declaring a for-type loop in order to avoid function calls each iterations. It saves CPU cycles.
-Noncompliant Code Example
-
-for i in my_function(): # Noncompliant
- ......
-
-
-Compliant Solution
-
-limit = my_function()
-for i in limit:
- ......
-
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC72.html b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC72.html
deleted file mode 100644
index 837f0493d..000000000
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC72.html
+++ /dev/null
@@ -1,21 +0,0 @@
-Executing SQL queries in loop induced unnecessary calculation by the cpu, RAM usage and network transfert.
-Noncompliant Code Example
-
- def foo():
- ...
- results = []
- for id in range(20):
- results.append(cursor.execute("SELECT name FROM users where id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
- ...
-
-Compliant Solution
-
-
- def foo():
- ...
- ids = range(20)
- results = cursor.execute("SELECT name FROM users where id IN ({0})".format(', '.join("?" * len(ids))), ids).fetchmany() # Compliant
- ...
- }
-
-
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC74.html b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC74.html
deleted file mode 100644
index 8d977de29..000000000
--- a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC74.html
+++ /dev/null
@@ -1,21 +0,0 @@
-Databases servers have to solves fileds regarding to schema. Knowing and using the schema save CPU cycles and network transfer.
-Noncompliant Code Example
-
- public void foo() {
- ...
- String baseQuery = "SELECT * FROM users"; // Noncompliant
-
- ...
- }
-
-
-Compliant Solution
-
-
- public void foo() {
- ...
- String query = "SELECT id,name, adress FROM users ";
- ...
- }
-
-
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java
deleted file mode 100644
index 03c88941b..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.python;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
-import org.sonar.api.Plugin;
-import org.sonar.api.SonarEdition;
-import org.sonar.api.SonarQubeSide;
-import org.sonar.api.SonarRuntime;
-import org.sonar.api.internal.PluginContextImpl;
-import org.sonar.api.internal.SonarRuntimeImpl;
-import org.sonar.api.utils.Version;
-
-public class PythonPluginTest {
- @Test
- public void test() {
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 9), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
- Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(sonarRuntime).build();
- new PythonPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(1);
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonRuleRepositoryTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonRuleRepositoryTest.java
deleted file mode 100644
index 101ff2841..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonRuleRepositoryTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SonarQube Python Plugin
- * Copyright (C) 2012-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package fr.greencodeinitiative.python;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.assertj.core.api.SoftAssertions;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.rule.RulesDefinition;
-
-public class PythonRuleRepositoryTest {
-
- private PythonRuleRepository pythonRuleRepository;
- private RulesDefinition.Context context;
- private RulesDefinition.Repository repository;
-
- @Before
- public void init() {
- pythonRuleRepository = new PythonRuleRepository();
- context = new RulesDefinition.Context();
- pythonRuleRepository.define(context);
- repository = context.repository(PythonRuleRepository.REPOSITORY_KEY);
- }
-
- @Test
- public void test() {
- assertThat(pythonRuleRepository.repositoryKey()).isEqualTo(PythonRuleRepository.REPOSITORY_KEY);
- assertThat(context.repositories()).hasSize(1).extracting("key").containsExactly(pythonRuleRepository.repositoryKey());
- assertThat(context.repositories().get(0).rules()).hasSize(6);
- assertThat(pythonRuleRepository.checkClasses()).hasSize(6);
- }
-
-
- /**
- * Check all rule keys must be prefixed by 'EC'
- */
- @Test
- public void testRuleKeyPrefix() {
- SoftAssertions assertions = new SoftAssertions();
- repository.rules().forEach(
- rule -> assertions.assertThat(rule.key()).startsWith("EC")
- );
- assertions.assertAll();
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequestTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequestTest.java
deleted file mode 100644
index e03a71fa2..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidFullSQLRequestTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class AvoidFullSQLRequestTest {
-
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/avoidFullSQLRequest.py", new AvoidFullSQLRequest());
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java
deleted file mode 100644
index 26d7b4db3..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class AvoidGettersAndSettersTest {
-
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/avoidGettersAndSetters.py", new AvoidGettersAndSetters());
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheckTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheckTest.java
deleted file mode 100644
index c58ed4bc8..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidGlobalVariableInFunctionCheckTest.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class AvoidGlobalVariableInFunctionCheckTest {
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/avoidGlobalVariableInFunction.py", new AvoidGlobalVariableInFunctionCheck());
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoopTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoopTest.java
deleted file mode 100644
index a982bf0ef..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidSQLRequestInLoopTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class AvoidSQLRequestInLoopTest {
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/avoidSQLRequestInLoop.py", new AvoidSQLRequestInLoop());
- PythonCheckVerifier.verifyNoIssue("src/test/resources/checks/avoidSQLRequestInLoopNoImports.py", new AvoidSQLRequestInLoop());
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheckTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheckTest.java
deleted file mode 100644
index 03450d068..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheckTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class AvoidTryCatchFinallyCheckTest {
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/avoidTryCatchFinallyCheck.py", new AvoidTryCatchFinallyCheck());
- }
-}
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoopTest.java
deleted file mode 100644
index 77b1feb31..000000000
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/checks/NoFunctionCallWhenDeclaringForLoopTest.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package fr.greencodeinitiative.python.checks;
-
-import org.junit.Test;
-import org.sonar.python.checks.utils.PythonCheckVerifier;
-
-public class NoFunctionCallWhenDeclaringForLoopTest {
- @Test
- public void test() {
- PythonCheckVerifier.verify("src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.py", new NoFunctionCallWhenDeclaringForLoop());
- }
-}
diff --git a/python-plugin/src/test/resources/checks/avoidFullSQLRequest.py b/python-plugin/src/test/resources/checks/avoidFullSQLRequest.py
deleted file mode 100644
index 217cb6c9a..000000000
--- a/python-plugin/src/test/resources/checks/avoidFullSQLRequest.py
+++ /dev/null
@@ -1,12 +0,0 @@
-def displayMessage(argument1):
- print(argument)
-
-displayMessage(' sElEcT * fRoM myTable') # Noncompliant {{Don't use the query SELECT * FROM}}
-displayMessage(' sElEcT user fRoM myTable')
-
-requestNonCompiliant = ' SeLeCt * FrOm myTable' # Noncompliant {{Don't use the query SELECT * FROM}}
-requestCompiliant = ' SeLeCt user FrOm myTable'
-displayMessage(requestNonCompiliant)
-displayMessage(requestCompiliant)
-
-
diff --git a/python-plugin/src/test/resources/checks/avoidGettersAndSetters.py b/python-plugin/src/test/resources/checks/avoidGettersAndSetters.py
deleted file mode 100644
index fd72053ad..000000000
--- a/python-plugin/src/test/resources/checks/avoidGettersAndSetters.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from datetime import date
-
-class Client():
-
- def __init__(self, age, weight):
- self.age = age
- self.weight = weight
-
- def set_age(self, age): # Noncompliant {{Avoid creating getter and setter methods in classes}}
- self.age = age
-
- def set_age(self, age2): # Noncompliant {{Avoid creating getter and setter methods in classes}}
- self.age = age2
-
- def get_age_in_five_years(self):
- a = Client()
- return a.age
-
- def get_age(self): # Noncompliant {{Avoid creating getter and setter methods in classes}}
- return self.age
-
- def is_major(self):
- return self.age >= 18
-
- def get_weight(self): # Noncompliant {{Avoid creating getter and setter methods in classes}}
- return self.weight
\ No newline at end of file
diff --git a/python-plugin/src/test/resources/checks/avoidGlobalVariableInFunction.py b/python-plugin/src/test/resources/checks/avoidGlobalVariableInFunction.py
deleted file mode 100644
index 9b77dfa72..000000000
--- a/python-plugin/src/test/resources/checks/avoidGlobalVariableInFunction.py
+++ /dev/null
@@ -1,43 +0,0 @@
-global_var = 'global'
-
-def print_global_var_details():
- print(len(global_var)) # Noncompliant
- print('Global var : ', global_var) # Noncompliant
- print('Global var : ' + global_var) # Noncompliant
- for c in global_var: # Noncompliant
- print(c)
- if len(global_var) > 0: # Noncompliant
- print('global_var len positive')
- elif 0 < len(global_var): # Noncompliant
- print('global_var len negative')
- else:
- print('global_var len = 0')
-
- try:
- print(global_var) # Noncompliant
- except:
- print(global_var) # Noncompliant
- else:
- print(global_var) # Noncompliant
- finally:
- print(global_var) # Noncompliant
-
- assert len(global_var) > 0, 'Failed' # Noncompliant
- assert len('test') > 0, 'Failed : ' + global_var # Noncompliant
- test = ''
- test += global_var # Noncompliant
- test = {'test': global_var, 'global_var': 1 } # Noncompliant
-
-# Compliant
-def print_var_length(local_var = global_var):
- global_var = 'local' # Here it create a local var and do not use the global var
- global_var: str = 'local' # Here it create a local var and do not use the global var
- global_var += 'local' # Here it create a local var and do not use the global var
- global_var = 'local' if True else 'global' # Here it create a local var and do not use the global var
- print(len(global_var)) # Compliant for the use, but not for the name of the var
- print(len(local_var))
- for global_var in local_var: # Compliant but not for the name
- print(global_var)
-
-print_global_var_details()
-print_var_length(global_var)
diff --git a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoop.py b/python-plugin/src/test/resources/checks/avoidSQLRequestInLoop.py
deleted file mode 100644
index 394088199..000000000
--- a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoop.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import mysql.connector
-import psycopg2
-import pyodbc
-import sqlite3
-
-def mysql_loop():
- connection = mysql.connector.connect(database='local')
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
- connection.close()
- return results
-
-def psycopg2_loop():
- connection = psycopg2.connect(database='local')
- cursor = connection.cursor()
- results = []
- id = 0
- while id <= 5:
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
- id += 1
- connection.close()
- return results
-
-def pyodbc_loop():
- connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=local')
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
- connection.close()
- return results
-
-def sqlite3_loop():
- connection = sqlite3.connect("local.db")
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # Noncompliant {{Avoid performing SQL queries within a loop}}
- connection.close()
- return results
diff --git a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopCheck.py b/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopCheck.py
deleted file mode 100644
index 7f98cd548..000000000
--- a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopCheck.py
+++ /dev/null
@@ -1,83 +0,0 @@
-import mysql.connector
-
-
-class AvoidSQLRequestInLoopCheck:
- maxrows = 20
-
- def testWithNoLoop(self):
- try :
- db = mysql.connector.connect(option_files='my.conf', use_pure=True)
- cursor = db.cursor(dictionary=True)
-
- cursor.execute('SELECT id, name FROM users LIMIT %(limit)s', {'limit': self.maxrows})
- for row in cursor.fetchall():
- print("{}: {}".format(row['id'], row['name']))
-
- cursor.close()
- db.close()
- except mysql.connector.Error as err:
- print("Got an exception: {}".format(err))
- db.close()
-
- def testWithForLoop(self):
- try:
- db = mysql.connector.connect(option_files='my.conf', use_pure=True)
- cursor = db.cursor(dictionary=True)
-
- for i in range(0, self.maxrows):
- cursor.execute("SELECT id, name FROM users WHERE id = %(id)s", {'id': i+1}) #Noncompliant
- for row in cursor.fetchall():
- print("{}: {}".format(row['id'], row['name']))
-
- cursor.close()
- db.close()
- except mysql.connector.Error as err:
- print("Got an exception: {}".format(err))
- db.close()
-
- def testWithWhileLoop(self):
- try:
- db = mysql.connector.connect(option_files='my.conf', use_pure=True)
- cursor = db.cursor(dictionary=True)
-
- i = 0
- while i < self.maxrows:
- cursor.execute("SELECT id, name FROM users WHERE id = %(id)s", {'id': i+1}) #Noncompliant
- for row in cursor.fetchall():
- print("name: {}".format(row['name']))
- i += 1
-
- cursor.close()
- db.close()
- except mysql.connector.Error as err:
- print("Got an exception: {}".format(err))
- db.close()
-
- def testWithWhileLoopUpdate(self):
- try:
- db = mysql.connector.connect(option_files='my.conf', use_pure=True)
- cursor=db.cursor()
-
- i = 0
- while i < self.maxrows:
- cursor.execute('UPDATE users set name=%(name)s where id=%(id)s', {'name': "anonymous", 'id': i+1})
- i+=1
- db.commit()
-
- cursor.close()
- db.close()
- except mysql.connector.Error as err:
- print("Got an exception: {}".format(err))
- db.close()
-
-if __name__ == '__main__':
- test = AvoidSQLRequestInLoopCheck()
-
- print("testWithNoLoop")
- test.testWithNoLoop()
- print("testWithForLoop")
- test.testWithForLoop()
- print("testWithWhileLoop")
- test.testWithWhileLoop()
- print("testWithWhileLoopUpdate")
- test.testWithWhileLoopUpdate()
diff --git a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopNoImports.py b/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopNoImports.py
deleted file mode 100644
index fe8513844..000000000
--- a/python-plugin/src/test/resources/checks/avoidSQLRequestInLoopNoImports.py
+++ /dev/null
@@ -1,26 +0,0 @@
-def mysql_loop():
- connection = mysql.connector.connect(database='local')
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # OK
- connection.close()
- return results
-
-def pyodbc_loop():
- connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=local')
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # OK
- connection.close()
- return results
-
-def sqlite3_loop():
- connection = sqlite3.connect("local.db")
- cursor = connection.cursor()
- results = []
- for id in range(5):
- results.append(cursor.execute("SELECT name FROM user WHERE id = ?", (id)).fetchone()) # OK
- connection.close()
- return results
diff --git a/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py b/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py
deleted file mode 100644
index a026587ed..000000000
--- a/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py
+++ /dev/null
@@ -1,29 +0,0 @@
-import os.path
-
-path = 'hello.txt'
-
-
-def my_function():
- x=0
-
- try: # Noncompliant {{Avoid the use of try-catch-finally}}
- print(x)
- except:
- print("Something went wrong")
- finally:
- print("The 'try except' is finished")
-
-def foo():
- try: # Noncompliant {{Avoid the use of try-catch-finally}}
- f = open(path)
- print(f.read())
- except:
- print('No such file '+path)
- finally:
- f.close()
-
-def boo():
- if os.path.isfile(path):
- fh = open(path, 'r')
- print(fh.read())
- fh.close
\ No newline at end of file
diff --git a/python-plugin/src/test/resources/checks/init_dbtest.sql b/python-plugin/src/test/resources/checks/init_dbtest.sql
deleted file mode 100644
index 9a7a0a524..000000000
--- a/python-plugin/src/test/resources/checks/init_dbtest.sql
+++ /dev/null
@@ -1,34 +0,0 @@
-DROP TABLE IF EXISTS users;
-
-CREATE TABLE users (
- id INT NOT NULL AUTO_INCREMENT,
- name VARCHAR(255),
- PRIMARY KEY (id)
-);
-
-INSERT INTO users(name) VALUES('a');
-INSERT INTO users(name) VALUES('b');
-INSERT INTO users(name) VALUES('c');
-INSERT INTO users(name) VALUES('d');
-INSERT INTO users(name) VALUES('e');
-INSERT INTO users(name) VALUES('f');
-INSERT INTO users(name) VALUES('g');
-INSERT INTO users(name) VALUES('h');
-INSERT INTO users(name) VALUES('i');
-INSERT INTO users(name) VALUES('j');
-INSERT INTO users(name) VALUES('k');
-INSERT INTO users(name) VALUES('l');
-INSERT INTO users(name) VALUES('m');
-INSERT INTO users(name) VALUES('n');
-INSERT INTO users(name) VALUES('o');
-INSERT INTO users(name) VALUES('p');
-INSERT INTO users(name) VALUES('q');
-INSERT INTO users(name) VALUES('r');
-INSERT INTO users(name) VALUES('s');
-INSERT INTO users(name) VALUES('t');
-INSERT INTO users(name) VALUES('u');
-INSERT INTO users(name) VALUES('v');
-INSERT INTO users(name) VALUES('w');
-INSERT INTO users(name) VALUES('x');
-INSERT INTO users(name) VALUES('y');
-INSERT INTO users(name) VALUES('z');
diff --git a/python-plugin/src/test/resources/checks/my.conf.sample b/python-plugin/src/test/resources/checks/my.conf.sample
deleted file mode 100644
index e10dc23bc..000000000
--- a/python-plugin/src/test/resources/checks/my.conf.sample
+++ /dev/null
@@ -1,5 +0,0 @@
-[client]
-host = localhost
-user = dbtest
-password = dbtest
-database = dbtest
diff --git a/python-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.py b/python-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.py
deleted file mode 100644
index a3755d3e3..000000000
--- a/python-plugin/src/test/resources/checks/noFunctionCallWhenDeclaringForLoop.py
+++ /dev/null
@@ -1,11 +0,0 @@
-def my_function():
- return 6
-
-for i in my_function(): # Noncompliant {{Do not call a function when declaring a for-type loop}}
- print("Test")
- my_function()
- pass
-
-
-
-my_function()
\ No newline at end of file
diff --git a/tool_build.sh b/tool_build.sh
index bfac031a1..c6f1fba5f 100755
--- a/tool_build.sh
+++ b/tool_build.sh
@@ -1,3 +1,4 @@
#!/usr/bin/env sh
+rm -rf ./lib/*.jar
mvn clean package -DskipTests