innoraft/drupal-quality-checker

Setups code quality checking tools for Drupal project.

2.0.0 2023-12-14 08:43 UTC

This package is auto-updated.

Last update: 2024-04-14 19:29:28 UTC


README

Overview

This composer package will provide some basic code quality checks before committing code by using https://github.com/phpro/grumphp. Check out this Lullabot article for more details.

This has been customised from vijaycs85/drupal-quality-checker for Innoraft needs.

Install

  1. Add innoraft/drupal-quality-checker to composer.json or just run

    composer require --dev innoraft/drupal-quality-checker
  2. Replace grumphp.yml in project's root directory (not Drupal root directory) with vendor/innoraft/drupal-quality-checker/grumphp.yml.dist

That's it. Now, all tasks (listed below) run on every git commit.

Note: As part of install, GrumPHP adds pre-commit hook to repository. Existing pre-commit might get destroyed when install/uninstall.

Out of the box

  1. PHPCS with Drupal standard.
  2. PHP Lint
  3. YAML Lint
  4. Composer
  5. Composer Normalize
  6. JSONLint
  7. Trufflehog

Long list of additional checks/validators available here.

ESLint task Setup

  1. Go to custom theme folder and add eslint package with npm

    npm install eslint --save-dev
    npm install eslint-config-airbnb --save-dev
  2. Now run this command at project's root directory

    cp vendor/innoraft/drupal-quality-checker/eslintrc.json.dist .eslintrc.json
  3. Update bin key for eslint task under grumphp.yml file with relative address to eslint's bin file.

    Example: if your theme name is drupal_theme then change it to web/themes/custom/drupal_theme/node_modules/.bin/eslint

Stylelint task Setup

  1. Go to custom theme folder and add stylelint package with npm

    npm install stylelint --save-dev
  2. Now run this command at project's root directory

    cp vendor/innoraft/drupal-quality-checker/stylelintrc.json.dist .stylelintrc.json
  3. Update bin key for stylelint task under grumphp.yml file with relative address to stylelint's bin file.

    Example: if your theme name is drupal_theme then change it to web/themes/custom/drupal_theme/node_modules/.bin/stylelint

Trufflehog task Setup

  1. Create a new folder tasks at project's root level.

  2. Now run this command at project's root directory

    cp vendor/innoraft/drupal-quality-checker/tasks/SecurityLeaks.php tasks
  3. Now add the following code in your composer.json file which is present at project's root directory. ( For reference you can check composer.json file of this package )

    "autoload": {
        "psr-4": {
            "Innoraft\\QualityChecker\\Trufflehog\\": "tasks"
        }
    },

    Once the code is added in composer.json then execute this command

    composer dump-autoload
  4. Install trufflehog ( If not already install ). You can execute the following command to achieve the same.

    curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b $HOME/.local/bin
  5. Please check and confirm if your grumphp.yml is updated with vendor/innoraft/drupal-quality-checker/grumphp.yml.dist ( Check and confirm if trufflehog tasks & service attribute is added in grumphp.yml file )

  6. Trufflehog is now ready to sniff your secrets :)