Skip to content

깃훅 가이드

dictionary-app은 husky로 git 훅을 관리한다. package.json의 prepare: "husky" 스크립트가 pnpm install 시점에 훅을 .husky/에 설치한다.

.husky/pre-commit
pnpm exec lint-staged
pnpm run build
  1. lint-staged로 스테이징된 파일에 코딩 컨벤션 (Prettier/oxlint)을 자동 적용한다.
    package.json
    {
    "lint-staged": {
    "**/*.{js,cjs,ts,tsx}": ["oxlint --fix", "prettier --write"],
    "**/*.{json,css,md,yaml,yml}": "prettier --write"
    }
    }
  2. pnpm run build(tsc -b && vite build)까지 실행해 타입 오류·빌드 실패를 커밋 전에 미리 잡는다 — lint-staged만으로는 타입체크가 되지 않기 때문이다.
  3. 두 단계 중 하나라도 실패하면 커밋이 차단된다.

커밋 메시지 규칙 (commitlint.config.cjs)

Section titled “커밋 메시지 규칙 (commitlint.config.cjs)”
commitlint.config.cjs
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore']],
'subject-empty': [2, 'never'],
'subject-max-length': [2, 'always', 50],
},
}
  • git commit --no-verify로 pre-commit 훅을 건너뛰지 않는다.
  • 훅이 실패하면 원인(포맷/린트/타입/빌드 오류)을 고쳐서 다시 커밋한다.