diff --git a/.github/workflows/manual_release.yml b/.github/workflows/manual_release.yml index 787a4400a..e3d225726 100644 --- a/.github/workflows/manual_release.yml +++ b/.github/workflows/manual_release.yml @@ -89,27 +89,6 @@ 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 diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 0d2f3d605..ff213b10c 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -69,27 +69,6 @@ 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fc0e43e..a23dd8551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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 diff --git a/INSTALL.md b/INSTALL.md index 716f51d09..46d6673fb 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -23,8 +23,6 @@ ecoCode # Root directory | +--java-plugin # JAVA | -+--javascript-plugin # JavaScript -| +--php-plugin # PHP | +--python-plugin # Python @@ -38,6 +36,5 @@ 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 7b34c611b..7a7be356b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ refer to the contribution section. 4 technologies are supported by ecoCode right now: - [Java](java-plugin/) -- [JavaScript](javascript-plugin/) +- [JavaScript](https://github.com/green-code-initiative/ecoCode-javascript) - [PHP](php-plugin/) - [Python](python-plugin/) @@ -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 ------------------ diff --git a/docker-compose.yml b/docker-compose.yml index 76f87d1ce..6e1351794 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,9 +18,6 @@ services: - type: bind source: ./java-plugin/target/ecocode-java-plugin-1.3.1-SNAPSHOT.jar target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.3.1-SNAPSHOT.jar - - type: bind - source: ./javascript-plugin/target/ecocode-javascript-plugin-1.3.1-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.3.1-SNAPSHOT.jar - type: bind source: ./php-plugin/target/ecocode-php-plugin-1.3.1-SNAPSHOT.jar target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.3.1-SNAPSHOT.jar 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 d9d7e5519..000000000 --- a/javascript-plugin/pom.xml +++ /dev/null @@ -1,130 +0,0 @@ - - - 4.0.0 - - - io.ecocode - ecocode-parent - 1.3.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.analyzer-commons - sonar-analyzer-commons - - - - org.junit.jupiter - junit-jupiter - test - - - - org.assertj - assertj-core - test - - - - org.mockito - mockito-junit-jupiter - test - - - - - - - - org.sonarsource.sonar-packaging-maven-plugin - sonar-packaging-maven-plugin - true - - ecocodejavascript - ${project.name} - fr.greencodeinitiative.javascript.JavaScriptPlugin - true - ${sonarqube.version} - ${java.version} - - - - - org.apache.maven.plugins - maven-shade-plugin - - - - 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 66dba696c..000000000 --- a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptPlugin.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2023 Green Code Initiative - * - * 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 General Public License - * along with this program. If not, see . - */ -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 f13409ce4..000000000 --- a/javascript-plugin/src/main/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinition.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2023 Green Code Initiative - * - * 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 General Public License - * along with this program. If not, see . - */ -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 598525441..000000000 --- a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json +++ /dev/null @@ -1,62 +0,0 @@ -[ - { - "key": "@ecocode/avoid-high-accuracy-geolocation", - "type": "CODE_SMELL", - "name": "Avoid using high accuracy geolocation in web applications", - "description": "\n\n

Rule details

\n

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.

\n

Examples

\n

Examples of non compliant code for this rule:

\n
var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 };\nfunction success(pos) {\n  console.log(pos.coords);\n}\n\nfunction error(err) {\n  console.warn(err);\n}\n\nnavigator.geolocation.getCurrentPosition(success, error, options);\n
\n

Examples of compliant code for this rule:

\n
// enableHighAccuracy is false by default, so not declaring it is correct\nfunction success(pos) {\n  console.log(pos);\n}\nnavigator.geolocation.getCurrentPosition(success);\n
\n
var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 };\nfunction success(pos) {\n  console.log(pos.coords);\n}\n\nfunction error(err) {\n  console.warn(err);\n}\n\nnavigator.geolocation.getCurrentPosition(success, error, options);\n
\n
Click here to access the rule details.", - "constantDebtMinutes": 5, - "severity": "MINOR", - "tags": [ - "eco-design", - "ecocode" - ] - }, - { - "key": "@ecocode/no-import-all-from-library", - "type": "CODE_SMELL", - "name": "Should not import all from librar", - "description": "\n\n

Rule details

\n

This rule aims to reduce weight of programs by using only needed modules. Many libraries export only one module by\ndefault, but some of them are exporting ES modules or submodules. We should use them to select more precisly needed\nmodules and avoid unnecessarily overloading files weight.

\n

\"Example

\n

Example with the well-known lodash library, if you only need "isEmpty" method.

