Skip to content

Commit

Permalink
commitlint.config: remove workaround for body
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tehraninasab committed Feb 4, 2023
1 parent 45f40e1 commit 91c4fa3
Showing 1 changed file with 44 additions and 65 deletions.
109 changes: 44 additions & 65 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,31 +381,24 @@ module.exports = {
return [!offence, message + errMessageSuffix];
},

"footer-notes-misplacement": ({ raw }: { raw: any }) => {
"footer-notes-misplacement": ({ body }: { body: any }) => {
let offence = false;

let rawStr = convertAnyToString(raw, "raw").trim();
let lineBreakIndex = rawStr.indexOf("\n");

if (lineBreakIndex >= 0) {
// Extracting bodyStr from rawStr rather than using body directly is a
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
let bodyStr = rawStr.substring(lineBreakIndex).trim();
if (body !== null) {
let bodyStr = convertAnyToString(body, "body");

if (bodyStr !== "") {
let seenBody = false;
let seenFooter = false;
let lines = bodyStr.split(/\r?\n/);
for (let line of lines) {
if (line.length === 0) {
continue;
}
seenBody = seenBody || !isFooterNote(line);
seenFooter = seenFooter || isFooterNote(line);
if (seenFooter && !isFooterNote(line)) {
offence = true;
break;
}
let seenBody = false;
let seenFooter = false;
let lines = bodyStr.split(/\r?\n/);
for (let line of lines) {
if (line.length === 0) {
continue;
}
seenBody = seenBody || !isFooterNote(line);
seenFooter = seenFooter || isFooterNote(line);
if (seenFooter && !isFooterNote(line)) {
offence = true;
break;
}
}
}
Expand All @@ -416,47 +409,38 @@ module.exports = {
];
},

"footer-references-existence": ({ raw }: { raw: any }) => {
"footer-references-existence": ({ body }: { body: any }) => {
let offence = false;

let rawStr = convertAnyToString(raw, "raw").trim();
let lineBreakIndex = rawStr.indexOf("\n");
if (body !== null) {
let bodyStr = convertAnyToString(body, "body");

if (lineBreakIndex >= 0) {
// Extracting bodyStr from rawStr rather than using body directly is a
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
let bodyStr = rawStr.substring(lineBreakIndex).trim();

if (bodyStr !== "") {
let lines = bodyStr.split(/\r?\n/);
let bodyReferences = new Set();
let references = new Set();
for (let line of lines) {
let matches = line.match(
/(?<=\[)([0-9]+)(?=\])/g
);
if (matches === null) {
continue;
}
for (let match of matches) {
if (isFooterReference(line)) {
references.add(match);
} else {
bodyReferences.add(match);
}
}
let lines = bodyStr.split(/\r?\n/);
let bodyReferences = new Set();
let references = new Set();
for (let line of lines) {
let matches = line.match(/(?<=\[)([0-9]+)(?=\])/g);
if (matches === null) {
continue;
}
for (let ref of bodyReferences) {
if (!references.has(ref)) {
offence = true;
break;
for (let match of matches) {
if (isFooterReference(line)) {
references.add(match);
} else {
bodyReferences.add(match);
}
}
for (let ref of references) {
if (!bodyReferences.has(ref)) {
offence = true;
break;
}
}
for (let ref of bodyReferences) {
if (!references.has(ref)) {
offence = true;
break;
}
}
for (let ref of references) {
if (!bodyReferences.has(ref)) {
offence = true;
break;
}
}
}
Expand Down Expand Up @@ -622,16 +606,11 @@ module.exports = {
];
},

"body-soft-max-line-length": ({ raw }: { raw: any }) => {
"body-soft-max-line-length": ({ body }: { body: any }) => {
let offence = false;

let rawStr = convertAnyToString(raw, "raw").trim();
let lineBreakIndex = rawStr.indexOf("\n");

if (lineBreakIndex >= 0) {
// Extracting bodyStr from rawStr rather than using body directly is a
// workaround for https://github.com/conventional-changelog/commitlint/issues/3428
let bodyStr = rawStr.substring(lineBreakIndex);
if (body !== null) {
let bodyStr = convertAnyToString(body, "body");

bodyStr = removeAllCodeBlocks(bodyStr).trim();

Expand Down

0 comments on commit 91c4fa3

Please sign in to comment.