lint-prettier.sh 880 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. set -e
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "${script_path}/.." || exit 1
  5. if [ "$#" -eq "0" ]; then
  6. mapfile -t files < <(
  7. git ls-files \
  8. --exclude-from .prettierignore \
  9. -- \
  10. '*.js'
  11. )
  12. else
  13. files=()
  14. for file in "$@"; do
  15. if [[ "${file}" == *".js" ]]; then
  16. files+=("${file}")
  17. fi
  18. done
  19. fi
  20. if (( ${#files[@]} )); then
  21. if ! command -v prettier >/dev/null 2>&1 ; then
  22. echo "prettier is not available, but JS files need linting! Either skip this script, or install prettier."
  23. exit 1
  24. fi
  25. if ! prettier --version | grep -qF '2.' ; then
  26. echo "You are using '$(prettier --version)', which appears to not be prettier 2."
  27. exit 1
  28. fi
  29. prettier --check "${files[@]}"
  30. else
  31. echo "No .js files to check."
  32. fi