conventional-changelog / conventional-changelog/commitlint

In a commit title "foo: bar baz", the text "bar baz" is considered a **subject**, but not if the text "foo" contains special chars

Open
#3,404 7 comments 0 reactions 0 assignees View on GitHub
parser question triage
Dominant language
TypeScript
Stars
18.7k
Forks
970
Avg merge
7h 33m
Merged PRs (30d)
49

Description

## Steps to Reproduce (for bugs)

Develop a local plugin like documented here:
https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-plugins.md#local-plugins
So the config file starts like this:

```
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 150],
'header-max-length': [2, 'always', 50],
'subject-full-stop': [2, 'never', '.'],
'type-empty': [1, 'never'],
'type-space-after-colon': [2, 'always'],
'subject-lowercase': [2, 'always'],
},
plugins: [
{
rules: {
'subject-lowercase': ({subject}) => {
if (subject === null || subject === undefined) {
// otherwise, String(null) might give us the stupid string "null"
throw new Error('Unexpected subject===null or subject===undefined happened');
}

let offence = false;
if (subject != null && subject.length > 1) {
let firstIsUpperCase = subject[0].toUpperCase() == subject[0];
let firstIsLowerCase = subject[0].toLowerCase() == subject[0];
let secondIsUpperCase = subject[1].toUpperCase() == subject[1];
let secondIsLowerCase = subject[1].toLowerCase() == subject[1];

offence = firstIsUpperCase && (!firstIsLowerCase)
// to whitelist acronyms
&& (!secondIsUpperCase) && secondIsLowerCase;
}

return [
!offence,
`Please use lowercase as the first letter for your subject, i.e. the text after your area/scope`
];

...

```

1. Run the plugin against a commit msg like `foo: bar baz`, it works.
2. Run the plugin against a commit msg like `foo.bar: baz` or `foo-bar: baz` or `foo,bar: baz`, then....

## Current Behavior

It crashes with "Unexpected subject===null or subject===undefined happened" because of the assertion.

## Expected Behavior

It should not crash. Subject should always be the text after the first colon.

## Affected packages

- [x] cli
- [x] core
- [ ] prompt
- [ ] config-angular

## Possible Solution

No idea, didn't yet dive in the source code of commitlint sorry.

## Your Environment

| Executable | Version |
| ---------------------: | :------ |
| `commitlint --version` | 17.1.2 |
| `git --version` | 2.37.3 |
| `node --version` | v16.17.0 |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.