From a4d91d28ba2f438468a3bedc3bf6a22eabfde90e Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 21 Sep 2021 14:40:55 -0400 Subject: [PATCH] Run check coding standard commands from the project root directory --- tests/check_coding_standards.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/check_coding_standards.sh b/tests/check_coding_standards.sh index 18b7b10..a830ef0 100755 --- a/tests/check_coding_standards.sh +++ b/tests/check_coding_standards.sh @@ -1,8 +1,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${SCRIPT_DIR}" +# Run commands from the project root directory. +cd .. + # Enforce line ending consistency in php files. -crlf_file=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;) +crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;) if [[ ! -z "${crlf_file}" ]]; then result="$(echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/')" echo "${result}" @@ -10,7 +13,7 @@ if [[ ! -z "${crlf_file}" ]]; then fi # Enforce indentation character consistency in php files. -tab_char=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;) +tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;) if [[ ! -z "${tab_char}" ]]; then result="$(echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/')" echo "${result}" @@ -59,14 +62,14 @@ EOF php --run "${script}" "${filename}" } export -f "find_invalid_indentation" -invalid_indentation=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;) +invalid_indentation=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;) if [[ ! -z "${invalid_indentation}" ]]; then echo "${invalid_indentation}" errors+=("${invalid_indentation}") fi # Prohibit trailing whitespace in php files. -trailing_whitespace=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H " +$" {} \;) +trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H " +$" {} \;) if [[ ! -z "${trailing_whitespace}" ]]; then result="$(echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/')" echo "${result}" @@ -74,7 +77,7 @@ if [[ ! -z "${trailing_whitespace}" ]]; then fi # Prohibit long lines in php files. -long_lines=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" ! -path "*/www/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120') +long_lines=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" ! -path "*/www/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120') if [[ ! -z "${long_lines}" ]]; then result="$(echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/')" echo "${result}" @@ -82,7 +85,7 @@ if [[ ! -z "${long_lines}" ]]; then fi # Prohibit @author in php files. -at_author=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;) +at_author=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;) if [[ ! -z "${at_author}" ]]; then result="$(echo -e "${at_author}" | perl -pe 's/^(.*)$/\@author found in \1/')" echo "${result}" @@ -90,7 +93,7 @@ if [[ ! -z "${at_author}" ]]; then fi # Prohibit screaming caps notation in php files. -caps=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H -e "FALSE[^']" -e "NULL" -e "TRUE" {} \;) +caps=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H -e "FALSE[^']" -e "NULL" -e "TRUE" {} \;) if [[ ! -z "${caps}" ]]; then result="$(echo -e "${caps}" | perl -pe 's/^(.*)$/All caps found in \1/')" echo "${result}" @@ -98,7 +101,7 @@ if [[ ! -z "${caps}" ]]; then fi # Require identical comparison operators (===, not ==) in php files. -equal=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "[^!=]==[^=]" {} \;) +equal=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "[^!=]==[^=]" {} \;) if [[ ! -z "${equal}" ]]; then result="$(echo -e "${equal}" | perl -pe 's/^(.*)$/Non-identical comparison operator found in \1/')" echo "${result}" @@ -106,7 +109,7 @@ if [[ ! -z "${equal}" ]]; then fi # Require keyword "elseif" to be used instead of "else if" so that all control keywords look like single words. -elseif=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "else\s+if" {} \;) +elseif=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "else\s+if" {} \;) if [[ ! -z "${elseif}" ]]; then result="$(echo -e "${elseif}" | perl -pe 's/^(.*)$/Found "else if" instead of "elseif" in \1/')" echo "${result}" @@ -114,7 +117,7 @@ if [[ ! -z "${elseif}" ]]; then fi # Require both braces on else statement line; "} else {" and not "}\nelse {". -elses=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp '^(\s+)?else(\s+)?{' {} \;) +elses=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp '^(\s+)?else(\s+)?{' {} \;) if [[ ! -z "${elses}" ]]; then result="$(echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/')" echo "${result}" @@ -122,7 +125,7 @@ if [[ ! -z "${elses}" ]]; then fi # Prohibit use of "is_null" and suggest using the strict comparison operator. -is_null=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H -e "is_null" {} \;) +is_null=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H -e "is_null" {} \;) if [[ ! -z "${is_null}" ]]; then result="$(echo -e "${is_null}" | perl -pe 's/^(.*)$/is_null found in \1. Replace with strict comparison (e.g. "\$x === null")./')" echo "${result}" @@ -130,8 +133,8 @@ if [[ ! -z "${is_null}" ]]; then fi # Determine which phpcs to use. -if [[ -f "../vendor/bin/phpcs" ]]; then - phpcs_to_use="../vendor/bin/phpcs" +if [[ -f "vendor/bin/phpcs" ]]; then + phpcs_to_use="vendor/bin/phpcs" else phpcs_to_use="phpcs" fi @@ -141,10 +144,10 @@ fi "${phpcs_to_use}" \ --extensions="php" \ --ignore="*/vendor/*" \ - --standard="ruleset.xml" \ + --standard="tests/ruleset.xml" \ -p \ -s \ - .. + . if [[ "${?}" -ne 0 ]]; then echo "Error: found standard violation(s)" errors+=("found standard violation(s)")