File tree Expand file tree Collapse file tree 4 files changed +55
-4
lines changed
Expand file tree Collapse file tree 4 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 4545 "type": "Test:",
4646 "description": "Adding missing tests or correcting existing tests"
4747 }
48- ]
48+ ],
49+ "rules": {
50+ "max-char-commit-message": true,
51+ "max-char": 72,
52+ "min-char": 10,
53+ "end-with-dot": false
54+ }
4955}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { choices, questions } from './promptConfig';
1111
1212const configuration = getConfig ( ) ;
1313const choicesList = choices ( configuration ) ;
14- const questionsList = questions ( choicesList ) ;
14+ const questionsList = questions ( choicesList , configuration ) ;
1515const argv = yargs
1616 . usage ( 'Usage: $0' )
1717 . alias ( 'v' , 'version' )
Original file line number Diff line number Diff line change 11import chalk from 'chalk' ;
2+ import { checkRulesMaxLength , checkRulesEndWithDot , checkRulesMinLength } from './rulesConfig' ;
23
34const choices = ( configuration ) => {
45 const choicesList = [ ] ;
@@ -17,7 +18,7 @@ const choices = (configuration) => {
1718 return choicesList ;
1819} ;
1920
20- const questions = ( choicesList ) => {
21+ const questions = ( choicesList , configuration ) => {
2122 const questionsList = [
2223 {
2324 type : 'list' ,
@@ -29,7 +30,12 @@ const questions = (choicesList) => {
2930 type : 'input' ,
3031 name : 'description' ,
3132 message : 'Enter your commit message:' ,
32- validate : input => ( input ? true : 'A commit message is mandatory!' ) ,
33+ validate : ( input ) => {
34+ if ( checkRulesEndWithDot ( input ) === false ) return 'The commit message can not end with a dot' ;
35+ else if ( checkRulesMaxLength ( input ) === false ) return `The commit message is not allowed to be longer as ${ configuration . rules [ 'max-char' ] } . Consider writing a body.` ;
36+ else if ( checkRulesMinLength ( input ) === false ) return `The commit message hast to be at least ${ configuration . rules [ 'min-char' ] } character.` ;
37+ return true ;
38+ } ,
3339 } ,
3440 {
3541 type : 'confirm' ,
Original file line number Diff line number Diff line change 1+ import getConfig from './getConfig' ;
2+
3+ const checkRulesMaxLength = ( input ) => {
4+ const configuration = getConfig ( ) ;
5+
6+ if ( configuration . rules [ 'max-char-commit-message' ] === true && input . length > configuration . rules [ 'max-char' ] ) {
7+ return false ;
8+ } else if ( ( configuration . rules [ 'max-char-commit-message' ] === true && input . length <= configuration . rules [ 'max-char' ] ) || configuration . rules [ 'max-char-commit-message' ] === false ) {
9+ return true ;
10+ }
11+
12+ return false ;
13+ } ;
14+
15+ const checkRulesMinLength = ( input ) => {
16+ const configuration = getConfig ( ) ;
17+
18+ if ( input . length < configuration . rules [ 'min-char' ] ) {
19+ return false ;
20+ } else if ( input . length >= configuration . rules [ 'min-char' ] ) {
21+ return true ;
22+ }
23+
24+ return false ;
25+ } ;
26+
27+ const checkRulesEndWithDot = ( input ) => {
28+ const configuration = getConfig ( ) ;
29+
30+ if ( configuration . rules [ 'end-with-dot' ] === true && input [ input . length - 1 ] === '.' ) {
31+ return false ;
32+ } else if ( configuration . rules [ 'end-with-dot' ] === false && input [ input . length - 1 ] !== '.' ) {
33+ return true ;
34+ }
35+
36+ return false ;
37+ } ;
38+
39+ export { checkRulesMaxLength , checkRulesMinLength , checkRulesEndWithDot } ;
You can’t perform that action at this time.
0 commit comments