@@ -56,6 +56,16 @@ describe('rules/require-space-before-keywords', function() {
5656 expect ( checker . checkString ( 'if (true) x++;else x--;' ) ) . to . have . no . errors ( ) ;
5757 } ) ;
5858
59+ it ( 'should not report missing space on function by default' , function ( ) {
60+ checker . configure ( { requireSpaceBeforeKeywords : true } ) ;
61+
62+ expect ( checker . checkString (
63+ '[].forEach(function (arg) {\n' +
64+ 'console.log(arg);\n' +
65+ '});'
66+ ) ) . to . have . no . errors ( ) ;
67+ } ) ;
68+
5969 it ( 'should report on all possible ES3 keywords if a value of true is supplied' , function ( ) {
6070 checker . configure ( { requireSpaceBeforeKeywords : true } ) ;
6171
@@ -79,4 +89,36 @@ describe('rules/require-space-before-keywords', function() {
7989 expect ( errors ) . to . have . one . validation . error . from ( 'requireSpaceBeforeKeywords' ) ;
8090 expect ( errors . explainError ( error ) ) . to . have . string ( 'Missing space before "catch" keyword' ) ;
8191 } ) ;
92+
93+ it ( 'should not report missing space on excluded keyword' , function ( ) {
94+ checker . configure ( { requireSpaceBeforeKeywords : { allExcept : [ 'else' ] } } ) ;
95+
96+ expect ( checker . checkString (
97+ 'if (true) {\n}else { x++; }'
98+ ) ) . to . have . no . errors ( ) ;
99+ } ) ;
100+
101+ it ( 'should report missing space in not excluded keywords' , function ( ) {
102+ checker . configure ( { requireSpaceBeforeKeywords : { allExcept : [ 'function' ] } } ) ;
103+
104+ var errors = checker . checkString ( 'if (true) {\n}else { x++; }' ) ;
105+ var error = errors . getErrorList ( ) [ 0 ] ;
106+
107+ expect ( errors ) . to . have . one . validation . error . from ( 'requireSpaceBeforeKeywords' ) ;
108+ expect ( errors . explainError ( error ) ) . to . have . string ( 'Missing space before "else" keyword' ) ;
109+ } ) ;
110+
111+ it ( 'should report missing space on function when not specified in allExcept array' , function ( ) {
112+ checker . configure ( { requireSpaceBeforeKeywords : { allExcept : [ 'else' ] } } ) ;
113+
114+ var errors = checker . checkString (
115+ '[].forEach(function (arg) {\n' +
116+ 'console.log(arg);\n' +
117+ '});'
118+ ) ;
119+ var error = errors . getErrorList ( ) [ 0 ] ;
120+
121+ expect ( errors ) . to . have . one . validation . error . from ( 'requireSpaceBeforeKeywords' ) ;
122+ expect ( errors . explainError ( error ) ) . to . have . string ( 'Missing space before "function" keyword' ) ;
123+ } ) ;
82124} ) ;
0 commit comments