From 97243151fae704136954f1469dde7bf45fd9cb92 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 26 Dec 2021 15:13:37 +0000 Subject: [PATCH] [TOOL] CS-fixer does not accept a list of files, so we need to run it on each file individually --- Makefile | 2 +- bin/php-cs-fixer | 7 +++---- bin/pre-commit | 10 +++------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 215b49b780..4ee0089f6c 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ test: tooling-docker docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'') cs-fixer: tooling-docker - @bin/php-cs-fixer $(call args,'') + @bin/php-cs-fixer $${CS_FIXER_FILE} doc-check: tooling-docker bin/php-doc-check diff --git a/bin/php-cs-fixer b/bin/php-cs-fixer index c1cc2f9c10..3cf9173a35 100755 --- a/bin/php-cs-fixer +++ b/bin/php-cs-fixer @@ -2,9 +2,8 @@ . bin/translate_container_name.sh -if [ "${#}" -eq 1 ]; then - docker exec "$(translate_container_name tooling_php_1)" /var/www/social/vendor/bin/php-cs-fixer -q -n --config=".php-cs-fixer.php" fix "${1}" -else - echo running without specific files? +if [ "$#" -eq 0 ] || [ -z "$*" ]; then docker exec "$(translate_container_name tooling_php_1)" /var/www/social/vendor/bin/php-cs-fixer -n --config=".php-cs-fixer.php" fix +else + docker exec "$(translate_container_name tooling_php_1)" sh -c "/var/www/social/vendor/bin/php-cs-fixer -q -n --config=\".php-cs-fixer.php\" fix --path-mode=intersection -- $*" fi diff --git a/bin/pre-commit b/bin/pre-commit index 9f3bf81f53..ce1c3a3c53 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -6,19 +6,15 @@ root="$(git rev-parse --show-toplevel)" staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")" if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then - files="" + echo "Running php-cs-fixer on edited files" for staged in ${staged_files}; do # work only with existing files if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then # use php-cs-fixer and get flag of correction - files="${staged} ${files}" + CS_FIXER_FILE="${staged}" make cs-fixer + git add "${staged}" fi done - if [ -n "${files}" ]; then - echo "Running php-cs-fixer on edited files" - make cs-fixer "${files}" - git add "${files}" - fi fi if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then