mirror of
https://github.com/sweetwisdom/everything-claude-code-zh.git
synced 2026-03-21 22:10:09 +00:00
Fix: Move Stop hook inline code to separate script file
Fixes #78 ## Problem The Stop hook used inline JavaScript code with `node -e`, which caused shell syntax errors on macOS/zsh due to special characters (parentheses, braces, arrow functions) being misinterpreted by the shell. Error message: /bin/sh: -c: line 0: syntax error near unexpected token \`(' ## Solution - Created scripts/hooks/check-console-log.js with the hook logic - Updated hooks/hooks.json to reference the external script - This follows the same pattern as other hooks in the plugin ## Benefits - Fixes shell compatibility issues across different environments - Improves code maintainability (separate, well-documented script) - Follows plugin's own best practices - Makes the code easier to test and debug ## Testing Tested on macOS with zsh - no more syntax errors. The hook still functions correctly to detect console.log statements.
This commit is contained in:
@@ -137,7 +137,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node -e \"const{execSync}=require('child_process');const fs=require('fs');let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{try{execSync('git rev-parse --git-dir',{stdio:'pipe'})}catch{console.log(d);process.exit(0)}try{const files=execSync('git diff --name-only HEAD',{encoding:'utf8',stdio:['pipe','pipe','pipe']}).split('\\n').filter(f=>/\\.(ts|tsx|js|jsx)$/.test(f)&&fs.existsSync(f));let hasConsole=false;for(const f of files){if(fs.readFileSync(f,'utf8').includes('console.log')){console.error('[Hook] WARNING: console.log found in '+f);hasConsole=true}}if(hasConsole)console.error('[Hook] Remove console.log statements before committing')}catch(e){}console.log(d)})\""
|
||||
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/check-console-log.js\""
|
||||
}
|
||||
],
|
||||
"description": "Check for console.log in modified files after each response"
|
||||
|
||||
Reference in New Issue
Block a user