Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .husky/pre-commit
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 통과"
Copy link
Collaborator

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을 명시해주는 건 어떨까요?

Suggested change
echo "🐶 Husky pre-commit 실행"
pnpm exec lint-staged && echo "🎉 lint-staged 통과"
echo "🐶 Husky pre-commit 실행"
pnpm exec lint-staged || exit 1
echo "🎉 lint-staged 통과"

명시적으로 exit 1을 걸어주면 린트검사를 통과하지 못했을 때 확실하게 커밋을 막을 수 있을 것 같습니다! 😄

추가적으로 해당 브랜치 pull받아서 확인했을 때,
error: cannot spawn .husky/pre-commit: No such file or directory에러가 발생하더라구요.
환경에 따라 스크립트를 실행할 쉘을 지정해주지 않으면 위와 같은 에러와 함께 스크립트가 실행되지 않을 수 있어서 스크립트 상단에 #!/bin/sh를 추가해주면 좋을 것 같아요!

Suggested change
echo "🐶 Husky pre-commit 실행"
pnpm exec lint-staged && echo "🎉 lint-staged 통과"
#!/bin/sh
echo "🐶 Husky pre-commit 실행"
pnpm exec lint-staged || exit 1
echo "🎉 lint-staged 통과"

Copy link
Collaborator Author

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로 함께 수정했습니다 ! 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint-staged 설정 깔끔하네요! 특히 eslint → prettier 순서로 구성해서, eslint에서 자동 수정 가능한 부분을 먼저 처리하고
마지막에 prettier로 스타일을 맞추는 흐름 좋습니다 👍

이 부분은 지극히 개인적으로 추가하면 더 좋을 것 같은 부분인데, repo에서 만약 scss / yaml(yml) / mdx 등을 사용한다면 포맷 대상에 해당 확장자들을 함께 포함해두는 것도 좋을 것 같아요 :)
현재까지 실제 사용하는 확장자 기준으로만 추가하면 충분할 것 같습니다! 현재 기준으로는 아래와 같이 되겠네요 ☺️

"lint-staged": {
  "*.{ts,tsx,js,jsx}": [
    "eslint --fix",
    "prettier --write"
  ],
  "*.{json,md,mdx,css,yml,yaml}": [
    "prettier --write"
  ]
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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",
Expand All @@ -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",
Expand Down
Loading