conventional-changelog / conventional-changelog/commitlint
Error when linting a message with the word "fix" in it using custom parser preset
- Dominant language
- TypeScript
- Stars
- 18.7k
- Forks
- 970
- Avg merge
- 7h 33m
- Merged PRs (30d)
- 49
Description
When using a custom parser preset, any form of the word "fix" seems to break parsing of references.
Running `echo "refs#111111 Fixed something" | commitlint` yields the following error:
```
{
references: [],
subject: 'Fixed something',
merge: null,
header: 'refs#111111 Fixed something',
body: null,
footer: null,
notes: [],
mentions: [],
revert: null,
raw: 'refs#111111 Fixed something\r\n'
}
⧗ input: refs#111111 Fixed something
✖ references may not be empty [references-empty]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
```
However, linting "refs#111111 This is a correct message" passes as expected.
`echo "refs#111111 This is a correct message" | commitlint`
```
{
references: [
{
action: null,
owner: null,
repository: null,
issue: '111111',
raw: 'refs#111111',
prefix: 'refs#'
}
],
subject: 'This is a correct message',
merge: null,
header: 'refs#111111 This is a correct message',
body: null,
footer: null,
notes: [],
mentions: [],
revert: null,
raw: 'refs#111111 This is a correct message\r\n'
}
```
## Expected Behavior
The mentioned commit message should pass validation
## Current Behavior
It seems as if any form of the word "fix" (e.g. "fixed", "fixes", "Fix..") must be the last word of the message or the linter will mistakenly fail.
## Affected packages
- [ ] cli
- [x] core (I suppose)
- [ ] prompt
- [ ] config-angular
## Steps to Reproduce (for bugs)
commitlint.config.js
module.exports = {
parserPreset: './commitlint.preset',
rules: {
'debug': [2, 'always'],
// Built-in rules
'header-full-stop': [2, 'never'], // Cannot have a trailing dot character
'references-empty': [2, 'never'], // Must have at least one referenced ticket
'subject-empty': [2, 'never'], // Must have a message (not just refs)
'subject-case': [2, 'always', 'sentence-case'], // Must be sentence-like (e.g. Added xy function)
// Custom rules
'subject-start': [2, 'never', ['-', 'refs', ':', '.']], // Message cannot start with these (format error)
'references-format': [2, 'always', /^,? ?refs#\d{5,}/] // Ban invalid refs format
},
plugins: [
{
rules: {
'debug': (parsed) => {
console.log(parsed);
return [true];
},
'subject-start': (parsed, when, value) => {
const { subject } = parsed;
if (!subject) {
return [true]; // subject-empty should handle missing subject
}
const negated = when === 'never';
const doesMach = negated ?
value.some(v => subject.trim().startsWith(v)) :
value.every(v => subject.trim().startsWith(v));
return [
negated ? !doesMach : doesMach,
`Subject ${negated ? 'may not' : 'must'} start with "${value.join('", "')}"`
];
},
'references-format': (parsed, when, matcher) => {
const { references } = parsed;
const negated = when === 'never';
const doesMach = negated ?
references.some(ref => ref.raw.trim().match(matcher)) :
references.every(ref => ref.raw.trim().match(matcher));
return [
negated ? !doesMach : doesMach,
`References ${negated ? 'may not' : 'must'} match format "${matcher}"`
];
}
}
}
]
};
commitlint.preset.js
module.exports = {
parserOpts: {
headerPattern: /^(?:(refs#\d{5,}(?:, ?refs#\d{5,})*) )?(.*)$/,
//headerPattern: /^((?:refs#\d{5,},?)*) ?(.*)$/,
headerCorrespondence: ['references', 'subject'],
issuePrefixes: ['refs#'],
issuePrefixesCaseSensitive: true
},
};
## Context
I am trying to configure commitlint for our custom message format `refs#TICKETNO Sentence case message`, where ticketno is a number at least 6 digits wide.
## Your Environment
| Executable | Version |
| ---------------------: | :------ |
| `commitlint --version` | @commitlint/cli@17.0.2 |
| `git --version` | git version 2.35.3.windows.1 |
| `node --version` | v14.16.0 |
Contributor guide
Assessment
This issue has not been assessed yet.