Skip to content

Commit 6007659

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 60929f3 commit 6007659

File tree

3 files changed

+51
-79
lines changed

3 files changed

+51
-79
lines changed

commitlint.config.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ module.exports = {
9191
);
9292
},
9393

94-
"footer-notes-misplacement": ({ raw }: { raw: any }) => {
95-
let rawStr = Helpers.convertAnyToString(raw, "raw").trim();
96-
return Plugins.footerNotesMisplacement(rawStr);
94+
"footer-notes-misplacement": ({ body }: { body: any }) => {
95+
let bodyStr = Helpers.convertAnyToString(body, "body").trim();
96+
return Plugins.footerNotesMisplacement(bodyStr);
9797
},
9898

99-
"footer-references-existence": ({ raw }: { raw: any }) => {
100-
let rawStr = Helpers.convertAnyToString(raw, "raw").trim();
101-
return Plugins.footerReferencesExistence(rawStr);
99+
"footer-references-existence": ({ body }: { body: any }) => {
100+
let bodyStr = Helpers.convertAnyToString(body, "body").trim();
101+
return Plugins.footerReferencesExistence(bodyStr);
102102
},
103103

104104
"prefer-slash-over-backslash": ({
@@ -165,12 +165,12 @@ module.exports = {
165165
},
166166

167167
"body-soft-max-line-length": (
168-
{ raw }: { raw: any },
168+
{ body }: { body: any },
169169
_: any,
170170
maxLineLength: number
171171
) => {
172-
let rawStr = Helpers.convertAnyToString(raw, "raw").trim();
173-
return Plugins.bodySoftMaxLineLength(rawStr, maxLineLength);
172+
let bodyStr = Helpers.convertAnyToString(body, "body").trim();
173+
return Plugins.bodySoftMaxLineLength(bodyStr, maxLineLength);
174174
},
175175

176176
"trailing-whitespace": ({ raw }: { raw: any }) => {

commitlint/helpers.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ export abstract class Helpers {
2222
): string {
2323
if (potentialString === null || potentialString === undefined) {
2424
// otherwise, String(null) might give us the stupid string "null"
25-
throw new Error(
26-
"Unexpected " +
27-
paramName +
28-
"===null or " +
29-
paramName +
30-
"===undefined happened"
31-
);
25+
return "";
3226
}
3327
return String(potentialString);
3428
}

commitlint/plugins.ts

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,22 @@ export abstract class Plugins {
152152
return [!offence, message + Helpers.errMessageSuffix];
153153
}
154154

155-
public static footerNotesMisplacement(rawStr: string) {
155+
public static footerNotesMisplacement(bodyStr: string) {
156156
let offence = false;
157157

158-
let lineBreakIndex = rawStr.indexOf("\n");
159-
160-
if (lineBreakIndex >= 0) {
161-
// Extracting bodyStr from rawStr rather than using body directly is a
162-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
163-
let bodyStr = rawStr.substring(lineBreakIndex).trim();
164-
165-
if (bodyStr !== "") {
166-
let seenBody = false;
167-
let seenFooter = false;
168-
let lines = bodyStr.split(/\r?\n/);
169-
for (let line of lines) {
170-
if (line.length === 0) {
171-
continue;
172-
}
173-
seenBody = seenBody || !Helpers.isFooterNote(line);
174-
seenFooter = seenFooter || Helpers.isFooterNote(line);
175-
if (seenFooter && !Helpers.isFooterNote(line)) {
176-
offence = true;
177-
break;
178-
}
158+
if (bodyStr !== "") {
159+
let seenBody = false;
160+
let seenFooter = false;
161+
let lines = bodyStr.split(/\r?\n/);
162+
for (let line of lines) {
163+
if (line.length === 0) {
164+
continue;
165+
}
166+
seenBody = seenBody || !Helpers.isFooterNote(line);
167+
seenFooter = seenFooter || Helpers.isFooterNote(line);
168+
if (seenFooter && !Helpers.isFooterNote(line)) {
169+
offence = true;
170+
break;
179171
}
180172
}
181173
}
@@ -186,44 +178,36 @@ export abstract class Plugins {
186178
];
187179
}
188180

189-
public static footerReferencesExistence(rawStr: string) {
181+
public static footerReferencesExistence(bodyStr: string) {
190182
let offence = false;
191183

192-
let lineBreakIndex = rawStr.indexOf("\n");
193-
194-
if (lineBreakIndex >= 0) {
195-
// Extracting bodyStr from rawStr rather than using body directly is a
196-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
197-
let bodyStr = rawStr.substring(lineBreakIndex).trim();
198-
199-
if (bodyStr !== "") {
200-
let lines = bodyStr.split(/\r?\n/);
201-
let bodyReferences = new Set();
202-
let references = new Set();
203-
for (let line of lines) {
204-
let matches = line.match(/(?<=\[)([0-9]+)(?=\])/g);
205-
if (matches === null) {
206-
continue;
207-
}
208-
for (let match of matches) {
209-
if (Helpers.isFooterReference(line)) {
210-
references.add(match);
211-
} else {
212-
bodyReferences.add(match);
213-
}
214-
}
184+
if (bodyStr !== "") {
185+
let lines = bodyStr.split(/\r?\n/);
186+
let bodyReferences = new Set();
187+
let references = new Set();
188+
for (let line of lines) {
189+
let matches = line.match(/(?<=\[)([0-9]+)(?=\])/g);
190+
if (matches === null) {
191+
continue;
215192
}
216-
for (let ref of bodyReferences) {
217-
if (!references.has(ref)) {
218-
offence = true;
219-
break;
193+
for (let match of matches) {
194+
if (Helpers.isFooterReference(line)) {
195+
references.add(match);
196+
} else {
197+
bodyReferences.add(match);
220198
}
221199
}
222-
for (let ref of references) {
223-
if (!bodyReferences.has(ref)) {
224-
offence = true;
225-
break;
226-
}
200+
}
201+
for (let ref of bodyReferences) {
202+
if (!references.has(ref)) {
203+
offence = true;
204+
break;
205+
}
206+
}
207+
for (let ref of references) {
208+
if (!bodyReferences.has(ref)) {
209+
offence = true;
210+
break;
227211
}
228212
}
229213
}
@@ -368,18 +352,12 @@ export abstract class Plugins {
368352
}
369353

370354
public static bodySoftMaxLineLength(
371-
rawStr: string,
355+
bodyStr: string,
372356
bodyMaxLineLength: number
373357
) {
374358
let offence = false;
375359

376-
let lineBreakIndex = rawStr.indexOf("\n");
377-
378-
if (lineBreakIndex >= 0) {
379-
// Extracting bodyStr from rawStr rather than using body directly is a
380-
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
381-
let bodyStr = rawStr.substring(lineBreakIndex);
382-
360+
if (bodyStr !== "") {
383361
bodyStr = Helpers.removeAllCodeBlocks(bodyStr).trim();
384362

385363
if (bodyStr !== "") {

0 commit comments

Comments
 (0)