-
Notifications
You must be signed in to change notification settings - Fork 4
[Init] Husky 세팅 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Init] Husky 세팅 #24
Changes from 3 commits
2e3eea4
3a8b44f
24159bd
33d5e29
7e9c98b
d9f00ad
6d00d57
d195bef
3cfcd6d
d2d1af2
74a08a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| echo "🐶 Husky pre-commit 실행" | ||
| pnpm exec lint-staged && echo "🎉 lint-staged 통과" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,17 @@ | |
| "dev": "vite", | ||
| "build": "tsc -b && vite build", | ||
| "lint": "eslint .", | ||
| "preview": "vite preview" | ||
| "preview": "vite preview", | ||
| "prepare": "husky" | ||
| }, | ||
| "lint-staged": { | ||
| "*.{ts,tsx,js,jsx}": [ | ||
| "eslint --fix", | ||
| "prettier --write" | ||
| ], | ||
| "*.{json,md,css}": [ | ||
| "prettier --write" | ||
| ] | ||
| }, | ||
|
Comment on lines
15
to
23
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lint-staged 설정 깔끔하네요! 특히 eslint → prettier 순서로 구성해서, eslint에서 자동 수정 가능한 부분을 먼저 처리하고 이 부분은 지극히 개인적으로 추가하면 더 좋을 것 같은 부분인데, repo에서 만약 scss / yaml(yml) / mdx 등을 사용한다면 포맷 대상에 해당 확장자들을 함께 포함해두는 것도 좋을 것 같아요 :) "lint-staged": {
"*.{ts,tsx,js,jsx}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,mdx,css,yml,yaml}": [
"prettier --write"
]
}
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀해주신 것처럼 scss/yml/yaml/mdx도 커밋에서 같이 포맷되면 편할 것 같아서 prettier 대상 확장자에 추가로 반영해뒀습니다 ! 감사합니다 🤩 |
||
| "dependencies": { | ||
| "eslint-import-resolver-typescript": "^4.4.4", | ||
|
|
@@ -31,6 +41,8 @@ | |
| "eslint-plugin-react-hooks": "^7.0.1", | ||
| "eslint-plugin-react-refresh": "^0.4.24", | ||
| "globals": "^16.5.0", | ||
| "husky": "^9.1.7", | ||
| "lint-staged": "^16.2.7", | ||
| "prettier": "3.7.4", | ||
| "typescript": "~5.9.3", | ||
| "typescript-eslint": "^8.46.4", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 방식
&&조건만으로도 린트 에러가 발생하면 스크립트가 자체적으로 commit을 종료해줄 것 같은데commit action이 확실히 중단될 수 있도록 실패 케이스(
||)에 대해exit 1을 명시해주는 건 어떨까요?명시적으로
exit 1을 걸어주면 린트검사를 통과하지 못했을 때 확실하게 커밋을 막을 수 있을 것 같습니다! 😄추가적으로 해당 브랜치 pull받아서 확인했을 때,
error: cannot spawn .husky/pre-commit: No such file or directory에러가 발생하더라구요.환경에 따라 스크립트를 실행할 쉘을 지정해주지 않으면 위와 같은 에러와 함께 스크립트가 실행되지 않을 수 있어서 스크립트 상단에
#!/bin/sh를 추가해주면 좋을 것 같아요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀해주신 대로
exit 1로 실패 케이스를 명확히 끊어주고 !#!/bin/sh도 추가해서 실행 환경에 따라 훅이 흔들리지 않게 수정했습니다 !그리고 찾아보니
cannot spawn .husky/pre-commit: No such file or directory는 줄바꿈(CRLF/LF) 때문에 발생하는 케이스도 있다고 해서 줄바꿈도 CRLF -> LF로 함께 수정했습니다 ! 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.