@@ -12,6 +12,9 @@ const parserOptions = {
12
12
} ,
13
13
} ;
14
14
15
+ const message =
16
+ 'Expected an empty line between variable declaration and usage.' ;
17
+
15
18
const ruleTester = new MultiTester ( parserOptions ) ;
16
19
17
20
ruleTester . run ( 'blank-line-declaration-usage' , rule , {
@@ -23,84 +26,135 @@ ruleTester.run('blank-line-declaration-usage', rule, {
23
26
` ,
24
27
errors : [
25
28
{
26
- message : 'error msg' ,
27
- type : 'VariableDeclaration ' ,
29
+ message,
30
+ type : 'Identifier ' ,
28
31
} ,
29
32
] ,
33
+ output : `
34
+ const test = 'test';
35
+
36
+ const testLength = test.length;
37
+ ` ,
30
38
} ,
31
39
{
32
40
code : `
33
41
const obj = {
34
42
foo: 'bar',
35
43
bar: 'foo',
36
- hi : 'bryce ',
44
+ life : 'ray ',
37
45
}
38
- Object.keys(obj)
46
+ Object.keys(obj)
39
47
` ,
40
48
errors : [
41
49
{
42
- message : 'error msg' ,
43
- type : 'VariableDeclaration ' ,
50
+ message,
51
+ type : 'Identifier ' ,
44
52
} ,
45
53
] ,
54
+ output : `
55
+ const obj = {
56
+ foo: 'bar',
57
+ bar: 'foo',
58
+ life: 'ray',
59
+ }
60
+
61
+ Object.keys(obj)
62
+ ` ,
46
63
} ,
47
64
{
48
65
code : `
49
66
function updateData() {
50
67
const obj = {
51
68
foo: 'bar',
52
69
bar: 'foo',
53
- hi : 'bryce ',
70
+ life : 'ray ',
54
71
}
55
72
56
- const formattedCategoryIds = Object.keys(obj).length
73
+ const ids = Object.keys(obj).length
57
74
? 'superLongStringSoThatItForcesTheLineToBeWrapped'
58
75
: 'justASimpleString';
59
- const APIUrl = \` ${ formattedCategoryIds } \` ;
76
+ ids.length ;
60
77
}
61
78
` ,
62
79
errors : [
63
80
{
64
- message : 'error msg' ,
65
- type : 'VariableDeclaration ' ,
81
+ message,
82
+ type : 'Identifier ' ,
66
83
} ,
67
84
] ,
85
+ output : `
86
+ function updateData() {
87
+ const obj = {
88
+ foo: 'bar',
89
+ bar: 'foo',
90
+ life: 'ray',
91
+ }
92
+
93
+ const ids = Object.keys(obj).length
94
+ ? 'superLongStringSoThatItForcesTheLineToBeWrapped'
95
+ : 'justASimpleString';
96
+
97
+ ids.length;
98
+ }
99
+ ` ,
68
100
} ,
69
101
{
70
102
code : `
71
103
const obj = {
72
104
foo: 'bar',
73
105
bar: 'foo',
74
- hi : 'bryce ',
106
+ life : 'ray ',
75
107
}
76
-
108
+
77
109
const {foo} = obj;
78
110
const length = foo.length;
79
111
` ,
80
112
errors : [
81
113
{
82
- message : 'error msg' ,
83
- type : 'VariableDeclaration ' ,
114
+ message,
115
+ type : 'Identifier ' ,
84
116
} ,
85
117
] ,
118
+ output : `
119
+ const obj = {
120
+ foo: 'bar',
121
+ bar: 'foo',
122
+ life: 'ray',
123
+ }
124
+
125
+ const {foo} = obj;
126
+
127
+ const length = foo.length;
128
+ ` ,
86
129
} ,
87
130
{
88
131
code : `
89
132
const obj = {
90
133
foo: 'bar',
91
134
bar: 'foo',
92
- hi : 'bryce ',
135
+ life : 'ray ',
93
136
}
94
-
95
- const {foo, bar, hi } = obj;
96
- const length = hi .length;
137
+
138
+ const {foo, bar, life } = obj;
139
+ const length = life .length;
97
140
` ,
98
141
errors : [
99
142
{
100
- message : 'error msg' ,
101
- type : 'VariableDeclaration ' ,
143
+ message,
144
+ type : 'Identifier ' ,
102
145
} ,
103
146
] ,
147
+ output : `
148
+ const obj = {
149
+ foo: 'bar',
150
+ bar: 'foo',
151
+ life: 'ray',
152
+ }
153
+
154
+ const {foo, bar, life} = obj;
155
+
156
+ const length = life.length;
157
+ ` ,
104
158
} ,
105
159
{
106
160
code : `
@@ -109,36 +163,53 @@ ruleTester.run('blank-line-declaration-usage', rule, {
109
163
` ,
110
164
errors : [
111
165
{
112
- message : 'error msg' ,
113
- type : 'VariableDeclaration ' ,
166
+ message,
167
+ type : 'Identifier ' ,
114
168
} ,
115
169
] ,
170
+ output : `
171
+ const filePath = context.getFilename();
172
+
173
+ const filename = path.basename(something, filePath);
174
+ ` ,
116
175
} ,
117
176
{
118
177
code : `
119
178
for (const file of files) {
120
179
const contents = readFileAsync(file, 'utf8');
121
180
const length = contents.length;
122
- }
181
+ }
123
182
` ,
124
183
errors : [
125
184
{
126
- message : 'error msg' ,
127
- type : 'VariableDeclaration ' ,
185
+ message,
186
+ type : 'Identifier ' ,
128
187
} ,
129
188
] ,
189
+ output : `
190
+ for (const file of files) {
191
+ const contents = readFileAsync(file, 'utf8');
192
+
193
+ const length = contents.length;
194
+ }
195
+ ` ,
130
196
} ,
131
197
{
132
198
code : `
133
- var cbSpy = sinon.spy();
134
- prototype.rows = [cbSpy];
199
+ const cbSpy = sinon.spy();
200
+ prototype.rows = [cbSpy];
135
201
` ,
136
202
errors : [
137
203
{
138
- message : 'error msg' ,
139
- type : 'VariableDeclaration ' ,
204
+ message,
205
+ type : 'Identifier ' ,
140
206
} ,
141
207
] ,
208
+ output : `
209
+ const cbSpy = sinon.spy();
210
+
211
+ prototype.rows = [cbSpy];
212
+ ` ,
142
213
} ,
143
214
] ,
144
215
valid : [
@@ -154,7 +225,7 @@ ruleTester.run('blank-line-declaration-usage', rule, {
154
225
const obj = {
155
226
foo: 'bar',
156
227
bar: 'foo',
157
- hi : 'bryce ',
228
+ life : 'ray ',
158
229
}
159
230
160
231
Object.keys(obj)
@@ -165,9 +236,9 @@ ruleTester.run('blank-line-declaration-usage', rule, {
165
236
const obj = {
166
237
foo: 'bar',
167
238
bar: 'foo',
168
- hi : 'bryce ',
239
+ life : 'ray ',
169
240
}
170
-
241
+
171
242
const {foo} = obj;
172
243
173
244
const length = foo.length;
0 commit comments