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.

69 lines
1.9 KiB

  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. trailing spaces
  9. # 3. missing space between keyword and parenthesis, e.g.: for(, if(, while(
  10. # 4. opening brace on its own line. It should always be on the same line as the
  11. # if/while/for/do statment.
  12. # 5. Missing space between right parenthesis and brace, e.g. 'for (...){'
  13. #
  14. # Invoke as: tools/check-style.sh
  15. #
  16. errors=0
  17. IFS=$'\n'
  18. found=
  19. # The mt=41 sets a red background for matched tabs:
  20. exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
  21. while read -u 3 f; do
  22. if [ -z "$found" ]; then
  23. echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
  24. found=1
  25. errors=1
  26. fi
  27. echo " $f"
  28. done
  29. found=
  30. # The mt=41 sets a red background for matched trailing spaces
  31. exec 3< <(GREP_COLORS='mt=41' grep '\s\+$' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
  32. while read -u 3 f; do
  33. if [ -z "$found" ]; then
  34. echo -e '\e[31m\e[01mError: found trailing spaces in the following files:\e[0m'
  35. found=1
  36. errors=1
  37. fi
  38. echo " $f"
  39. done
  40. found=
  41. exec 3< <(GREP_COLORS='mt=41' grep '^\s*{\s*$' include/ docs/*.rst -rn --color=always)
  42. while read -u 3 f; do
  43. if [ -z "$found" ]; then
  44. 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'
  45. found=1
  46. errors=1
  47. fi
  48. echo " $f"
  49. done
  50. found=
  51. exec 3< <(grep '\<\(if\|for\|while\)(\|){' include/ tests/*.{cpp,py,h} -rn --color=always)
  52. while read -u 3 line; do
  53. if [ -z "$found" ]; then
  54. echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m'
  55. found=1
  56. errors=1
  57. fi
  58. echo " $line"
  59. done
  60. exit $errors