summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-01-26 18:52:44 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-01-27 11:44:16 +0100
commit62ea1f21858c69f6921c775ba7a3de201f0514d8 (patch)
tree7a4da88706e8a5513e1e13e993b2acc212cae3b1 /scripts
parenta662508ddde4043ece36d8ea9b424368891d892c (diff)
downloadqtlocation-mapboxgl-62ea1f21858c69f6921c775ba7a3de201f0514d8.tar.gz
[core] remove trailing whitespace, add trailing newlines, add space after //
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/codestyle.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/codestyle.sh b/scripts/codestyle.sh
new file mode 100755
index 0000000000..3ed74f17c2
--- /dev/null
+++ b/scripts/codestyle.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+# Treats all characters as bytes, removes Unicode awareness from (broken?) macOS sed.
+export LC_ALL=C
+
+if [ `uname -s` = 'Darwin' ]; then
+ # BSD sed accepts a file extension.
+ SED="sed -i''"
+else
+ # GNU sed does not.
+ SED="sed -i"
+fi
+
+# Gather list of files
+FILES=$(git ls-files "*.hpp" "*.cpp" "*.h" "*.mm" "*.m" "*.c" "*.java" "*.xml" "*.ejs" "*.gradle" |
+ sed '/^platform\/android\/MapboxGLAndroidSDK\/src\/main\/java\/com\/almeros\// d;/^src\/clipper\// d;/^platform\/ios\/uitest\/OCMock/d')
+
+# Adds trailing newlines to files.
+echo "Checking for missing trailing newlines..."
+echo "${FILES}" | tr '\n' '\0' | xargs -0 ${SED} -e '$a\'
+
+# Removes trailing whitespace.
+echo "Checking for trailing whitespace..."
+echo "${FILES}" | tr '\n' '\0' | xargs -0 ${SED} 's/ *$// '
+
+# Add space after // comments. Does not replace // within double quotes.
+# Part of the regex is from http://stackoverflow.com/a/11503678
+echo "Checking for missing spaces after comments..."
+echo "${FILES}" | tr '\n' '\0' | xargs -0 perl -p -i -e 's/(?<!(:|\/))\/\/(?=[^ \/\n])(?=(?:[^"]*"[^"]*")*[^"]*\Z)/\/\/ /g'
+
+git diff --exit-code -- ${FILES} || {
+ echo "Some files were modified during code style checking."
+ exit 1
+}