fix(commit-validate): guard extractMessage against non-commit commands#83
Conversation
📝 WalkthroughWalkthrough
ChangesCommit validation
Estimated code review effort: 2 (Simple) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
🧹 Nitpick comments (1)
scripts/commit-validate.js (1)
18-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove redundant
git commitcheck.The addition of this early guard guarantees that the command contains a
git commitinvocation. Consequently, the identical regex check at line 46 is now always true, making it redundant, and the fallback return at line 53 is unreachable dead code.Consider replacing lines 46-53 with the simplified logic:
const afterCommit = command.split(/\bcommit\b/)[1] || ''; const hasExplicitFlag = /(?:-m|--message|-F|--file|--amend)\b/.test(afterCommit); if (!hasExplicitFlag) return { msg: null, form: 'editor' }; return { msg: null, form: 'unknown' };🤖 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 `@scripts/commit-validate.js` around lines 18 - 26, Simplify the post-guard command classification by removing the redundant git commit regex check and its unreachable fallback in the commit-validation flow. After the existing guard, derive the text after the commit keyword, detect explicit message-related flags there, and return the editor form when absent or unknown when present.
🤖 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.
Nitpick comments:
In `@scripts/commit-validate.js`:
- Around line 18-26: Simplify the post-guard command classification by removing
the redundant git commit regex check and its unreachable fallback in the
commit-validation flow. After the existing guard, derive the text after the
commit keyword, detect explicit message-related flags there, and return the
editor form when absent or unknown when present.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b84080a6-2d72-4909-8a4c-5de6e8c53e9d
📒 Files selected for processing (1)
scripts/commit-validate.js
Fixes #82.
Bug
extractMessage()inscripts/commit-validate.jsruns its-m/--message/heredoc/-F/--filesub-patterns unconditionally, with no check that the command is actually agit commit. Any Bash command containing a heredoc, or an unrelated-mflag, gets misread as a commit message and validated against the conventional-commit pattern — blocking work that has nothing to do with committing.Concretely, this blocks something as simple as:
Fix
Add an early guard so none of the sub-patterns run unless the command actually contains a real
git commitinvocation.Verification
Tested directly against the patched script:
git commit -m "feat: add thing") → passes (exit 0)git commit -m "not conventional") → still blocks correctly (exit 2), same error as beforeNo existing tests reference this script, so no test suite changes.
Summary by CodeRabbit