#!/usr/bin/env bash

# Check for trailing whitespace

# Exit on first failing command.
set -e
# Exit on unset variable.
set -u

while read -r line; do
  if grep \
    "\s$" \
    --line-number \
    --with-filename \
    --binary-files=without-match \
    --exclude="*third-party*" \
    "${line}"; then
    echo "ERROR: Found trailing whitespace";
    exit 1;
  fi
done < <(git ls-files)
