Skip to content

chore: let commit bodies cite issue references#399

Merged
TylerVigario merged 1 commit into
mainfrom
fix/commitlint-footer-trap
Jun 16, 2026
Merged

chore: let commit bodies cite issue references#399
TylerVigario merged 1 commit into
mainfrom
fix/commitlint-footer-trap

Conversation

@TylerVigario

@TylerVigario TylerVigario commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Commit bodies couldn't cite #123 naturally: the conventional parser treats any body line containing a reference as the start of the footer, so footer-leading-blank failed 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 for body-max-line-length and footer-max-line-length. The rule's protection here is ~nil: git trailers (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.

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:

  • the parser patch was over-built — a preset-internals import, a new devDependency, and a NUL-byte unmatchable prefix, with a comment documenting how it could silently break;
  • testing the config is a rare practice that here amounted to either re-testing commitlint's own rules or guarding our bespoke scope plugin against its own requirements. If that plugin warranted that level of coverage, the honest move would be to extract it as its own package with its own tests — not test it in place and drag @commitlint/load/lint into the repo to do it.

The husky commit-msg hook already exercises the config on every commit.

Dogfood

This PR's commit body cites #365 / #370 / #397 mid-line — positions that failed before this change — and the hook validated it.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 10, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.issuePrefixes to prevent #NNN in the body from triggering footer parsing, while spreading in the conventional preset’s parser options.
  • Add test/commitlint.test.js to gate the intended commitlint behaviors (including the historical trap case and BREAKING CHANGE footer detection).
  • Add @commitlint/load and @commitlint/lint as 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.

Comment thread package.json Outdated
Comment on lines +129 to +133
"devDependencies": {
"@commitlint/cli": "^21.0.2",
"@commitlint/config-conventional": "^21.0.2",
"@commitlint/lint": "^21.0.2",
"@commitlint/load": "^21.0.2",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TylerVigario TylerVigario changed the title fix(core): stop mid-body issue references from poisoning footer parsing fix(core): let commit bodies cite issue references (disable footer-leading-blank) Jun 10, 2026
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>
@TylerVigario TylerVigario force-pushed the fix/commitlint-footer-trap branch from 6c50a75 to fb7fefc Compare June 16, 2026 20:15
@TylerVigario TylerVigario changed the title fix(core): let commit bodies cite issue references (disable footer-leading-blank) chore: let commit bodies cite issue references Jun 16, 2026
@TylerVigario TylerVigario merged commit 85edd60 into main Jun 16, 2026
8 checks passed
@TylerVigario TylerVigario deleted the fix/commitlint-footer-trap branch June 16, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants