This commit is contained in:
ClaudiaFang 2026-07-17 16:18:11 +08:00 committed by GitHub
commit 8a14ec78fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# PostToolUse hook (Write|Edit): warns if the touched file contains an eslint-disable comment.
# Does not block the edit — see feedback memory "no lint-disable bypass".
set -euo pipefail
f=$(jq -r '.tool_input.file_path // .tool_response.filePath // empty')
case "$f" in
*.ts | *.tsx | *.js | *.mjs) ;;
*) exit 0 ;;
esac
if [ -f "$f" ] && grep -q 'eslint-disable' "$f" 2>/dev/null; then
jq -n --arg f "$f" \
'{systemMessage: ("eslint-disable found in " + $f + " — fix the underlying lint issue instead of disabling the rule. If a disable is truly warranted, name the specific rule, add a one-line justification, and flag it to the user.")}'
fi

16
.claude/settings.json Normal file
View file

@ -0,0 +1,16 @@
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/warn-eslint-disable.sh\"",
"timeout": 10
}
]
}
]
}
}

14
.husky/pre-commit Normal file → Executable file
View file

@ -1 +1,15 @@
disabled=$(git diff --cached -U0 -- '*.ts' '*.tsx' '*.js' '*.mjs' \
| grep -E '^\+' \
| grep -Ev '^\+\+\+' \
| grep -E 'eslint-disable' || true)
if [ -n "$disabled" ]; then
echo "error: commit adds eslint-disable comment(s):"
echo "$disabled"
echo
echo "Fix the underlying lint issue instead of disabling the rule."
echo "If a disable is genuinely warranted, name the specific rule, add a one-line justification, and flag it in the PR description."
exit 1
fi
npm run lint && npm run build