Repository navigation
fix(lint): trim trailing whitespace off the message handed to ignore matchers - #4960
Merged
escapedcat merged 2 commits intoAug 21, 2026
Conversation
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The normalization is confined to ignore predicate evaluation, while parsing, rules, and reported input continue to receive the original message; the added unit and CLI tests cover the relevant positive, negative, and regression paths.
|
| Filename | Overview |
|---|---|
| @commitlint/lint/src/lint.ts | Trims trailing whitespace only for ignore matching and leaves the original message unchanged for all subsequent parsing and reporting. |
| @commitlint/lint/src/lint.test.ts | Thoroughly covers normalized matcher input, preserved leading whitespace and raw messages, whitespace-only matching, and rule-evaluation regressions. |
| @commitlint/cli/src/cli.test.ts | Verifies exact ignore matching through edit and stdin paths, including a nonmatching negative case. |
| @commitlint/cli/fixtures/ignores-exact/commitlint.config.js | Provides a focused strict-equality ignore fixture backed by intentionally failing lint rules. |
Reviews (1): Last reviewed commit: "fix(lint): trim trailing whitespace off ..." | Re-trigger Greptile
Member
|
Thanks |
Merged
via the queue into
conventional-changelog:master
with commit Aug 21, 2026
a6f279b
12 checks passed
sys-support
pushed a commit
to 3caravelle/renovate
that referenced
this pull request
Sep 21, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@commitlint/cli](https://commitlint.js.org/) ([source](https://github.com/conventional-changelog/commitlint/tree/HEAD/@commitlint/cli)) | [`21.2.2` → `21.2.3`](https://renovatebot.com/diffs/npm/@commitlint%2fcli/21.2.2/21.2.3) |  |  | | [@commitlint/config-conventional](https://commitlint.js.org/) ([source](https://github.com/conventional-changelog/commitlint/tree/HEAD/@commitlint/config-conventional)) | [`21.2.2` → `21.2.3`](https://renovatebot.com/diffs/npm/@commitlint%2fconfig-conventional/21.2.2/21.2.3) |  |  | --- ### Release Notes <details> <summary>conventional-changelog/commitlint (@​commitlint/cli)</summary> ### [`v21.2.3`](https://github.com/conventional-changelog/commitlint/blob/HEAD/@​commitlint/cli/CHANGELOG.md#2123-2026-09-19) [Compare Source](conventional-changelog/commitlint@v21.2.2...v21.2.3) ##### Bug Fixes - **lint:** trim trailing whitespace off the message handed to ignore matchers ([#​4960](conventional-changelog/commitlint#4960)) ([a6f279b](conventional-changelog/commitlint@a6f279b)) </details> <details> <summary>conventional-changelog/commitlint (@​commitlint/config-conventional)</summary> ### [`v21.2.3`](https://github.com/conventional-changelog/commitlint/blob/HEAD/@​commitlint/config-conventional/CHANGELOG.md#2123-2026-09-19) [Compare Source](conventional-changelog/commitlint@v21.2.2...v21.2.3) ##### Bug Fixes - **rules:** report the case that matched in case rule failure messages ([#​4962](conventional-changelog/commitlint#4962)) ([9f5f7bc](conventional-changelog/commitlint@9f5f7bc)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi44MS4zIiwidXBkYXRlZEluVmVyIjoiNDIuODEuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: https://git.3caravelle.net/3Caravelle/renovate/pulls/59 Co-authored-by: Renovate Bot <renovate-bot@3caravelle.com>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
@commitlint/linthands the raw message to the ignore matchers, and a message read from a file orfrom git history still carries its trailing newlines. An
ignoresmatcher that compares the messageby value therefore never matches, and the commit gets linted anyway.
@commitlint/readappends a newline to the contents of the commit message file inget-edit-commit.ts, and git has already put one there, so a commit-msg hook hands"Initialize project using Create React App\n\n"to the matcher. Commits read from history arrivethe same way, and a piped message keeps the newline the shell adds. This is the case @escapedcat
reproduced in the issue thread, where the matcher printed
STARThello\n\nENDand returned false.Where the fix goes
The trim happens in
@commitlint/lint, on the value passed toisIgnored, and nowhere else.Trimming in
@commitlint/read/src/get-edit-commit.tslooked like the smaller change but it is thewrong place. It changes the string every consumer of that package sees, and a commit message is
newline significant.
parsed.rawcarries the message through to the rules, andbody-leading-blankand
footer-leading-blankindex into its lines whilesigned-off-byandtrailer-existsread ittoo. Linting
"\nfeat: thing\n\nbody\n\n"underbody-leading-blankfails today and starts passingif the read layer trims, which is a rule quietly changing its answer. Trimming before the ignore
check leaves the message that reaches the parser byte for byte identical, so no rule can move. It
also covers every input source at once, because they all reach this same call.
Only the end of the message is trimmed. The default matchers in
@commitlint/is-ignoredareanchored to the start of the message, so trimming the start would make them match messages they do
not match today, and a linter that begins skipping commits it used to check is the worse failure.
Running the last 600 commit messages of this repository through
isIgnoredwith a blank first lineadded shows the size of that: trimming the end changes 0 of the 600 ignore decisions, trimming both
ends changes 28 of them. Those 28 are release commits and reverts that would silently stop being
linted.
@commitlint/is-ignoreditself is untouched, so anyone calling it directly keeps thebehavior they have.
Motivation and Context
Fixes #3162
The repository's own documentation contradicts the current behavior.
docs/reference/configuration.mdpresents
ignores: [(commit) => commit === ""]as the worked example of the option, and no messageread through
--editor through--from/--tocan ever equal"". The existing test in@commitlint/cli/src/cli.test.tspasses only because its fixture usescommit.includes("WIP")rather than a comparison by value, which is what hid this.
One clarification on the example in the issue title. A truly empty
--editmessage never reacheslint()at all, becausecli.tsdrops messages that are blank after trimming before it lints. Thereachable form of the bug is the one above, where a matcher compares against real message text.
Usage examples
How Has This Been Tested?
Unit tests in
@commitlint/lint/src/lint.test.tscover a matcher comparing by value against amessage with trailing newlines, the exact value a matcher receives, the documented empty-message
matcher firing on a whitespace-only message, leading whitespace being preserved, a semver message
behind a blank first line still being linted, and a multi-line message with a body and a footer
producing the same result with and without trailing newlines.
End-to-end tests in
@commitlint/cli/src/cli.test.tscover the--editpath and the stdin pathagainst a new
fixtures/ignores-exactfixture whose matcher compares by value, plus the negativecase where the message does not match.
On the test commit alone, five of the new lint tests and two of the new cli tests fail on assertions
rather than on build or import errors, so the coverage is not vacuous.
Regression check against real messages: the last 600 commit messages of this repository were shaped
the way
@commitlint/readhands them over, then linted against@commitlint/config-conventionalonmaster and on this branch. All 600 produce identical outcomes, with the same 6 invalid messages and
the same reported output on both sides.
What I ran locally on Node 22 and pnpm 11:
pnpm buildpnpm test, the full suite, 91 files and 1227 tests, no type errorsnpx oxlintandnpx oxfmt --checkover the changed files, both cleannpx commitlint --from 013c3582 --to HEAD --verbose, 0 problems on both commitsOne note on the last two.
pnpm lintandpnpm formatat the repository root also walk anuntracked
.cache/directory that corepack drops in the checkout, and they fail on master for thesame reason, so I ran oxlint and oxfmt against the changed files instead.
One thing left alone
lint("\n\n")still rejects withExpected a raw commitfrom the parser, because the guard aboveparsechecksmessage === ""and a whitespace-only message does not hit it. The CLI never reachesthat path since it drops blank messages before linting, and tightening the guard would change the
error that
lint()throws when it is called with no arguments. That looked like its own change.Types of changes
Checklist:
implementation.
No documentation change is needed here. The
ignoresexample indocs/reference/configuration.mdalready describes what the option is meant to do, and this change makes that description true, so I
verified the example works rather than editing it.