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