Files
Shipwright/scripts/check-whitespace.sh
amafresh325 94f950f8d7 German (#7315)
Co-authored-by: serprex <159546+serprex@users.noreply.github.com>
2026-10-05 16:54:09 +00:00

27 lines
752 B
Bash
Executable File

#!/bin/sh
# Fail if any C/C++ source in soh/ outside soh/include contains tabs or
# trailing whitespace. Pass --fix to strip trailing whitespace in place
# (tabs still need fixing by hand).
cd "$(dirname "$0")/.." || exit 2
# git grep over the checked sources, extra args go before the file list
grep_sources() {
git --no-pager grep "$@" -- 'soh/*.c' 'soh/*.cpp' 'soh/*.h' 'soh/*.hpp' ':!soh/include'
}
if [ "$1" = "--fix" ]; then
grep_sources -lE '[[:space:]]+$' | xargs -r sed -i -E 's/[[:space:]]+$//'
fi
status=0
if grep_sources -n "$(printf '\t')"; then
echo "replace tabs with spaces"
status=1
fi
if grep_sources -nE '[[:space:]]+$'; then
echo "remove trailing whitespace (or run with --fix)"
status=1
fi
exit $status