From c9f9137e59f9c674d70ff3ec25d74867da296c32 Mon Sep 17 00:00:00 2001 From: damcav35 <51324122+damcav35@users.noreply.github.com> Date: Tue, 22 Jul 2025 11:14:41 +0200 Subject: [PATCH] feat: add some precommit (#274) - ensure correct formatting with shfmt - ensure correct syntax with shellcheck Co-authored-by: damien cavagnini --- .pre-commit-config.yaml | 14 ++++++++++++++ hooks/shellcheck.sh | 7 +++++++ hooks/shfmt.sh | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100755 hooks/shellcheck.sh create mode 100755 hooks/shfmt.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8942630..f98f44e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,3 +8,17 @@ repos: language: script pass_filenames: true files: "^bin/hardening/" + - id: shfmt + name: shfmt.sh + description: Ensure correct formatting + entry: hooks/shfmt.sh + language: script + pass_filenames: true + files: "^(bin|tests)/hardening/" + - id: shellcheck + name: shellcheck.sh + description: Ensure correct syntax + entry: hooks/shellcheck.sh + language: script + pass_filenames: true + files: "^(bin|tests)/hardening/" diff --git a/hooks/shellcheck.sh b/hooks/shellcheck.sh new file mode 100755 index 0000000..1710077 --- /dev/null +++ b/hooks/shellcheck.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for script in "$@"; do + /usr/bin/shellcheck --exclude=SC2317 --color=always --shell=bash -x --source-path=SCRIPTDIR "$script" +done + +exit 0 diff --git a/hooks/shfmt.sh b/hooks/shfmt.sh new file mode 100755 index 0000000..a85e615 --- /dev/null +++ b/hooks/shfmt.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for script in "$@"; do + shfmt -l -i 4 -w "$script" +done + +exit 0