@@ -68,27 +68,31 @@ new RuleTester().run("exports-style", rule, {
68
68
invalid : [
69
69
{
70
70
code : "exports = {foo: 1}" ,
71
+ output : null ,
71
72
globals : { module : false , exports : true } ,
72
73
errors : [
73
74
"Unexpected access to 'exports'. Use 'module.exports' instead." ,
74
75
] ,
75
76
} ,
76
77
{
77
78
code : "exports.foo = 1" ,
79
+ output : null ,
78
80
globals : { module : false , exports : true } ,
79
81
errors : [
80
82
"Unexpected access to 'exports'. Use 'module.exports' instead." ,
81
83
] ,
82
84
} ,
83
85
{
84
86
code : "module.exports = exports = {foo: 1}" ,
87
+ output : null ,
85
88
globals : { module : false , exports : true } ,
86
89
errors : [
87
90
"Unexpected access to 'exports'. Use 'module.exports' instead." ,
88
91
] ,
89
92
} ,
90
93
{
91
94
code : "exports = module.exports = {foo: 1}" ,
95
+ output : null ,
92
96
globals : { module : false , exports : true } ,
93
97
errors : [
94
98
"Unexpected access to 'exports'. Use 'module.exports' instead." ,
@@ -97,6 +101,7 @@ new RuleTester().run("exports-style", rule, {
97
101
98
102
{
99
103
code : "exports = {foo: 1}" ,
104
+ output : null ,
100
105
options : [ "module.exports" ] ,
101
106
globals : { module : false , exports : true } ,
102
107
errors : [
@@ -105,6 +110,7 @@ new RuleTester().run("exports-style", rule, {
105
110
} ,
106
111
{
107
112
code : "exports.foo = 1" ,
113
+ output : null ,
108
114
options : [ "module.exports" ] ,
109
115
globals : { module : false , exports : true } ,
110
116
errors : [
@@ -113,6 +119,7 @@ new RuleTester().run("exports-style", rule, {
113
119
} ,
114
120
{
115
121
code : "module.exports = exports = {foo: 1}" ,
122
+ output : null ,
116
123
options : [ "module.exports" ] ,
117
124
globals : { module : false , exports : true } ,
118
125
errors : [
@@ -121,6 +128,7 @@ new RuleTester().run("exports-style", rule, {
121
128
} ,
122
129
{
123
130
code : "exports = module.exports = {foo: 1}" ,
131
+ output : null ,
124
132
options : [ "module.exports" ] ,
125
133
globals : { module : false , exports : true } ,
126
134
errors : [
@@ -130,6 +138,7 @@ new RuleTester().run("exports-style", rule, {
130
138
131
139
{
132
140
code : "exports = {foo: 1}" ,
141
+ output : null ,
133
142
options : [ "exports" ] ,
134
143
globals : { module : false , exports : true } ,
135
144
errors : [
@@ -138,6 +147,7 @@ new RuleTester().run("exports-style", rule, {
138
147
} ,
139
148
{
140
149
code : "module.exports = {foo: 1}" ,
150
+ output : "exports.foo = 1;" ,
141
151
options : [ "exports" ] ,
142
152
globals : { module : false , exports : true } ,
143
153
errors : [
@@ -146,14 +156,183 @@ new RuleTester().run("exports-style", rule, {
146
156
} ,
147
157
{
148
158
code : "module.exports.foo = 1" ,
159
+ output : "exports.foo = 1" ,
149
160
options : [ "exports" ] ,
150
161
globals : { module : false , exports : true } ,
151
162
errors : [
152
163
"Unexpected access to 'module.exports'. Use 'exports' instead." ,
153
164
] ,
154
165
} ,
166
+ {
167
+ code : "module.exports = { a: 1 }" ,
168
+ output : "exports.a = 1;" ,
169
+ options : [ "exports" ] ,
170
+ globals : { module : false , exports : true } ,
171
+ errors : [
172
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
173
+ ] ,
174
+ } ,
175
+ {
176
+ code : "module.exports = { a: 1, b: 2 }" ,
177
+ output : "exports.a = 1;\n\nexports.b = 2;" ,
178
+ options : [ "exports" ] ,
179
+ globals : { module : false , exports : true } ,
180
+ errors : [
181
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
182
+ ] ,
183
+ } ,
184
+ {
185
+ code :
186
+ "module.exports = { // before a\na: 1, // between a and b\nb: 2 // after b\n}" ,
187
+ output :
188
+ "// before a\nexports.a = 1;\n\n// between a and b\nexports.b = 2;\n// after b" ,
189
+ options : [ "exports" ] ,
190
+ globals : { module : false , exports : true } ,
191
+ errors : [
192
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
193
+ ] ,
194
+ } ,
195
+ {
196
+ code : "foo(module.exports = {foo: 1})" ,
197
+ output : null ,
198
+ options : [ "exports" ] ,
199
+ globals : { module : false , exports : true } ,
200
+ errors : [
201
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
202
+ ] ,
203
+ } ,
204
+ {
205
+ code :
206
+ "if(foo){ module.exports = { foo: 1};} else { module.exports = {foo: 2};}" ,
207
+ output : null ,
208
+ options : [ "exports" ] ,
209
+ globals : { module : false , exports : true } ,
210
+ errors : [
211
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
212
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
213
+ ] ,
214
+ } ,
215
+ {
216
+ code : "function bar() { module.exports = { foo: 1 }; }" ,
217
+ output : null ,
218
+ options : [ "exports" ] ,
219
+ globals : { module : false , exports : true } ,
220
+ errors : [
221
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
222
+ ] ,
223
+ } ,
224
+ {
225
+ code : "module.exports = { get a() {} }" ,
226
+ output : null ,
227
+ options : [ "exports" ] ,
228
+ globals : { module : false , exports : true } ,
229
+ errors : [
230
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
231
+ ] ,
232
+ } ,
233
+ {
234
+ code : "module.exports = { set a(a) {} }" ,
235
+ output : null ,
236
+ options : [ "exports" ] ,
237
+ globals : { module : false , exports : true } ,
238
+ errors : [
239
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
240
+ ] ,
241
+ } ,
242
+ {
243
+ code : "module.exports = { a }" ,
244
+ output : "exports.a = a;" ,
245
+ options : [ "exports" ] ,
246
+ parserOptions : { ecmaVersion : 6 } ,
247
+ globals : { module : false , exports : true } ,
248
+ errors : [
249
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
250
+ ] ,
251
+ } ,
252
+ {
253
+ code : "module.exports = { ...a }" ,
254
+ output : null ,
255
+ options : [ "exports" ] ,
256
+ parserOptions : { ecmaVersion : 9 } ,
257
+ globals : { module : false , exports : true } ,
258
+ errors : [
259
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
260
+ ] ,
261
+ } ,
262
+ {
263
+ code : "module.exports = { ['a' + 'b']: 1 }" ,
264
+ output : "exports['a' + 'b'] = 1;" ,
265
+ options : [ "exports" ] ,
266
+ parserOptions : { ecmaVersion : 6 } ,
267
+ globals : { module : false , exports : true } ,
268
+ errors : [
269
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
270
+ ] ,
271
+ } ,
272
+ {
273
+ code : "module.exports = { 'foo': 1 }" ,
274
+ output : "exports['foo'] = 1;" ,
275
+ options : [ "exports" ] ,
276
+ parserOptions : { ecmaVersion : 6 } ,
277
+ globals : { module : false , exports : true } ,
278
+ errors : [
279
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
280
+ ] ,
281
+ } ,
282
+ {
283
+ code : "module.exports = { foo(a) {} }" ,
284
+ output : "exports.foo = function (a) {};" ,
285
+ options : [ "exports" ] ,
286
+ parserOptions : { ecmaVersion : 8 } ,
287
+ globals : { module : false , exports : true } ,
288
+ errors : [
289
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
290
+ ] ,
291
+ } ,
292
+ {
293
+ code : "module.exports = { *foo(a) {} }" ,
294
+ output : "exports.foo = function* (a) {};" ,
295
+ options : [ "exports" ] ,
296
+ parserOptions : { ecmaVersion : 6 } ,
297
+ globals : { module : false , exports : true } ,
298
+ errors : [
299
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
300
+ ] ,
301
+ } ,
302
+ {
303
+ code : "module.exports = { async foo(a) {} }" ,
304
+ output : "exports.foo = async function (a) {};" ,
305
+ options : [ "exports" ] ,
306
+ parserOptions : { ecmaVersion : 8 } ,
307
+ globals : { module : false , exports : true } ,
308
+ errors : [
309
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
310
+ ] ,
311
+ } ,
312
+ {
313
+ code : "module.exports.foo()" ,
314
+ output : "exports.foo()" ,
315
+ options : [ "exports" ] ,
316
+ parserOptions : { ecmaVersion : 8 } ,
317
+ globals : { module : false , exports : true } ,
318
+ errors : [
319
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
320
+ ] ,
321
+ } ,
322
+ {
323
+ code : "a = module.exports.foo + module.exports['bar']" ,
324
+ output : "a = exports.foo + exports['bar']" ,
325
+ options : [ "exports" ] ,
326
+ parserOptions : { ecmaVersion : 8 } ,
327
+ globals : { module : false , exports : true } ,
328
+ errors : [
329
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
330
+ "Unexpected access to 'module.exports'. Use 'exports' instead." ,
331
+ ] ,
332
+ } ,
155
333
{
156
334
code : "module.exports = exports = {foo: 1}" ,
335
+ output : null ,
157
336
options : [ "exports" ] ,
158
337
globals : { module : false , exports : true } ,
159
338
errors : [
@@ -163,6 +342,7 @@ new RuleTester().run("exports-style", rule, {
163
342
} ,
164
343
{
165
344
code : "exports = module.exports = {foo: 1}" ,
345
+ output : null ,
166
346
options : [ "exports" ] ,
167
347
globals : { module : false , exports : true } ,
168
348
errors : [
@@ -172,6 +352,7 @@ new RuleTester().run("exports-style", rule, {
172
352
} ,
173
353
{
174
354
code : "module.exports = exports = {foo: 1}; exports = obj" ,
355
+ output : null ,
175
356
options : [ "exports" , { allowBatchAssign : true } ] ,
176
357
globals : { module : false , exports : true } ,
177
358
errors : [
@@ -180,6 +361,7 @@ new RuleTester().run("exports-style", rule, {
180
361
} ,
181
362
{
182
363
code : "exports = module.exports = {foo: 1}; exports = obj" ,
364
+ output : null ,
183
365
options : [ "exports" , { allowBatchAssign : true } ] ,
184
366
globals : { module : false , exports : true } ,
185
367
errors : [
0 commit comments