Files
app/.claude/hooks/lint.cjs
2026-03-12 12:43:56 +01:00

48 lines
1.3 KiB
JavaScript

const { execSync } = require('child_process')
const path = require('path')
const PROJECT_ROOT = path.resolve(__dirname, '../..')
let input = ''
process.stdin.on('data', chunk => { input += chunk })
process.stdin.on('end', () => {
try {
const data = JSON.parse(input)
const filePath = data.tool_input?.file_path
if (!filePath) process.exit(0)
const ext = path.extname(filePath).toLowerCase()
if (ext === '.php') {
try {
const result = execSync(
`php vendor/bin/phpstan analyse "${filePath}" --level=5 --no-progress --error-format=raw`,
{ cwd: PROJECT_ROOT, encoding: 'utf8', timeout: 30000 }
)
if (result.trim()) {
process.stderr.write('[PHPStan]\n' + result.trim() + '\n')
}
} catch (e) {
if (e.stdout?.trim()) {
process.stderr.write('[PHPStan]\n' + e.stdout.trim() + '\n')
}
}
}
if (['.js', '.jsx'].includes(ext) && filePath.includes('src')) {
try {
execSync(
`npx eslint "${filePath}" --max-warnings 0`,
{ cwd: PROJECT_ROOT, encoding: 'utf8', timeout: 30000 }
)
} catch (e) {
if (e.stdout?.trim()) {
process.stderr.write('[ESLint]\n' + e.stdout.trim() + '\n')
}
}
}
} catch {
// JSON parse error - ignore
}
})