From bf811cd38e30e63e0ddd7ca5138fb4e115933b2e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:02:52 -0800 Subject: [PATCH] BATS: require `shellcheck` on test files BATS: add `*.bats` to `.gitattributes` --- .gitattributes | 1 + .pre-commit-config.yaml | 4 +--- hooks/dot-bash.sh | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index de622e06..8a908054 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ *.sh text eol=lf *.bash text eol=lf +*.bats text eol=lf # Docs allow trailing whitespaces *.md whitespace=-blank-at-eol diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af5f30af..8c3f3525 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: hooks: - id: git-check # Configure in .gitattributes - id: shellcheck - exclude: ".bats$" - id: shfmt exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks @@ -38,10 +37,9 @@ repos: types: [file] - id: dot-bash name: Check .bash files against bash-it requirements - exclude: "test/test_helper.bash" entry: ./hooks/dot-bash.sh language: system - files: "\\.bash$" + files: "\\.ba[ts][sh]$" types: [file] - id: clean-files-txt name: Check that clean_files.txt is sorted alphabetically. diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 253cb595..94a03708 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -12,7 +12,8 @@ for file in "$@"; do # Confirm expected schellcheck header # LINE1="$(head -n 1 "${file}")" - if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then + SCSH="${file##*.}" + if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then echo "Bash include file \`${file}\` has bad/missing shellcheck header" exit_code=1 fi