summaryrefslogtreecommitdiff
path: root/.ci/scripts/format/script.sh
diff options
context:
space:
mode:
Diffstat (limited to '.ci/scripts/format/script.sh')
-rw-r--r--.ci/scripts/format/script.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/.ci/scripts/format/script.sh b/.ci/scripts/format/script.sh
new file mode 100644
index 000000000..5ab828d5e
--- /dev/null
+++ b/.ci/scripts/format/script.sh
@@ -0,0 +1,37 @@
1#!/bin/bash -ex
2
3if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \
4 dist/*.svg dist/*.xml; then
5 echo Trailing whitespace found, aborting
6 exit 1
7fi
8
9# Default clang-format points to default 3.5 version one
10CLANG_FORMAT=clang-format-6.0
11$CLANG_FORMAT --version
12
13if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
14 # Get list of every file modified in this pull request
15 files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)"
16else
17 # Check everything for branch pushes
18 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
19fi
20
21# Turn off tracing for this because it's too verbose
22set +x
23
24for f in $files_to_lint; do
25 d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
26 if ! [ -z "$d" ]; then
27 echo "!!! $f not compliant to coding style, here is the fix:"
28 echo "$d"
29 fail=1
30 fi
31done
32
33set -x
34
35if [ "$fail" = 1 ]; then
36 exit 1
37fi