check_code_format.sh 750 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. #
  3. # Script to determine if .js files in Pull Request are properly formatted.
  4. # Exits with non 0 exit code if formatting is needed.
  5. FILES_TO_CHECK=$(git diff --name-only master | grep -E "\.js$")
  6. if [ -z "${FILES_TO_CHECK}" ]; then
  7. echo "No .js files to check for formatting."
  8. exit 0
  9. fi
  10. FORMAT_DIFF=$(git diff -U0 master -- ${FILES_TO_CHECK} |
  11. ../clang/share/clang/clang-format-diff.py -p1 -style=Google)
  12. if [ -z "${FORMAT_DIFF}" ]; then
  13. # No formatting necessary.
  14. echo "All files in PR properly formatted."
  15. exit 0
  16. else
  17. # Found diffs.
  18. echo "ERROR: Found formatting errors!"
  19. echo "${FORMAT_DIFF}"
  20. echo "See https://goo.gl/wUEkW9 for instructions to format your PR."
  21. exit 1
  22. fi