Jason Rhinelander | ac42789 | 2016-08-28 13:00:44 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Script to check include/test code for common pybind11 code style errors. |
| 4 | # Currently just checks for tabs used instead of spaces. |
| 5 | # |
| 6 | # Invoke as: tools/check-style.sh |
| 7 | # |
| 8 | |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 9 | errors=0 |
| 10 | IFS=$'\n' |
| 11 | found= |
Jason Rhinelander | d472f0f | 2016-08-29 20:59:48 -0400 | [diff] [blame] | 12 | # The mt=41 sets a red background for matched tabs: |
Wenzel Jakob | 85f07e1 | 2016-09-04 23:00:49 +0900 | [diff] [blame^] | 13 | exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always) |
Jason Rhinelander | 5a3570c | 2016-08-29 19:04:12 -0400 | [diff] [blame] | 14 | while read -u 3 f; do |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 15 | if [ -z "$found" ]; then |
Jason Rhinelander | ac42789 | 2016-08-28 13:00:44 -0400 | [diff] [blame] | 16 | echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m' |
| 17 | found=1 |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 18 | errors=1 |
Jason Rhinelander | ac42789 | 2016-08-28 13:00:44 -0400 | [diff] [blame] | 19 | fi |
| 20 | |
| 21 | echo " $f" |
| 22 | done |
| 23 | |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 24 | found= |
Wenzel Jakob | 85f07e1 | 2016-09-04 23:00:49 +0900 | [diff] [blame^] | 25 | exec 3< <(grep '\<\(if\|for\|while\)(\|){' include/ tests/*.{cpp,py,h} -rn --color=always) |
Jason Rhinelander | 5a3570c | 2016-08-29 19:04:12 -0400 | [diff] [blame] | 26 | while read -u 3 line; do |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 27 | if [ -z "$found" ]; then |
| 28 | echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m' |
| 29 | found=1 |
| 30 | errors=1 |
| 31 | fi |
| 32 | |
| 33 | echo " $line" |
| 34 | done |
| 35 | |
| 36 | exit $errors |