Skip to content

Enforce consistent indentation (spaces only) in shell scripts #54

Closed

Description

@KSXGitHub

Problem

build.sh mixes tab- and space-based indentation. Most of the file is indented with 2 spaces, but a few blocks use tabs, and one block even mixes both within itself.

Counting leading whitespace in build.sh (at the current master, 7acb32f):

  • 76 lines start with a space
  • 11 lines start with a tab (the updpkgsums, test, and post_process blocks)

The post_process block is the clearest offender — three lines are tab-indented while the eval line beside them is space-indented:

if [ -n "$post_process" ]; then
<TAB>echo '::group::Executing post process commands'
<TAB>cd /tmp/local-repo/
    eval "$post_process"          # <-- 2 spaces, not a tab
<TAB>echo '::endgroup::'
fi

This renders unevenly depending on each viewer's tab width and makes diffs noisier than they need to be (it surfaced while reviewing #52).

Proposal

Standardize on spaces only, at 2-space indentation — that is already the majority style in build.sh and matches entrypoint.sh. A one-time reformat of the tab-indented blocks would bring the repo to a single consistent style.

Tooling to keep it consistent going forward

The repo currently has no formatter, linter, or CI wired up, so nothing prevents mixed indentation from creeping back in. Options, roughly from lightest to strongest:

  1. .editorconfig — the baseline. An editor-agnostic file that declares the intended style so most IDEs/editors indent correctly on save. Covers every file type, not just shell:

    root = true
    
    [*]
    indent_style = space
    indent_size = 2
    end_of_line = lf
    charset = utf-8
    insert_final_newline = true
    trim_trailing_whitespace = true
    
    [*.md]
    trim_trailing_whitespace = false
  2. shfmt (mvdan/sh) — the gofmt/prettier of shell. It reformats scripts to a canonical style (shfmt -i 2 -w build.sh) and reads .editorconfig automatically. In CI, shfmt -d . prints a diff and exits non-zero on any deviation, so unformatted code fails the check. This is the strongest guarantee for shell specifically.

  3. editorconfig-checker — validates all files against .editorconfig in CI (broader than shell; catches Dockerfile/YAML/Markdown too).

  4. A CI workflow — since there is no .github/workflows/ yet, a small lint workflow running shfmt -d (and, complementarily, shellcheck for correctness) on push/PR would enforce this automatically. shellcheck alone is not enough for this: it is a correctness/portability linter and does not check indentation style.

  5. pre-commit — optional local enforcement via a git hook (there are ready-made shfmt/editorconfig-checker/shellcheck hooks) so violations are caught before they are even pushed.

A reasonable minimum is .editorconfig + shfmt -d in CI: the first declares intent to editors, the second mechanically enforces it. editorconfig-checker and pre-commit are nice-to-haves on top.

I'm happy to open a PR for whichever combination you prefer (e.g. reformat build.sh to spaces + add .editorconfig + a shfmt CI check).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions