Improve linting

[?]
Mar 21, 2023, 10:47 AM
HCY72TQRK2H7LRTEPPHDWTUVINPHZBGMTASY7FJRYS2WXCBRSMYQC

Dependencies

Change contents

  • edit in demo-full.sh at line 8
    [2.10]
    [2.10]
    echo "${BASH_SOURCE[0]}"
    nix run nixpkgs#shellcheck -- -S style -x "${BASH_SOURCE[0]}" || return 1
    echo "$(dirname "${BASH_SOURCE[0]}")/bash/libdemo.sh"
    nix run nixpkgs#shellcheck -- -S style -x "$(dirname "${BASH_SOURCE[0]}")/bash/libdemo.sh" || return 1
    local f
  • replacement in demo-full.sh at line 14
    [2.91][2.91:202]()
    demoheader "$(dirname "${f}" | sed 's|^\./||')"
    shellcheck_dir "$(dirname "${f}")" || return 1
    [2.91]
    [2.202]
    echo "${f}"
    nix run nixpkgs#shellcheck -- -S style -x "${f}" || return 1
  • edit in demo-full.sh at line 20
    [2.222]
    [2.222]
    local f
  • replacement in demo-full.sh at line 28
    [2.404][2.404:423]()
    lint || exit 1
    run
    [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=0
    do_interactive=1
    while [[ $# -gt 0 ]]; do
    case $1 in
    -l|--lint)
    do_lint=1
    shift
    ;;
    -a|--auto)
    do_interactive=0
    shift
    ;;
    -h|--help|-\?)
    usage
    exit 0
    ;;
    -*)
    echo "Unknown option $1"
    exit 1
    ;;
    *)
    POSITIONAL_ARGS+=("$1") # save positional arg
    shift
    ;;
    esac
    done
    if [ "${do_lint}" = 1 ]; then
    lint || exit 1
    else
    LIBDEMO_INTERACTIVE="${do_interactive}" run
    fi
  • edit in bash/libdemo.sh at line 169
    [3.3605][2.496:976]()
    shellcheck_dir() {
    local path="${1}"
    shift
    pushd "${path}" > /dev/null || return 1
    set +e
    local retval=0
    while IFS= read -r f; do
    if shellcheck -S style -x "${f}"; then
    :
    else
    retval=1
    fi
    done < <(grep --exclude-dir .git "${@}" -l -R -e '^#\!.*sh' -e '^# shellcheck shell' | sort)
    popd > /dev/null || return 1
    return "${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 script
    source-path=SCRIPTDIR
    # Suggest adding a default case in `case` statements
    enable=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 values
    enable=quote-safe-variables
    # Suggest putting braces around all variable references
    enable=require-variable-braces