Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript plugin #67

Merged
merged 9 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions .github/workflows/manual_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ jobs:
- name: Export UPLOAD_URL
id: export_upload_url
run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT
updload-java:
upload-java:
name: Upload Java Plugin
runs-on: ubuntu-latest
needs: build
steps:
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 - Java Plugin
id: upload-release-asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -89,19 +89,40 @@ 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
updload-php:
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:
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
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -110,19 +131,19 @@ jobs:
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
updload-python:
upload-python:
name: Upload Python Plugin
runs-on: ubuntu-latest
needs: build
steps:
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
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Export UPLOAD_URL
id: export_upload_url
run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT
updload-java:
upload-java:
name: Upload Java Plugin
runs-on: ubuntu-latest
needs: build
Expand All @@ -69,7 +69,28 @@ 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
updload-php:
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
Expand All @@ -90,7 +111,7 @@ jobs:
asset_path: lib/ecocode-php-plugin-${{ github.ref_name }}.jar
asset_name: ecocode-php-plugin-${{ github.ref_name }}.jar
asset_content_type: application/zip
updload-python:
upload-python:
name: Upload Python Plugin
runs-on: ubuntu-latest
needs: build
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [#44](https://github.com/green-code-initiative/ecoCode/pull/44) Update the PHP description rules
- [#67](https://github.com/green-code-initiative/ecoCode/pull/67) Add JavaScript plugin

### Changed

Expand Down Expand Up @@ -89,4 +90,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[0.1.1]: https://github.com/green-code-initiative/ecoCode/compare/v0.1.0...v0.1.1

[0.1.0]: https://github.com/green-code-initiative/ecoCode/releases/tag/v0.1.0
[0.1.0]: https://github.com/green-code-initiative/ecoCode/releases/tag/v0.1.0
27 changes: 16 additions & 11 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
- [Installation notes / requirements](#installation-notes--requirements)
- [Project structure](#project-structure)
- [Links](#links)
- [Plugin-specific guides](#plugin-specific-guides)

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 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.

Project structure
-----------------

Here is a preview of project tree :

```txt
ecoCode # Root directory
ecoCode # Root directory
|
+--java-plugin # JAVA
+--java-plugin # JAVA
|
+--php-plugin # PHP
+--javascript-plugin # JavaScript
|
+--python-plugin # Python
+--php-plugin # PHP
|
+--python-plugin # Python
|
\--docker-compose.yml # Docker compose file
```

You will find more information about the plugins’ architecture in their folders

Links
-----
Plugin-specific guides
----------------------

- Java how-to : https://github.com/SonarSource/sonar-java/blob/master/docs/CUSTOM_RULES_101.md
- Python how-to : https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/python-custom-rules
- PHP how-to : https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/php-custom-rules
- [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)
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
![Logo](docs/resources/logo-large.png)
======================================

*ecoCode* is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
_ecoCode_ is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
the project is to provide a list of static code analyzers to highlight code structures that may have a negative
ecological impact: energy and resources over-consumption, "fatware", shortening terminals' lifespan, etc.

ecoCode is based on evolving catalogs of [good practices](docs/rules), for various technologies. A SonarQube plugin then
implement these catalogs as rules for scanning your projects.
_ecoCode_ is based on evolving catalogs of [good practices](docs/rules), for various technologies. A SonarQube plugin
then implement these catalogs as rules for scanning your projects.

**Warning**: this is still a very early stage project. Any feedback or contribution will be highly appreciated. Please
refer to the contribution section.

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_OF_CONDUCT.md)

🌿 SonarQube Plugins
-------------------

3 technologies are supported by the plugin right now:
4 technologies are supported by ecoCode right now:

- [Java](java-plugin/)
- [JavaScript](javascript-plugin/)
- [PHP](php-plugin/)
- [Python](python-plugin/)

Expand All @@ -31,10 +32,10 @@ refer to the contribution section.

There is two kind of plugins :

- One for web / backoffice (PHP, Python, Java), using smells described in the 2nd edition of the repository published in
september 2015
- One for web / backoffice (PHP, Python, Java, JavaScript), using smells described in the 2nd edition of the repository
published in september 2015.
You can find all the
rules [here (in french)](https://docs.google.com/spreadsheets/d/1nujR4EnajnR0NSXjvBW3GytOopDyTfvl3eTk2XGLh5Y/edit#gid=1386834576)
rules [here (in french)](https://docs.google.com/spreadsheets/d/1nujR4EnajnR0NSXjvBW3GytOopDyTfvl3eTk2XGLh5Y/edit#gid=1386834576).
The current repository is for web / backOffice
- One for mobile (Android), using [a set of smells](https://olegoaer.perso.univ-pau.fr/android-energy-smells/) theorised
by Olivier Le Goaër for Android.
Expand All @@ -45,7 +46,9 @@ There is two kind of plugins :
Code is parsed to be transformed as AST. AST will allow you to access one or more nodes of your code.
For example, you’ll be able to access of all your `for` loop, to explore content etc.

To better understand AST structure, y a can use [AST Explorer](https://astexplorer.net/)
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
------------------
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
- type: bind
source: ./java-plugin/target/ecocode-java-plugin-0.3.0-SNAPSHOT.jar
target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-0.3.0-SNAPSHOT.jar
- type: bind
source: ./javascript-plugin/target/ecocode-javascript-plugin-0.3.0-SNAPSHOT.jar
target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-0.3.0-SNAPSHOT.jar
- type: bind
source: ./php-plugin/target/ecocode-php-plugin-0.3.0-SNAPSHOT.jar
target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-0.3.0-SNAPSHOT.jar
Expand Down
22 changes: 22 additions & 0 deletions javascript-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.
Loading