Skip to content

fix(rules): report the case that matched in case rule failure messages - #4962

Merged
escapedcat merged 2 commits into
conventional-changelog:masterfrom
dylanpulver:fix/case-rule-message-matched-cases
Aug 22, 2026
Merged

escapedcat merged 2 commits into
conventional-changelog:masterfrom
dylanpulver:fix/case-rule-message-matched-cases

Conversation

@dylanpulver

Copy link
Copy Markdown
Contributor

Description

All five case rules listed every configured case in the failure message, matched or not. Under never they now name only the case(s) the input matched.

For the scope-case: [2, "never", ["sentence-case", "start-case"]] example in #3501:

-✖   scope must not be sentence-case, start-case [scope-case]
+✖   scope must not be sentence-case [scope-case]

start-case never matched ClearlyDefined, because startCase() returns Clearly Defined. It appeared in the message only because it was configured.

Under always a failure means nothing matched, so those messages keep listing every configured case.

Motivation and Context

#3501 reads as if start-case fired on a camel-cased scope. #3312 has the same shape: JTD types -> JSON schema types is reported as upper-case when only sentence-case matches. Case semantics are untouched, per the conclusion in #3501.

Usage examples

// commitlint.config.js
export default {
	rules: { "scope-case": [2, "never", ["sentence-case", "start-case"]] },
};
echo 'fix(ClearlyDefined): Make `Described` use `CurationFacets`' | commitlint
# before: ✖   scope must not be sentence-case, start-case [scope-case]
# after:  ✖   scope must not be sentence-case [scope-case]

Under config-conventional, each rejected subject now names its own reason:

fix(scope): Some message  ->  subject must not be sentence-case
fix(scope): Some Message  ->  subject must not be sentence-case, start-case
fix(scope): SomeMessage   ->  subject must not be sentence-case, pascal-case
fix(scope): SOMEMESSAGE   ->  subject must not be sentence-case, start-case, upper-case

How Has This Been Tested?

pnpm build and pnpm test pass. 20 new unit tests, four per rule: never matching one case, never matching a subset, always matching none, never matching none. Reverting the source change fails 10 of them plus the config-conventional message test.

Verdict neutrality was measured. 56,909 unique conventional commit messages from 16 public repos went through the five rules under 14 configs spanning always, never, and per-check when objects. Of 796,726 pass/fail verdicts, 0 changed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have verified that any documentation examples I added/changed actually work.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • For a feature/bug fix, my commits follow the test-driven flow: a failing-test commit, then the implementation.

@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified.

The five rules preserve their existing pass/fail calculation while retaining all matching checks solely to improve failure-message precision, and the added tests cover single matches, multiple matches, no matches, and conventional-config integration.

Important Files Changed

Filename Overview
@commitlint/rules/src/body-case.ts Collects matching body-case checks and uses them to produce more precise never failure messages.
@commitlint/rules/src/header-case.ts Applies the same matched-case diagnostic behavior to headers while preserving validation results.
@commitlint/rules/src/scope-case.ts Reports matching scope cases while retaining existing segmented-scope and delimiter handling.
@commitlint/rules/src/subject-case.ts Reports matching subject cases without altering the existing Unicode-aware subject eligibility logic.
@commitlint/rules/src/type-case.ts Reports only matching type cases for failed never rules while preserving existing verdict semantics.
@commitlint/config-conventional/src/index.test.ts Updates integration expectations to verify input-specific subject-case diagnostics.

Reviews (1): Last reviewed commit: "fix(rules): report the case that matched..." | Re-trigger Greptile

@escapedcat
escapedcat added this pull request to the merge queue Aug 22, 2026
Merged via the queue into conventional-changelog:master with commit 9f5f7bc Aug 22, 2026
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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@commitlint%2fcli/21.2.3?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@commitlint%2fcli/21.2.2/21.2.3?slim=true) |
| [@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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@commitlint%2fconfig-conventional/21.2.3?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@commitlint%2fconfig-conventional/21.2.2/21.2.3?slim=true) |

---

### Release Notes

<details>
<summary>conventional-changelog/commitlint (@&#8203;commitlint/cli)</summary>

### [`v21.2.3`](https://github.com/conventional-changelog/commitlint/blob/HEAD/@&#8203;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 ([#&#8203;4960](conventional-changelog/commitlint#4960)) ([a6f279b](conventional-changelog/commitlint@a6f279b))

</details>

<details>
<summary>conventional-changelog/commitlint (@&#8203;commitlint/config-conventional)</summary>

### [`v21.2.3`](https://github.com/conventional-changelog/commitlint/blob/HEAD/@&#8203;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 ([#&#8203;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>
Vivswan added a commit to Vivswan/repo-platform that referenced this pull request Nov 20, 2026
…21.2.3 names in a subject-case failure

commitlint 21.2.3 reports the case a subject matched instead of the four the rule refuses (conventional-changelog/commitlint#4962). The verdict is the same; only the line a committer reads is shorter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants