Files
swupd-client/scripts/shellcheck.bash
T
Otavio Pontes ce0943982a shellcheck: Error SC2119 doesn't apply to our use cases
Ignoring error SC2119 because they are false positives and I don't see cases
where that would return anything useful for us.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2020-04-30 08:50:48 -07:00

34 lines
972 B
Bash
Executable File

#!/bin/bash
# Wrapper to run shellcheck with configurations used by swupd project and
# doing necessary changes to validate bats files
# Ignored checks:
# - SC1008: This shebang was unrecognized.
# We need to skip this check when processing bats tests because the shebang
# is not a shell.
# - SC2119: Use foo "$@" if function's $1 should mean script's $1.
# We need to skip this check because in many ocassions we use functions
# that are not expecting arguments, but still shellcheck will detect this
# as error because the show_help which is called from all functions uses $@
if [ "$#" -ne 1 ]; then
cat <<-EOM
Invalid number of arguments
Usage:
./scripts/shellcheck.bash <shellscript_file>
EOM
exit 1
fi
file="$1"
if [[ "${file/*./}" == "bats" ]]; then
sed 's/^@.*/func() {/' "$file" |
sed 's/^load.*/source test\/functional\/testlib.bash/' |
shellcheck -s bash -x -e SC1008,SC2119 /dev/stdin
else
shellcheck -x "$file" -e SC2119
fi