blob: 1bc8b32690fc7778719dc20532018cff167b2acd [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 Rhinelanderd472f0f2016-08-29 20:59:48 -040012# The mt=41 sets a red background for matched tabs:
Wenzel Jakob85f07e12016-09-04 23:00:49 +090013exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
Jason Rhinelander5a3570c2016-08-29 19:04:12 -040014while read -u 3 f; do
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040015 if [ -z "$found" ]; then
Jason Rhinelanderac427892016-08-28 13:00:44 -040016 echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
17 found=1
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040018 errors=1
Jason Rhinelanderac427892016-08-28 13:00:44 -040019 fi
20
21 echo " $f"
22done
23
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040024found=
Wenzel Jakob85f07e12016-09-04 23:00:49 +090025exec 3< <(grep '\<\(if\|for\|while\)(\|){' include/ tests/*.{cpp,py,h} -rn --color=always)
Jason Rhinelander5a3570c2016-08-29 19:04:12 -040026while read -u 3 line; do
Jason Rhinelanderdbc4bf62016-08-28 14:53:04 -040027 if [ -z "$found" ]; then
28 echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m'
29 found=1
30 errors=1
31 fi
32
33 echo " $line"
34done
35
36exit $errors