Improve linting
[?]
Mar 21, 2023, 10:47 AM
HCY72TQRK2H7LRTEPPHDWTUVINPHZBGMTASY7FJRYS2WXCBRSMYQCDependencies
Change contents
- edit in demo-full.sh at line 8
echo "${BASH_SOURCE[0]}"nix run nixpkgs#shellcheck -- -S style -x "${BASH_SOURCE[0]}" || return 1echo "$(dirname "${BASH_SOURCE[0]}")/bash/libdemo.sh"nix run nixpkgs#shellcheck -- -S style -x "$(dirname "${BASH_SOURCE[0]}")/bash/libdemo.sh" || return 1local f - replacement in demo-full.sh at line 14
demoheader "$(dirname "${f}" | sed 's|^\./||')"shellcheck_dir "$(dirname "${f}")" || return 1echo "${f}"nix run nixpkgs#shellcheck -- -S style -x "${f}" || return 1 - edit in demo-full.sh at line 20
local f - replacement in demo-full.sh at line 28
lint || exit 1run[2.404]usage() {echo "$0: run all 'demo.sh' scripts using libdemo"echo " -l|--lint: run linter first"echo " -a|--auto: run in automatic mode"echo " -h|--help|-?: Show usage"}do_lint=0do_interactive=1while [[ $# -gt 0 ]]; docase $1 in-l|--lint)do_lint=1shift;;-a|--auto)do_interactive=0shift;;-h|--help|-\?)usageexit 0;;-*)echo "Unknown option $1"exit 1;;*)POSITIONAL_ARGS+=("$1") # save positional argshift;;esacdoneif [ "${do_lint}" = 1 ]; thenlint || exit 1elseLIBDEMO_INTERACTIVE="${do_interactive}" runfi - edit in bash/libdemo.sh at line 169
shellcheck_dir() {local path="${1}"shiftpushd "${path}" > /dev/null || return 1set +elocal retval=0while IFS= read -r f; doif shellcheck -S style -x "${f}"; then:elseretval=1fidone < <(grep --exclude-dir .git "${@}" -l -R -e '^#\!.*sh' -e '^# shellcheck shell' | sort)popd > /dev/null || return 1return "${retval}"} - file addition: .shellcheckrc[3.2]
# https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md# Look for 'source'd files relative to the checked scriptsource-path=SCRIPTDIR# Suggest adding a default case in `case` statementsenable=add-default-case# Suggest explicitly using -n in `[ $var ]`enable=avoid-nullary-conditions# Turn on warnings for unassigned uppercase variables# enable=check-unassigned-uppercase# Turn on warnings for unquoted variables with safe valuesenable=quote-safe-variables# Suggest putting braces around all variable referencesenable=require-variable-braces