Skip to content

Commit 37c7c5b

Browse files
author
Marek Fiala
committed
feat(tools): Add shellcheck for shell scripts to CI
- shellcheck fixes in shell scripts
1 parent c50dfa2 commit 37c7c5b

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,14 @@ repos:
208208
- id: astyle_py
209209
# If you are modifying astyle version, update tools/format.sh as well
210210
args: ['--astyle-version=3.4.7', '--rules=tools/ci/astyle-rules.yml']
211+
- repo: https://github.com/shellcheck-py/shellcheck-py
212+
rev: v0.9.0.5
213+
hooks:
214+
- id: shellcheck
215+
name: shellcheck bash
216+
args: ['--shell', 'bash', '-x']
217+
files: 'install.sh|export.sh'
218+
- id: shellcheck
219+
name: shellcheck dash (export.sh)
220+
args: ['--shell', 'dash', '-x']
221+
files: 'export.sh'

.shellcheckrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This is shellcheck config file
2+
# Files that are checked: install.sh, export.sh
3+
4+
# Do not complain about variables determined at runtime (IDF_PATH)
5+
disable=SC1090

export.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ __main() {
6565
self_path="${BASH_SOURCE}"
6666
elif [ -n "${ZSH_VERSION-}" ]
6767
then
68+
# shellcheck disable=SC2296 # ignore parameter starts with '{' because it's zsh
6869
self_path="${(%):-%x}"
6970
fi
7071

@@ -138,7 +139,7 @@ __main() {
138139

139140
if [ -n "$BASH" ]
140141
then
141-
path_prefix=${PATH%%${old_path}}
142+
path_prefix="${PATH%%"${old_path}"}"
142143
# shellcheck disable=SC2169,SC2039 # unreachable with 'dash'
143144
if [ -n "${path_prefix}" ]; then
144145
__verbose "Added the following directories to PATH:"
@@ -201,7 +202,7 @@ __cleanup() {
201202
# Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
202203
# to check whether we are using a private Python environment
203204

204-
return $1
205+
return "$1"
205206
}
206207

207208

@@ -222,7 +223,7 @@ __enable_autocomplete() {
222223
elif [ -n "${BASH_SOURCE-}" ]
223224
then
224225
WARNING_MSG="WARNING: Failed to load shell autocompletion for bash version: $BASH_VERSION!"
225-
# shellcheck disable=SC3028,SC3054,SC2086 # code block for 'bash' only
226+
# shellcheck disable=SC3028,SC3054,SC2086,SC2169 # code block for 'bash' only
226227
[ ${BASH_VERSINFO[0]} -lt 4 ] && { echo "$WARNING_MSG"; return; }
227228
eval "$(env LANG=en _IDF.PY_COMPLETE=$SOURCE_BASH idf.py)" || echo "$WARNING_MSG"
228229
fi

install.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ while getopts ":h" option; do
1818
h)
1919
"${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" print_help sh
2020
exit;;
21+
\?)
22+
;;
2123
esac
2224
done
2325

24-
TARGETS=`"${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract targets "$@"`
26+
TARGETS=$("${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract targets "$@")
2527

2628
echo "Installing ESP-IDF tools"
27-
"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install --targets=${TARGETS}
29+
"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install --targets="${TARGETS}"
2830

29-
FEATURES=`"${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract features "$@"`
31+
FEATURES=$("${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract features "$@")
3032

3133
echo "Installing Python environment and packages"
32-
"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install-python-env --features=${FEATURES}
34+
"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install-python-env --features="${FEATURES}"
3335

3436
echo "All done! You can now run:"
3537
echo ""

0 commit comments

Comments
 (0)