Skip to content

Enforce shell linting/formatting and modernize scripts#657

Merged
runesoerensen merged 23 commits intomainfrom
fix-formatting
Mar 16, 2026
Merged

Enforce shell linting/formatting and modernize scripts#657
runesoerensen merged 23 commits intomainfrom
fix-formatting

Conversation

@runesoerensen
Copy link
Contributor

@runesoerensen runesoerensen commented Mar 15, 2026

Add shell script linting (ShellCheck) and formatting (shfmt) enforcement, and modernize all shell scripts to follow consistent conventions.

Linting & formatting infrastructure

  • Add .shellcheckrc with enable=all for maximum strictness
  • Add .editorconfig configuring shfmt (tabs, binary_next_line, switch_case_indent, shell_variant=bash)
  • Add Makefile targets: lint (meta), lint-scripts (ShellCheck), check-format / format (shfmt)
  • Add lint job to GitHub Actions CI (ShellCheck + shfmt)
  • Exclude vendored test/shunit2.sh from both linting and formatting
  • Add .editorconfig and .shellcheckrc to buildpack.toml publish ignore list

ShellCheck fixes

  • Quote all variable expansions ($var -> "${var}")
  • Replace [ ] with [[ ]] for bash-specific tests
  • Replace -a/-o compound tests with &&/||
  • Replace [ ! -z with [[ -n
  • Fix unquoted array expansions and glob patterns
  • Add targeted # shellcheck disable= directives for intentional patterns (e.g. word-splitting of $pkgs, dynamically sourced files)

shfmt formatting

  • Normalize all indentation to tabs (consistent with heredoc <<- requirement)
  • Apply switch_case_indent, binary_next_line formatting rules
  • Consistent spacing around redirections (>, >>, <, &>)

Shell script modernization

  • Shebangs: Standardize to #!/usr/bin/env bash across all scripts (including converting sbin/add-version from #!/bin/sh and adding a shebang to test/utils.sh)
  • BUILDPACK_DIR: Replace $0-based path resolution with BASH_SOURCE[0] pattern (BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)) — more reliable when sourced, and lets ShellCheck follow source paths without # shellcheck source= hints
  • set -euo pipefail: Enable strict error handling everywhere (-u for unset variable detection, -o pipefail for pipeline failures). Add :- defaults to all optional/environment variables (${GOVERSION:-}, ${GO_INSTALL_PACKAGE_SPEC:-}, etc.)
  • Explicit source dependencies: Move output.sh sourcing out of common.sh into each caller, making dependency chains visible
  • Remove unnecessary operations: Drop mkdir -p "$1" "$2" (platform guarantees dirs exist), cd "$1/" && pwd canonicalization (platform passes absolute paths), and a broken no-op pushd/popd in test/run.sh
  • Variable naming: Rename all buildpack API variables to uppercase convention:
    • build -> BUILD_DIR
    • env_dir -> ENV_DIR
    • cache_root -> CACHE_DIR
    • cache -> GO_CACHE_DIR (the namespaced .heroku/go subdirectory)
    • buildpack/testpack -> BUILDPACK_DIR

GUS-W-21598655

@runesoerensen runesoerensen marked this pull request as ready for review March 16, 2026 01:36
@runesoerensen runesoerensen requested a review from a team as a code owner March 16, 2026 01:36
@runesoerensen runesoerensen merged commit e7e323e into main Mar 16, 2026
9 checks passed
@runesoerensen runesoerensen deleted the fix-formatting branch March 16, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants