Skip to content

Commit 1085d91

Browse files
committed
fix(parse): allow setting fieldPattern in parserOpts
1 parent 3f71f50 commit 1085d91

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

@commitlint/parse/src/index.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ test('keep -side notes- in the body section', async () => {
187187
expect(actual.body).toBe(body);
188188
});
189189

190+
test('allows separating -side nodes- by setting parserOpts.fieldPattern', async () => {
191+
const message =
192+
'type(scope): subject\n\nbody text\n-authorName-\nrenovate[bot]';
193+
const changelogOpts = {
194+
parserOpts: {
195+
fieldPattern: /^-(.*)-$/,
196+
},
197+
};
198+
const actual = await parse(message, undefined, changelogOpts.parserOpts);
199+
200+
expect(actual.body).toBe('body text');
201+
expect(actual).toHaveProperty('authorName', 'renovate[bot]');
202+
});
203+
190204
test('parses references leading subject', async () => {
191205
const message = '#1 some subject';
192206
const opts = await require('conventional-changelog-angular');

@commitlint/parse/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default async function parse(
1111
const defaultOpts = (await defaultChangelogOpts).parserOpts;
1212
const opts = {
1313
...defaultOpts,
14+
fieldPattern: null,
1415
...(parserOpts || {}),
15-
fieldPattern: null
1616
};
1717
const parsed = parser(message, opts) as Commit;
1818
parsed.raw = message;

@commitlint/types/src/parse.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type Parser = (
3434

3535
export interface ParserOptions {
3636
commentChar?: string;
37+
fieldPattern?: RegExp;
3738
headerCorrespondence?: string[];
3839
headerPattern?: RegExp;
3940
issuePrefixes?: string[];

0 commit comments

Comments
 (0)