Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdn
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
cdn
Merge requests
!10
Issue
#3347168
: Match core's code quality checks
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Issue
#3347168
: Match core's code quality checks
issue/cdn-3347168:3347168-match-core-quality-checks
into
4.x
Overview
0
Commits
2
Pipelines
0
Changes
6
Closed
Wim Leers
requested to merge
issue/cdn-3347168:3347168-match-core-quality-checks
into
4.x
2 years ago
Overview
0
Commits
2
Pipelines
0
Changes
6
Expand
0
0
Merge request reports
Compare
4.x
version 1
1ff8fce0
2 years ago
4.x (base)
and
latest version
latest version
66604163
2 commits,
2 years ago
version 1
1ff8fce0
1 commit,
2 years ago
6 files
+
145
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
scripts/commit-code-check.sh
0 → 100755
+
120
−
0
Options
#!/usr/bin/env bash
# NAME
# commit-code-check.sh - Run all code quality checks.
#
# SYNOPSIS
# bash scripts/commit-code-check.sh
#
# DESCRIPTION
# Performs the following quality checks, closely matching core's commit-code-check.sh:
# - Spell checking.
# - PHPCS checks PHP and YAML files.
# - PHPStan checks PHP files.
# - ESLint checks YAML files.
# cSpell:disable
cd
"
$(
dirname
"
$0
"
)
/../"
||
exit
;
DRUPALCI
=
0
while
test
$#
-gt
0
;
do
case
"
$1
"
in
-h
|
--help
)
echo
"Drupal code quality checks"
echo
" "
echo
"options:"
echo
"-h, --help show brief help"
echo
"--drupalci a special mode for DrupalCI"
echo
" "
exit
0
;;
--drupalci
)
DRUPALCI
=
1
shift
;;
*
)
break
;;
esac
done
MODULE_DIRECTORY
=
$(
pwd
)
# Find the site root directory. Check up to three directories above.
DIR
=
$(
pwd
)
for
i
in
{
0..3
}
;
do
DIR
=
$(
dirname
"
$DIR
"
)
if
test
-f
"
$DIR
/core/composer.json"
;
then
CORE_DIRECTORY
=
"
$DIR
"
break
fi
done
# Set up variables to make colored output simple. Color output is disabled on
# DrupalCI because it is breaks reporting.
# @todo https://www.drupal.org/project/drupalci_testbot/issues/3181869
if
[[
"
$DRUPALCI
"
==
"1"
]]
;
then
red
=
""
green
=
""
reset
=
""
else
red
=
$(
tput setaf 1
&&
tput bold
)
green
=
$(
tput setaf 2
)
title
=
$(
tput setaf 4
&&
tput bold
)
reset
=
$(
tput sgr0
)
fi
# This script assumes that composer install and yarn install have already been
# run and all dependencies are updated.
FINAL_STATUS
=
0
print_separator
()
{
printf
"
\n
${
title
}
"
printf
--
'-%.0s'
{
1..100
}
printf
"
${
reset
}
\n
"
}
print_title
()
{
print_separator
printf
"
${
title
}
$1
${
reset
}
"
print_separator
}
print_results
()
{
RESULTS
=
$1
LABEL
=
$2
if
[
"
$RESULTS
"
-ne
"0"
]
;
then
# If there are failures set the status to a number other than 0.
FINAL_STATUS
=
1
printf
"
\n
${
title
}
$LABEL
:
${
red
}
failed
${
reset
}
\n
"
else
printf
"
\n
${
title
}
$LABEL
:
${
green
}
passed
${
reset
}
\n
"
fi
}
print_title
"[1/4] PHPCS"
$CORE_DIRECTORY
/vendor/bin/phpcs
$MODULE_DIRECTORY
-ps
--standard
=
"
$CORE_DIRECTORY
/core/phpcs.xml.dist"
print_results
$?
"PHPCS"
print_title
"[2/4] PHPStan"
php
-d
apc.enabled
=
0
-d
apc.enable_cli
=
0
$CORE_DIRECTORY
/vendor/bin/phpstan analyze
--no-progress
--configuration
=
"
$MODULE_DIRECTORY
/phpstan.neon.dist"
$MODULE_DIRECTORY
print_results
$?
"PHPStan"
print_title
"[3/4] CSpell"
cd
$CORE_DIRECTORY
/core
&&
yarn run
-s
spellcheck
--no-progress
--root
$MODULE_DIRECTORY
-c
.cspell.json
"**"
&&
cd
-
print_results
$?
"CSpell"
print_title
"[4/4] eslint:yaml"
cd
$CORE_DIRECTORY
/core
&&
yarn eslint
--resolve-plugins-relative-to
.
--ext
.yml
$MODULE_DIRECTORY
&&
cd
-
print_results
$?
"eslint:yaml"
print_separator
if
[[
"
$FINAL_STATUS
"
==
"1"
]]
;
then
printf
"
${
red
}
Drupal code quality checks failed.
${
reset
}
"
if
[[
"
$DRUPALCI
"
==
"1"
]]
;
then
printf
"
\n
To reproduce this output locally:
\n
"
printf
"* Apply the change as a patch, or from the merge request branch
\n
"
printf
"* Run this command locally: sh ./scripts/commit-code-check.sh"
fi
print_separator
fi
exit
$FINAL_STATUS
Loading