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 Jan 31, 2023
1 parent 051add3 commit cf92cd5
Showing 1 changed file with 45 additions and 64 deletions.
109 changes: 45 additions & 64 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,33 +298,26 @@ module.exports = {
];
},

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

}
}
return [
Expand All @@ -333,46 +326,39 @@ 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;
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);
}
for (let match of matches){
if (isFooterReference(line)) {
references.add(match);
}
else {
bodyReferences.add(match);
}
else {
bodyReferences.add(match);
}
}
for (let ref of bodyReferences) {
if (!references.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;
}
}
for (let ref of references) {
if (!bodyReferences.has(ref)) {
offence = true;
break;
}
}
}
Expand Down Expand Up @@ -516,16 +502,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 cf92cd5

Please sign in to comment.