Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recognise all-caps strings in the subject #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
47 changes: 47 additions & 0 deletions engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down