Skip to content

Commit ea23c65

Browse files
fix(parse): allow setting fieldPattern in parserOpts (#3538)
* chore(parse): run prettier on index.test.ts * fix(parse): allow setting fieldPattern in parserOpts
1 parent 07f9949 commit ea23c65

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

Diff for: @commitlint/parse/src/index.test.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,38 @@ test('registers inline #', async () => {
169169
});
170170

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

183-
const message = header + "\n\n" + body
183+
const message = header + '\n\n' + body;
184184

185185
const actual = await parse(message);
186186

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');

Diff for: @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;

Diff for: @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)