From 5a91a7fcd01c28944e8f550f5bbaa2f0c2c0506c Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Thu, 8 Oct 2020 18:53:28 +0100 Subject: [PATCH] feat: recognise all-caps strings in the subject --- engine.js | 20 +++++++++++++++++++- engine.test.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/engine.js b/engine.js index 24a42b7c..0d28d1bc 100644 --- a/engine.js +++ b/engine.js @@ -17,13 +17,31 @@ var headerLength = function(answers) { ); }; +var isLetter = function(character) { + if (typeof character !== "string" || !character.trim()) { + return false + } + return character.toUpperCase() !== character.toLowerCase(); +} + +var isUppercaseLetter = function(character) { + if (typeof character !== "string" || !character.trim()) { + return false + } + return character === character.toUpperCase(); +} + var maxSummaryLength = function(options, answers) { return options.maxHeaderWidth - headerLength(answers); }; var filterSubject = function(subject, disableSubjectLowerCase) { subject = subject.trim(); - if (!disableSubjectLowerCase && subject.charAt(0).toLowerCase() !== subject.charAt(0)) { + if ( + !disableSubjectLowerCase && + subject.charAt(0).toLowerCase() !== subject.charAt(0) && + (!subject.charAt(1) || !isLetter(subject.charAt(1)) || !isUppercaseLetter(subject.charAt(1))) + ) { subject = subject.charAt(0).toLowerCase() + subject.slice(1, subject.length); } diff --git a/engine.test.js b/engine.test.js index aacd134f..1674483c 100644 --- a/engine.test.js +++ b/engine.test.js @@ -101,6 +101,53 @@ describe('commit message', function() { ) ).to.equal(`${type}(${upperCaseScope}): ${subject}\n\n${body}`); }); + it('all caps subject, disableSubjectLowerCase off', function() { + var allCapsSubject = `XML changes`; + expect( + commitMessage( + { + type, + scope, + subject: allCapsSubject, + body + }, + { + ...defaultOptions, + disableSubjectLowerCase: false // <--- + } + ) + ).to.equal(`${type}(${scope}): ${allCapsSubject}\n\n${body}`); + }); + it('all caps subject, disableSubjectLowerCase on', function() { + var allCapsSubject = `XML changes`; + expect( + commitMessage( + { + type, + scope, + subject: allCapsSubject, + body + }, + { + ...defaultOptions, + disableSubjectLowerCase: true // <--- + } + ) + ).to.equal(`${type}(${scope}): ${allCapsSubject}\n\n${body}`); + }); + it('subject starts with number', function() { + var subjectWithNumber = `2nd iteration`; + expect( + commitMessage( + { + type, + scope, + subject: subjectWithNumber, + body + } + ) + ).to.equal(`${type}(${scope}): ${subjectWithNumber}\n\n${body}`); + }); it('header and body w/ uppercase subject', function() { var upperCaseSubject = subject.toLocaleUpperCase(); expect(