refactor(githooks): use non-capturing groups for unread regex captures

The commit-msg header regex captured the optional scope and breaking-change
marker but never read them. Make those groups non-capturing so only the type
and subject are captured, per review feedback.
This commit is contained in:
Claude
2026-06-27 11:37:19 +00:00
parent 73e5f61671
commit 69cd0ccdbb

View File

@@ -80,14 +80,14 @@ function collectErrors (header) {
errors.push(`header is ${header.length} characters; keep it within ${HEADER_MAX_LENGTH}`)
}
const match = /^([^():!]+)(\([^)]*\))?(!)?: (.*)$/.exec(header)
const match = /^([^():!]+)(?:\([^)]*\))?(?:!)?: (.*)$/.exec(header)
if (!match) {
errors.push('header must match "type(optional scope): subject", e.g. "fix(core): handle empty input"')
return errors
}
const type = match[1]
const subject = match[4]
const subject = match[2]
if (type !== type.toLowerCase()) {
errors.push(`type "${type}" must be lower-case`)