pybind11/tools/check-style.sh
Jason Rhinelander 5a3570c47c Fix check-style exit status
The check-style exit status wasn't being propagated properly because
the loops were running in a subshell (and so the change the the
`errors` variable wasn't in the active command shell).  This fixes it
by running the greps in subshells and the loops in the main shell.

This also avoids the if(/for(/while( style check on
tests/CMakeLists.txt, since it *does* have if() statements with no space
that are producing error messages, but that is (acceptable) CMake style.
2016-08-29 19:04:12 -04:00

36 lines
790 B
Bash
Executable File

#!/bin/bash
#
# Script to check include/test code for common pybind11 code style errors.
# Currently just checks for tabs used instead of spaces.
#
# Invoke as: tools/check-style.sh
#
errors=0
IFS=$'\n'
found=
exec 3< <(grep $'\t' include/ tests/ docs/*.rst -rl)
while read -u 3 f; do
if [ -z "$found" ]; then
echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
found=1
errors=1
fi
echo " $f"
done
found=
exec 3< <(grep '\<\(if\|for\|while\)(' include/ tests/*.{cpp,py,h} -r --color=always)
while read -u 3 line; do
if [ -z "$found" ]; then
echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m'
found=1
errors=1
fi
echo " $line"
done
exit $errors