Add shellcheck lint

Run shellcheck [1] on the bash files.

[1]: https://www.shellcheck.net/

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-01-09 10:38:48 -07:00
committed by Jeremy Soller
parent 623d3ce8ab
commit 7205f1a49e
5 changed files with 47 additions and 5 deletions

View File

@ -16,6 +16,9 @@ jobs:
- name: Check formatting - name: Check formatting
run: ./scripts/lint/02-clang-format.sh run: ./scripts/lint/02-clang-format.sh
- name: Check shell scripts
run: ./scripts/lint/03-shellcheck.sh
tool: tool:
strategy: strategy:
matrix: matrix:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
FILES=($(git ls-files '*.[ch]')) readarray -t FILES < <(git ls-files '*.c' '*.h')
FMT_OPTS=( FMT_OPTS=(
"-style=file" "-style=file"

View File

@ -29,6 +29,7 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
make \ make \
pkgconf \ pkgconf \
sdcc \ sdcc \
shellcheck \
xxd xxd
elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
sudo dnf install \ sudo dnf install \
@ -41,6 +42,7 @@ elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
gcc \ gcc \
make \ make \
sdcc \ sdcc \
ShellCheck \
systemd-devel \ systemd-devel \
vim-common vim-common
elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
@ -55,6 +57,7 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
make \ make \
pkgconf \ pkgconf \
sdcc \ sdcc \
shellcheck \
systemd-libs \ systemd-libs \
vim vim
else else

36
scripts/lint/03-shellcheck.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# Check if any shell scripts have issues.
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
. "$LINT_DIR/util.sh"
echo -n "Checking shell scripts..."
if ! command -v shellcheck > /dev/null; then
skipped "shellcheck not found"
exit 0
fi
readarray -t FILES < <(git ls-files '*.sh')
needs_formatting=()
for file in "${FILES[@]}"; do
# SC1091: Ignore external scripts
if ! shellcheck -f quiet --exclude=SC1091 "$file"; then
needs_formatting+=("$file")
fi
done
if [[ "${#needs_formatting[@]}" != "0" ]]; then
failed
for file in "${needs_formatting[@]}"; do
echo "- $file"
done
exit 1
fi
passed

View File

@ -60,7 +60,7 @@ do
else else
F="$(date "+%T")" F="$(date "+%T")"
last_E="$(sudo cat /sys/class/powercap/intel-rapl\:0/energy_uj)" last_E="$(sudo cat '/sys/class/powercap/intel-rapl:0/energy_uj')"
sleep 1 sleep 1
if [ "${has_bat}" == "1" ] if [ "${has_bat}" == "1" ]
@ -73,15 +73,15 @@ do
F="${F}\t$(printf "%.2f" "${bat_W}")" F="${F}\t$(printf "%.2f" "${bat_W}")"
fi fi
E="$(sudo cat /sys/class/powercap/intel-rapl\:0/energy_uj)" E="$(sudo cat '/sys/class/powercap/intel-rapl:0/energy_uj')"
W="$(echo "(${E} - ${last_E})/1000000" | bc -lq)" W="$(echo "(${E} - ${last_E})/1000000" | bc -lq)"
F="${F}\t$(printf "%.1f" "${W}")" F="${F}\t$(printf "%.1f" "${W}")"
PL1_uW="$(sudo cat /sys/class/powercap/intel-rapl\:0/constraint_0_power_limit_uw)" PL1_uW="$(sudo cat '/sys/class/powercap/intel-rapl:0/constraint_0_power_limit_uw')"
PL1_W="$(echo "${PL1_uW}/1000000" | bc -lq)" PL1_W="$(echo "${PL1_uW}/1000000" | bc -lq)"
F="${F}\t$(printf "%.1f" "${PL1_W}")" F="${F}\t$(printf "%.1f" "${PL1_W}")"
PL2_uW="$(sudo cat /sys/class/powercap/intel-rapl\:0/constraint_1_power_limit_uw)" PL2_uW="$(sudo cat '/sys/class/powercap/intel-rapl:0/constraint_1_power_limit_uw')"
PL2_W="$(echo "${PL2_uW}/1000000" | bc -lq)" PL2_W="$(echo "${PL2_uW}/1000000" | bc -lq)"
F="${F}\t$(printf "%.1f" "${PL2_W}")" F="${F}\t$(printf "%.1f" "${PL2_W}")"