File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed
Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ import getConfig from '../getConfig' ;
2+
3+ const configuration = getConfig ( ) ;
4+
5+ const rules = {
6+ endWithDot : {
7+ message : 'The commit message can not end with a dot' ,
8+ check : ( input ) => {
9+ if ( input [ input . length - 1 ] === '.' ) return false ;
10+ return true ;
11+ } ,
12+ } ,
13+ maxChar : {
14+ message : `The commit message is not allowed to be longer as ${ configuration . rules [ 'max-char' ] } . Consider writing a body.` ,
15+ check : ( input ) => {
16+ if ( input . length > configuration . rules [ 'max-char' ] ) return false ;
17+ return true ;
18+ } ,
19+ } ,
20+ minChar : {
21+ message : `The commit message has to be at least ${ configuration . rules [ 'min-char' ] } character.` ,
22+ check : ( input ) => {
23+ if ( input . length < configuration . rules [ 'min-char' ] ) return false ;
24+ return true ;
25+ } ,
26+ } ,
27+ } ;
28+
29+ export default rules ;
Original file line number Diff line number Diff line change 1+ import entries from 'object.entries' ;
2+ import getConfig from '../getConfig' ;
3+ import rules from './availableRules' ;
4+
5+ const configuration = getConfig ( ) ;
6+
7+ const ruleWarningMessages = ( input ) => {
8+ let warningMessage = '' ;
9+ const configRuleEntries = entries ( configuration . rules ) ;
10+
11+ configRuleEntries . forEach ( ( rule ) => {
12+ const camelCaseRuleName = ( rule [ 0 ] ) . replace ( / - ( [ a - z ] ) / g, g => ( g [ 1 ] . toUpperCase ( ) ) ) ;
13+ const ruleIs = rules [ camelCaseRuleName ] . check ( input ) ;
14+
15+ if ( ! ruleIs ) {
16+ warningMessage += `${ rules [ camelCaseRuleName ] . message } \n` ;
17+ }
18+ } ) ;
19+
20+ return warningMessage ;
21+ } ;
22+
23+ export default ruleWarningMessages ;
Original file line number Diff line number Diff line change 1+ import test from 'ava' ;
2+ import rules from '../../lib/rules/availableRules' ;
3+
4+ test ( 'rules endWithDot' , ( t ) => {
5+ const endWithDot = rules . endWithDot . check ( 'input with dot.' ) ;
6+ const endWithoutDot = rules . endWithDot . check ( 'input with dot' ) ;
7+ t . deepEqual ( endWithDot , false ) ;
8+ t . deepEqual ( endWithoutDot , true ) ;
9+ } ) ;
10+
11+ test ( 'rules minChar' , ( t ) => {
12+ const notMinChar = rules . minChar . check ( 'less' ) ;
13+ const minChar = rules . minChar . check ( 'this are more than 10 characters' ) ;
14+ t . deepEqual ( notMinChar , false ) ;
15+ t . deepEqual ( minChar , true ) ;
16+ } ) ;
17+
18+ test ( 'rules mxChar' , ( t ) => {
19+ const moreThanMaxChar = rules . maxChar . check ( 'this are more than 72 characters, believe me or not but the value moreThanMaxChar will be false ;-P' ) ;
20+ const lessThanMaxChar = rules . maxChar . check ( 'this are less than 72 characters' ) ;
21+ t . deepEqual ( moreThanMaxChar , false ) ;
22+ t . deepEqual ( lessThanMaxChar , true ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ import test from 'ava' ;
2+ import ruleWaringMessages from '../../lib/rules/ruleWarningMessages' ;
3+
4+ test ( 'ruleWarningMessages' , ( t ) => {
5+ const messages = ruleWaringMessages ( 'input.' ) ;
6+ t . deepEqual ( messages , 'The commit message has to be at least 10 character.\nThe commit message can not end with a dot\n' ) ;
7+ } ) ;
You can’t perform that action at this time.
0 commit comments