check-indent.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. #
  3. # Midnight Commander - check source code indentation
  4. #
  5. # Copyright (C) 2015
  6. # The Free Software Foundation, Inc.
  7. #
  8. # Written by:
  9. # Slava Zanko <slavazanko@gmail.com>, 2015
  10. #
  11. # This file is part of the Midnight Commander.
  12. #
  13. # The Midnight Commander is free software: you can redistribute it
  14. # and/or modify it under the terms of the GNU General Public License as
  15. # published by the Free Software Foundation, either version 3 of the License,
  16. # or (at your option) any later version.
  17. #
  18. # The Midnight Commander is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU General Public License
  24. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. set -e
  26. set -x
  27. findUnindentedFiles() {
  28. local directory=$1
  29. find "${directory}" -name '*.[ch]' -print0 | \
  30. xargs -0 indent \
  31. --gnu-style \
  32. --format-first-column-comments \
  33. --indent-level4 \
  34. --brace-indent0 \
  35. --line-length100 \
  36. --no-tabs \
  37. --blank-lines-after-procedures
  38. return $(git ls-files --modified | wc -l)
  39. }
  40. ( findUnindentedFiles "lib" && findUnindentedFiles "src" && findUnindentedFiles "tests" ) || {
  41. echo "Sources not indented"
  42. git ls-files --modified
  43. exit 1
  44. }