innoraft / drupal-quality-checker
Setups code quality checking tools for Drupal project.
Installs: 38 585
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 7
Open Issues: 0
Language:Shell
Type:project
Requires
- drupal/coder: ^8.3
- ergebnis/composer-normalize: ^2.0
- friendsoftwig/twigcs: ^6.0
- palantirnet/drupal-rector: ^0.13.1
- phpro/grumphp: ^2.0
- phpstan/phpstan: ^1.9
- squizlabs/php_codesniffer: ^3.7
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
-
Add
innoraft/drupal-quality-checker
tocomposer.json
or just runcomposer require --dev innoraft/drupal-quality-checker
-
Replace
grumphp.yml
in project's root directory (not Drupal root directory) withvendor/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. Existingpre-commit
might get destroyed when install/uninstall.
Out of the box
- PHPCS with Drupal standard.
- PHP Lint
- YAML Lint
- Composer
- Composer Normalize
- JSONLint
- Trufflehog
Long list of additional checks/validators available here.
To automatically setup all the packages, follow the below steps:
-
Download the setup.sh file and place it outside the docroot.
-
Update Line 12 of setup.sh having the command
composer require --dev innoraft/drupal-quality-checker
. Use the appropriate environment for your setup. For example, if you are working with Lando, uselando composer require --dev innoraft/drupal-quality-checker
. -
Update Line 102 of setup.sh having the command
composer dump-autoload
. Use the appropriate environment for your setup. For example, if you are working with Lando, uselando composer dump-autoload
. -
From outside the docroot run this command that will make the bash script executable
chmod +x setup.sh
-
To execute the bash script run this command from outside the docroot
./setup.sh
-
After executing the script, a prompt will appear asking for the base directory name , site name and custom theme name, which need to be entered
-
Few other prompts will appear where consent is needed to download the required package for the configuration
-
When prompted for tasks to run, select any option, as grumphp.yml is already included in the package and will be used for setup, making this selection less critical:
-
After this, please wait for some time for the script to execute and the setup to be completed.
Incase you want to install them individually, follow the below steps:
ESLint task Setup
-
Go to custom theme folder and add eslint package with npm
npm install eslint --save-dev npm install eslint-config-airbnb --save-dev
-
Now run this command at project's root directory
cp vendor/innoraft/drupal-quality-checker/eslintrc.json.dist .eslintrc.json
For multisite run the following command
cp vendor/innoraft/drupal-quality-checker/eslintrc.json.dist docroot/sites/<sitename>/themes/custom/<themename>/.eslintrc.json
-
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 toweb/themes/custom/drupal_theme/node_modules/.bin/eslint
Stylelint task Setup
-
Go to custom theme folder and add stylelint package with npm
npm install stylelint --save-dev
-
Now run this command at project's root directory
cp vendor/innoraft/drupal-quality-checker/stylelintrc.json.dist .stylelintrc.json
For multisite run the following command
cp vendor/innoraft/drupal-quality-checker/stylelintrc.json.dist docroot/sites/<sitename>/themes/custom/<themename>/.stylelintrc.json
-
For multisite run the following command
npm install stylelint-config-standard
-
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 toweb/themes/custom/drupal_theme/node_modules/.bin/stylelint
Trufflehog task Setup
-
Create a new folder
tasks
at project's root level. -
Now run this command at project's root directory
cp vendor/innoraft/drupal-quality-checker/tasks/SecurityLeaks.php tasks
-
Now add the following code in your
composer.json
file which is present at project's root directory. ( For reference you can checkcomposer.json
file of this package )"autoload": { "psr-4": { "Innoraft\\QualityChecker\\Trufflehog\\": "tasks" } },
Once the code is added in
composer.json
then execute this commandcomposer dump-autoload
-
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
-
Please check and confirm if your
grumphp.yml
is updated withvendor/innoraft/drupal-quality-checker/grumphp.yml.dist
( Check and confirm if trufflehog tasks & service attribute is added ingrumphp.yml
file ) -
Trufflehog
is now ready to sniff your secrets:)