Skip to content

Commit 258b7e2

Browse files
committed
Add Shellcheck
This adds [Shellcheck](https://www.shellcheck.net) to: - `make lint` - Circle CI - pre-commit config All reported warnings are fixed.
1 parent d99ec08 commit 258b7e2

21 files changed

+225
-157
lines changed

.circleci/conditional_skip.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ set +e
66

77
SKIP_TAG="\[skip tests\]"
88

9-
if [[ ! -z ${CIRCLE_TAG} ]]; then
9+
# shellcheck disable=SC2154
10+
if [[ -n ${CIRCLE_TAG} ]]; then
1011
# TAG build - never skip those
1112
echo "Tagged commit, not skipping build"
1213
exit 0
1314
fi
1415

16+
# shellcheck disable=SC2154
1517
if [[ -z ${CIRCLE_PR_NUMBER} ]]; then
1618
# Not a PR, also never skip
1719
echo "Not a PR, not skipping build"
@@ -20,7 +22,7 @@ fi
2022

2123
if [[ -a ~/.local/BASE_COMMIT ]]; then
2224
# The is a PR and we know the base commit (see fetch_pr_base_commit.sh)
23-
LOG_RANGE="$(cat ~/.local/BASE_COMMIT)..${CIRCLE_SHA1}"
25+
LOG_RANGE="$(cat ~/.local/BASE_COMMIT)..${CIRCLE_SHA1:?}"
2426
else
2527
# Otherwise just look at the HEAD commit
2628
LOG_RANGE="-1"

.circleci/config.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ templates:
5353
SOLC_VERSION: 'v0.6.3'
5454

5555

56+
orbs:
57+
shellcheck: circleci/[email protected]
58+
5659
executors:
5760
docker:
5861
parameters:
@@ -696,6 +699,11 @@ workflows:
696699
requires:
697700
- prepare-system-linux
698701

702+
- shellcheck/check:
703+
name: shellcheck
704+
requires:
705+
- prepare-system-linux
706+
699707
- lint:
700708
name: lint-3.7
701709
py-version: "3.7"
@@ -789,6 +797,7 @@ workflows:
789797
- test-unit-3.7
790798
- test-fuzz-3.7
791799
- test-mocked-3.7
800+
- shellcheck
792801

793802
- test:
794803
name: test-integration-matrix-parity-3.7
@@ -807,6 +816,7 @@ workflows:
807816
- test-unit-3.7
808817
- test-fuzz-3.7
809818
- test-mocked-3.7
819+
- shellcheck
810820

811821
- finalize:
812822
requires:
@@ -928,6 +938,11 @@ workflows:
928938
requires:
929939
- prepare-system-linux
930940

941+
- shellcheck/check:
942+
name: shellcheck
943+
requires:
944+
- prepare-system-linux
945+
931946
- lint:
932947
name: lint-3.7
933948
py-version: "3.7"
@@ -1021,7 +1036,7 @@ workflows:
10211036
- test-unit-3.7
10221037
- test-fuzz-3.7
10231038
- test-mocked-3.7
1024-
1039+
- shellcheck
10251040

10261041
- test:
10271042
name: test-integration-matrix-parity-3.7
@@ -1040,6 +1055,7 @@ workflows:
10401055
- test-unit-3.7
10411056
- test-fuzz-3.7
10421057
- test-mocked-3.7
1058+
- shellcheck
10431059

10441060
- finalize:
10451061
requires:

.circleci/enforce_decreasing_lint_errors.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ function compare_pylint_reports() {
4444
previous_error_count=$(wc -l "${old}" | cut '-d ' -f1)
4545

4646
if [[ $new_error_count -gt $previous_error_count ]]; then
47-
diff ${old} ${new}
47+
diff "${old}" "${new}"
4848

4949
# DO NOT overwrite the old report in the cache, we want to keep the
5050
# version with the lower number of errors
5151
else
5252
# This PR fixed errors, move the new report over the old one to enforce
5353
# a new lower bound on the number of errors
54-
mv ${new} ${old}
54+
mv "${new}" "${old}"
5555
fi
5656
else
5757
# Save the report to compare on subsequent runs
58-
mv ${new} ${old}
58+
mv "${new}" "${old}"
5959
fi
6060
}
6161

@@ -74,17 +74,17 @@ function compare_mypy_reports() {
7474
fi
7575

7676
if [[ -e "${old}" ]]; then
77-
if ! ./.circleci/lint_report.py ${old} ${new}; then
77+
if ! ./.circleci/lint_report.py "${old}" "${new}"; then
7878
# DO NOT overwrite the old report in the cache, we want to keep the
7979
# version with the lower number of errors
8080
#
8181
# If this PR fixed errors, move the new report over the old one to
8282
# enforce a new lower bound on the number of errors
83-
mv ${new} ${old}
83+
mv "${new}" "${old}"
8484
fi
8585
else
8686
# Save the report to compare on subsequent runs
87-
mv ${new} ${old}
87+
mv "${new}" "${old}"
8888
fi
8989
}
9090

@@ -96,19 +96,20 @@ old_report_mypy="${CACHE_DIR}/mypy"
9696
new_report_pylint=$(mktemp)
9797
new_report_mypy=$(mktemp)
9898

99-
if [[ ! -z ${CIRCLECI} ]]; then
99+
# shellcheck disable=SC2154
100+
if [[ -n ${CIRCLECI} ]]; then
100101
JOBS=8
101102
else
102103
JOBS=0
103104
fi
104105

105106
pylint --jobs=${JOBS} \
106107
--load-plugins=tools.pylint.gevent_checker,tools.pylint.assert_checker \
107-
raiden/ tools/scenario-player/ > ${new_report_pylint} || true
108+
raiden/ tools/scenario-player/ > "${new_report_pylint}" || true
108109

109110
mypy --config-file /dev/null --strict --disallow-subclassing-any \
110111
--disallow-any-expr --disallow-any-decorated --disallow-any-explicit \
111-
--disallow-any-generics raiden tools > ${new_report_mypy} || true
112+
--disallow-any-generics raiden tools > "${new_report_mypy}" || true
112113

113114
exit_code=0
114115

.circleci/fetch_geth_parity_solc.sh

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
set -e
44
set -x
55

6+
[[ -n ${OS_NAME:?} ]]
7+
[[ -n ${GETH_VERSION:?} ]]
8+
[[ -n ${PARITY_VERSION:?} ]]
9+
[[ -n ${SOLC_VERSION:?} ]]
10+
611
if [[ -z ${LOCAL_BASE} ]]; then
712
LOCAL_BASE=~/.local
813
fi
@@ -11,41 +16,41 @@ GETH_PATH="${LOCAL_BASE}/bin/geth-${OS_NAME}-${GETH_VERSION}"
1116
if [[ ! -x ${GETH_PATH} ]]; then
1217
mkdir -p ${LOCAL_BASE}/bin
1318
TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t 'gethtmp')
14-
pushd ${TEMP}
19+
pushd "${TEMP}"
1520
GETH_URL_VAR="GETH_URL_${OS_NAME}"
16-
curl -o geth.tar.gz ${!GETH_URL_VAR}
21+
curl -o geth.tar.gz "${!GETH_URL_VAR}"
1722
tar xzf geth.tar.gz
1823
cd geth*/
19-
install -m 755 geth ${GETH_PATH}
24+
install -m 755 geth "${GETH_PATH}"
2025

