Skip to content

Commit c3bd59d

Browse files
committed
feat: add rule for BREAKING CHANGE: in subject
`BREAKING CHANGE:` is a footer thing Fixed conventional-changelog#3810
1 parent 84b4a94 commit c3bd59d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

@commitlint/rules/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {scopeEnum} from './scope-enum';
2121
import {scopeMaxLength} from './scope-max-length';
2222
import {scopeMinLength} from './scope-min-length';
2323
import {signedOffBy} from './signed-off-by';
24+
import {subjectBreaking} from './subject-breaking';
2425
import {subjectCase} from './subject-case';
2526
import {subjectEmpty} from './subject-empty';
2627
import {subjectFullStop} from './subject-full-stop';
@@ -58,6 +59,7 @@ export default {
5859
'scope-max-length': scopeMaxLength,
5960
'scope-min-length': scopeMinLength,
6061
'signed-off-by': signedOffBy,
62+
'subject-breaking': subjectBreaking,
6163
'subject-case': subjectCase,
6264
'subject-empty': subjectEmpty,
6365
'subject-full-stop': subjectFullStop,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import parse from '@commitlint/parse';
2+
import {subjectBreaking} from './subject-breaking';
3+
4+
const messages = {
5+
empty: 'test: \nbody',
6+
filled: 'BREAKING CHANGE: this one',
7+
};
8+
9+
const parsed = {
10+
empty: parse(messages.empty),
11+
filled: parse(messages.filled),
12+
};
13+
14+
test('without subject should succeed', async () => {
15+
const [actual] = subjectBreaking(await parsed.empty);
16+
const expected = true;
17+
expect(actual).toEqual(expected);
18+
});
19+
20+
test('subject fail with BREAKING CHANGE:', async () => {
21+
const [actual] = subjectBreaking(await parsed.filled);
22+
const expected = false;
23+
expect(actual).toEqual(expected);
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {SyncRule} from '@commitlint/types';
2+
3+
export const subjectBreaking: SyncRule = (parsed) => {
4+
const result = parsed.subject?.startsWith('BREAKING CHANGE:');
5+
6+
return [!result, 'move BREAKING CHANGE: to footer'];
7+
};

0 commit comments

Comments
 (0)