From 3eb8e4be197500e6d9ed0559bc69fc9012697988 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Wed, 1 Feb 2023 23:29:28 +0100 Subject: [PATCH 1/7] Add JavaScript plugin --- javascript-plugin/pom.xml | 155 ++++++++++++++++++ .../javascript/JavaScriptPlugin.java | 12 ++ .../javascript/JavaScriptRulesDefinition.java | 19 +++ .../l10n/javascript/rules.json | 14 ++ .../javascript/JavaScriptPluginTest.java | 41 +++++ .../JavaScriptRulesDefinitionTest.java | 22 +++ pom.xml | 11 ++ 7 files changed, 274 insertions(+) create mode 100644 javascript-plugin/pom.xml create mode 100644 javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java create mode 100644 javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java create mode 100644 javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json create mode 100644 javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java create mode 100644 javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml new file mode 100644 index 000000000..69027e2a0 --- /dev/null +++ b/javascript-plugin/pom.xml @@ -0,0 +1,155 @@ + + + 4.0.0 + + + io.ecocode + ecocode-parent + 0.3.0-SNAPSHOT + + + ecocode-javascript-plugin + sonar-plugin + + ecoCode JavaScript Sonar Plugin + 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 + + ${project.artifactId} + ${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 new file mode 100644 index 000000000..6959ea2e1 --- /dev/null +++ b/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..fe3522177 --- /dev/null +++ b/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java @@ -0,0 +1,19 @@ +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"; + 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 new file mode 100644 index 000000000..a8a0c320d --- /dev/null +++ b/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json @@ -0,0 +1,14 @@ +[ + { + "key": "@ecocode/no-multiple-access-dom-element", + "type": "CODE_SMELL", + "name": "Disallow multiple access of same DOM element", + "description": "This rule aims to reduce DOM access assigning its object to variable when access multiple time. It saves CPU cycles.\n

Noncompliant Code Example

\n
\ndocument.getElementById('block1').innerHTML = \"Hello World\";\ndocument.getElementById('block1').style.width = \"50px\";\n
\n

Compliant Solution

\n
\nvar block1 = document.getElementById('block1');\nblock1.innerHTML = \"Hello World\";\nblock1.style.width = \"50px\";\n
\n", + "url": "https://github.com/green-code-initiative/ecoCode-linter/blob/main/eslint-plugin/docs/rules/no-multiple-access-dom-element.md", + "constantDebtMinutes": 5, + "severity": "MINOR", + "tags": [ + "eco-conception" + ] + } +] diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java new file mode 100644 index 000000000..a558e0626 --- /dev/null +++ b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java @@ -0,0 +1,41 @@ +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 new file mode 100644 index 000000000..60bdc8510 --- /dev/null +++ b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java @@ -0,0 +1,22 @@ +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/pom.xml b/pom.xml index d5e2a62b9..bebd9c40d 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ 2.1.0.1111 3.19.0.10254 3.25.0.9077 + 9.13.0.20537 1.21.0.505 true 3.4.1 @@ -99,6 +100,15 @@ provided + + + org.sonarsource.javascript + sonar-javascript-plugin + sonar-plugin + ${sonarjavascript.version} + provided + + org.sonarsource.php @@ -198,6 +208,7 @@ python-plugin java-plugin + javascript-plugin php-plugin From 32ffab98148665159c0b634bc3a44d9430f4edc3 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Sun, 5 Mar 2023 13:19:14 +0100 Subject: [PATCH 2/7] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2781664b1..68b69a842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -88,4 +89,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 \ No newline at end of file +[0.1.0]: https://github.com/green-code-initiative/ecoCode/releases/tag/v0.1.0 From 6fc4da23cce3cad4da6cd82837fe90fdb9d2e50c Mon Sep 17 00:00:00 2001 From: utarwyn Date: Sun, 5 Mar 2023 13:19:57 +0100 Subject: [PATCH 3/7] Update GitHub workflows --- .github/workflows/manual_release.yml | 39 +++++++++++++++++++++------- .github/workflows/tag_release.yml | 27 ++++++++++++++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.github/workflows/manual_release.yml b/.github/workflows/manual_release.yml index b7ed447f3..787a4400a 100644 --- a/.github/workflows/manual_release.yml +++ b/.github/workflows/manual_release.yml @@ -68,11 +68,11 @@ 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 @@ -80,7 +80,7 @@ jobs: 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 }} @@ -89,11 +89,32 @@ 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 @@ -101,7 +122,7 @@ jobs: 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 }} @@ -110,11 +131,11 @@ 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 @@ -122,7 +143,7 @@ jobs: 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 }} diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 4dab9db52..0d2f3d605 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -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 @@ -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 @@ -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 From 588527975d51899d2ce4f79aed5da99b03423cd0 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Sun, 5 Mar 2023 13:24:10 +0100 Subject: [PATCH 4/7] Update README --- INSTALL.md | 10 ++++++---- README.md | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 15379d9fd..f043801e1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -13,13 +13,15 @@ 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 ``` diff --git a/README.md b/README.md index d705897bd..17eeb2a18 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ refer to the contribution section. 🌿 SonarQube Plugins ------------------- -3 technologies are supported by the plugin right now: +4 technologies are supported by the plugin right now: - [Java](java-plugin/) +- [JavaScript](javascript-plugin/) - [PHP](php-plugin/) - [Python](python-plugin/) @@ -31,7 +32,7 @@ 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 +- 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) From 3704fa372b8bc310eea7735296ee00475a4762e8 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Tue, 7 Mar 2023 23:20:18 +0100 Subject: [PATCH 5/7] Update README --- INSTALL.md | 17 ++++++++------ README.md | 20 +++++++++-------- javascript-plugin/README.md | 22 +++++++++++++++++++ .../l10n/javascript/rules.json | 5 ++--- 4 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 javascript-plugin/README.md diff --git a/INSTALL.md b/INSTALL.md index f043801e1..14bf48ec9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,11 +1,13 @@ - [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 ----------------- @@ -28,9 +30,10 @@ ecoCode # Root directory 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) diff --git a/README.md b/README.md index 17eeb2a18..64179d495 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ ![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 ------------------- -4 technologies are supported by the plugin right now: +4 technologies are supported by ecoCode right now: - [Java](java-plugin/) - [JavaScript](javascript-plugin/) @@ -32,10 +32,10 @@ refer to the contribution section. There is two kind of plugins : -- One for web / backoffice (PHP, Python, Java, JavaScript), 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. @@ -46,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 ------------------ diff --git a/javascript-plugin/README.md b/javascript-plugin/README.md new file mode 100644 index 000000000..b6095a6ea --- /dev/null +++ b/javascript-plugin/README.md @@ -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. 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 index a8a0c320d..7b013a977 100644 --- a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json +++ b/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json @@ -3,12 +3,11 @@ "key": "@ecocode/no-multiple-access-dom-element", "type": "CODE_SMELL", "name": "Disallow multiple access of same DOM element", - "description": "This rule aims to reduce DOM access assigning its object to variable when access multiple time. It saves CPU cycles.\n

Noncompliant Code Example

\n
\ndocument.getElementById('block1').innerHTML = \"Hello World\";\ndocument.getElementById('block1').style.width = \"50px\";\n
\n

Compliant Solution

\n
\nvar block1 = document.getElementById('block1');\nblock1.innerHTML = \"Hello World\";\nblock1.style.width = \"50px\";\n
\n", - "url": "https://github.com/green-code-initiative/ecoCode-linter/blob/main/eslint-plugin/docs/rules/no-multiple-access-dom-element.md", + "description": "\n\n

Rule details

\n

This rule aims to reduce DOM access assigning its object to variable when access multiple time. It saves CPU cycles.

\n

Examples

\n

Examples of incorrect code for this rule:

\n
var el1 = document.getElementById("block1").test1;\nvar el2 = document.getElementById("block1").test2;\n
\n

Examples of correct code for this rule:

\n
var blockElement = document.getElementById("block1");\nvar el1 = blockElement.test1;\nvar el2 = blockElement.test2;\n
\n
Click here to access the rule details.", "constantDebtMinutes": 5, "severity": "MINOR", "tags": [ - "eco-conception" + "eco-design" ] } ] From 21e12505b050ef28e4d5981fd3350a29fc839230 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Wed, 8 Mar 2023 12:56:02 +0100 Subject: [PATCH 6/7] Add JavaScript plugin in Docker Compose file --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index b9a205e5e..ee04d9080 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 From 3ead1069c63d8f26dac88ead68e0f902f4576ab4 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Thu, 9 Mar 2023 13:04:54 +0100 Subject: [PATCH 7/7] Adapt JavaScript plugin key with new convention --- javascript-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml index 69027e2a0..d7db6adfc 100644 --- a/javascript-plugin/pom.xml +++ b/javascript-plugin/pom.xml @@ -63,7 +63,7 @@ sonar-packaging-maven-plugin true - ${project.artifactId} + ecocodejavascript ${project.name} fr.greencodeinitiative.javascript.JavaScriptPlugin true