2126
GETH_MD5_VAR="GETH_MD5_${OS_NAME}"
22-
if [[ ! -n ${!GETH_MD5_VAR} ]]; then
23-
COMPUTED_MD5=$(md5sum ${GETH_PATH} | cut '-d ' -f1)
27+
if [[ -z ${!GETH_MD5_VAR} ]]; then
28+
COMPUTED_MD5=$(md5sum "${GETH_PATH}" | cut '-d ' -f1)
2429

25-
if [[ ${COMPUTED_MD5} != ${!GETH_MD5_VAR} ]]; then
30+
if [[ ${COMPUTED_MD5} != "${!GETH_MD5_VAR}" ]]; then
2631
exit 1;
2732
fi
2833
fi
2934
fi
30-
ln -sfn ${GETH_PATH} ${LOCAL_BASE}/bin/geth
35+
ln -sfn "${GETH_PATH}" "${LOCAL_BASE}"/bin/geth
3136

3237
PARITY_PATH="${LOCAL_BASE}/bin/parity-${OS_NAME}-${PARITY_VERSION}"
3338
if [[ ! -x ${PARITY_PATH} ]]; then
3439
mkdir -p ${LOCAL_BASE}/bin
3540
PARITY_URL_VAR="PARITY_URL_${OS_NAME}"
36-
curl -L ${!PARITY_URL_VAR} > ${PARITY_PATH}
37-
chmod 775 ${PARITY_PATH}
41+
curl -L "${!PARITY_URL_VAR}" > "${PARITY_PATH}"
42+
chmod 775 "${PARITY_PATH}"
3843

