From 5dbb6aea8f5ceaff9f6ce3f6fd1099cb6e46ff6d Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Mon, 2 Mar 2026 20:53:52 +0100 Subject: [PATCH] Set up shfmt --- bin/git-check-assertions | 11 +++++++---- default.nix | 4 ++++ flake.nix | 5 ++++- test/git-check-assertions.bats | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bin/git-check-assertions b/bin/git-check-assertions index a023370..f7fe936 100755 --- a/bin/git-check-assertions +++ b/bin/git-check-assertions @@ -25,7 +25,10 @@ set -euo pipefail assert_fails() { - ! "$@" || { echo "Expected command to fail, but it succeeded."; exit 1; } + ! "$@" || { + echo "Expected command to fail, but it succeeded." + exit 1 + } } export -f assert_fails @@ -42,9 +45,9 @@ for commit_hash in "${commits[@]}"; do git -c advice.detachedHead=false checkout -q "$commit_hash" commit_msg="$(git log -1 --format=%B "$commit_hash")" # shellcheck disable=SC2016 - block="$(printf '%s\n' "$commit_msg" \ - | sed -n '/^```git-check-assertions[[:space:]]*$/,/^```[[:space:]]*$/p' \ - | sed '1d;$d')" + block="$(printf '%s\n' "$commit_msg" | + sed -n '/^```git-check-assertions[[:space:]]*$/,/^```[[:space:]]*$/p' | + sed '1d;$d')" if [ -n "$block" ]; then echo "git-check-assertions block in $commit_hash:" printf '%s\n' "$block" | sed 's/^/> /' diff --git a/default.nix b/default.nix index e159ff1..a956baf 100644 --- a/default.nix +++ b/default.nix @@ -8,6 +8,7 @@ shellcheck-minimal, gitMinimal, resholve, + shfmt, }: let @@ -20,6 +21,7 @@ resholve.mkDerivation { src = fs.toSource { root = ./.; fileset = fs.unions [ + ./.editorconfig ./bin ./test ]; @@ -33,11 +35,13 @@ resholve.mkDerivation { shellcheck-minimal bats gitMinimal + shfmt ]; checkPhase = '' runHook preCheck shellcheck bin/git-check-assertions test/git-check-assertions.bats + shfmt -d bin/git-check-assertions test/git-check-assertions.bats ./test/git-check-assertions.bats runHook postCheck ''; diff --git a/flake.nix b/flake.nix index 55f8f46..60198ee 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,10 @@ { packages.default = pkgs.callPackage ./default.nix { }; devShells.default = pkgs.mkShell { - packages = with pkgs; [ bats ]; + packages = with pkgs; [ + bats + shfmt + ]; }; } ); diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index 9c5006f..4ad07e9 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -4,7 +4,7 @@ setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' - DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)" PATH="$DIR/../bin:$PATH" git init -b main