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 | 5a3570c | 2016-08-29 19:04:12 -0400 | [diff] [blame^] | 12 | exec 3< <(grep $'\t' include/ tests/ docs/*.rst -rl) |
| 13 | while read -u 3 f; do |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 14 | if [ -z "$found" ]; then |
Jason Rhinelander | ac42789 | 2016-08-28 13:00:44 -0400 | [diff] [blame] | 15 | echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m' |
| 16 | found=1 |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 17 | errors=1 |
Jason Rhinelander | ac42789 | 2016-08-28 13:00:44 -0400 | [diff] [blame] | 18 | fi |
| 19 | |
| 20 | echo " $f" |
| 21 | done |
| 22 | |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 23 | found= |
Jason Rhinelander | 5a3570c | 2016-08-29 19:04:12 -0400 | [diff] [blame^] | 24 | exec 3< <(grep '\<\(if\|for\|while\)(' include/ tests/*.{cpp,py,h} -r --color=always) |
| 25 | while read -u 3 line; do |
Jason Rhinelander | dbc4bf6 | 2016-08-28 14:53:04 -0400 | [diff] [blame] | 26 | if [ -z "$found" ]; then |
| 27 | echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m' |
| 28 | found=1 |
| 29 | errors=1 |
| 30 | fi |
| 31 | |
| 32 | echo " $line" |
| 33 | done |
| 34 | |
| 35 | exit $errors |