Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ module.exports = {
'too-many-spaces': [RuleStatus.Error, 'always'],
'commit-hash-alone': [RuleStatus.Error, 'always'],
'title-uppercase': [RuleStatus.Error, 'always'],
'proper-revert-message': [RuleStatus.Error, 'always'],
},
// Commitlint automatically ignores some kinds of commits like Revert commit messages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 last things to do in this PR:

  • (Nit) Add an EOL before this comment above, to visually separate it better from the rule configuration list.
  • Remove the TODO comment related to this PR, at line 363.

// We need to set this value to false to apply our rules on these messages.
defaultIgnores: false,
plugins: [
// TODO (ideas for more rules):
// * Detect if paragraphs in body have been cropped too shortly (less than 64 chars), and suggest same auto-wrap command that body-soft-max-line-length suggests, since it unwraps and wraps (both).
Expand Down Expand Up @@ -602,6 +606,28 @@ module.exports = {
`Please use full URLs instead of #XYZ refs.`
];
},

'proper-revert-message': ({header, body}: {header: any, body: any}) => {
let offence = false;

if (header.match(/^[Rr]evert ".+"$/) !== null) {

// does msg have a body?
if (body !== null) {
let bodyStr = convertAnyToString(body, "body").trim();
let lines = bodyStr.split('\n');
offence = lines[0].match(/^This reverts commit [^ ]{40}\.$/) !== null && lines.length == 1;
}
else {
offence = true;
}
}

return [
!offence,
`Please explain why you're reverting`
];
},

'title-uppercase': ({header}: {header:any}) => {
let headerStr = convertAnyToString(header, "header");
Expand All @@ -625,6 +651,7 @@ module.exports = {
`Please watch out for too many whitespaces in the text`
];
},


'type-space-after-colon': ({header}: {header:any}) => {
let headerStr = convertAnyToString(header, "header");
Expand Down
52 changes: 52 additions & 0 deletions commitlintplugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,58 @@ test('proper-issue-refs3', () => {
});


test('proper-revert-message1', () => {
let commitMsgWithoutProperRevertMessage =
'Revert "add abbreviations.ts"\n\n' +
'This reverts commit 0272f587c7eece147e8d1756116b0b43e11c34ac.';
let properRevertMessage1 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage);
expect(properRevertMessage1.status).not.toBe(0);
});


test('proper-revert-message2', () => {
let commitMsgWithProperRevertMessage =
'Revert "add abbreviations.ts"\n\n' +
'This reverts commit 0272f587c7eece147e8d1756116b0b43e11c34ac\n' +
'because/otherwise bla bla.'
let properRevertMessage2 = runCommitLintOnMsg(commitMsgWithProperRevertMessage);
expect(properRevertMessage2.status).toBe(0);
});


test('proper-revert-message3', () => {
let commitMsgWithoutProperRevertMessage = 'Revert "add abbreviations.ts"';
let properRevertMessage3 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage);
expect(properRevertMessage3.status).not.toBe(0);
});


test('proper-revert-message4', () => {
let commitMsgWithProperRevertMessage = 'Revert .NET6 upd as it broke CI';
let properRevertMessage4 = runCommitLintOnMsg(commitMsgWithProperRevertMessage);
expect(properRevertMessage4.status).toBe(0);
});


test('proper-revert-message5', () => {
let commitMsgWithoutProperRevertMessage =
'Revert "add abbreviations.ts"\n\n' +
'This reverts commit 0272f587 because bla bla.\n';

let properRevertMessage5 = runCommitLintOnMsg(commitMsgWithoutProperRevertMessage);
expect(properRevertMessage5.status).toBe(0);
});


test('proper-revert-message6', () => {
let commitMsgWithProperRevertMessage =
'Revert "process overhaul" to fix CI\n\n';

let properRevertMessage6 = runCommitLintOnMsg(commitMsgWithProperRevertMessage);
expect(properRevertMessage6.status).toBe(0);
});


test('subject-lowercase1', () => {
let commitMsgWithUppercaseAfterColon = "foo: Bar baz";
let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon);
Expand Down