Add a simple bashfmt test
If someone ever made a bashfmt script, that would be a lovely hack!
This commit is contained in:
31
test/test-bashfmt.sh
Executable file
31
test/test-bashfmt.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# check for any bash files that aren't properly formatted
|
||||
# TODO: this is hardly exhaustive
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
|
||||
cd "${ROOT}"
|
||||
|
||||
find_files() {
|
||||
git ls-files | grep -e '\.sh$' -e '\.bash$'
|
||||
}
|
||||
|
||||
bad_files=$(
|
||||
for i in $(find_files); do
|
||||
# search for more than one leading space, to ensure we use tabs
|
||||
if grep -q '^ ' "$i"; then
|
||||
echo "$i"
|
||||
fi
|
||||
done
|
||||
)
|
||||
|
||||
if [[ -n "${bad_files}" ]]; then
|
||||
echo 'FAIL'
|
||||
echo 'The following bash files are not properly formatted:'
|
||||
echo "${bad_files}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user