Andrew Geissler | 7d6e629 | 2018-05-24 12:06:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script reformats source files using the clang-format utility. |
| 4 | # |
| 5 | # Files are changed in-place, so make sure you don't have anything open in an |
| 6 | # editor, and you may want to commit before formatting in case of awryness. |
| 7 | # |
| 8 | # This must be run on a clean repository to succeed |
| 9 | |
| 10 | DIR=$(pwd) |
| 11 | cd ${DIR} |
| 12 | |
| 13 | set -e |
| 14 | |
| 15 | echo "Formatting code under $DIR/" |
| 16 | |
Gunnar Mills | 3f48959 | 2020-06-11 13:13:17 -0500 | [diff] [blame] | 17 | : ${CLANG_FORMAT:=clang-format} |
| 18 | |
Andrew Geissler | 7d6e629 | 2018-05-24 12:06:58 -0700 | [diff] [blame] | 19 | # Only validate certain areas of the code base for |
| 20 | # formatting due to some imported code in webui |
| 21 | |
| 22 | if [ -f ".clang-format" ]; then |
Gunnar Mills | 3f48959 | 2020-06-11 13:13:17 -0500 | [diff] [blame] | 23 | $CLANG_FORMAT -i `git ls-files '*.js'` |
Andrew Geissler | 7d6e629 | 2018-05-24 12:06:58 -0700 | [diff] [blame] | 24 | git --no-pager diff --exit-code |
| 25 | fi |