Run core development checks
Body
Introduction
Since 9.2.x, tests on DrupalCI for Drupal core run a script to check code quality as part of core test runs. The script is core/scripts/dev/commit-code-check.sh.
This script makes the following checks on the files:
- cspell - Checks spelling.
- phpcs - Checks PHP coding standards.
- eslint - Checks JavaScript coding standards.
- stylelint - Checks CSS coding standards.
- CSS & JS compiled file check - Verifies that the patch/merge request contains the correct changes for built CSS and JavaScript asset files.
- vendor - Verifies that there are no changes to
vendoras this is managed by Composer. - core/node_modules - Verifies that there are no changes to
core/node_modulesas this is managed by yarn. - file mode - Verifies that all files are file mode
644. - PHPStan - Performs static analysis on the code base to detect bugs.
When a patch or merge request fails testing and reports "Custom Commands Failed", one or more of the above checks has failed.
Run the checks locally
You will need:
- composer
- nodejs version 18.0 or later, with npm and/or corepack
- If you have an earlier version of nodejs, you may need to use nvm in order to obtain a newer version
- yarn
- via corepack if your version of nodejs includes corepack
- via npm if your version of nodejs does not include corepack
Ensure PHP and Javascript dependencies are up to date with their locked versions. Run from the Drupal root directory:
composer install cd core yarn install cd ..- The checks can be run locally. Here are some options.
Apply the change as a patch
bash ./core/scripts/dev/commit-code-check.shFrom the merge request branch
bash ./core/scripts/dev/commit-code-check.sh --branch [BRANCH_TO MERGE_TO eg. 9.2.x]If you've staged the changes.
bash ./core/scripts/dev/commit-code-check.sh --cached
Add the command to a git pre-commit hook
You can use the command in a git pre-commit hook:
#!/bin/bash
TOP_LEVEL=$(git rev-parse --show-toplevel);
# Ensure the script exists. It was introduced in 9.2.x.
if [ -a "$TOP_LEVEL/core/scripts/dev/commit-code-check.sh" ] ; then
$TOP_LEVEL/core/scripts/dev/commit-code-check.sh --cached
fiKnowledge Category