#!/bin/sh
# Checks for trailing whitespace

git grep --cached -I -n --no-color -P '[ \t]+$' -- ':/' |
awk '
    BEGIN {
        FS = ":"
        OFS = ":"
        ret = 0
    }
    {
        # Only warn for markdown files (*.md) to accomodate text editors
        # which do not properly handle trailing whitespace.
        # (e.g. GitHub web editor)
        if ($1 ~ /\.md$/) {
            severity = "WARN"
        } else {
            severity = "ERROR"
            ret = 1
        }
        print severity, $1, $2, " trailing whitespace."
    }
    END {
        exit ret
    }
'

Implement Travis CI trailing whitespace check
Implement Travis CI trailing whitespace check

While our checkstyle configuration already checks for trailing
whitespace in our java files, it does not cover all text files in our
repository. Notably: our documentation files and other configuration
files such as `build.gradle`.

While we could probably coax checkstyle and gradle to check for these
files, it is much easier to just hook onto our existing "Travis CI
checks" architecture to implement this check.

Trailing whitespace should be considered an error, however we treat
trailing whitespace in markdown (`*.md`) files as warnings instead to
accomodate developers who prefer to edit documentation using the GitHub
web interface which does not provide facilities to easily detect and
remove trailing whitespace.
