php强制对齐,[强迫症福利] 使用 PHPStorm 对齐数组的键值对
用 php-cs-fixer 自動(dòng)格式化,一個(gè)配置配合 Git 自動(dòng)格式化,補(bǔ)充樓上。
示例 Git Hook
忽略前端的代碼格式化,修改一下就可以用。
#!/bin/bash
#
# check PHP code syntax error and standard with phpcs
# https://blog.csdn.net/xsgnzb/article/details/52222366?locationNum=4&fps=1
# https://blog.csdn.net/ljihe/article/details/80826071
# =================== how to use ====================
# cp ./build/pre-commit.sh ./.git/hooks/pre-commit
# chmod 777 ./.git/hooks/pre-commit
# git commit -h
# git commit -n -m 'pass hook' #bypass pre-commit and commit-msg hooks
# ==================== end ==========================
PROJECT=$(git rev-parse --show-toplevel)
cd $PROJECT
SFILES=$(git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\.php$)
# Determine if a file list is passed
if [ "$#" -ne 0 ]
then
exit 0
fi
echo "Checking PHP Lint..."
for FILE in $SFILES
do
php -l -d display_errors=0 $FILE
if [ $? != 0 ]
then
echo "Fix the php error before commit."
exit 1
fi
FILES="$FILES $PROJECT/$FILE"
done
phpcsfixer_path=$(cd `dirname $0`; pwd)"/../../build/php-cs-fixer"
gulp_path=$(cd `dirname $0`; pwd)"/../../frontend/node_modules/.bin/gulp"
prettier_path=$(cd `dirname $0`; pwd)"/../../frontend/node_modules/.bin/prettier"
# format code style
if [ "$FILES" != "" ]
then
echo "Running Code Sniffer..."
isCheck=""
for FILE in $SFILES
do
IGNORE_PATH=(
'vendor'
)
for IGNORE_ITEM in ${IGNORE_PATH[@]}
do
if [[ ${FILE} =~ ${IGNORE_ITEM} ]]
then
echo "Ignore file of "${IGNORE_ITEM}
continue 2
fi
done
#result=`~/.composer/vendor/bin/php-cs-fixer fix $FILE --config=.php_cs.dist`
#result=`php-cs-fixer fix $FILE --config=.php_cs.dist`
result=`php $phpcsfixer_path fix $FILE --config=.php_cs.dist`
if [ "$result" != "" ]
then
echo $result
isCheck=$result
git add $FILE
fi
done
if [ "$isCheck" != "" ]
then
echo "The file has been automatically formatted."
fi
fi
# for js
jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" "*.vue" "*.css" "*.less" | tr '\n' ' ')
[ -z "$jsfiles" ] && exit 0
# format iview
$gulp_path iview --gulpfile frontend/gulpfile.js
# Prettify all staged .js files
echo "$jsfiles" | xargs $prettier_path --config frontend/.prettierrc.js --ignore-path frontend/.prettierignore --write
# Add back the modified/prettified files to staging
echo "$jsfiles" | xargs git add
git update-index -g
exit $?
總結(jié)
以上是生活随笔為你收集整理的php强制对齐,[强迫症福利] 使用 PHPStorm 对齐数组的键值对的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑一族该怎样保护眼睛电脑如何护眼模式
- 下一篇: ajax php 动态,jQuery+P