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.

83 lines
2.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years 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. exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
  22. while read -u 3 f; do
  23. if [ -z "$found" ]; then
  24. echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
  25. found=1
  26. errors=1
  27. fi
  28. echo " $f"
  29. done
  30. found=
  31. # The mt=41 sets a red background for matched MS-DOS CRLF line endings
  32. exec 3< <(GREP_COLORS='mt=41' grep -IUlr $'\r' include/ tests/*.{cpp,py,h} docs/*.rst --color=always)
  33. while read -u 3 f; do
  34. if [ -z "$found" ]; then
  35. echo -e '\e[31m\e[01mError: found CRLF characters in the following files:\e[0m'
  36. found=1
  37. errors=1
  38. fi
  39. echo " $f"
  40. done
  41. found=
  42. # The mt=41 sets a red background for matched trailing spaces
  43. exec 3< <(GREP_COLORS='mt=41' grep '\s\+$' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
  44. while read -u 3 f; do
  45. if [ -z "$found" ]; then
  46. echo -e '\e[31m\e[01mError: found trailing spaces in the following files:\e[0m'
  47. found=1
  48. errors=1
  49. fi
  50. echo " $f"
  51. done
  52. found=
  53. exec 3< <(grep '\<\(if\|for\|while\|catch\)(\|){' include/ tests/*.{cpp,py,h} -rn --color=always)
  54. while read -u 3 line; do
  55. if [ -z "$found" ]; then
  56. echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m'
  57. found=1
  58. errors=1
  59. fi
  60. echo " $line"
  61. done
  62. found=
  63. exec 3< <(GREP_COLORS='mt=41' grep '^\s*{\s*$' include/ docs/*.rst -rn --color=always)
  64. while read -u 3 f; do
  65. if [ -z "$found" ]; then
  66. echo -e '\e[31m\e[01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files: \e[0m'
  67. found=1
  68. errors=1
  69. fi
  70. echo " $f"
  71. done
  72. exit $errors