Git hooks are executable scripts in .git/hooks/ that run automatically at specific Git events. The most important for code quality: pre-commit (runs before a commit is created) and pre-push (runs before pushing).
The problem with native hooks: .git/hooks/ isn't committed to the repository, so every developer must install hooks manually.
Husky solves this by storing hooks in .husky/ (committed to the repo) and auto-installing them via an npm prepare script.
lint-staged runs linters only on staged files (not the entire project), making hooks fast even in large codebases.
Recommended setup for Symfony projects:
pre-commit: lint-staged with PHP CS Fixer (PSR-12), ESLint, Stylelintcommit-msg: commitlint with Conventional Commits configpre-push: PHPUnit test suitepost-merge: Auto-runcomposer install/npm installwhen lockfiles change
CI/CD pipelines serve as the final safety net — hooks can be bypassed with --no-verify, but pipelines cannot.
Kommentare
Kommentare werden von Remark42 bereitgestellt. Beim Laden werden Daten an unseren Kommentar-Server übertragen.