check-style.sh 878 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
# The mt=41 sets a red background for matched tabs:
exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/ docs/*.rst -rn --color=always)
14
while read -u 3 f; do
15
    if [ -z "$found" ]; then
16
17
        echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
        found=1
18
        errors=1
19
20
21
22
23
    fi

    echo "    $f"
done

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