From 135d3ebad9ad3a74245746bebcf8069d2978fa95 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Tue, 28 Feb 2023 23:20:18 -0500 Subject: [PATCH] refactor(config): [rules] prefer `trailer-exists` over `signed-off-by` - conventional-changelog/commitlint#2578 - allows use of `Co-authored-by` trailer - requires use of `BREAKING-CHANGE` trailer over `BREAKING CHANGE` keyword Signed-off-by: Lexus Drumgold --- CONTRIBUTING.md | 2 +- README.md | 11 --------- .../__snapshots__/rules.integration.snap | 23 ------------------ src/config/__tests__/parser-preset.spec.ts | 4 ++-- .../__tests__/rules.integration.spec.ts | 24 +++---------------- src/config/parser-preset.ts | 2 +- src/config/rules.ts | 2 +- src/types/__tests__/note-keyword.spec-d.ts | 4 ---- src/types/note-keyword.ts | 2 +- 9 files changed, 9 insertions(+), 65 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c058d9d..b6cc8e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -168,7 +168,7 @@ This means every commit must conform to the following format: [body] -[BREAKING CHANGE: ] +[BREAKING-CHANGE: ] [footer(s)] ``` diff --git a/README.md b/README.md index bf33559..ed8b3a7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ Shareable [`commitlint`][1] config enforcing [conventional commits][2] - [`scope-enum`](#scope-enum) - [`scope-max-length`](#scope-max-length) - [`scope-min-length`](#scope-min-length) - - [`signed-off-by`](#signed-off-by) - [`subject-empty`](#subject-empty) - [`subject-full-stop`](#subject-full-stop) - [`subject-min-length`](#subject-min-length) @@ -271,16 +270,6 @@ code when not met. min(scopes()) ``` -#### `signed-off-by` - -- **condition**: `message` has `value` -- **rule**: `always` -- **value**: - - ```ts - 'Signed-off-by:' - ``` - #### `subject-empty` - **condition**: `subject` is empty diff --git a/src/config/__snapshots__/rules.integration.snap b/src/config/__snapshots__/rules.integration.snap index 7378d0f..54f3b22 100644 --- a/src/config/__snapshots__/rules.integration.snap +++ b/src/config/__snapshots__/rules.integration.snap @@ -123,23 +123,6 @@ exports[`integration:config/rules > @commitlint/lint > scope-min-length > should ] `; -exports[`integration:config/rules > @commitlint/lint > signed-off-by > should error without sign off 1`] = ` -[ - { - "level": 2, - "message": "message must be signed off", - "name": "signed-off-by", - "valid": false, - }, - { - "level": 2, - "message": "message must have \`Signed-off-by:\` trailer", - "name": "trailer-exists", - "valid": false, - }, -] -`; - exports[`integration:config/rules > @commitlint/lint > subject-empty > should error on missing subject 1`] = ` [ { @@ -187,12 +170,6 @@ exports[`integration:config/rules > @commitlint/lint > subject-min-length > shou exports[`integration:config/rules > @commitlint/lint > trailer-exists > should error on missing "Signed-off-by" trailer 1`] = ` [ - { - "level": 2, - "message": "message must be signed off", - "name": "signed-off-by", - "valid": false, - }, { "level": 2, "message": "message must have \`Signed-off-by:\` trailer", diff --git a/src/config/__tests__/parser-preset.spec.ts b/src/config/__tests__/parser-preset.spec.ts index 83dd9db..69c3678 100644 --- a/src/config/__tests__/parser-preset.spec.ts +++ b/src/config/__tests__/parser-preset.spec.ts @@ -226,8 +226,8 @@ describe('unit:config/parserPreset', () => { subject = testSubject.parserOpts.noteKeywords }) - it('should only contain 2 keywords', () => { - expect(subject).to.deep.equal(['BREAKING CHANGE', 'BREAKING-CHANGE']) + it('should only contain 1 keyword', () => { + expect(subject).to.deep.equal(['BREAKING-CHANGE']) }) }) diff --git a/src/config/__tests__/rules.integration.spec.ts b/src/config/__tests__/rules.integration.spec.ts index 206cda7..08f2db0 100644 --- a/src/config/__tests__/rules.integration.spec.ts +++ b/src/config/__tests__/rules.integration.spec.ts @@ -145,7 +145,7 @@ describe('integration:config/rules', () => { it('should error if footer comes after 1 new line', async () => { // Arrange const commit: string = - 'test: some message\n\nbody\nBREAKING CHANGE: It will be significant' + 'test: some message\n\nbody\nBREAKING-CHANGE: It will be significant' // Act const result = await linter(signoff(commit, 0)) @@ -355,26 +355,8 @@ describe('integration:config/rules', () => { }) describe('signed-off-by', () => { - let rule: string - let severity: Severity - - beforeAll(() => { - rule = 'signed-off-by' - severity = Severity.Error - }) - - it('should error without sign off', async () => { - // Arrange - const commit: string = - 'chore(tests): [codecov] label critical files\n\n- https://docs.codecov.com/docs/manual-critical-file-labelling' - - // Act - const result = await linter(commit) - - // Expect - expect(result.errors).to.have.ruleOutcome(rule, severity) - expect(result.warnings).to.be.an('array').that.is.empty - expect(result.errors).toMatchSnapshot() + it('should be disabled', () => { + expect(testSubject['body-case']).to.be.level(Severity.Disabled) }) }) diff --git a/src/config/parser-preset.ts b/src/config/parser-preset.ts index b01fdde..b637365 100644 --- a/src/config/parser-preset.ts +++ b/src/config/parser-preset.ts @@ -29,7 +29,7 @@ const parserPreset: ParserPreset = { issuePrefixesCaseSensitive: true, mergeCorrespondence: null, mergePattern: null, - noteKeywords: ['BREAKING CHANGE', 'BREAKING-CHANGE'], + noteKeywords: ['BREAKING-CHANGE'], referenceActions: Object.values(ReferenceAction), revertCorrespondence: [ 'type', diff --git a/src/config/rules.ts b/src/config/rules.ts index 9758450..98fbdb0 100644 --- a/src/config/rules.ts +++ b/src/config/rules.ts @@ -42,7 +42,7 @@ const rules: RulesConfig = { 'scope-enum': [Severity.Error, 'always', scopes()], 'scope-max-length': [Severity.Error, 'always', max(scopes())], 'scope-min-length': [Severity.Error, 'always', min(scopes())], - 'signed-off-by': [Severity.Error, 'always', 'Signed-off-by:'], + 'signed-off-by': [Severity.Disabled], 'subject-case': [Severity.Disabled], 'subject-empty': [Severity.Error, 'never'], 'subject-exclamation-mark': [Severity.Disabled], diff --git a/src/types/__tests__/note-keyword.spec-d.ts b/src/types/__tests__/note-keyword.spec-d.ts index 9771212..243e16a 100644 --- a/src/types/__tests__/note-keyword.spec-d.ts +++ b/src/types/__tests__/note-keyword.spec-d.ts @@ -6,10 +6,6 @@ import type TestSubject from '../note-keyword' describe('unit-d:types/NoteKeyword', () => { - it('should extract "BREAKING CHANGE"', () => { - expectTypeOf().extract('BREAKING CHANGE').toBeString() - }) - it('should extract "BREAKING-CHANGE"', () => { expectTypeOf().extract('BREAKING-CHANGE').toBeString() }) diff --git a/src/types/note-keyword.ts b/src/types/note-keyword.ts index dc56998..a2192d0 100644 --- a/src/types/note-keyword.ts +++ b/src/types/note-keyword.ts @@ -8,6 +8,6 @@ * * @see https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-commits-parser/README.md#notekeywords */ -type NoteKeyword = 'BREAKING CHANGE' | 'BREAKING-CHANGE' +type NoteKeyword = 'BREAKING-CHANGE' export type { NoteKeyword as default }