├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ └── feature-request.yml └── workflows │ ├── ci.yml │ ├── publish.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── Makefile ├── README.md ├── RULES.md ├── docker-compose.yml ├── eslint-plugin ├── .eslint-doc-generatorrc.js ├── .eslintrc.js ├── .gitignore ├── .yarn │ └── releases │ │ └── yarn-4.9.1.cjs ├── .yarnrc.yml ├── README.md ├── dist │ └── rules.js ├── docs │ ├── license-header.txt │ └── rules │ │ ├── avoid-autoplay.md │ │ ├── avoid-brightness-override.md │ │ ├── avoid-css-animations.md │ │ ├── avoid-high-accuracy-geolocation.md │ │ ├── avoid-keep-awake.md │ │ ├── limit-db-query-results.md │ │ ├── no-empty-image-src-attribute.md │ │ ├── no-import-all-from-library.md │ │ ├── no-multiple-access-dom-element.md │ │ ├── no-multiple-style-changes.md │ │ ├── no-torch.md │ │ ├── prefer-collections-with-pagination.md │ │ ├── prefer-lighter-formats-for-image-files.md │ │ ├── prefer-shorthand-css-notations.md │ │ └── provide-print-css.md ├── lib │ ├── rule-list.js │ ├── rules │ │ ├── avoid-autoplay.js │ │ ├── avoid-brightness-override.js │ │ ├── avoid-css-animations.js │ │ ├── avoid-high-accuracy-geolocation.js │ │ ├── avoid-keep-awake.js │ │ ├── limit-db-query-results.js │ │ ├── no-empty-image-src-attribute.js │ │ ├── no-import-all-from-library.js │ │ ├── no-multiple-access-dom-element.js │ │ ├── no-multiple-style-changes.js │ │ ├── no-torch.js │ │ ├── prefer-collections-with-pagination.js │ │ ├── prefer-lighter-formats-for-image-files.js │ │ ├── prefer-shorthand-css-notations.js │ │ └── provide-print-css.js │ └── standalone.js ├── package.json ├── tests │ ├── dist │ │ └── rules.test.js │ └── lib │ │ ├── files │ │ └── logo.svg │ │ ├── rule-list.test.js │ │ ├── rules │ │ ├── avoid-autoplay.js │ │ ├── avoid-brightness-override.js │ │ ├── avoid-css-animations.js │ │ ├── avoid-high-accuracy-geolocation.js │ │ ├── avoid-keep-awake.js │ │ ├── limit-db-query-results.js │ │ ├── no-empty-image-src-attribute.js │ │ ├── no-import-all-from-library.js │ │ ├── no-multiple-access-dom-element.js │ │ ├── no-multiple-style-changes.js │ │ ├── no-torch.js │ │ ├── prefer-collections-with-pagination.js │ │ ├── prefer-lighter-formats-for-image-files.js │ │ ├── prefer-shorthand-css-notations.js │ │ └── provide-print-css.js │ │ └── standalone.test.js └── yarn.lock ├── sonar-plugin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── greencodeinitiative │ │ │ └── creedengo │ │ │ └── javascript │ │ │ ├── CheckList.java │ │ │ ├── DeprecatedEcoCodeRule.java │ │ │ ├── ESLintRulesBundle.java │ │ │ ├── JavaScriptPlugin.java │ │ │ ├── JavaScriptRuleRepository.java │ │ │ ├── JavaScriptRulesDefinition.java │ │ │ ├── TypeScriptRuleRepository.java │ │ │ ├── TypeScriptRulesDefinition.java │ │ │ └── checks │ │ │ ├── AvoidAutoPlay.java │ │ │ ├── AvoidBrightnessOverride.java │ │ │ ├── AvoidCSSAnimations.java │ │ │ ├── AvoidHighAccuracyGeolocation.java │ │ │ ├── AvoidKeepAwake.java │ │ │ ├── LimitDbQueryResult.java │ │ │ ├── NoEmptyImageSrcAttribute.java │ │ │ ├── NoImportAllFromLibrary.java │ │ │ ├── NoMultipleAccessDomElement.java │ │ │ ├── NoMultipleStyleChanges.java │ │ │ ├── NoTorch.java │ │ │ ├── PreferCollectionsWithPagination.java │ │ │ ├── PreferLighterFormatsForImageFiles.java │ │ │ ├── PreferShorthandCSSNotations.java │ │ │ └── ProvidePrintCSS.java │ └── resources │ │ └── org │ │ └── greencodeinitiative │ │ └── creedengo │ │ └── profiles │ │ ├── javascript_profile.json │ │ └── typescript_profile.json │ └── test │ └── java │ └── org │ └── greencodeinitiative │ └── creedengo │ └── javascript │ ├── CheckListTest.java │ ├── ESLintRulesBundleTest.java │ ├── JavaScriptPluginTest.java │ ├── JavaScriptRuleRepositoryTest.java │ ├── JavaScriptRulesDefinitionTest.java │ ├── TypeScriptRuleRepositoryTest.java │ └── TypeScriptRulesDefinitionTest.java ├── sonar-project.properties └── test-project ├── .gitignore ├── .yarn └── releases │ └── yarn-4.9.1.cjs ├── .yarnrc.yml ├── README.md ├── eslint.config.mjs ├── package.json ├── sonar-project.properties ├── src ├── avoid-autoplay.js ├── avoid-brightness-override.js ├── avoid-high-accuracy-geolocation.js ├── avoid-keep-awake-react-native-fn.js ├── avoid-keep-awake-react-native-hook.js ├── import-all-from-library.js ├── limit-db-query-results.js ├── modular-import-from-library.js ├── no-css-animations.js ├── no-empty-image-src-attribute.js ├── no-multiple-access-dom-element.js ├── no-torch.js ├── prefer-collections-with-pagination.ts ├── prefer-lighter-formats-for-image-files.js ├── prefer-shorthand-css-notations.js ├── provide-print-css.js └── rule-no-multiple-style-changes.js ├── tool_send_to_sonar.sh ├── tsconfig.json └── yarn.lock /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug Report 2 | description: This form is to report unexpected behavior in creedengo-javascript. 3 | labels: ["💉 bug: unconfirmed"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thank you for taking your precious time to file an issue! 🙏 We are sorry for the inconvenience this issue has caused you and want to resolve it as soon as possible. 9 | 10 | Help us help you! We know that your time is precious and hate to ask for any more of it, but the first step in fixing this issue is to understand the issue. Taking some extra time to ensure that we are able to reproduce the issue will help us significantly in resolving the issue. 11 | - type: textarea 12 | id: current-behavior 13 | attributes: 14 | label: Current Behavior 15 | description: What is the behavior that currently you experience? 16 | validations: 17 | required: true 18 | - type: textarea 19 | id: expected-behavior 20 | attributes: 21 | label: Expected Behavior 22 | description: What is the behavior that you expect to happen? 23 | validations: 24 | required: true 25 | - type: textarea 26 | id: reproduction 27 | attributes: 28 | label: Steps to Reproduce 29 | description: Please provide some instructions to reproduce the issue. Be as detailed as possible. 30 | value: | 31 | 1. 32 | validations: 33 | required: true 34 | - type: textarea 35 | id: logs 36 | attributes: 37 | label: Failure Logs 38 | description: Please include any relevant log snippets or files here. This will be automatically formatted into code, so no need for backticks. 39 | render: shell 40 | - type: input 41 | id: plugin-version 42 | attributes: 43 | label: creedengo-javascript Version 44 | description: Please provide the version of creedengo-javascript that you are using. 45 | validations: 46 | required: true 47 | - type: input 48 | id: sonarqube-version 49 | attributes: 50 | label: SonarQube Version 51 | description: Please provide the version of SonarQube that you are using if this is applicable. 52 | - type: textarea 53 | id: additional 54 | attributes: 55 | label: Additional Information 56 | description: Is there any additional information that you can provide? 57 | - type: markdown 58 | attributes: 59 | value: | 60 | > If we are not able to reproduce the issue, we will likely prioritize fixing other issues we can reproduce. Please do your best to fill out all of the sections above. 61 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Start a Discussion 4 | about: "Start a discussion to share your experience with creedengo-javascript" 5 | url: https://github.com/green-code-initiative/creedengo-javascript/discussions/new/choose 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: ✨ Feature Request 2 | description: This form is to request a new feature in creedengo-javascript. 3 | labels: ["🚀 enhancement"] 4 | body: 5 | - type: textarea 6 | id: solution 7 | attributes: 8 | label: Solution you'd like 9 | description: Please write a clear and concise description of what you want to happen. 10 | validations: 11 | required: true 12 | - type: textarea 13 | id: problem-related 14 | attributes: 15 | label: Is your feature request related to a problem? 16 | description: Please write a clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 17 | - type: textarea 18 | id: alternatives 19 | attributes: 20 | label: Alternatives you've considered 21 | description: Please include a clear and concise description of any alternative solutions or features you've considered. 22 | - type: textarea 23 | id: additional 24 | attributes: 25 | label: Additional Information 26 | description: Is there any additional information or screenshots that you want to provide? 27 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | tags: 7 | - "[0-9]+.[0-9]+.[0-9]+" 8 | pull_request: 9 | types: [opened, synchronize, reopened] 10 | 11 | jobs: 12 | test: 13 | name: Lint and Test 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [18.x, 20.x] 19 | java-version: [11] 20 | 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v4 24 | with: 25 | fetch-depth: 0 26 | 27 | - name: Use Node.js ${{ matrix.node-version }} 28 | uses: actions/setup-node@v4 29 | with: 30 | node-version: ${{ matrix.node-version }} 31 | 32 | - name: Use JDK ${{ matrix.java-version }} 33 | uses: actions/setup-java@v4 34 | with: 35 | distribution: temurin 36 | java-version: ${{ matrix.java-version }} 37 | 38 | - name: Install dependencies 39 | run: yarn install --immutable 40 | working-directory: eslint-plugin 41 | 42 | - name: Lint eslint-plugin 43 | run: yarn lint 44 | working-directory: eslint-plugin 45 | 46 | - name: Test eslint-plugin 47 | run: yarn test:cov 48 | working-directory: eslint-plugin 49 | 50 | - name: Verify SonarQube plugin 51 | run: mvn -e -B verify 52 | working-directory: sonar-plugin 53 | 54 | - name: SonarCloud Scan 55 | uses: SonarSource/sonarqube-scan-action@master 56 | if: | 57 | (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 58 | matrix.node-version == '20.x' && 59 | github.actor != 'dependabot[bot]' 60 | env: 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 63 | 64 | integration-test: 65 | name: Integration test 66 | runs-on: ubuntu-latest 67 | 68 | steps: 69 | - name: Checkout 70 | uses: actions/checkout@v4 71 | 72 | - name: Use Node.js 20.x 73 | uses: actions/setup-node@v4 74 | with: 75 | node-version: 20.x 76 | 77 | - name: Use JDK 11 78 | uses: actions/setup-java@v4 79 | with: 80 | distribution: temurin 81 | java-version: 11 82 | 83 | - name: Install dependencies 84 | run: yarn install --immutable 85 | working-directory: eslint-plugin 86 | 87 | - name: Build SonarQube plugin 88 | run: mvn -e -B package 89 | working-directory: sonar-plugin 90 | 91 | - name: Check SonarQube with the plugin 92 | run: docker compose up --wait 93 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - "[0-9]+.[0-9]+.[0-9]+" 7 | 8 | permissions: 9 | packages: write 10 | 11 | env: 12 | NODE_VERSION: 20.x 13 | 14 | jobs: 15 | publish-npm: 16 | runs-on: ubuntu-latest 17 | permissions: 18 | id-token: write 19 | steps: 20 | - name: Checkout tag "${{ github.ref_name }}" 21 | uses: actions/checkout@v4 22 | with: 23 | ref: ${{ github.ref_name }} 24 | 25 | - name: Use Node.js ${{ env.NODE_VERSION }} 26 | uses: actions/setup-node@v4 27 | with: 28 | node-version: ${{ env.NODE_VERSION }} 29 | registry-url: "https://registry.npmjs.org" 30 | 31 | - name: Install dependencies 32 | run: yarn install --immutable 33 | working-directory: eslint-plugin 34 | 35 | - name: Copy LICENSE 36 | run: cp LICENSE.md eslint-plugin/ 37 | 38 | - name: Publish package on NPM 39 | run: npm publish --provenance --access public 40 | working-directory: eslint-plugin 41 | env: 42 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 43 | 44 | publish-github: 45 | runs-on: ubuntu-latest 46 | steps: 47 | - name: Checkout tag "${{ github.ref_name }}" 48 | uses: actions/checkout@v4 49 | with: 50 | ref: ${{ github.ref_name }} 51 | 52 | - name: Use Node.js ${{ env.NODE_VERSION }} 53 | uses: actions/setup-node@v4 54 | with: 55 | node-version: ${{ env.NODE_VERSION }} 56 | 57 | - name: Install dependencies 58 | run: yarn install --immutable 59 | working-directory: eslint-plugin 60 | 61 | - name: Copy LICENSE 62 | run: cp LICENSE.md eslint-plugin/ 63 | 64 | - name: Add scope to package name 65 | run: npx --yes change-package-name @${{ github.repository_owner }}/creedengo-eslint-plugin 66 | working-directory: eslint-plugin 67 | 68 | - name: Configure GitHub Packages registry 69 | uses: bduff9/use-npmrc@v2.0.0 70 | with: 71 | working-directory: eslint-plugin 72 | dot-npmrc: | 73 | //npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN} 74 | @${{ github.repository_owner }}:registry=https://npm.pkg.github.com 75 | always-auth=true 76 | 77 | - name: Publish package on GitHub Packages 78 | run: npm publish 79 | working-directory: eslint-plugin 80 | env: 81 | NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editors & OS 2 | .DS_Store 3 | .idea 4 | .vscode 5 | *.iml 6 | 7 | # Maven 8 | target 9 | dependency-reduced-pom.xml 10 | 11 | # Auto-generated files 12 | coverage 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: build 4 | 5 | clean: 6 | cd sonar-plugin && mvn clean 7 | 8 | build: clean 9 | cd sonar-plugin && mvn package -DskipTests 10 | 11 | compile: clean 12 | cd sonar-plugin && mvn compile 13 | 14 | docker-clean: 15 | docker compose down --volumes 16 | 17 | docker-init: 18 | docker compose up --build -d 19 | 20 | docker-logs: 21 | docker compose logs -f 22 | 23 | start: 24 | docker compose start 25 | 26 | stop: 27 | docker compose stop 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Creedengo-JS 2 | 3 | _creedengo_ 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. 4 | 5 | Websites are becoming increasingly heavy and complex over the years. They represent an important part 6 | of the digital environmental footprint. The JavaScript/TypeScript part of the project focuses on providing rules and guidelines to optimize web applications and server-side code written in JavaScript and TypeScript. 7 | 8 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 9 | ![Build](https://github.com/green-code-initiative/creedengo-javascript/actions/workflows/ci.yml/badge.svg) 10 | [![Sonar Quality gate](https://img.shields.io/sonar/quality_gate/green-code-initiative_ecoCode-linter?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/project/overview?id=green-code-initiative_ecoCode-linter) 11 | 12 | ## 🌿 SonarQube plugin 13 | 14 | _Creedengo_ JavaScript is an "eco-responsibility" static code analyzer for projects based on the JavaScript ecosystem. It 15 | can handle JavaScript, TypeScript and all frameworks that use them. Its main purpose is to work with website source 16 | code, but it can also analyze back-end code. 17 | 18 | This project proposes rules for the following technologies: 19 | 20 | - JavaScript 21 | - TypeScript 22 | - NestJS 23 | - React (JSX) 24 | - React Native / Expo 25 | 26 | ## 🔧 ESLint plugin 27 | 28 | This project uses an internal ESLint plugin to analyze your source code. 29 | 30 | If you are not using SonarQube, we have a solution for you: the linter is working nicely on its own! \ 31 | Follow instructions in the [dedicated README file](eslint-plugin/README.md) to use it as a standalone plugin. 32 | 33 | ## 🛒 Distribution 34 | 35 | [![sonar-plugin version](https://img.shields.io/github/v/release/green-code-initiative/creedengo-javascript?label=SonarQube%20plugin)](https://github.com/green-code-initiative/creedengo-javascript/releases/latest) 36 | [![eslint-plugin version](https://img.shields.io/npm/v/@creedengo/eslint-plugin?label=ESLint%20plugin)](https://npmjs.com/package/@creedengo/eslint-plugin) 37 | 38 | **The plugin is available from the official SonarQube marketplace! Check the 39 | [version matrix here](https://docs.sonarsource.com/sonarqube/latest/instance-administration/plugin-version-matrix/).** 40 | 41 | Ready to use binaries for SonarQube are also 42 | available [from GitHub](https://github.com/green-code-initiative/creedengo-javascript/releases). \ 43 | Make sure to place the binary inside `extensions/plugins/` folder of your SonarQube instance. 44 | 45 | The standalone version of the ESLint plugin is available from [npmjs](https://npmjs.com/package/@creedengo/eslint-plugin). 46 | 47 | ## 🧩 Compatibility 48 | 49 | | Plugins Version | SonarQube version | ESLint version | 50 | | --------------- | ----------------- | -------------- | 51 | | 2.2+ | 9.9.+ LTA to 25.3 | 7.x, 8.x, 9.x | 52 | | 2.0, 2.1 | 9.9.+ LTA to 25.3 | 7.x, 8.x | 53 | | 1.4, 1.5 | 9.9.+ LTA to 10.7 | 7.x, 8.x | 54 | 55 | ## 🤝 Contribution 56 | 57 | You have an idea or you want to help us improving this project? \ 58 | We are open to your suggestions and contributions! Open an issue or PR 🚀 59 | 60 | Check out the [CONTRIBUTING.md](CONTRIBUTING.md) file 61 | and follow the various guides to start contributing. 62 | 63 | Thank you to all the people who already contributed to creedengo-javascript! 64 | 65 | - Elise Dubillot 66 | - Laetitia Bézie 67 | -------------------------------------------------------------------------------- /RULES.md: -------------------------------------------------------------------------------- 1 | Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `creedengo-rules-specifications` repository. 2 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: sonarqube_creedengo_javascript 3 | 4 | services: 5 | sonar: 6 | image: sonarqube:25.3.0.104237-community 7 | container_name: sonar_creedengo_javascript 8 | ports: 9 | - "9000:9000" 10 | networks: 11 | - sonarnet 12 | depends_on: 13 | db: 14 | condition: service_healthy 15 | environment: 16 | SONAR_JDBC_USERNAME: sonar 17 | SONAR_JDBC_PASSWORD: sonar 18 | SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube 19 | SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: "true" 20 | volumes: 21 | - type: bind 22 | source: ./sonar-plugin/target/creedengo-javascript-plugin-2.1.1-SNAPSHOT.jar 23 | target: /opt/sonarqube/extensions/plugins/creedengo-javascript-plugin-2.1.1-SNAPSHOT.jar 24 | - "extensions:/opt/sonarqube/extensions" 25 | - "logs:/opt/sonarqube/logs" 26 | - "data:/opt/sonarqube/data" 27 | healthcheck: 28 | test: wget -qO- http://sonar:9000/api/system/status | grep -q -e '"status":"UP"' -e '"status":"DB_MIGRATION_NEEDED"' -e '"status":"DB_MIGRATION_RUNNING"' || exit 1 29 | interval: 10s 30 | timeout: 10s 31 | retries: 5 32 | 33 | db: 34 | image: postgres:16-alpine 35 | container_name: postgresql_creedengo_javascript 36 | networks: 37 | - sonarnet 38 | volumes: 39 | - pg_data:/var/lib/postgresql/data 40 | environment: 41 | POSTGRES_USER: sonar 42 | POSTGRES_PASSWORD: sonar 43 | POSTGRES_DB: sonarqube 44 | PGDATA: pg_data:/var/lib/postgresql/data/pgdata 45 | healthcheck: 46 | test: ["CMD-SHELL", "pg_isready -U sonar -d sonarqube"] 47 | interval: 5s 48 | timeout: 5s 49 | retries: 5 50 | 51 | networks: 52 | sonarnet: 53 | driver: bridge 54 | 55 | volumes: 56 | data: 57 | logs: 58 | extensions: 59 | pg_data: 60 | -------------------------------------------------------------------------------- /eslint-plugin/.eslint-doc-generatorrc.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** @type {import('eslint-doc-generator').GenerateOptions} */ 4 | const config = { 5 | configEmoji: [["flat/recommended", "✅"]], 6 | postprocess: (doc) => { 7 | return doc.replace(/✅\s*✅/gu, "✅"); 8 | }, 9 | }; 10 | 11 | module.exports = config; 12 | -------------------------------------------------------------------------------- /eslint-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs 3 | * Copyright © 2023 Green Code Initiative (https://green-code-initiative.org) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | "use strict"; 20 | 21 | module.exports = { 22 | root: true, 23 | extends: [ 24 | "eslint:recommended", 25 | "plugin:eslint-plugin/recommended", 26 | "plugin:node/recommended", 27 | "plugin:prettier/recommended", 28 | ], 29 | plugins: ["license-header"], 30 | parserOptions: { 31 | ecmaVersion: 2020, 32 | }, 33 | env: { 34 | node: true, 35 | }, 36 | overrides: [ 37 | { 38 | files: ["tests/**/*.js"], 39 | env: { mocha: true }, 40 | }, 41 | ], 42 | rules: { 43 | "node/no-unpublished-require": "off", 44 | "license-header/header": ["error", "./docs/license-header.txt"], 45 | }, 46 | }; 47 | -------------------------------------------------------------------------------- /eslint-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | # Yarn 2 | .pnp.* 3 | .yarn/* 4 | !.yarn/patches 5 | !.yarn/plugins 6 | !.yarn/releases 7 | !.yarn/sdks 8 | !.yarn/versions 9 | node_modules 10 | 11 | # Auto-generated files 12 | *-report.json 13 | .nyc_output 14 | dist/pack 15 | -------------------------------------------------------------------------------- /eslint-plugin/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | compressionLevel: mixed 2 | 3 | enableGlobalCache: false 4 | 5 | nodeLinker: node-modules 6 | 7 | yarnPath: .yarn/releases/yarn-4.9.1.cjs 8 | -------------------------------------------------------------------------------- /eslint-plugin/dist/rules.js: -------------------------------------------------------------------------------- 1 | /* 2 | * creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs 3 | * Copyright © 2023 Green Code Initiative (https://green-code-initiative.org) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * @fileoverview JavaScript linter of Creedengo project (Sonar mode) 21 | * @author Green Code Initiative 22 | */ 23 | "use strict"; 24 | 25 | const rules = require("../lib/rule-list"); 26 | 27 | module.exports = { 28 | rules: rules.map((rule) => ({ 29 | ruleId: `@creedengo/${rule.ruleName}`, 30 | ruleModule: rule.ruleModule, 31 | ruleConfig: [], 32 | })), 33 | }; 34 | -------------------------------------------------------------------------------- /eslint-plugin/docs/license-header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs 3 | * Copyright © 2023 Green Code Initiative (https://green-code-initiative.org) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | -------------------------------------------------------------------------------- /eslint-plugin/docs/rules/avoid-autoplay.md: -------------------------------------------------------------------------------- 1 | # Avoid autoplay for videos and audio content (`@creedengo/avoid-autoplay`) 2 | 3 | ⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅ `recommended`. 4 | 5 | 6 | 7 | ## Why is this an issue? 8 | 9 | Automatic videos and audio files activation (autoplay) during web pages loading uses resources on each tier (device, 10 | network, data center). In many cases, automatic playback is not necessary. Moreover, it can draw users' attention and 11 | distract them from the initially requested service. Therefore, whenever possible, these playbacks should be initiated by 12 | the users and by not using the autoplay attributes in the `