Skip to content

Commit cf92cd5

Browse files
committed
commitlint.config: remove workaround for body
The workaround is not needed anymore because we're now using a recent-enough version of commitlint that includes the fix for the bug [1]. [1] conventional-changelog/commitlint#3428
1 parent 051add3 commit cf92cd5

File tree

1 file changed

+45
-64
lines changed

1 file changed

+45
-64
lines changed

commitlint.config.ts

+45-64
Original file line numberDiff line numberDiff line change
@@ -298,33 +298,26 @@ module.exports = {
298298
];
299299
},
300300

301-
'footer-notes-misplacement': ({raw}: {raw:any}) => {
301+
'footer-notes-misplacement': ({body}: {body:any}) => {
302302
let offence = false;
303303

304-
let rawStr = convertAnyToString(raw, "raw").trim();
305-
let lineBreakIndex = rawStr.indexOf('\n');
306-
307-
if (lineBreakIndex >= 0){
308-
// Extracting bodyStr from rawStr rather than using body directly is a
309-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
310-
let bodyStr = rawStr.substring(lineBreakIndex).trim();
304+
if (body !== null) {
305+
let bodyStr = convertAnyToString(body, "body");
311306

312-
if (bodyStr !== ''){
313-
let seenBody = false;
314-
let seenFooter = false;
315-
let lines = bodyStr.split(/\r?\n/);
316-
for (let line of lines) {
317-
if (line.length === 0){
318-
continue;
319-
}
320-
seenBody = seenBody || !isFooterNote(line);
321-
seenFooter = seenFooter || isFooterNote(line);
322-
if (seenFooter && !isFooterNote(line)) {
323-
offence = true;
324-
break;
325-
}
326-
307+
let seenBody = false;
308+
let seenFooter = false;
309+
let lines = bodyStr.split(/\r?\n/);
310+
for (let line of lines) {
311+
if (line.length === 0){
312+
continue;
313+
}
314+
seenBody = seenBody || !isFooterNote(line);
315+
seenFooter = seenFooter || isFooterNote(line);
316+
if (seenFooter && !isFooterNote(line)) {
317+
offence = true;
318+
break;
327319
}
320+
328321
}
329322
}
330323
return [
@@ -333,46 +326,39 @@ module.exports = {
333326
]
334327
},
335328

336-
'footer-references-existence': ({raw}: {raw:any}) => {
329+
'footer-references-existence': ({body}: {body:any}) => {
337330
let offence = false;
338331

339-
let rawStr = convertAnyToString(raw, "raw").trim();
340-
let lineBreakIndex = rawStr.indexOf('\n');
332+
if (body !== null) {
333+
let bodyStr = convertAnyToString(body, "body");
341334

342-
if (lineBreakIndex >= 0){
343-
// Extracting bodyStr from rawStr rather than using body directly is a
344-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
345-
let bodyStr = rawStr.substring(lineBreakIndex).trim();
346-
347-
if (bodyStr !== ''){
348-
let lines = bodyStr.split(/\r?\n/);
349-
let bodyReferences = new Set();
350-
let references = new Set();
351-
for (let line of lines) {
352-
let matches = line.match(/(?<=\[)([0-9]+)(?=\])/g);
353-
if (matches === null) {
354-
continue;
335+
let lines = bodyStr.split(/\r?\n/);
336+
let bodyReferences = new Set();
337+
let references = new Set();
338+
for (let line of lines) {
339+
let matches = line.match(/(?<=\[)([0-9]+)(?=\])/g);
340+
if (matches === null) {
341+
continue;
342+
}
343+
for (let match of matches){
344+
if (isFooterReference(line)) {
345+
references.add(match);
355346
}
356-
for (let match of matches){
357-
if (isFooterReference(line)) {
358-
references.add(match);
359-
}
360-
else {
361-
bodyReferences.add(match);
362-
}
347+
else {
348+
bodyReferences.add(match);
363349
}
364350
}
365-
for (let ref of bodyReferences) {
366-
if (!references.has(ref)) {
367-
offence = true;
368-
break;
369-
}
351+
}
352+
for (let ref of bodyReferences) {
353+
if (!references.has(ref)) {
354+
offence = true;
355+
break;
370356
}
371-
for (let ref of references) {
372-
if (!bodyReferences.has(ref)) {
373-
offence = true;
374-
break;
375-
}
357+
}
358+
for (let ref of references) {
359+
if (!bodyReferences.has(ref)) {
360+
offence = true;
361+
break;
376362
}
377363
}
378364
}
@@ -516,16 +502,11 @@ module.exports = {
516502
];
517503
},
518504

519-
'body-soft-max-line-length': ({raw}: {raw:any}) => {
505+
'body-soft-max-line-length': ({body}: {body:any}) => {
520506
let offence = false;
521507

522-
let rawStr = convertAnyToString(raw, "raw").trim();
523-
let lineBreakIndex = rawStr.indexOf('\n');
524-
525-
if (lineBreakIndex >= 0){
526-
// Extracting bodyStr from rawStr rather than using body directly is a
527-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
528-
let bodyStr = rawStr.substring(lineBreakIndex);
508+
if (body !== null) {
509+
let bodyStr = convertAnyToString(body, "body");
529510

530511
bodyStr = removeAllCodeBlocks(bodyStr).trim();
531512

0 commit comments

Comments
 (0)