Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: Check commit subject for minimum length
Browse files Browse the repository at this point in the history
Do not allow commit subjects having less than 3 characters. This check
do not include the type (e.g. 'feat', 'chore', ...)
  • Loading branch information
ikhemissi authored and brokenmass committed Oct 27, 2016
1 parent ba5fbd4 commit 9f41dbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Issues: MOL-1234
The **header** is the only mandatory part of the commit message.

The first line (type + subject) is limited to 50 characters **[enforced]**

Any other line should be limited to 72 character **[automatic wrapping]**

This allows the message to be easier to read on GitHub as well as in various git tools.
Expand All @@ -87,7 +88,6 @@ Must be one of the following:
The subject contains succinct description of the change:

* Use the imperative, present tense: "change" not "changed" nor "changes"
* Lowercase only **[automatic fix]**
* No dot (.) at the end.

### Body
Expand Down
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ inquirer.registerPrompt('limitedInput', require('./prompt/LimitedInput'));

const MAX_SUBJECT_LENGTH = 50;
const MAX_LINE_WIDTH = 72;
const MIN_SUBJECT_LENGTH = 3;
const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${MIN_SUBJECT_LENGTH} characters`;

module.exports = {
prompter: (cz, commit) => {
Expand Down Expand Up @@ -53,6 +55,11 @@ module.exports = {
type: 'limitedInput',
name: 'subject',
maxLength: MAX_SUBJECT_LENGTH,
filter: (input) => {
const subject = input.trim();
return subject.endsWith('.') ? subject.substr(0, subject.length - 1).trim() : subject;
},
validate: (input) => input.length >= MIN_SUBJECT_LENGTH || MIN_SUBJECT_LENGTH_ERROR_MESSAGE,
leadingLabel: (answers) => `${answers.type}:`,
message: 'Write a short, imperative mood description of the change:'
},
Expand All @@ -64,12 +71,12 @@ module.exports = {
{
type: 'input',
name: 'breaking',
message: 'List any breaking changes:\nBREAKING CHANGE: '
message: 'List any breaking changes:\n BREAKING CHANGE:'
},
{
type: 'input',
name: 'footer',
message: 'Reference any task that this commit closes:\nIssues: '
message: 'Reference any task that this commit closes:\n Issues:'
}
])
.then((answers) => {
Expand All @@ -79,7 +86,7 @@ module.exports = {
width: MAX_LINE_WIDTH
};

const head = (answers.type + ': ' + answers.subject.trim()).toLowerCase();
const head = answers.type + ': ' + answers.subject;

// Wrap these lines at MAX_LINE_WIDTH characters
const body = wrap(answers.body, wrapOptions);
Expand Down

0 comments on commit 9f41dbf

Please sign in to comment.