chore: let commit bodies cite issue references#399
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a commitlint parsing edge case where mid-body #123 references were being misclassified as the start of the footer, causing footer-leading-blank false positives. It does so by overriding commitlint’s parser options to make issue-reference detection unmatchable while preserving conventional preset parsing behavior (including BREAKING CHANGE note detection), and adds a dedicated AVA “gate” test suite to prevent regressions.
Changes:
- Override commitlint
parserPreset.parserOpts.issuePrefixesto prevent#NNNin the body from triggering footer parsing, while spreading in the conventional preset’s parser options. - Add
test/commitlint.test.jsto gate the intended commitlint behaviors (including the historical trap case and BREAKING CHANGE footer detection). - Add
@commitlint/loadand@commitlint/lintas declared devDependencies to support the new test suite.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/commitlint.test.js |
Adds AVA tests that lint messages against the real project commitlint config to prevent the mid-body #NNN footer-parsing regression and preserve BREAKING CHANGE detection. |
package.json |
Declares commitlint libraries used directly by the new test suite. |
package-lock.json |
Locks dependency graph updates corresponding to the new declared devDependencies. |
.commitlintrc.mjs |
Overrides parser options to disable issue-reference detection while keeping the conventional preset’s parser behavior intact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "devDependencies": { | ||
| "@commitlint/cli": "^21.0.2", | ||
| "@commitlint/config-conventional": "^21.0.2", | ||
| "@commitlint/lint": "^21.0.2", | ||
| "@commitlint/load": "^21.0.2", |
There was a problem hiding this comment.
Fixed in 02d4e16 — declared conventional-changelog-conventionalcommits@^9.3.1 in devDependencies, the same range @commitlint/config-conventional@21 resolves, so npm dedupes to a single copy (verified with npm ls). Same defect class I'd fixed for the test's @commitlint/load/lint imports but missed in the config file itself — interestingly n/no-extraneous-import passes .commitlintrc.mjs clean, so this one needed your eyes.
There was a problem hiding this comment.
Resolved differently in 6c50a75 — the approach was reworked (see the updated PR description): the parser-opts patch is gone entirely, so .commitlintrc.mjs no longer imports conventional-changelog-conventionalcommits and the dependency was removed rather than declared. The fix is now a one-line rule disable; the only new devDependencies are @commitlint/load/@commitlint/lint for the gate test, both declared.
Disable footer-leading-blank. The conventional parser treats any body line containing a "#123" reference as the start of the footer, so the rule failed valid messages position-dependently — it bit the commit messages of #365, #370, and #397, each worked around by writing "PR 365". Its protection here is ~nil: git trailers like Co-Authored-By are never parser footer-starts, and a glued BREAKING CHANGE still parses as a note, so the blank line it wants is purely stylistic. Off, commit bodies can reference #123 naturally — including this message, which would have failed before. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6c50a75 to
fb7fefc
Compare
Commit bodies couldn't cite
#123naturally: the conventional parser treats any body line containing a reference as the start of the footer, sofooter-leading-blankfailed valid messages position-dependently. It bit the commit messages of #365, #370, and #397, each worked around by writing "PR 365" — a rule carried in a head instead of the machine.The change
One line:
footer-leading-blank: [0], documented inline — the same[0]pattern this config already uses forbody-max-line-lengthandfooter-max-line-length. The rule's protection here is ~nil: git trailers (Co-Authored-By) are never parser footer-starts, and a gluedBREAKING CHANGEstill parses as a note, so the blank line it wants is purely stylistic.No config test (changed from the first draft)
An earlier version of this branch patched the parser and added a test gating the commitlint config. Both dropped:
@commitlint/load/lintinto the repo to do it.The husky
commit-msghook already exercises the config on every commit.Dogfood
This PR's commit body cites
#365/#370/#397mid-line — positions that failed before this change — and the hook validated it.🤖 Generated with Claude Code