Untitled Diff

Criado O diff nunca expira
68 remoções
491 linhas
49 adições
476 linhas
#!/bin/bash
#!/bin/bash
#
#
# This script performs code quality checks.
# This script performs code quality checks.
#
#
# @internal
# @internal
# This script is not covered by Drupal core's backwards compatibility promise.
# This script is not covered by Drupal core's backwards compatibility promise.
# It exists only for core development purposes.
# It exists only for core development purposes.
#
#
# The script makes the following checks:
# The script makes the following checks:
# - Spell checking.
# - Spell checking.
# - File modes.
# - File modes.
# - No changes to core/node_modules directory.
# - No changes to core/node_modules directory.
# - PHPCS checks PHP and YAML files.
# - PHPCS checks PHP and YAML files.
# - PHPStan checks PHP files.
# - ESLint checks JavaScript and YAML files.
# - ESLint checks JavaScript and YAML files.
# - Checks .es6.js and .js files are equivalent.
# - Stylelint checks CSS files.
# - Stylelint checks CSS files.
# - Checks .pcss.css and .css files are equivalent.
# - Checks .pcss.css and .css files are equivalent.


# cSpell:disable
# cSpell:disable


# Searches an array.
# Searches an array.
contains_element() {
contains_element() {
local e
local e
for e in ${@:2}; do [[ "$e" == "$1" ]] && return 0; done
for e in ${@:2}; do [[ "$e" == "$1" ]] && return 0; done
return 1
return 1
}
}


CACHED=0
CACHED=0
DRUPALCI=0
DRUPALCI=0
BRANCH=""
BRANCH=""
while test $# -gt 0; do
while test $# -gt 0; do
case "$1" in
case "$1" in
-h|--help)
-h|--help)
echo "Drupal code quality checks"
echo "Drupal code quality checks"
echo " "
echo " "
echo "options:"
echo "options:"
echo "-h, --help show brief help"
echo "-h, --help show brief help"
echo "--branch BRANCH creates list of files to check by comparing against a branch"
echo "--branch BRANCH creates list of files to check by comparing against a branch"
echo "--cached checks staged files"
echo "--cached checks staged files"
echo "--drupalci a special mode for DrupalCI"
echo "--drupalci a special mode for DrupalCI"
echo " "
echo " "
echo "Example usage: sh ./core/scripts/dev/commit-code-check.sh --branch 9.2.x"
echo "Example usage: sh ./core/scripts/dev/commit-code-check.sh --branch 9.2.x"
exit 0
exit 0
;;
;;
--branch)
--branch)
BRANCH="$2"
BRANCH="$2"
if [[ "$BRANCH" == "" ]]; then
if [[ "$BRANCH" == "" ]]; then
printf "The --branch option requires a value. For example: --branch 9.2.x\n"
printf "The --branch option requires a value. For example: --branch 9.2.x\n"
exit;
exit;
fi
fi
shift 2
shift 2
;;
;;
--cached)
--cached)
CACHED=1
CACHED=1
shift
shift
;;
;;
--drupalci)
--drupalci)
DRUPALCI=1
DRUPALCI=1
shift
shift
;;
;;
*)
*)
break
break
;;
;;
esac
esac
done
done


# Set up variables to make colored output simple. Color output is disabled on
# Set up variables to make colored output simple. Color output is disabled on
# DrupalCI because it is breaks reporting.
# DrupalCI because it is breaks reporting.
# @todo https://www.drupal.org/project/drupalci_testbot/issues/3181869
# @todo https://www.drupal.org/project/drupalci_testbot/issues/3181869
if [[ "$DRUPALCI" == "1" ]]; then
if [[ "$DRUPALCI" == "1" ]]; then
red=""
red=""
green=""
green=""
reset=""
reset=""
DRUPAL_VERSION=$(php -r "include 'vendor/autoload.php'; print preg_replace('#\.[0-9]+-dev#', '.x', \Drupal::VERSION);")
DRUPAL_VERSION=$(php -r "include 'vendor/autoload.php'; print preg_replace('#\.[0-9]+-dev#', '.x', \Drupal::VERSION);")
else
else
red=$(tput setaf 1 && tput bold)
red=$(tput setaf 1 && tput bold)
green=$(tput setaf 2)
green=$(tput setaf 2)
reset=$(tput sgr0)
reset=$(tput sgr0)
fi
fi


# Gets list of files to check.
# Gets list of files to check.
if [[ "$BRANCH" != "" ]]; then
if [[ "$BRANCH" != "" ]]; then
FILES=$(git diff --name-only $BRANCH HEAD);
FILES=$(git diff --name-only $BRANCH HEAD);
elif [[ "$CACHED" == "0" ]]; then
elif [[ "$CACHED" == "0" ]]; then
# For DrupalCI patch testing or when running without --cached or --branch,
# For DrupalCI patch testing or when running without --cached or --branch,
# list of all changes in the working directory.
# list of all changes in the working directory.
FILES=$(git ls-files --other --modified --exclude-standard --exclude=vendor)
FILES=$(git ls-files --other --modified --exclude-standard --exclude=vendor)
else
else
# Check staged files only.
# Check staged files only.
if git rev-parse --verify HEAD >/dev/null 2>&1
if git rev-parse --verify HEAD >/dev/null 2>&1
then
then
AGAINST=HEAD
AGAINST=HEAD
else
else
# Initial commit: diff against an empty tree object
# Initial commit: diff against an empty tree object
AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
fi
FILES=$(git diff --cached --name-only $AGAINST);
FILES=$(git diff --cached --name-only $AGAINST);
fi
fi