lint-swift.sh 819 B

123456789101112131415161718192021222324252627282930313233
  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. files=()
  7. while IFS= read -r file; do
  8. files+=("$file")
  9. done < <(
  10. git ls-files '*.swift'
  11. )
  12. else
  13. files=()
  14. for file in "$@"; do
  15. if [[ "${file}" == *".swift" ]] ; then
  16. files+=("${file}")
  17. fi
  18. done
  19. fi
  20. if (( ${#files[@]} )); then
  21. if ! command -v swift-format >/dev/null 2>&1 ; then
  22. echo "swift-format is not available, but Swift files need linting! Either skip this script, or install swift-format."
  23. exit 1
  24. fi
  25. swift-format -i "${files[@]}"
  26. echo "Maybe some files have changed. Sorry, but swift-format doesn't indicate what happened."
  27. else
  28. echo "No .swift files to check."
  29. fi