From 9cfba31e3f5c55d6e3f01bc43c1598662c959c37 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 20 Oct 2022 16:33:49 +0330 Subject: [PATCH 1/6] add obviouswords.ts --- obviouswords.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 obviouswords.ts diff --git a/obviouswords.ts b/obviouswords.ts new file mode 100644 index 00000000..e6c6fd34 --- /dev/null +++ b/obviouswords.ts @@ -0,0 +1,5 @@ +export let obviousWords = [ + "change", + "update", + "modify" +] \ No newline at end of file From c53d1d2db844398abb3a67ec6650ee921b188541 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 20 Oct 2022 16:58:06 +0330 Subject: [PATCH 2/6] commitlintplugins.test: add one failing test --- commitlintplugins.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index aa700ff1..2c874a50 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -87,6 +87,13 @@ test('prefer-slash-over-backslash2', () => { }); +test('reject-obvious-words1', () => { + let commitMsgWithObviousWordAfterColon = "foo: modify bla bla"; + let rejectObviousWord1 = runCommitLintOnMsg(commitMsgWithObviousWordAfterColon); + expect(rejectObviousWord1.status).not.toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From 418d06b7d8ab6c93dfbb8c4b8d473b8272599c71 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 24 Oct 2022 12:59:49 +0330 Subject: [PATCH 3/6] commitlint.config: add a rule to pass the test --- commitlint.config.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/commitlint.config.ts b/commitlint.config.ts index 048da458..2d846446 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -36,6 +36,7 @@ module.exports = { 'trailing-whitespace': [RuleStatus.Error, 'always'], 'prefer-slash-over-backslash': [RuleStatus.Error, 'always'], 'type-space-before-paren': [RuleStatus.Error, 'always'], + 'reject-obvious-words': [RuleStatus.Error, 'always'], }, plugins: [ // TODO (ideas for more rules): @@ -81,6 +82,22 @@ module.exports = { ]; }, + 'reject-obvious-words': ({header}: {header:any}) => { + let headerStr = convertAnyToString(header, "header"); + let offence = false; + + let colonFirstIndex = headerStr.indexOf(":"); + let titleStartIndex = Math.max(0, colonFirstIndex + 1); + let title = headerStr.substring(titleStartIndex, headerStr.length).trim(); + let firstWordInTitle = title.split(' ')[0]; + offence = firstWordInTitle == 'modify' + + return [ + !offence, + `Please don't use followin` + ]; + }, + 'type-space-after-colon': ({header}: {header:any}) => { let headerStr = convertAnyToString(header, "header"); From a7c50135d40362383ff05aa883f5131513531a3c Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 24 Oct 2022 13:01:27 +0330 Subject: [PATCH 4/6] commitlintplugins.test: add another failing test --- commitlintplugins.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index 2c874a50..aab8d117 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -90,10 +90,19 @@ test('prefer-slash-over-backslash2', () => { test('reject-obvious-words1', () => { let commitMsgWithObviousWordAfterColon = "foo: modify bla bla"; let rejectObviousWord1 = runCommitLintOnMsg(commitMsgWithObviousWordAfterColon); + console.log('==========>' + rejectObviousWord1.stdout) expect(rejectObviousWord1.status).not.toBe(0); }); +test('reject-obvious-words2', () => { + let commitMsgWithObviousWordAfterColon = "foo: change bla bla"; + let rejectObviousWord2 = runCommitLintOnMsg(commitMsgWithObviousWordAfterColon); + console.log('==========>' + rejectObviousWord2.stdout) + expect(rejectObviousWord2.status).not.toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon); From ab8a65803db59af6d849562f16d817b249d7618f Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 24 Oct 2022 13:07:32 +0330 Subject: [PATCH 5/6] commitlint.config: fix rule to use obviouswords.ts --- commitlint.config.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index 2d846446..d67b1f41 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -1,3 +1,5 @@ +import {obviousWords} from './obviouswords' + // to convert from 'any' type function convertAnyToString(potentialString: any, paramName: string): string { if (potentialString === null || potentialString === undefined) { @@ -90,11 +92,11 @@ module.exports = { let titleStartIndex = Math.max(0, colonFirstIndex + 1); let title = headerStr.substring(titleStartIndex, headerStr.length).trim(); let firstWordInTitle = title.split(' ')[0]; - offence = firstWordInTitle == 'modify' + offence = obviousWords.includes(firstWordInTitle); return [ !offence, - `Please don't use followin` + `Please don't use obvious words such as ${firstWordInTitle} in the commit title` ]; }, From d750716c57833c061b82a950ec2989da2a276289 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 24 Oct 2022 13:13:18 +0330 Subject: [PATCH 6/6] commitlintplugins.test: add another test --- commitlintplugins.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commitlintplugins.test.ts b/commitlintplugins.test.ts index aab8d117..3f8d9649 100644 --- a/commitlintplugins.test.ts +++ b/commitlintplugins.test.ts @@ -90,7 +90,7 @@ test('prefer-slash-over-backslash2', () => { test('reject-obvious-words1', () => { let commitMsgWithObviousWordAfterColon = "foo: modify bla bla"; let rejectObviousWord1 = runCommitLintOnMsg(commitMsgWithObviousWordAfterColon); - console.log('==========>' + rejectObviousWord1.stdout) + // console.log('==========>' + rejectObviousWord1.stdout) expect(rejectObviousWord1.status).not.toBe(0); }); @@ -98,11 +98,19 @@ test('reject-obvious-words1', () => { test('reject-obvious-words2', () => { let commitMsgWithObviousWordAfterColon = "foo: change bla bla"; let rejectObviousWord2 = runCommitLintOnMsg(commitMsgWithObviousWordAfterColon); - console.log('==========>' + rejectObviousWord2.stdout) + // console.log('==========>' + rejectObviousWord2.stdout) expect(rejectObviousWord2.status).not.toBe(0); }); +test('reject-obvious-words3', () => { + let commitMsgWithoutObviousWordAfterColon = "foo: bla bla bla"; + let rejectObviousWord3 = runCommitLintOnMsg(commitMsgWithoutObviousWordAfterColon); + // console.log('==========>' + rejectObviousWord3.stdout) + expect(rejectObviousWord3.status).toBe(0); +}); + + test('subject-lowercase1', () => { let commitMsgWithUppercaseAfterColon = "foo: Bar baz"; let subjectLowerCase1 = runCommitLintOnMsg(commitMsgWithUppercaseAfterColon);