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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@ node_modules/
package.json
package-lock.json
yarn.lock

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Bb]uild/
_[Bb]uild/
[Dd]eploy/
_[Dd]eploy/

# NUNIT
*.VisualState.xml
TestResult.xml
TestResults.xml

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
27 changes: 27 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ module.exports = {
'proper-issue-refs': [RuleStatus.Error, 'always'],
'too-many-spaces': [RuleStatus.Error, 'always'],
'commit-hash-alone': [RuleStatus.Error, 'always'],
'proper-revert-message': [RuleStatus.Error, 'always'],
},
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 @@ -558,6 +560,30 @@ module.exports = {
`Please use full URLs instead of #XYZ refs.`
];
},

'proper-revert-message': ({raw}: {raw: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/3412
let bodyStr = rawStr.substring(lineBreakIndex).trim()
let lines = bodyStr.split('\n');
if (lines.length == 1) {
if (lines[0].match('This reverts commit ') !== null) {
offence = true;
}
}
}

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


'too-many-spaces': ({raw}: {raw:any}) => {
Expand All @@ -570,6 +596,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
19 changes: 18 additions & 1 deletion commitlintplugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,28 @@ test('proper-issue-refs3', () => {
let commitMsgWithHashtagRefInBlock =
"foo: this is only a title" + "\n\n" + "Bar baz:\n\n```\ntype Foo = string #123\n```";
let properIssueRefs3 = runCommitLintOnMsg(commitMsgWithHashtagRefInBlock);
console.log('HERE =======>' + properIssueRefs3.stdout)
expect(properIssueRefs3.status).toBe(0);
});


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 9bb557e54830690b8a8e403d1b74780d86b07b4c\n\n' +
'We need to revert this commit, because/otherwise bla bla.'
let properRevertMessage2 = runCommitLintOnMsg(commitMsgWithProperRevertMessage);
expect(properRevertMessage2.status).toBe(0);
});


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