#!/bin/sh
set -eu

ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT_DIR"

FILES=$(find Package.swift Sources Tests -type f -name '*.swift' | sort)

if [ -z "$FILES" ]; then
  echo "No Swift files found."
  exit 0
fi

if grep -n '[[:blank:]]$' $FILES; then
  echo "Trailing whitespace found."
  exit 1
fi

if grep -n "$(printf '\t')" $FILES; then
  echo "Tabs found; use spaces for Swift source indentation."
  exit 1
fi

echo "Lint passed."
