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