Split formatters, add dry run exit codes
This commit is contained in:
parent
e664352139
commit
6b856f9731
18
src/entry.sh
18
src/entry.sh
@ -46,6 +46,24 @@ main() {
|
|||||||
process
|
process
|
||||||
return $?
|
return $?
|
||||||
;;
|
;;
|
||||||
|
prettier)
|
||||||
|
__initVariables "$@"
|
||||||
|
source ${INCLUDES_PATH}/prettier.shinc
|
||||||
|
__prettier
|
||||||
|
return $?
|
||||||
|
;;
|
||||||
|
csscomb)
|
||||||
|
__initVariables "$@"
|
||||||
|
source ${INCLUDES_PATH}/csscomb.shinc
|
||||||
|
__csscomb
|
||||||
|
return $?
|
||||||
|
;;
|
||||||
|
php-cs-fixer)
|
||||||
|
__initVariables "$@"
|
||||||
|
source ${INCLUDES_PATH}/php-cs-fixer.shinc
|
||||||
|
__phpFixer
|
||||||
|
return $?
|
||||||
|
;;
|
||||||
help|--help|-h)
|
help|--help|-h)
|
||||||
usage
|
usage
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
14
src/inc/formatters/csscomb.shinc
Normal file
14
src/inc/formatters/csscomb.shinc
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
__csscomb() {
|
||||||
|
__msg "Csscomb:"
|
||||||
|
|
||||||
|
if [[ ${DRY_RUN} -eq 0 ]]; then
|
||||||
|
csscomb -v "$@"
|
||||||
|
else
|
||||||
|
csscomb --lint -v "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $?
|
||||||
|
}
|
||||||
57
src/inc/formatters/php-cs-fixer.shinc
Normal file
57
src/inc/formatters/php-cs-fixer.shinc
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
__phpFixer() {
|
||||||
|
local failed=0
|
||||||
|
|
||||||
|
__msg "PHP-cs-fixer"
|
||||||
|
|
||||||
|
# Cannot chain php files without specifying a config CS file :(
|
||||||
|
if [[ ${DRY_RUN} -eq 0 ]]; then
|
||||||
|
for file in "${PHP_FILES[@]}"; do
|
||||||
|
php-cs-fixer fix "${file}"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
local needs_fixing=()
|
||||||
|
local invalid_syntax=()
|
||||||
|
|
||||||
|
for file in "${PHP_FILES[@]}"; do
|
||||||
|
php-cs-fixer fix --dry-run "${file}"
|
||||||
|
case $? in
|
||||||
|
0)
|
||||||
|
#all good
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
invalid_syntax+=("${file}")
|
||||||
|
;;
|
||||||
|
8)
|
||||||
|
needs_fixing+=("${file}")
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__err "There was an error with php-cs-fixer configuration"
|
||||||
|
failed=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#needs_fixing[@]} -gt 0 ]]; then
|
||||||
|
failed=1
|
||||||
|
|
||||||
|
__err "Needs fixing:" 1
|
||||||
|
for file in "${needs_fixing[@]}"; do
|
||||||
|
__msg "${file}" 2
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${#invalid_syntax[@]} -gt 0 ]]; then
|
||||||
|
failed=1
|
||||||
|
|
||||||
|
__err "Invalid syntax:" 1
|
||||||
|
for file in "${invalid_syntax[@]}"; do
|
||||||
|
__msg "${file}" 2
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
return ${failed}
|
||||||
|
}
|
||||||
15
src/inc/formatters/prettier.shinc
Normal file
15
src/inc/formatters/prettier.shinc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
__prettier() {
|
||||||
|
__msg "Prettier:"
|
||||||
|
|
||||||
|
if [[ ${DRY_RUN} -eq 0 ]]; then
|
||||||
|
prettier --write "$@"
|
||||||
|
else
|
||||||
|
__msg "Listing (: unprettiered :) files:" 1
|
||||||
|
prettier --list-different "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $?
|
||||||
|
}
|
||||||
@ -1,54 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
source ${INCLUDES_PATH}/formatters/prettier.shinc
|
||||||
__csscomb() {
|
source ${INCLUDES_PATH}/formatters/csscomb.shinc
|
||||||
if [[ ${DRY_RUN} -eq 0 ]]; then
|
source ${INCLUDES_PATH}/formatters/php-cs-fixer.shinc
|
||||||
csscomb "$@"
|
|
||||||
else
|
|
||||||
csscomb --lint "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__prettier() {
|
|
||||||
if [[ ${DRY_RUN} -eq 0 ]]; then
|
|
||||||
prettier --write "$@"
|
|
||||||
else
|
|
||||||
prettier --list-different "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
__phpFixer() {
|
|
||||||
# Cannot chain php files without specifying a config CS file :(
|
|
||||||
if [[ ${DRY_RUN} -eq 0 ]]; then
|
|
||||||
for file in "${PHP_FILES[@]}"; do
|
|
||||||
php-cs-fixer fix "${file}"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
for file in "${PHP_FILES[@]}"; do
|
|
||||||
php-cs-fixer fix --dry-run "${file}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
process() {
|
process() {
|
||||||
|
local failed=0
|
||||||
|
|
||||||
# Run css comb
|
# Run css comb
|
||||||
if [[ ${#CSS_FILES[@]} -ne 0 ]]; then
|
if [[ ${#CSS_FILES[@]} -ne 0 ]]; then
|
||||||
__csscomb "${CSS_FILES[@]}"
|
__csscomb "${CSS_FILES[@]}"
|
||||||
|
[[ $? -ne 0 ]] && failed=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run JS prettier
|
# Run JS prettier
|
||||||
if [[ ${#JS_FILES[@]} -ne 0 ]]; then
|
if [[ ${#JS_FILES[@]} -ne 0 ]]; then
|
||||||
__prettier --write "${JS_FILES[@]}"
|
__prettier "${JS_FILES[@]}"
|
||||||
|
[[ $? -ne 0 ]] && failed=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run PHP cs fixer
|
# Run PHP cs fixer
|
||||||
if [[ ${#PHP_FILES[@]} -ne 0 ]]; then
|
if [[ ${#PHP_FILES[@]} -ne 0 ]]; then
|
||||||
__phpFixer ${PHP_FILES[@]}
|
__phpFixer ${PHP_FILES[@]}
|
||||||
|
[[ $? -ne 0 ]] && failed=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return ${failed}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ __initVariables() {
|
|||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
__err "Specified path does not exist: ${1}"
|
__err "Specified path does not exist: ${1}"
|
||||||
else
|
else
|
||||||
CSS_FILES+=(${1})
|
CSS_FILES+=("${1}")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*.js|*.jsx)
|
*.js|*.jsx)
|
||||||
@ -34,7 +34,7 @@ __initVariables() {
|
|||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
__err "Specified path does not exist: ${1}"
|
__err "Specified path does not exist: ${1}"
|
||||||
else
|
else
|
||||||
JS_FILES+=(${1})
|
JS_FILES+=("${1}")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*.php|*.phtml)
|
*.php|*.phtml)
|
||||||
@ -42,7 +42,7 @@ __initVariables() {
|
|||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
__err "Specified path does not exist: ${1}"
|
__err "Specified path does not exist: ${1}"
|
||||||
else
|
else
|
||||||
PHP_FILES+=(${1})
|
PHP_FILES+=("${1}")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user