lint-shell-scripts.sh 688 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. set -e pipefail
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "$script_path/.."
  5. if ! command -v shellcheck &>/dev/null ; then
  6. echo "shellcheck is not available. Either skip this script, or install shellcheck."
  7. exit 1
  8. fi
  9. ERRORS=()
  10. while IFS= read -r f; do
  11. if file "$f" | grep --quiet shell; then
  12. {
  13. shellcheck "$f" && echo -e "[\033[0;32mOK\033[0m]: successfully linted $f"
  14. } || {
  15. ERRORS+=("$f")
  16. }
  17. fi
  18. done < <(git ls-files -- \
  19. '*.sh' \
  20. ':!:Toolchain' \
  21. ':!:Ports' \
  22. ':!:Shell/Tests' \
  23. )
  24. if (( ${#ERRORS[@]} )); then
  25. echo "Files failing shellcheck: ${ERRORS[*]}"
  26. exit 1
  27. fi