aboutsummaryrefslogtreecommitdiff
path: root/test/lint
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2018-06-12 17:48:52 +0200
committerpracticalswift <practicalswift@users.noreply.github.com>2018-06-12 21:49:04 +0200
commitc8176b3cc7556d7bcec39a55ae4d6ba16453baaa (patch)
tree54350892b613591cd3eafb8b4edfd75eedcb0183 /test/lint
parent634bd970013eca90f4b4c1f9044eec8c97ba62c2 (diff)
downloadbitcoin-c8176b3cc7556d7bcec39a55ae4d6ba16453baaa.tar.xz
Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python
Diffstat (limited to 'test/lint')
-rwxr-xr-xtest/lint/lint-python-utf8-encoding.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/lint/lint-python-utf8-encoding.sh b/test/lint/lint-python-utf8-encoding.sh
new file mode 100755
index 0000000000..ce973e710a
--- /dev/null
+++ b/test/lint/lint-python-utf8-encoding.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#
+# Make sure we explicitly open all text files using UTF-8 (or ASCII) encoding to
+# avoid potential issues on the BSDs where the locale is not always set.
+
+EXIT_CODE=0
+OUTPUT=$(git grep " open(" -- "*.py" | grep -vE "encoding=.(ascii|utf8|utf-8)." | grep -vE "open\([^,]*, ['\"][^'\"]*b[^'\"]*['\"]")
+if [[ ${OUTPUT} != "" ]]; then
+ echo "Python's open(...) seems to be used to open text files without explicitly"
+ echo "specifying encoding=\"utf8\":"
+ echo
+ echo "${OUTPUT}"
+ EXIT_CODE=1
+fi
+exit ${EXIT_CODE}