lint-shell-scripts.sh 748 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "$script_path/.."
  5. if [ "$#" -eq "0" ]; then
  6. mapfile -t files < <(
  7. git ls-files -- \
  8. '*.sh' \
  9. ':!:Toolchain' \
  10. ':!:Ports' \
  11. ':!:Userland/Shell/Tests'
  12. )
  13. else
  14. files=()
  15. for file in "$@"; do
  16. if [[ "${file}" == *".sh" ]]; then
  17. files+=("${file}")
  18. fi
  19. done
  20. fi
  21. if (( ${#files[@]} )); then
  22. if ! command -v shellcheck &>/dev/null ; then
  23. echo "shellcheck is not available, but shell files need linting! Either skip this script, or install shellcheck."
  24. exit 1
  25. fi
  26. shellcheck "${files[@]}"
  27. else
  28. echo "No .sh files to check."
  29. fi