Skip to content

Commit f37923b

Browse files
aichbauerJPeer264
authored andcommitted
Fix: apply length check on type + scope + message (closes #35) (#42)
* 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
1 parent 67892ae commit f37923b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/questions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ const questions = (config) => {
6565
type: 'input',
6666
name: 'description',
6767
message: 'Enter your commit message:',
68-
validate: (input) => {
69-
const warnings = ruleWarningMessages(input.trim(), config);
68+
validate: (input, answers) => {
69+
if (input.length === 0) {
70+
return 'The commit message is not allowed to be empty';
71+
}
72+
73+
const scope = answers.scope || '';
74+
const type = combineTypeScope(answers.type, scope.trim());
75+
const combinedInput = `${type} ${input.trim()}`;
76+
const warnings = ruleWarningMessages(combinedInput, config);
7077

7178
return warnings || true;
7279
},

test/questions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ test('COMMIT | validate functions in questions', (t) => {
111111
const config = getConfig();
112112
const questionsList = questions(config);
113113

114-
t.is(questionsList[2].validate('input text'), true);
115-
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');
114+
t.is(questionsList[2].validate('', 'Fix: '), 'The commit message is not allowed to be empty');
115+
t.is(questionsList[2].validate('input text', 'Fix: '), true);
116+
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');
116117
});
117118

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

0 commit comments

Comments
 (0)