\n

Options

\n

You can externally add your own libraries to be checked.\nTo add your own libraries you need to modify your .eslintrc.js by adding the following rule configuration:

\n
module.exports = {\n  ...yourConf,\n  rules: {\n    "no-import-all-from-library": [\n      "warn",\n      {\n        notAllowedLibraries: ["some-lib"], // will check for -> import someLib from "some-lib"\n        importByNamespaceNotAllowedLibraries: ["some-other-lib"], // will check for -> import * as someOtherLib from "some-other-lib"\n      },\n    ],\n  },\n};\n
\n

Examples

\n

Examples of non-compliant code for this rule:

\n
// Example with lodash\nimport lodash from "lodash";\nimport { isEmpty } from "lodash";\nimport * as lodash from "lodash";\n\n// Example with underscore\nimport _ from "underscore";\n
\n

Examples of compliant code for this rule:

\n
// Example with lodash (uses submodules)\nimport isEmpty from "lodash/isEmpty";\nimport intersect from "lodash/intersect";\n\n// Example with underscore (uses esm modules)\nimport map from "underscore/modules/map.js";\n
\n
Click here to access the rule details.", - "constantDebtMinutes": 5, - "severity": "MINOR", - "tags": [ - "eco-design", - "ecocode" - ] - }, - { - "key": "@ecocode/no-multiple-access-dom-element", - "type": "CODE_SMELL", - "name": "Disallow multiple access of same DOM element", - "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-design", - "ecocode" - ] - }, - { - "key": "@ecocode/no-multiple-style-changes", - "type": "CODE_SMELL", - "name": "Disallow multiple style changes at once", - "description": "\n\n

Rule Details

\n

This rule aims to disallow batching multiple style changes at once.

\n

To limit the number of repaint/reflow, it is advised to batch style modifications by adding a class containing all style\nchanges that will generate a unique reflow.

\n

Examples

\n

Examples of non-compliant code for this rule:

\n
<script>\n  element.style.height = "800px";\n  element.style.width = "600px";\n  element.style.color = "red";\n</script>\n
\n

Examples of compliant code for this rule:

\n
<style>\n  .in-error {\n    color: red;\n    height: 800px;\n    width: 800px;\n  }\n</style>\n\n<script>\n  element.addClass("in-error");\n</script>\n
\n
Click here to access the rule details.", - "constantDebtMinutes": 5, - "severity": "MINOR", - "tags": [ - "eco-design", - "ecocode" - ] - }, - { - "key": "@ecocode/prefer-collections-with-pagination", - "type": "CODE_SMELL", - "name": "Prefer API collections with pagination", - "description": "\n\n

Rule details

\n

This rule aims to reduce the size and thus the network weight of API returns that may contain many elements. This rule\nis built for the NestJS framework but can work with a controller @Controller() and a decorated method @Get().

\n

Examples

\n

Examples of non-compliant code for this rule:

\n
@Controller()\nclass Test {\n  @Get()\n  public find(): Promise<string[]> {}\n}\n
\n

Examples of compliant code for this rule:

\n
interface Pagination {\n  items: string[];\n  currentPage: number;\n  totalPages: number;\n}\n\n@Controller()\nclass Test {\n  @Get()\n  public find(): Promise<Pagination> {}\n}\n
\n
Click 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 84534777c..000000000 --- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package fr.greencodeinitiative.javascript; - -import org.junit.jupiter.api.Test; -import org.sonar.api.Plugin; -import org.sonar.api.SonarRuntime; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -class JavaScriptPluginTest { - - @Test - void extensions() { - SonarRuntime sonarRuntime = mock(SonarRuntime.class); - Plugin.Context context = new Plugin.Context(sonarRuntime); - new JavaScriptPlugin().define(context); - assertThat(context.getExtensions()).hasSize(1); - } - -} 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 e90f75d95..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.jupiter.api.Test; -import org.sonar.api.server.rule.RulesDefinition; - -import static org.assertj.core.api.Assertions.assertThat; - -class JavaScriptRulesDefinitionTest { - - @Test - 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 0a13b79b0..cb734538d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,6 @@ ecocode-rules-specifications python-plugin java-plugin - javascript-plugin php-plugin @@ -58,7 +57,6 @@ 7.19.0.31550 4.3.0.11660 3.29.0.9684 - 10.2.0.21568 2.5.0.1358 @@ -106,15 +104,6 @@ provided - - - org.sonarsource.javascript - sonar-javascript-plugin - ${sonarjavascript.version} - sonar-plugin - provided - - org.sonarsource.php