printf "There are no files to check. If you have staged a commit use the --cached option.\n"
printf "There are no files to check. If you have staged a commit use the --cached option.\n"
exit;
exit;
fi;
fi;
# This script assumes that composer install and yarn install have already been
# This script assumes that composer install and yarn install have already been
# run and all dependencies are updated.
# run and all dependencies are updated.
FINAL_STATUS=0
FINAL_STATUS=0
DEPENDENCIES_NEED_INSTALLING=0
DEPENDENCIES_NEED_INSTALLING=0
# Ensure PHP development dependencies are installed.
# Ensure PHP development dependencies are installed.
# @todo https://github.com/composer/composer/issues/4497 Improve this to
# @todo https://github.com/composer/composer/issues/4497 Improve this to
# determine if dependencies in the lock file match the installed versions.
# determine if dependencies in the lock file match the installed versions.
# Using composer install --dry-run is not valid because it would depend on
# Using composer install --dry-run is not valid because it would depend on
# user-facing strings in Composer.
# user-facing strings in Composer.
if ! [[ -f 'vendor/bin/phpcs' ]]; then
if ! [[ -f 'vendor/bin/phpcs' ]]; then
printf "Drupal's PHP development dependencies are not installed. Run 'composer install' from the root directory.\n"
printf "Drupal's PHP development dependencies are not installed. Run 'composer install' from the root directory.\n"
DEPENDENCIES_NEED_INSTALLING=1;
DEPENDENCIES_NEED_INSTALLING=1;
fi
fi
cd "$TOP_LEVEL/core"
cd "$TOP_LEVEL/core"
# Ensure JavaScript development dependencies are installed.
# Ensure JavaScript development dependencies are installed.
yarn check -s 2>/dev/null
yarn check -s 2>/dev/null
if [ "$?" -ne "0" ]; then
if [ "$?" -ne "0" ]; then
printf "Drupal's JavaScript development dependencies are not installed or cannot be resolved. Run 'yarn install' inside the core directory, or 'yarn check -s' to list other errors.\n"
printf "Drupal's JavaScript development dependencies are not installed or cannot be resolved. Run 'yarn install' inside the core directory, or 'yarn check -s' to list other errors.\n"
DEPENDENCIES_NEED_INSTALLING=1;
DEPENDENCIES_NEED_INSTALLING=1;
fi
fi
if [ $DEPENDENCIES_NEED_INSTALLING -ne 0 ]; then
if [ $DEPENDENCIES_NEED_INSTALLING -ne 0 ]; then
exit 1;
exit 1;
fi
fi
# Check all files for spelling in one go for better performance.
# Check all files for spelling in one go for better performance.
yarn run -s spellcheck --no-must-find-files -c $TOP_LEVEL/core/.cspell.json $ABS_FILES
yarn run -s spellcheck --no-must-find-files -c $TOP_LEVEL/core/.cspell.json $ABS_FILES
if [ "$?" -ne "0" ]; then
if [ "$?" -ne "0" ]; then
# If there are failures set the status to a number other than 0.
# If there are failures set the status to a number other than 0.
FINAL_STATUS=1
FINAL_STATUS=1
printf "\nCSpell: ${red}failed${reset}\n"
printf "\nCSpell: ${red}failed${reset}\n"
else
else
printf "\nCSpell: ${green}passed${reset}\n"
printf "\nCSpell: ${green}passed${reset}\n"
fi
fi
cd "$TOP_LEVEL"
cd "$TOP_LEVEL"
# Add a separator line to make the output easier to read.
# Add a separator line to make the output easier to read.
printf "\n"
printf "\n"
printf -- '-%.0s' {1..100}
printf -- '-%.0s' {1..100}
printf "\n"
printf "\n"
# When the file core/phpcs.xml.dist has been changed, then PHPCS must check all files.
# Run PHPStan on all files on DrupalCI or when phpstan files are changed.
if [[ $PHPCS_XML_DIST_FILE_CHANGED == "1" ]]; then
# APCu is disabled to ensure that the composer classmap is not corrupted.
if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]] || [[ "$DRUPALCI" == "1" ]]; then