feat: commit時にstageされたファイルのみ自動でformatとlintを実行するように#5047
feat: commit時にstageされたファイルのみ自動でformatとlintを実行するように#5047renkonmaster wants to merge 10 commits intomasterfrom
Conversation
|
Preview (prod) → https://5047-prod.traq-preview.trapti.tech/ |
There was a problem hiding this comment.
Pull request overview
This PR implements automatic formatting and linting on commit for staged files only, using lint-staged and husky. The goal is to ensure all commits are properly formatted and linted, eliminating the need for manual "lint & format" commits.
Changes:
- Added lint-staged configuration to run eslint and prettier checks on staged files
- Added husky prepare script to enable git hooks
- Created pre-commit hook to execute lint-staged
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| package.json | Added "prepare" script for husky, added lint-staged dependency, and configured lint-staged rules for TypeScript/JavaScript and formatting |
| package-lock.json | Added lint-staged and its dependencies (commander, listr2, micromatch, etc.) |
| .husky/pre-commit | Created git pre-commit hook that executes npx lint-staged |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5047 +/- ##
==========================================
- Coverage 62.77% 62.60% -0.17%
==========================================
Files 108 108
Lines 3097 3097
Branches 630 630
==========================================
- Hits 1944 1939 -5
- Misses 1040 1048 +8
+ Partials 113 110 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughHusky と lint-staged を導入し、 Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as 開発者
participant Git as Git (commit)
participant Husky as Husky (.husky/pre-commit)
participant LintStaged as lint-staged
participant Tools as ESLint/Prettier
Dev->>Git: git commit
Git->>Husky: run pre-commit hook
Husky->>LintStaged: npx lint-staged
LintStaged->>Tools: run ESLint/Prettier on staged files
Tools-->>LintStaged: success / fail
alt success
LintStaged-->>Husky: exit 0
Husky-->>Git: allow commit
else fail
LintStaged-->>Husky: non-zero exit
Husky-->>Git: abort commit
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Line 29: The package.json "prepare" script is invalid because it uses
"husky:prepare"; update the "prepare" script value to "husky" so Husky v9 runs
correctly during npm install—locate the "prepare" key in package.json, replace
"husky:prepare" with "husky", and ensure no other scripts reference the old
"husky:prepare" token.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
.husky/pre-commitlint-staged.config.jspackage.json
|
ながらく放置していました 🙇♂️ |
uni-kakurenbo
left a comment
There was a problem hiding this comment.
ありがとうございます。
一か所だけ気になったのでコメントしました
docs/development.md
Outdated
|
|
||
| このリポジトリでは [husky](https://typicode.github.io/husky/) と [lint-staged](https://github.com/okonet/lint-staged) を利用して、コミット時にステージされたファイルへ自動でフォーマット(prettier)とlint(eslint --fix)が実行されます。 | ||
|
|
||
| 特別な操作は不要で、通常通りコミットするだけで自動的に修正・整形が行われます。 |
There was a problem hiding this comment.
prepare:husky しなくても動くんだっけ
There was a problem hiding this comment.
prepare:husky は必要でした.
prepare:husky は各自で実行する感じですか?それとも postinstall などに含めて、npm install 時に実行するようにしたほうがいいですか?
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/development.md`:
- Line 19: 行のコマンド例に付いているシェルプロンプト記号を削除してください — マークダウンの該当行の "$ npm run
husky:prepare" をプレフィックスなしの "npm run husky:prepare" に置き換え、MD014
警告が出ないようコマンド例をプロンプト無し表記に統一してください。
|
一度 |
概要
commit時に自動でformatとlintを実行するようにした
対象となるファイルはstageされたファイルのみ
なぜこの PR を入れたいのか
close: #4784
動作確認の手順
pre-commitの末尾にexit 1を書き、commitしたときのLogPR を出す前の確認事項
備考
@yas-ako とペアプロしました
Summary by CodeRabbit