husky+lint-staged で eslint --fix をコミット時に実行する#1168
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1168 +/- ##
=======================================
Coverage 55.30% 55.30%
=======================================
Files 87 87
Lines 11089 11089
=======================================
Hits 6133 6133
Misses 4956 4956
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
master の webpack→esbuild 移行 (npm 化) に追従: - package.json: master ベースに husky/lint-staged を再追加 - yarn.lock 削除 (master の選択を採用) - .husky/pre-commit: yarn → npx に変更 - package-lock.json: husky/lint-staged を反映
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughHusky と lint-staged を設定して、Git プリコミットフック経由でステージング済みの TypeScript ファイルに対して自動的に ESLint を実行するツールチェーンを導入しました。 ChangesPre-commit Linting Setup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.husky/pre-commit:
- Line 1: 現在の pre-commit フック contains the fallback "npx lint-staged -q || node
-e ''" which swallows failures; remove the "|| node -e ''" fallback so that the
command "npx lint-staged -q" can fail the hook, i.e. keep only the lint-staged
invocation (or replace the fallback with an explicit non-zero exit if needed) so
ESLint/lint-staged errors cause the pre-commit to fail; update the line that
currently reads "npx lint-staged -q || node -e ''" accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05be8981-f185-46e0-86b3-d6c0c9357ab2
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
.husky/pre-commitpackage.json
| @@ -0,0 +1 @@ | |||
| npx lint-staged -q || node -e '' | |||
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 1) 現在のフック内容確認(リポジトリ内)
sed -n '1,40p' .husky/pre-commit
# 2) シェル評価の事実確認(false が右辺で成功に変わる)
bash -lc "false || node -e ''"; echo "exit_code=$?"
# 期待値: exit_code=0Repository: EC-CUBE/ec-cube2
Length of output: 222
|| node -e '' により pre-commit 失敗が握りつぶされています
lint-staged / eslint が失敗してもフック全体が成功終了し、問題のある変更がそのままコミット可能になります。PR 目的(コミット時の自動整形・検証)と逆の挙動です。
修正案
-npx lint-staged -q || node -e ''
+npx lint-staged -q📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| npx lint-staged -q || node -e '' | |
| npx lint-staged -q |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.husky/pre-commit at line 1, 現在の pre-commit フック contains the fallback "npx
lint-staged -q || node -e ''" which swallows failures; remove the "|| node -e
''" fallback so that the command "npx lint-staged -q" can fail the hook, i.e.
keep only the lint-staged invocation (or replace the fallback with an explicit
non-zero exit if needed) so ESLint/lint-staged errors cause the pre-commit to
fail; update the line that currently reads "npx lint-staged -q || node -e ''"
accordingly.
There was a problem hiding this comment.
ご指摘ありがとうございます。
|| node -e '' は意図的に残しています。本 PR は EC-CUBE 4系 PR #4661 および #6337 の方針を踏襲したもので、4系PRの方針に以下の記述があります。
- 実行要件(php + node.js)を満たさない環境の場合は何も起こらないようにする。
- コード整形に失敗した際にcommit不可となってしまうのを避けるため、整形不可のコードがcommit対象だった場合もフック成功とみなす。
本 PR の目的は「コミット時の自動整形」のみで、lint エラーで commit をブロックする意図はありません(eslint --fix が修正できないコードをコミット禁止にするのは過剰と判断)。
そのため || node -e '' は維持します。
There was a problem hiding this comment.
@nanasess ご説明ありがとうございます。意図的な設計であることを理解しました。
EC-CUBE 4系の方針(環境要件を満たさない場合は何もしない・整形失敗時もコミットをブロックしない)を踏襲した設計であることを承知しました。この方針は理にかなっており、指摘を取り下げます。
✏️ Learnings added
Learnt from: nanasess
Repo: EC-CUBE/ec-cube2 PR: 1168
File: .husky/pre-commit:1-1
Timestamp: 2026-05-07T00:17:52.020Z
Learning: In the EC-CUBE/ec-cube2 repository, the `.husky/pre-commit` hook intentionally uses `npx lint-staged -q || node -e ''` to always exit successfully. This follows the EC-CUBE v4 policy (PRs `#4661` and `#6337`): (1) do nothing if the environment doesn't meet requirements (php + node.js not available), and (2) do not block commits when auto-formatting fails. The purpose of the hook is auto-formatting only (`eslint --fix`), not enforcing lint compliance as a gate. The `|| node -e ''` fallback must NOT be flagged as swallowing errors — it is intentional design.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
- v15 → v17 へメジャーアップデート - v17 は Node.js 22.22.1+ 必須 / Git 2.32.0+ 必須 - husky は ^9.1.7 (最新) のまま
husky+lint-staged でコミット時に
*.tsファイルを自動整形するsee EC-CUBE/ec-cube#4661
.husky/pre-commitを使用するlint-staged 2>&1 | echoが動作しないためlint-staged -qに変更refs EC-CUBE/ec-cube#6337
Summary by CodeRabbit
リリースノート