3944
PARITY_SHA256_VAR="PARITY_SHA256_${OS_NAME}"
40-
if [[ ! -n ${!PARITY_SHA256_VAR} ]]; then
41-
COMPUTED_SHA256=$(sha256sum ${PARITY_PATH} | cut '-d ' -f1)
45+
if [[ -z ${!PARITY_SHA256_VAR} ]]; then
46+
COMPUTED_SHA256=$(sha256sum "${PARITY_PATH}" | cut '-d ' -f1)
4247

43-
if [[ ${COMPUTED_SHA256} != ${!PARITY_SHA256_VAR} ]]; then
48+
if [[ ${COMPUTED_SHA256} != "${!PARITY_SHA256_VAR}" ]]; then
4449
exit 1;
4550
fi
4651
fi
4752
fi
48-
ln -sfn ${PARITY_PATH} ${LOCAL_BASE}/bin/parity
53+
ln -sfn "${PARITY_PATH}" "${LOCAL_BASE}"/bin/parity
4954

5055
# Only deal with solc for Linux since it's only used for testing
5156
if [[ ${OS_NAME} != "LINUX" ]]; then
@@ -56,7 +61,7 @@ SOLC_PATH="${LOCAL_BASE}/bin/solc-${OS_NAME}-${SOLC_VERSION}"
5661
if [[ ! -x ${SOLC_PATH} ]]; then
5762
mkdir -p ${LOCAL_BASE}/bin
5863
SOLC_URL_VAR="SOLC_URL_${OS_NAME}"
59-
curl -L ${!SOLC_URL_VAR} > ${SOLC_PATH}
60-
chmod 775 ${SOLC_PATH}
64+
curl -L "${!SOLC_URL_VAR}" > "${SOLC_PATH}"
65+
chmod 775 "${SOLC_PATH}"
6166
fi
62-
ln -sfn ${SOLC_PATH} ${LOCAL_BASE}/bin/solc
67+
ln -sfn "${SOLC_PATH}" "${LOCAL_BASE}"/bin/solc

.circleci/fetch_pr_base_commit.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC2154
34
if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then
45
# If this is a PR get the base commit from the GitHub API
5-
PR_DETAILS_URL="https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}"
6-
BASE_COMMIT=$(curl ${PR_DETAILS_URL} | jq -r .base.sha)
6+
PR_DETAILS_URL="https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME:?}/${CIRCLE_PROJECT_REPONAME:?}/pulls/${CIRCLE_PR_NUMBER}"
7+
BASE_COMMIT=$(curl "${PR_DETAILS_URL}" | jq -r .base.sha)
78
if [[ ${BASE_COMMIT} =~ ^[0-9a-zA-Z]{40}$ ]]; then
8-
echo ${BASE_COMMIT} > ~/.local/BASE_COMMIT
9+
echo "${BASE_COMMIT}" > ~/.local/BASE_COMMIT
910
fi
1011
fi

.circleci/fetch_ssh_hostkey.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ FINGERPRINT="$2"
77

88
PUBKEY=$(mktemp)
99

10-
ssh-keyscan -H ${HOST} > ${PUBKEY} 2>/dev/null
10+
ssh-keyscan -H "${HOST}" > "${PUBKEY}" 2>/dev/null
1111

12-
if [[ $(ssh-keygen -l -f ${PUBKEY} | cut -d ' ' -f 2) != ${FINGERPRINT} ]]; then
12+
if [[ $(ssh-keygen -l -f "${PUBKEY}" | cut -d ' ' -f 2) != "${FINGERPRINT}" ]]; then
1313
echo "Warning fingerprint mismatch while fetching public key for ${HOST}"
1414
exit 1
1515
fi
1616

17-
cat ${PUBKEY} >> ~/.ssh/known_hosts
17+
cat "${PUBKEY}" >> ~/.ssh/known_hosts

.circleci/get_archive_tag.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -ex
33

4-
if [[ ! -z ${CIRCLE_TAG} ]]; then
4+
# shellcheck disable=SC2154
5+
if [[ -n ${CIRCLE_TAG} ]]; then
56
export ARCHIVE_TAG=${CIRCLE_TAG}
67
if [[ ${CIRCLE_TAG} = "*-rc*" ]]; then
78
export RELEASE_TYPE="RC"
@@ -16,7 +17,7 @@ else
1617
export RELEASE_TYPE="NIGHTLY"
1718
fi
1819

