Skip to content

Commit c8176b3

Browse files
Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python
1 parent 634bd97 commit c8176b3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2018 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Make sure we explicitly open all text files using UTF-8 (or ASCII) encoding to
8+
# avoid potential issues on the BSDs where the locale is not always set.
9+
10+
EXIT_CODE=0
11+
OUTPUT=$(git grep " open(" -- "*.py" | grep -vE "encoding=.(ascii|utf8|utf-8)." | grep -vE "open\([^,]*, ['\"][^'\"]*b[^'\"]*['\"]")
12+
if [[ ${OUTPUT} != "" ]]; then
13+
echo "Python's open(...) seems to be used to open text files without explicitly"
14+
echo "specifying encoding=\"utf8\":"
15+
echo
16+
echo "${OUTPUT}"
17+
EXIT_CODE=1
18+
fi
19+
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)