From 3f71f508c5163accb017e71c930007eac6f8578c Mon Sep 17 00:00:00 2001 From: Gilmore Davidson Date: Tue, 14 Feb 2023 17:25:11 +1100 Subject: [PATCH 1/2] chore(parse): run prettier on index.test.ts --- @commitlint/parse/src/index.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/@commitlint/parse/src/index.test.ts b/@commitlint/parse/src/index.test.ts index cb6baf3e67..812d3ce5a8 100644 --- a/@commitlint/parse/src/index.test.ts +++ b/@commitlint/parse/src/index.test.ts @@ -169,18 +169,18 @@ 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); From b124e25073d4c20a8299b0f0a1b0b7af7b87df47 Mon Sep 17 00:00:00 2001 From: Gilmore Davidson Date: Tue, 14 Feb 2023 17:25:45 +1100 Subject: [PATCH 2/2] fix(parse): allow setting fieldPattern in parserOpts --- @commitlint/parse/src/index.test.ts | 14 ++++++++++++++ @commitlint/parse/src/index.ts | 2 +- @commitlint/types/src/parse.ts | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/@commitlint/parse/src/index.test.ts b/@commitlint/parse/src/index.test.ts index 812d3ce5a8..a0b1814981 100644 --- a/@commitlint/parse/src/index.test.ts +++ b/@commitlint/parse/src/index.test.ts @@ -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'); diff --git a/@commitlint/parse/src/index.ts b/@commitlint/parse/src/index.ts index 5037173589..284c3e61b6 100644 --- a/@commitlint/parse/src/index.ts +++ b/@commitlint/parse/src/index.ts @@ -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; diff --git a/@commitlint/types/src/parse.ts b/@commitlint/types/src/parse.ts index 2654086d66..3eb026247e 100644 --- a/@commitlint/types/src/parse.ts +++ b/@commitlint/types/src/parse.ts @@ -34,6 +34,7 @@ export type Parser = ( export interface ParserOptions { commentChar?: string; + fieldPattern?: RegExp; headerCorrespondence?: string[]; headerPattern?: RegExp; issuePrefixes?: string[];