blob: 08b8e8645d771f5e4d98003e59955e45aafc4daa [file] [log] [blame]
Jason Rhinelanderac427892016-08-28 13:00:44 -04001#!/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 Rhinelanderdbc4bf62016-08-28 14:53:04 -04009errors=0
10IFS=$'\n'
11found=
Jason Rhinelander5a3570c2016-08-29 19:04:12 -040012exec 3< <(grep $'\t' include/ tests/ docs/*.rst -rl)
13while read -u 3 f; do
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040014 if [ -z "$found" ]; then
Jason Rhinelanderac427892016-08-28 13:00:44 -040015 echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
16 found=1
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040017 errors=1
Jason Rhinelanderac427892016-08-28 13:00:44 -040018 fi
19
20 echo " $f"
21done
22
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040023found=
Jason Rhinelander5a3570c2016-08-29 19:04:12 -040024exec 3< <(grep '\<\(if\|for\|while\)(' include/ tests/*.{cpp,py,h} -r --color=always)
25while read -u 3 line; do
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040026 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"
33done
34
35exit $errors