Skip to content

Commit 7a2ed8a

Browse files
committed
fix: use array for file list in lint-staged.sh to handle spaces in paths
1 parent 6e3fd13 commit 7a2ed8a

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

.claude/hooks/lint-staged.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,26 @@ fi
4242
EDITED_FILES=$(awk '{print $2}' "$LOG_FILE" | sort -u)
4343

4444
# Filter staged files to src/ and tests/ that were edited in this session
45-
FILES_TO_LINT=""
45+
declare -a FILES_TO_LINT=()
4646
while IFS= read -r file; do
4747
case "$file" in
4848
src/*.js|src/*.ts|src/*.tsx|tests/*.js|tests/*.ts|tests/*.tsx) ;;
4949
*) continue ;;
5050
esac
5151
if echo "$EDITED_FILES" | grep -qxF "$file"; then
52-
FILES_TO_LINT="${FILES_TO_LINT:+$FILES_TO_LINT }$file"
52+
FILES_TO_LINT+=("$file")
5353
fi
5454
done <<< "$STAGED"
5555

56-
if [ -z "$FILES_TO_LINT" ]; then
56+
if [ "${#FILES_TO_LINT[@]}" -eq 0 ]; then
5757
exit 0
5858
fi
5959

6060
# Run biome check on the specific files.
6161
# Intentional fail-open: if biome crashes or OOMs (non-zero exit with no output),
6262
# the commit is allowed through. We only block when there is actionable lint output.
6363
cd "$WORK_ROOT" || exit 0
64-
# shellcheck disable=SC2086
65-
LINT_OUTPUT=$(npx biome check --no-errors-on-unmatched $FILES_TO_LINT 2>&1) || LINT_EXIT=$?
64+
LINT_OUTPUT=$(npx biome check --no-errors-on-unmatched "${FILES_TO_LINT[@]}" 2>&1) || LINT_EXIT=$?
6665

6766
if [ "${LINT_EXIT:-0}" -ne 0 ] && [ -n "$LINT_OUTPUT" ]; then
6867
# Truncate output to first 30 lines to keep denial message readable

docs/examples/claude-code-hooks/lint-staged.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,26 @@ fi
4242
EDITED_FILES=$(awk '{print $2}' "$LOG_FILE" | sort -u)
4343

4444
# Filter staged files to src/ and tests/ that were edited in this session
45-
FILES_TO_LINT=""
45+
declare -a FILES_TO_LINT=()
4646
while IFS= read -r file; do
4747
case "$file" in
4848
src/*.js|src/*.ts|src/*.tsx|tests/*.js|tests/*.ts|tests/*.tsx) ;;
4949
*) continue ;;
5050
esac
5151
if echo "$EDITED_FILES" | grep -qxF "$file"; then
52-
FILES_TO_LINT="${FILES_TO_LINT:+$FILES_TO_LINT }$file"
52+
FILES_TO_LINT+=("$file")
5353
fi
5454
done <<< "$STAGED"
5555

56-
if [ -z "$FILES_TO_LINT" ]; then
56+
if [ "${#FILES_TO_LINT[@]}" -eq 0 ]; then
5757
exit 0
5858
fi
5959

6060
# Run biome check on the specific files.
6161
# Intentional fail-open: if biome crashes or OOMs (non-zero exit with no output),
6262
# the commit is allowed through. We only block when there is actionable lint output.
6363
cd "$WORK_ROOT" || exit 0
64-
# shellcheck disable=SC2086
65-
LINT_OUTPUT=$(npx biome check --no-errors-on-unmatched $FILES_TO_LINT 2>&1) || LINT_EXIT=$?
64+
LINT_OUTPUT=$(npx biome check --no-errors-on-unmatched "${FILES_TO_LINT[@]}" 2>&1) || LINT_EXIT=$?
6665

6766
if [ "${LINT_EXIT:-0}" -ne 0 ] && [ -n "$LINT_OUTPUT" ]; then
6867
# Truncate output to first 30 lines to keep denial message readable

0 commit comments

Comments
 (0)