19-
echo "export ARCHIVE_TAG=${ARCHIVE_TAG}" >> ${BASH_ENV}
20-
echo "export RELEASE_TYPE=${RELEASE_TYPE}" >> ${BASH_ENV}
20+
echo "export ARCHIVE_TAG=${ARCHIVE_TAG}" >> "${BASH_ENV}"
21+
echo "export RELEASE_TYPE=${RELEASE_TYPE}" >> "${BASH_ENV}"
2122

2223
set +ex

.circleci/run_tests.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_type=$3
1010
# Remove the above arguments, every thing extra will be passed down to coverage
1111
shift 3
1212

13-
mkdir -p ${test_report_dir}
13+
mkdir -p "${test_report_dir}"
1414

1515
# Using 9min as the dormant timeout, CircleCI will kill the container after
1616
# 10min
@@ -39,21 +39,22 @@ dormant_signal=SIGUSR1
3939
--color=yes \
4040
--log-config='raiden:DEBUG' \
4141
--random \
42-
--junit-xml=${test_report_dir}/results.xml \
43-
--blockchain-type=${blockchain_type} \
42+
--junit-xml="${test_report_dir}"/results.xml \
43+
--blockchain-type="${blockchain_type}" \
4444
--select-fail-on-missing \
4545
--select-from-file selected-tests.txt \
4646
"${@}"
4747

4848
# Skip log splitting for unit tests
49-
if [ "${test_type}" != "unit" ]; then
50-
if [ -n ${RAIDEN_TESTS_LOGSDIR} ]; then
49+
if [[ "${test_type}" != "unit" ]]; then
50+
# shellcheck disable=SC2154
51+
if [[ -n ${RAIDEN_TESTS_LOGSDIR} ]]; then
5152
# Enable nullglob, otherwise the loop bellow would do one iteration
5253
# over the pattern, leading to a failure, since the pattern is not a
5354
# valid file.
5455
shopt -s nullglob
5556

56-
for test_directory in ${RAIDEN_TESTS_LOGSDIR}/*; do
57+
for test_directory in "${RAIDEN_TESTS_LOGSDIR}"/*; do
5758
# Pytest's paremetrize tests have brackets in their names, e.g.
5859
# `test_api_open_channel_invalid_input[matrix-False-0-1]`, the
5960
# expression bellow must have the test_directory variable in quotes to

.circleci/select_tests.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ output_file=$(mktemp)
1414
--collect-only \
1515
--quiet \
1616
"--blockchain-type=${blockchain_type}" \
17-
${additional_args} > ${output_file}
17+
${additional_args:+"$additional_args"} > "${output_file}"
1818
} || {
1919
# Print pytest's output if test selection failed. This may happen if a
2020
# depencency is broken or if the codebase has syntax errors.
21-
cat ${output_file};
21+
cat "${output_file}"
2222
exit 1;
2323
}
2424

2525
# Save the tests in a file, it will be used by follow up steps
26-
cat ${output_file} \
26+
# shellcheck disable=SC2002
27+
cat "${output_file}" \
2728
| grep '::' \
2829
| circleci tests split --split-by=timings --timings-type=testname \
2930
| grep '::' > selected-tests.txt

.circleci/upload_to_s3.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,32 @@ dir=$3
1010
bucket=$4
1111
endpoint=$5
1212

13+
[[ -n ${RELEASE_TYPE:?} ]]
14+
1315
s3cmd \
14-
--access_key ${access_key} \
15-
--secret_key ${secret_key} \
16-
--host ${endpoint} \
16+
--access_key "${access_key}" \
17+
--secret_key "${secret_key}" \
18+
--host "${endpoint}" \
1719
--host-bucket "%(bucket)s.${endpoint}" \
1820
--no-progress \
1921
--stats \
2022
--no-delete-removed \
2123
--guess-mime-type \
2224
--acl-public \
2325
put \
24-
${dir}/_LATEST*.txt \
25-
s3://${bucket}/
26+
"${dir}"/_LATEST*.txt \
27+
s3://"${bucket}"/
2628

2729
s3cmd \
28-
--access_key ${access_key} \
29-
--secret_key ${secret_key} \
30-
--host ${endpoint} \
30+
--access_key "${access_key}" \
31+
--secret_key "${secret_key}" \
32+
--host "${endpoint}" \
3133
--host-bucket "%(bucket)s.${endpoint}" \
3234
--no-progress \
3335
--stats \
3436
--no-delete-removed \
3537
--guess-mime-type \
3638
--acl-public \
3739
put \
38-
${dir}/raiden* \
39-
s3://${bucket}/${RELEASE_TYPE}/
40+
"${dir}"/raiden* \
41+
s3://"${bucket}"/"${RELEASE_TYPE}"/

0 commit comments

Comments
 (0)