Skip to content

Commit

Permalink
feat: add rule for BREAKING CHANGE: in subject
Browse files Browse the repository at this point in the history
`BREAKING CHANGE:` is a footer thing

Fixed conventional-changelog#3810
  • Loading branch information
abitrolly committed Jan 4, 2024
1 parent 84b4a94 commit c3bd59d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions @commitlint/rules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {scopeEnum} from './scope-enum';
import {scopeMaxLength} from './scope-max-length';
import {scopeMinLength} from './scope-min-length';
import {signedOffBy} from './signed-off-by';
import {subjectBreaking} from './subject-breaking';
import {subjectCase} from './subject-case';
import {subjectEmpty} from './subject-empty';
import {subjectFullStop} from './subject-full-stop';
Expand Down Expand Up @@ -58,6 +59,7 @@ export default {
'scope-max-length': scopeMaxLength,
'scope-min-length': scopeMinLength,
'signed-off-by': signedOffBy,
'subject-breaking': subjectBreaking,
'subject-case': subjectCase,
'subject-empty': subjectEmpty,
'subject-full-stop': subjectFullStop,
Expand Down
24 changes: 24 additions & 0 deletions @commitlint/rules/src/subject-breaking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import parse from '@commitlint/parse';
import {subjectBreaking} from './subject-breaking';

const messages = {
empty: 'test: \nbody',
filled: 'BREAKING CHANGE: this one',
};

const parsed = {
empty: parse(messages.empty),
filled: parse(messages.filled),
};

test('without subject should succeed', async () => {
const [actual] = subjectBreaking(await parsed.empty);
const expected = true;
expect(actual).toEqual(expected);
});

test('subject fail with BREAKING CHANGE:', async () => {
const [actual] = subjectBreaking(await parsed.filled);
const expected = false;
expect(actual).toEqual(expected);
});
7 changes: 7 additions & 0 deletions @commitlint/rules/src/subject-breaking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {SyncRule} from '@commitlint/types';

export const subjectBreaking: SyncRule = (parsed) => {
const result = parsed.subject?.startsWith('BREAKING CHANGE:');

return [!result, 'move BREAKING CHANGE: to footer'];
};

0 comments on commit c3bd59d

Please sign in to comment.