Skip to content

Commit

Permalink
fix(parse): allow setting fieldPattern in parserOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmoreorless committed Feb 14, 2023
1 parent 3f71f50 commit 1085d91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions @commitlint/parse/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ test('keep -side notes- in the body section', async () => {
expect(actual.body).toBe(body);
});

test('allows separating -side nodes- by setting parserOpts.fieldPattern', async () => {
const message =
'type(scope): subject\n\nbody text\n-authorName-\nrenovate[bot]';
const changelogOpts = {
parserOpts: {
fieldPattern: /^-(.*)-$/,
},
};
const actual = await parse(message, undefined, changelogOpts.parserOpts);

expect(actual.body).toBe('body text');
expect(actual).toHaveProperty('authorName', 'renovate[bot]');
});

test('parses references leading subject', async () => {
const message = '#1 some subject';
const opts = await require('conventional-changelog-angular');
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/parse/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default async function parse(
const defaultOpts = (await defaultChangelogOpts).parserOpts;
const opts = {
...defaultOpts,
fieldPattern: null,
...(parserOpts || {}),
fieldPattern: null
};
const parsed = parser(message, opts) as Commit;
parsed.raw = message;
Expand Down
1 change: 1 addition & 0 deletions @commitlint/types/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type Parser = (

export interface ParserOptions {
commentChar?: string;
fieldPattern?: RegExp;
headerCorrespondence?: string[];
headerPattern?: RegExp;
issuePrefixes?: string[];
Expand Down

0 comments on commit 1085d91

Please sign in to comment.