name: lint-staged-git-hook
description: lint-staged pre-commit hook for running linters only on Git-staged files. Pattern-matched task runners, auto-fix before commit, integration with husky, and staged-only analysis to minimize CI overhead. Sources: okonet/lint-staged (MIT).
origin: yana-ai — synthesized from okonet/lint-staged (MIT)
license: Apache-2.0
version: 1.0.0
compatibility: yana-ai >= 1.3.49
/lint-staged-git-hook
When to Use
- Run ESLint/Prettier/ktlint only on files being committed (not the whole repo)
- Auto-fix formatting before commit so developers never push bad style
- Yamtam hook layer: run security checks on staged files only to keep hooks fast
- Monorepo: pattern-match different tools per package directory
Do NOT use for
- Full CI pipeline analysis (lint-staged runs only on staged files, not all changed files in a PR)
- Post-commit hooks (use [[merkle-tree-audit]] for post-commit integrity)
Setup
npm install --save-dev lint-staged husky
npx husky init
echo "npx lint-staged" > .husky/pre-commit
lint-staged.config.js (recommended format)
export default {
'**/*.{ts,tsx,js,jsx}': [
'eslint --fix --max-warnings 0',
'prettier --write',
],
'**/*.py': [
'black --check',
'ruff check --fix',
],
'**/*.kt': [
'ktlint --format',
],
'**/*.{json,yaml,yml}': [
'prettier --write',
],
'**/*.sh': [
'shellcheck --severity=warning',
],
'*': [
'gitleaks protect --staged --no-banner',
],
}
Advanced: function-style tasks
export default {
'**/*.ts?(x)': () => 'tsc --noEmit',
'**/*.{js,ts}': (stagedFiles) => {
if (stagedFiles.length > 5) {
return [`eslint --fix ${stagedFiles.join(' ')}`, 'jest --passWithNoTests --findRelatedTests']
}
return [`eslint --fix ${stagedFiles.join(' ')}`]
},
}
Integration with yamtam tool-proxy.sh hook
set -e
npx lint-staged
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
if [ -n "$STAGED" ]; then
echo "$STAGED" | xargs -I{} bash core/scripts/tool-proxy.sh "cat {}" 2>/dev/null || true
fi
bash core/scripts/validate-manifest.sh
Anti-Fake-Pass Checklist
❌ lint-staged without husky → config exists but pre-commit hook never runs
❌ Auto-fix modifies files not re-staged → commit contains unfixed version of the file
❌ '*.ts': ['tsc --noEmit', stagedFiles] → tsc ignores passed filenames; use () => 'tsc --noEmit'
❌ shellcheck path not found → lint-staged silently passes (non-zero exit check)
❌ gitleaks not installed → secret scan step skipped with no error
❌ concurrent: false not set when tasks write same file → race condition between formatter and linter