You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

3 months ago
  1. #!/bin/bash
  2. #
  3. # Script to check include/test code for common pybind11 code style errors.
  4. #
  5. # This script currently checks for
  6. #
  7. # 1. use of tabs instead of spaces
  8. # 2. MSDOS-style CRLF endings
  9. # 3. trailing spaces
  10. # 4. missing space between keyword and parenthesis, e.g.: for(, if(, while(
  11. # 5. Missing space between right parenthesis and brace, e.g. 'for (...){'
  12. # 6. opening brace on its own line. It should always be on the same line as the
  13. # if/while/for/do statment.
  14. #
  15. # Invoke as: tools/check-style.sh
  16. #
  17. errors=0
  18. IFS=$'\n'
  19. found=
  20. # The mt=41 sets a red background for matched tabs:
  21. GREP_COLORS='mt=41' GREP_COLOR='41' grep $'\t' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always |
  22. while read f; do
  23. if [ -z "$found" ]; then
  24. echo -e '\033[31m\033[01mError: found tabs instead of spaces in the following files:\033[0m'
  25. found=1
  26. errors=1
  27. fi
  28. echo " $f"
  29. done
  30. found=
  31. grep -IUlr $'\r' include tests/*.{cpp,py,h} docs/*.rst --color=always |
  32. while read f; do
  33. if [ -z "$found" ]; then
  34. echo -e '\033[31m\033[01mError: found CRLF characters in the following files:\033[0m'
  35. found=1
  36. errors=1
  37. fi
  38. echo " $f"
  39. done
  40. found=
  41. # The mt=41 sets a red background for matched trailing spaces
  42. GREP_COLORS='mt=41' GREP_COLOR='41' grep '[[:blank:]]\+$' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always |
  43. while read f; do
  44. if [ -z "$found" ]; then
  45. echo -e '\033[31m\033[01mError: found trailing spaces in the following files:\033[0m'
  46. found=1
  47. errors=1
  48. fi
  49. echo " $f"
  50. done
  51. found=
  52. grep '\<\(if\|for\|while\|catch\)(\|){' include tests/*.{cpp,py,h} -rn --color=always |
  53. while read line; do
  54. if [ -z "$found" ]; then
  55. echo -e '\033[31m\033[01mError: found the following coding style problems:\033[0m'
  56. found=1
  57. errors=1
  58. fi
  59. echo " $line"
  60. done
  61. found=
  62. GREP_COLORS='mt=41' GREP_COLOR='41' grep '^\s*{\s*$' include docs/*.rst -rn --color=always |
  63. while read f; do
  64. if [ -z "$found" ]; then
  65. echo -e '\033[31m\033[01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files: \033[0m'
  66. found=1
  67. errors=1
  68. fi
  69. echo " $f"
  70. done
  71. exit $errors