Skip to content

Commit

Permalink
fix(parse): allow setting fieldPattern in parserOpts (#3538)
Browse files Browse the repository at this point in the history
* chore(parse): run prettier on index.test.ts

* fix(parse): allow setting fieldPattern in parserOpts
  • Loading branch information
gilmoreorless authored Feb 17, 2023
1 parent 07f9949 commit ea23c65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
34 changes: 24 additions & 10 deletions @commitlint/parse/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,38 @@ test('registers inline #', async () => {
});

test('keep -side notes- in the body section', async () => {
const header = "type(some/scope): subject"
const body =
"CI on master branch caught this:\n\n" +
"```\n" +
"Unhandled Exception:\n" +
const header = 'type(some/scope): subject';
const body =
'CI on master branch caught this:\n\n' +
'```\n' +
'Unhandled Exception:\n' +
"System.AggregateException: One or more errors occurred. (Some problem when connecting to 'api.mycryptoapi.com/eth')\n\n" +
"--- End of stack trace from previous location where exception was thrown ---\n\n" +
"at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n" +
"...\n" +
"```";
'--- End of stack trace from previous location where exception was thrown ---\n\n' +
'at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n' +
'...\n' +
'```';

const message = header + "\n\n" + body
const message = header + '\n\n' + body;

const actual = await parse(message);

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 ea23c65

Please sign in to comment.