Skip to content

Commit

Permalink
Fix: apply length check on type + scope + message (closes #35) (#42)
Browse files Browse the repository at this point in the history
* Fix: apply length check on type + scope + message

* Test: update tests for new length check

* Feat: add validation for empty commit message

* Test: add empty commit message

* Fix: predefine might empty answer.scope
  • Loading branch information
aichbauer authored and JPeer264 committed Oct 1, 2017
1 parent 67892ae commit f37923b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ const questions = (config) => {
type: 'input',
name: 'description',
message: 'Enter your commit message:',
validate: (input) => {
const warnings = ruleWarningMessages(input.trim(), config);
validate: (input, answers) => {
if (input.length === 0) {
return 'The commit message is not allowed to be empty';
}

const scope = answers.scope || '';
const type = combineTypeScope(answers.type, scope.trim());
const combinedInput = `${type} ${input.trim()}`;
const warnings = ruleWarningMessages(combinedInput, config);

return warnings || true;
},
Expand Down
5 changes: 3 additions & 2 deletions test/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ test('COMMIT | validate functions in questions', (t) => {
const config = getConfig();
const questionsList = questions(config);

t.is(questionsList[2].validate('input text'), true);
t.is(questionsList[2].validate('This message has over 72 characters. So this test will definitely fail. I can guarantee that I am telling the truth'), 'The commit message is not allowed to be longer as 72 character, but is 115 character long. Consider writing a body.\n');
t.is(questionsList[2].validate('', 'Fix: '), 'The commit message is not allowed to be empty');
t.is(questionsList[2].validate('input text', 'Fix: '), true);
t.is(questionsList[2].validate('This message has over 72 characters. So this test will definitely fail. I can guarantee that I am telling the truth', 'Fix: '), 'The commit message is not allowed to be longer as 72 character, but is 125 character long. Consider writing a body.\n');
});

test('COMMIT | when and default functions in questions', (t) => {
Expand Down

0 comments on commit f37923b

Please sign in to comment.