본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)310k · #122

setup-pre-commit

하는 일

Husky와 lint-staged를 추가해, 커밋 전에 Prettier 포맷, 타입 검사, 테스트가 실행되도록 안내합니다. 커밋 전에 문제를 잡고 싶은 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓모든 커밋에서 코드가 자동으로 포맷되기를 원할 때.
  • ✓커밋이 통과하기 전에 타입 검사와 테스트가 실행되기를 원할 때.
  • ✓프로젝트에 Husky나 lint-staged를 설정하고 있을 때.

스킬 링크

https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/mattpocock/skills/blob/main/skills/misc/setup-pre-commit/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“커밋하기 전에 코드가 포맷되고 테스트되도록 사전 커밋 검사를 설정해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 도구를 설치하고, Prettier, 타입 검사, 테스트를 실행하는 사전 커밋 파일을 만듭니다. 포맷 설정이 없으면 설정 파일도 추가합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Setup Pre-Commit Hooks

What This Sets Up

  • Husky pre-commit hook
  • lint-staged running Prettier on all staged files
  • Prettier config (if missing)
  • typecheck and test scripts in the pre-commit hook

Steps

1. Detect package manager

Check for package-lock.json (npm), pnpm-lock.yaml (pnpm), yarn.lock (yarn), bun.lockb (bun). Use whichever is present. Default to npm if unclear.

2. Install dependencies

Install as devDependencies:

husky lint-staged prettier

3. Initialize Husky

npx husky init

This creates .husky/ dir and adds prepare: "husky" to package.json.

4. Create .husky/pre-commit

Write this file (no shebang needed for Husky v9+):

npx lint-staged
npm run typecheck
npm run test

Adapt: Replace npm with detected package manager. If repo has no typecheck or test script in package.json, omit those lines and tell the user.

5. Create .lintstagedrc

{
  "*": "prettier --ignore-unknown --write"
}

6. Create .prettierrc (if missing)

Only create if no Prettier config exists. Use these defaults:

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": true,
  "arrowParens": "always"
}

7. Verify

  • .husky/pre-commit exists and is executable
  • .lintstagedrc exists
  • prepare script in package.json is "husky"
  • prettier config exists
  • Run npx lint-staged to verify it works

8. Commit

Stage all changed/created files and commit with message: Add pre-commit hooks (husky + lint-staged + prettier)

This will run through the new pre-commit hooks: a good smoke test that everything works.

Notes

  • Husky v9+ doesn't need shebangs in hook files
  • prettier --ignore-unknown skips files Prettier can't parse (images, etc.)
  • The pre-commit runs lint-staged first (fast, staged-only), then full typecheck and tests
자주 묻는 질문

훅은 무엇을 실행하나요?

스테이징된 파일에 Prettier를 적용하는 lint-staged를 실행한 뒤, 프로젝트에 있다면 typecheck와 test 스크립트를 실행합니다.

기존 Prettier 설정을 덮어쓰나요?

아닙니다. Prettier 설정이 없을 때만 설정 파일을 만듭니다.

npm, pnpm, yarn에서도 작동하나요?

예. 프로젝트가 쓰는 패키지 관리자를 감지하며, 불분명하면 npm을 기본값으로 씁니다.

상세 정보

작성자의 원본 설명

Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.

repo: mattpocock/skills

인기도

GitHub 스타
310k
순위
#122
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