-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmd-lint-fix.sh
More file actions
executable file
·40 lines (33 loc) · 1.12 KB
/
Copy pathmd-lint-fix.sh
File metadata and controls
executable file
·40 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
set -euo pipefail
# tested with: claude code v2.1.122
# =============================================================================
# Markdown Lint Fix: PostToolUse auto-fixer
# =============================================================================
# when a .md file is written or edited, runs markdownlint-fix on it.
# prevents markdown-lint CI failures from accumulating.
#
# Hook type: PostToolUse (matcher: "Write", "Edit")
# =============================================================================
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // ""')
# only act on Write and Edit
if [[ "$TOOL_NAME" != "Write" && "$TOOL_NAME" != "Edit" ]]; then
exit 0
fi
# get the file path
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
exit 0
fi
# only act on markdown files
if [[ "$FILE_PATH" != *.md ]]; then
exit 0
fi
# only fix if the file exists
if [ ! -f "$FILE_PATH" ]; then
exit 0
fi
# run markdownlint-fix (silently, don't block on failure)
npx --yes markdownlint-cli2-fix "$FILE_PATH" 2>/dev/null || true
exit 0