@@ -56,6 +56,16 @@ describe('rules/require-space-before-keywords', function() {
56
56
expect ( checker . checkString ( 'if (true) x++;else x--;' ) ) . to . have . no . errors ( ) ;
57
57
} ) ;
58
58
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
+
59
69
it ( 'should report on all possible ES3 keywords if a value of true is supplied' , function ( ) {
60
70
checker . configure ( { requireSpaceBeforeKeywords : true } ) ;
61
71
@@ -79,4 +89,36 @@ describe('rules/require-space-before-keywords', function() {
79
89
expect ( errors ) . to . have . one . validation . error . from ( 'requireSpaceBeforeKeywords' ) ;
80
90
expect ( errors . explainError ( error ) ) . to . have . string ( 'Missing space before "catch" keyword' ) ;
81
91
} ) ;
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
+ } ) ;
82
124
} ) ;
0 commit comments