Skip to content

Commit df0bdc3

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 df0bdc3

File tree

3 files changed

+64
-80
lines changed

3 files changed

+64
-80
lines changed

commitlint.config.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ 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(
96+
body,
97+
"body"
98+
).trim();
99+
return Plugins.footerNotesMisplacement(bodyStr);
97100
},
98101

99-
"footer-references-existence": ({ raw }: { raw: any }) => {
100-
let rawStr = Helpers.convertAnyToString(raw, "raw").trim();
101-
return Plugins.footerReferencesExistence(rawStr);
102+
"footer-references-existence": ({ body }: { body: any }) => {
103+
let bodyStr = Helpers.convertAnyToString(
104+
body,
105+
"body"
106+
).trim();
107+
return Plugins.footerReferencesExistence(bodyStr);
102108
},
103109

104110
"prefer-slash-over-backslash": ({
@@ -165,12 +171,18 @@ module.exports = {
165171
},
166172

167173
"body-soft-max-line-length": (
168-
{ raw }: { raw: any },
174+
{ body }: { body: any },
169175
_: any,
170176
maxLineLength: number
171177
) => {
172-
let rawStr = Helpers.convertAnyToString(raw, "raw").trim();
173-
return Plugins.bodySoftMaxLineLength(rawStr, maxLineLength);
178+
let bodyStr = Helpers.convertAnyToString(
179+
body,
180+
"body"
181+
).trim();
182+
return Plugins.bodySoftMaxLineLength(
183+
bodyStr,
184+
maxLineLength
185+
);
174186
},
175187

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

commitlint/helpers.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@ export abstract class Helpers {
1919
public static convertAnyToString(
2020
potentialString: any,
2121
paramName: string
22-
): string {
22+
): any {
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 null;
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 !== null) {
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 !== null) {
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 !== null) {
383361
bodyStr = Helpers.removeAllCodeBlocks(bodyStr).trim();
384362

385363
if (bodyStr !== "") {

0 commit comments

Comments
 (0)