Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/Build] Add shell script linting using shellcheck #7925

Merged
merged 2 commits into from
Nov 7, 2024

Commits on Nov 7, 2024

  1. format.sh: run shellcheck on all shell scripts

    This runs the `shellcheck` linter against all shell scripts in the
    repo. Download the tool automatically if it's not found, at least on
    Linux+x86_64.
    
    Also run shellcheck in CI.
    
    Signed-off-by: Russell Bryant <rbryant@redhat.com>
    russellb committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    b70364a View commit details
    Browse the repository at this point in the history
  2. Make shellcheck run cleanly

    This fixes a bunch of warnings from shellcheck. A sample of things
    addressed here include:
    
    - Quote variables to avoid accidental globbing or variable splitting.
      For example, as a best practice, `cd ${foo}` should be written as
      `cd "${foo}"`. Otherwise, a directory with a space in the name would
      break in the script.
    
    - Remove unused variables and fix a variable name typo.
    
    - Simplify error checking: `if command` instead of
      `command; if [ $?  -eq 0 ]`.
    
    - Remove an unnecessary echo, i.e. `$(echo $(command) | foo)` can
      instead be `$(command | foo)`.
    
    - Specify `#!/bin/bash` in scripts that did not include it.
    
    Note that I left one script ignored for the moment, as the required
    change seemed like it wraranted its own separate commit.
    
    Signed-off-by: Russell Bryant <rbryant@redhat.com>
    russellb committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    1077fda View commit details
    Browse the repository at this point in the history