check-nl-at-eof.sh 650 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. cd -P -- "$(dirname -- "$0")/.."
  4. nl_at_eof() {
  5. local file="$1"
  6. if ! [ -f "$file" ]; then
  7. return
  8. fi
  9. case "$file" in
  10. *.png|*rebar3)
  11. return
  12. ;;
  13. scripts/erlfmt)
  14. return
  15. ;;
  16. *.jks)
  17. return
  18. ;;
  19. esac
  20. local lastbyte
  21. lastbyte="$(tail -c 1 "$file" 2>&1)"
  22. if [ "$lastbyte" != '' ]; then
  23. echo "$file"
  24. return 1
  25. fi
  26. }
  27. n=0
  28. while read -r file; do
  29. if ! nl_at_eof "$file"; then
  30. echo "nl_at_eof: $file"
  31. n=$(( n + 1 ))
  32. fi
  33. done < <(git ls-files)
  34. exit $n