Skip to content

Commit 47776a9

Browse files
Add linter: Make sure all shell scripts opt out of locale dependence using "export LC_ALL=C"
1 parent 3352da8 commit 47776a9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/lint/lint-shell-locale.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 all shell scripts:
8+
# a.) explicitly opt out of locale dependence using "export LC_ALL=C", or
9+
# b.) explicitly opt in to locale dependence using the annotation below.
10+
11+
export LC_ALL=C
12+
13+
EXIT_CODE=0
14+
for SHELL_SCRIPT in $(git ls-files -- "*.sh" | grep -vE "src/(secp256k1|univalue)/"); do
15+
if grep -q "# This script is intentionally locale dependent by not setting \"export LC_ALL=C\"" "${SHELL_SCRIPT}"; then
16+
continue
17+
fi
18+
FIRST_NON_COMMENT_LINE=$(grep -vE '^(#.*|)$' "${SHELL_SCRIPT}" | head -1)
19+
if [[ ${FIRST_NON_COMMENT_LINE} != "export LC_ALL=C" ]]; then
20+
echo "Missing \"export LC_ALL=C\" (to avoid locale dependence) as first non-comment non-empty line in ${SHELL_SCRIPT}"
21+
EXIT_CODE=1
22+
fi
23+
done
24+
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)