From 79ba0ae913e71ada60db71c45fd535f1423319d1 Mon Sep 17 00:00:00 2001 From: lachtan Date: Sun, 15 Mar 2026 16:28:34 +0100 Subject: [PATCH] Add shellcheck hook and configuration --- .claude/hooks/shellcheck.sh | 22 ++++++++++++++++++++++ .claude/settings.json | 15 +++++++++++++++ .shellcheckrc | 12 ++++++++++++ 3 files changed, 49 insertions(+) create mode 100755 .claude/hooks/shellcheck.sh create mode 100644 .claude/settings.json create mode 100644 .shellcheckrc diff --git a/.claude/hooks/shellcheck.sh b/.claude/hooks/shellcheck.sh new file mode 100755 index 0000000..9bb3609 --- /dev/null +++ b/.claude/hooks/shellcheck.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -E -o errexit -o nounset -o pipefail + +# Exit silently if required tools are missing +command -v shellcheck > /dev/null 2>&1 || exit 0 +command -v file > /dev/null 2>&1 || exit 0 +command -v jq > /dev/null 2>&1 || exit 0 + +input=$(cat) +file_path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // empty') + +[[ -z "$file_path" || ! -f "$file_path" ]] && exit 0 + +file_type=$(file --brief "$file_path") +case "$file_type" in + *"Bourne-Again shell"*|*"bash"*|*"/bin/bash"*) ;; + *"shell script"*|*"/bin/sh"*) ;; + *) exit 0 ;; +esac + +shellcheck --format=gcc "$file_path" >&2 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..ca95610 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": ".claude/hooks/shellcheck.sh" + } + ] + } + ] + } +} diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..e4dafde --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,12 @@ +# Default shell for sourced files without shebang (SC2148) +shell=bash + +# Sourced files define variables used by other files after source +disable=SC2034 + +# Non-constant and external source paths are intentional +disable=SC1090 +disable=SC1091 + +# Functions invoked indirectly via trap/callback +disable=SC2317