conventional-changelog / conventional-changelog/commitlint
Distinguish null and empty-string for header fields
- Dominant language
- TypeScript
- Stars
- 18.7k
- Forks
- 970
- Avg merge
- 7h 33m
- Merged PRs (30d)
- 49
Description
## Expected Behavior
Superfluous `scope` should be reported by the `scope-empty` rule, i.e., `feat(): something` should be reported.
## Current Behavior
The `scope-empty` rule does not report on superfluous `scope`, though the test case said that it should, but the test assertion does not seem to match the behavior:
https://github.com/conventional-changelog/commitlint/blob/59849dc8df7fa645c2528970b933edfd27f9c31e/%40commitlint/rules/src/scope-empty.test.ts#L46-L50
The root cause is that [the `conventional-commits-parser` always converts falsy values to `null`](https://github.com/conventional-changelog/conventional-changelog/blob/be1246c68f5dc4e6f28996129951a75bbf1cf307/packages/conventional-commits-parser/lib/parser.js#L172), which causes `null` and `""` not distinguishable.
## Affected packages
- [x] `@commitlint/rules`
- [x] `conventional-commits-parser`
## Possible Solution
Somehow disable the falsy conversion.
## Steps to Reproduce
```sh
mkdir commitlint-superfluous-scope
cd commitlint-superfluous-scope
npm init -y
npm install @commitlint/cli
echo '
module.exports = {
rules: {
"scope-empty": [2, "always"],
},
}
' > .commitlintrc.js
echo "feat(): something" | node_modules/.bin/commitlint # passed but it should report error
```
## Context
I want to write some rules to avoid the usage of the superfluous `scope` and some custom header fields, but I found that it is impossible because of the falsy conversion, and I don't want to fix it on the regex-level:
```diff
-headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$/,
+headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]+)\))?: (.*)$/,
```
since the lint message will be super confusing.
## Your Environment
| Executable | Version |
| ---------------------: | :------ |
| `commitlint --version` | 9.1.2 |
Contributor guide
Assessment
This issue has not been assessed yet.