11var Checker = require ( '../../../lib/checker' ) ;
22var expect = require ( 'chai' ) . expect ;
3+ var reportAndFix = require ( '../../lib/assertHelpers' ) . reportAndFix ;
34
45describe ( 'rules/validate-newline-after-array-elements' , function ( ) {
56 var checker ;
@@ -18,8 +19,71 @@ describe('rules/validate-newline-after-array-elements', function() {
1819 } ) ;
1920
2021 describe ( 'true option' , function ( ) {
22+ var rules = { validateNewlineAfterArrayElements : true } ;
23+
2124 beforeEach ( function ( ) {
22- checker . configure ( { validateNewlineAfterArrayElements : true } ) ;
25+ checker . configure ( rules ) ;
26+ } ) ;
27+
28+ reportAndFix ( {
29+ name : 'should report for multi-line-line array with many elements' ,
30+ rules : rules ,
31+ errors : 2 ,
32+ input : 'var x = [\n 1, 2, 3\n];' ,
33+ output : 'var x = [\n 1,\n 2,\n 3\n];'
34+ } ) ;
35+
36+ reportAndFix ( {
37+ name : 'should report for multi-line array with many elements and one item on the first line' ,
38+ rules : rules ,
39+ errors : 1 ,
40+ input : 'var x = [0,\n' +
41+ '1,\n' +
42+ '2,\n' +
43+ '3\n' +
44+ '];\n' ,
45+ output : 'var x = [\n' +
46+ '0,\n' +
47+ '1,\n' +
48+ '2,\n' +
49+ '3\n' +
50+ '];\n'
51+ } ) ;
52+
53+ reportAndFix ( {
54+ name : 'should report for multi-line array with many elements and one item on the last line' ,
55+ rules : rules ,
56+ errors : 1 ,
57+ input : 'var x = [\n' +
58+ '1,\n' +
59+ '2,\n' +
60+ '3,\n' +
61+ '4];\n' ,
62+ output : 'var x = [\n' +
63+ '1,\n' +
64+ '2,\n' +
65+ '3,\n' +
66+ '4\n' +
67+ '];\n'
68+ } ) ;
69+
70+ reportAndFix ( {
71+ name : 'should report for multi-line array with many elements on each line' ,
72+ rules : rules ,
73+ errors : 3 ,
74+ input : 'var x = [\n' +
75+ '1, 1,\n' +
76+ '2, 2,\n' +
77+ '3, 3\n' +
78+ '];\n' ,
79+ output : 'var x = [\n' +
80+ '1,\n' +
81+ ' 1,\n' +
82+ '2,\n' +
83+ ' 2,\n' +
84+ '3,\n' +
85+ ' 3\n' +
86+ '];\n'
2387 } ) ;
2488
2589 it ( 'should not report for empty array' , function ( ) {
@@ -36,10 +100,6 @@ describe('rules/validate-newline-after-array-elements', function() {
36100 expect ( checker . checkString ( 'var x = [1, 2, 3];' ) ) . to . have . no . errors ( ) ;
37101 } ) ;
38102
39- it ( 'should report for single-line array with many elements' , function ( ) {
40- expect ( checker . checkString ( 'var x = [\n 1, 2, 3\n];' ) ) . to . have . error . count . equal ( 2 ) ;
41- } ) ;
42-
43103 it ( 'should not report for multi-line array without elements' , function ( ) {
44104 expect ( checker . checkString (
45105 'var x = [\n' +
@@ -58,36 +118,6 @@ describe('rules/validate-newline-after-array-elements', function() {
58118 ) ) . to . have . no . errors ( ) ;
59119 } ) ;
60120
61- it ( 'should report for multi-line array with many elements and one item on the first line' , function ( ) {
62- expect ( checker . checkString (
63- 'var x = [0,\n' +
64- '1,\n' +
65- '2,\n' +
66- '3\n' +
67- '];\n'
68- ) ) . to . have . one . validation . error . from ( 'validateNewlineAfterArrayElements' ) ;
69- } ) ;
70-
71- it ( 'should report for multi-line array with many elements and one item on the last line' , function ( ) {
72- expect ( checker . checkString (
73- 'var x = [\n' +
74- '1,\n' +
75- '2,\n' +
76- '3,\n' +
77- '4];\n'
78- ) ) . to . have . one . validation . error . from ( 'validateNewlineAfterArrayElements' ) ;
79- } ) ;
80-
81- it ( 'should report for multi-line array with many elements on each line' , function ( ) {
82- expect ( checker . checkString (
83- 'var x = [\n' +
84- '1, 1,\n' +
85- '2, 2,\n' +
86- '3, 3\n' +
87- '];\n'
88- ) ) . to . have . error . count . equal ( 3 ) ;
89- } ) ;
90-
91121 it ( 'should not report for one-line array with many holes' , function ( ) {
92122 expect ( checker . checkString (
93123 'var x = [\n' +
@@ -100,8 +130,10 @@ describe('rules/validate-newline-after-array-elements', function() {
100130 } ) ;
101131
102132 describe ( 'with value 3' , function ( ) {
133+ var rules = { validateNewlineAfterArrayElements : 3 } ;
134+
103135 beforeEach ( function ( ) {
104- checker . configure ( { validateNewlineAfterArrayElements : 3 } ) ;
136+ checker . configure ( rules ) ;
105137 } ) ;
106138
107139 it ( 'should not report for one-line array with 3 elements' , function ( ) {
@@ -110,52 +142,76 @@ describe('rules/validate-newline-after-array-elements', function() {
110142 ) ) . to . have . no . errors ( ) ;
111143 } ) ;
112144
113- it ( 'should report for multi-line array with 3 elements' , function ( ) {
114- expect ( checker . checkString (
115- 'var x = [\n' +
145+ reportAndFix ( {
146+ name : 'should report for multi-line array with 3 elements' ,
147+ rules : rules ,
148+ errors : 1 ,
149+ input : 'var x = [\n' +
116150 ' 1, 2\n' +
151+ '];' ,
152+ output : 'var x = [\n' +
153+ ' 1,\n' +
154+ ' 2\n' +
117155 '];'
118- ) ) . to . have . one . validation . error . from ( 'validateNewlineAfterArrayElements' ) ;
119156 } ) ;
120157 } ) ;
121158
122159 describe ( 'maximum 3' , function ( ) {
160+ var rules = { validateNewlineAfterArrayElements : { maximum : 3 } } ;
161+
123162 beforeEach ( function ( ) {
124- checker . configure ( { validateNewlineAfterArrayElements : { maximum : 3 } } ) ;
163+ checker . configure ( rules ) ;
164+ } ) ;
165+
166+ reportAndFix ( {
167+ name : 'should report for multi-line array with 3 elements' ,
168+ rules : rules ,
169+ errors : 1 ,
170+ input : 'var x = [\n' +
171+ ' 1, 2\n' +
172+ '];' ,
173+ output : 'var x = [\n' +
174+ ' 1,\n' +
175+ ' 2\n' +
176+ '];'
125177 } ) ;
126178
127179 it ( 'should not report for one-line array with 3 elements' , function ( ) {
128180 expect ( checker . checkString (
129181 'var x = [1, 2, 3];'
130182 ) ) . to . have . no . errors ( ) ;
131183 } ) ;
132-
133- it ( 'should report for multi-line array with 3 elements' , function ( ) {
134- expect ( checker . checkString (
135- 'var x = [\n' +
136- ' 1, 2\n' +
137- '];'
138- ) ) . to . have . one . validation . error . from ( 'validateNewlineAfterArrayElements' ) ;
139- } ) ;
140184 } ) ;
141185
142186 describe ( 'maximum 2, ignoreBrackets true' , function ( ) {
187+ var rules = { validateNewlineAfterArrayElements : { maximum : 2 , ignoreBrackets : true } } ;
188+
143189 beforeEach ( function ( ) {
144- checker . configure ( { validateNewlineAfterArrayElements : { maximum : 2 , ignoreBrackets : true } } ) ;
190+ checker . configure ( rules ) ;
145191 } ) ;
146192
147- it ( 'should report for one-line array with 3 elements' , function ( ) {
148- expect ( checker . checkString (
149- 'var x = [1, 2, 3];'
150- ) ) . to . have . error . count . equal ( 2 ) ;
193+ reportAndFix ( {
194+ name : 'should report for one-line array with 3 elements' ,
195+ rules : rules ,
196+ errors : 2 ,
197+ input : 'var x = [1, 2, 3];' ,
198+ output : 'var x = [1,\n' +
199+ ' 2,\n' +
200+ ' 3];'
151201 } ) ;
152202
153- it ( 'should report for multi-line array with 3 elements' , function ( ) {
154- expect ( checker . checkString (
155- 'var x = [0,\n' +
156- ' 1, 2, 3,\n' +
203+ reportAndFix ( {
204+ name : 'should report for multi-line array with 3 elements' ,
205+ rules : rules ,
206+ errors : 2 ,
207+ input : 'var x = [0,\n' +
208+ ' 1, 2, 3,\n' +
209+ '4];' ,
210+ output : 'var x = [0,\n' +
211+ ' 1,\n' +
212+ ' 2,\n' +
213+ ' 3,\n' +
157214 '4];'
158- ) ) . to . have . error . count . equal ( 2 ) ;
159215 } ) ;
160216
161217 it ( 'should not report for multi-line array with elements on 2 lines' , function ( ) {
@@ -168,8 +224,24 @@ describe('rules/validate-newline-after-array-elements', function() {
168224 } ) ;
169225
170226 describe ( 'ignoreBrackets true' , function ( ) {
227+ var rules = { validateNewlineAfterArrayElements : { ignoreBrackets : true } } ;
228+
171229 beforeEach ( function ( ) {
172- checker . configure ( { validateNewlineAfterArrayElements : { ignoreBrackets : true } } ) ;
230+ checker . configure ( rules ) ;
231+ } ) ;
232+
233+ reportAndFix ( {
234+ name : 'should report for multi-line array with 3 elements' ,
235+ rules : rules ,
236+ errors : 2 ,
237+ input : 'var x = [0,\n' +
238+ ' 1, 2, 3,\n' +
239+ '4];' ,
240+ output : 'var x = [0,\n' +
241+ ' 1,\n' +
242+ ' 2,\n' +
243+ ' 3,\n' +
244+ '4];'
173245 } ) ;
174246
175247 it ( 'should not report for one-line array with 3 elements' , function ( ) {
@@ -178,14 +250,6 @@ describe('rules/validate-newline-after-array-elements', function() {
178250 ) ) . to . have . no . errors ( ) ;
179251 } ) ;
180252
181- it ( 'should report for multi-line array with 3 elements' , function ( ) {
182- expect ( checker . checkString (
183- 'var x = [0,\n' +
184- ' 1, 2, 3,\n' +
185- '4];'
186- ) ) . to . have . error . count . equal ( 2 ) ;
187- } ) ;
188-
189253 it ( 'should not report for multi-line array with elements on 2 lines' , function ( ) {
190254 expect ( checker . checkString (
191255 'var x = [0,\n' +
0 commit comments