check-style.sh 790 Bytes
Newer Older
1
2
3
4
5
6
7
8
#!/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
#

9
10
11
errors=0
IFS=$'\n'
found=
12
13
exec 3< <(grep $'\t' include/ tests/ docs/*.rst -rl)
while read -u 3 f; do
14
    if [ -z "$found" ]; then
15
16
        echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
        found=1
17
        errors=1
18
19
20
21
22
    fi

    echo "    $f"
done

23
found=
24
25
exec 3< <(grep '\<\(if\|for\|while\)(' include/ tests/*.{cpp,py,h} -r --color=always)
while read -u 3 line; do
26
27
28
29
30
31
32
33
34
35
    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