Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rule for BREAKING CHANGE: in header #3838

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions @commitlint/rules/src/header-breaking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import parse from '@commitlint/parse';
import {headerBreaking} from './header-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] = headerBreaking(await parsed.empty);
const expected = true;
expect(actual).toEqual(expected);
});

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

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

return [!result, 'move BREAKING CHANGE: to footer'];
};
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 {headerBreaking} from './header-breaking';
import {subjectCase} from './subject-case';
import {subjectEmpty} from './subject-empty';
import {subjectFullStop} from './subject-full-stop';
Expand All @@ -47,6 +48,7 @@ export default {
'footer-max-length': footerMaxLength,
'footer-max-line-length': footerMaxLineLength,
'footer-min-length': footerMinLength,
'header-breaking': headerBreaking,
'header-case': headerCase,
'header-full-stop': headerFullStop,
'header-max-length': headerMaxLength,
Expand Down