diff --git a/.gitignore b/.gitignore index 0c4c5e479..42cf43de5 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/commitlint.config.ts b/commitlint.config.ts index ae908d369..3a494e5bb 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -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). @@ -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}) => { @@ -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"); diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 31d8c906a..4bc340c7b 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -348,11 +348,29 @@ 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 "add abbreviations.ts"\n\n' + + 'This reverts commit 0272f587c7eece147e8d1756116b0b43e11c34ac,\n' + + '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);