diff --git a/@commitlint/parse/src/index.test.ts b/@commitlint/parse/src/index.test.ts index cb6baf3e67..a0b1814981 100644 --- a/@commitlint/parse/src/index.test.ts +++ b/@commitlint/parse/src/index.test.ts @@ -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'); 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[];