Skip to content

Commit 7f2bf64

Browse files
committed
run-codesniffer overhauled.
* Output directory changed. * Logic simplified. * Now checks Shells and Tasks. * Option stubbed to cause script to exit >0 when sniffs fail. (For future use in "strict" Travis runs.)
1 parent 3455631 commit 7f2bf64

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

run-codesniffer

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ usage ()
66
cat <<EOT
77
88
${0##*/}
9-
Convenience wrapper around code sniffing tool. If $1 is provided, a
9+
Convenience wrapper around code sniffing tool. If \$1 is provided, a
1010
summary and full reports will be generated, rather than being output
1111
to the standard output.
1212
1313
Usage:
14-
bin/${0##*/} [save reports]
14+
bin/${0##*/} [save reports?]
1515
1616
Specify 'y' as the first argument to save reports in the tmp directory,
1717
else full and summary reports are generated but not saved to a file.
@@ -30,16 +30,15 @@ umask a+rw
3030
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
3131
BIN_DIR="${DIR}/bin"
3232
TMP_DIR="${DIR}/tmp"
33-
REPORT_DIR="${TMP_DIR}/reports"
33+
REPORT_DIR="${TMP_DIR}/code-sniffs"
34+
FULL_REPORT_FILE="${REPORT_DIR}/report-full.txt"
35+
SUMMARY_REPORT_FILE="${REPORT_DIR}/report-summary.txt"
3436

35-
FULL_REPORT_FILE="${REPORT_DIR}/full-codesniff.txt"
36-
SUMMARY_REPORT_FILE="${REPORT_DIR}/summary-codesniff.txt"
37-
SNIFF_FOLDERS=("${DIR}/Controller" "${DIR}/Model" "${DIR}/View" "${DIR}/Lib")
37+
CODE_STANDARD="Vendor/loadsys/loadsys_codesniffer/Loadsys"
38+
SNIFF_FOLDERS=("${DIR}/Controller" "${DIR}/Model" "${DIR}/View" "${DIR}/Lib" "${DIR}/Console/Command")
39+
SNIFF_FAIL_CAUSES_SCRIPT_FAIL=1 # 1 = false. This script will therefore always exit 0.
3840

39-
test -n "$1"
40-
SAVE_REPORTS=$?
41-
42-
# Bail out if phpcs isn't available to us
41+
# Bail out if phpcs isn't available to us.
4342
PHPCS="$( which phpcs )"
4443
if [ $? -gt 0 ]; then
4544
PHPCS="$BIN_DIR/phpcs"
@@ -52,22 +51,28 @@ if [ $? -gt 0 ]; then
5251
fi
5352
echo "## Found phpcs at: ${PHPCS}"
5453

55-
if [ $SAVE_REPORTS ]; then
56-
# Generate Full and Summary Reports and save to a file.
54+
if [ -z "$1" ]; then
55+
echo "## Printing reports..."
56+
SAVE_REPORTS=1 # 1 = false. DON'T save reports when no args provided.
57+
COVERAGE="--report-full --report-summary"
58+
else
59+
echo "## Saving reports..."
60+
SAVE_REPORTS=0 # 0 = true. Save reports to files, not print to screen.
5761
COVERAGE="--report-full=${FULL_REPORT_FILE} --report-summary=${SUMMARY_REPORT_FILE}"
5862
mkdir -p "$REPORT_DIR"
59-
else
60-
# Generate Full and Summary Reports but print to screen.
61-
COVERAGE="--report-full --report-summary"
6263
fi
6364

64-
# Should always be available, since it is a sub-dependency of the
65-
# loadsys/cakephp-shell-scripts composer package itself.
66-
CODE_STANDARD=Vendor/loadsys/loadsys_codesniffer/Loadsys
65+
"$PHPCS" -p --extensions=php --standard="$CODE_STANDARD" ${COVERAGE} ${SNIFF_FOLDERS[@]}
66+
SNIFF_RESULT=$?
6767

68-
$PHPCS -p --extensions=php --standard="$CODE_STANDARD" ${COVERAGE} ${SNIFF_FOLDERS[@]}
69-
70-
if [ $SAVE_REPORTS ] && [ $? -eq 0 ]; then
68+
if [ $SAVE_REPORTS -eq 0 ]; then
7169
echo "## Full report created at: ${FULL_REPORT_FILE}"
7270
echo "## Summary report created at: ${SUMMARY_REPORT_FILE}"
7371
fi
72+
73+
# Exit based on whether sniff fails should count as a "failure".
74+
if [ $SNIFF_FAIL_CAUSES_SCRIPT_FAIL -eq 0 ]; then
75+
exit $SNIFF_RESULT
76+
else
77+
exit 0
78+
fi

0 commit comments

Comments
 (0)