@@ -4,8 +4,8 @@ import typescriptConfig from '../../../config/typescript';
4
4
5
5
import { RuleTester } from 'eslint' ;
6
6
import fs from 'fs' ;
7
- import semver from 'semver' ;
8
7
import eslintPkg from 'eslint/package.json' ;
8
+ import semver from 'semver' ;
9
9
10
10
// TODO: figure out why these tests fail in eslint 4
11
11
const isESLint4TODO = semver . satisfies ( eslintPkg . version , '^4' ) ;
@@ -108,34 +108,50 @@ ruleTester.run('no-unused-modules', rule, {
108
108
// tests for exports
109
109
ruleTester . run ( 'no-unused-modules' , rule , {
110
110
valid : [
111
-
112
- test ( { options : unusedExportsOptions ,
111
+ test ( {
112
+ options : unusedExportsOptions ,
113
113
code : 'import { o2 } from "./file-o";export default () => 12' ,
114
- filename : testFilePath ( './no-unused-modules/file-a.js' ) } ) ,
115
- test ( { options : unusedExportsOptions ,
114
+ filename : testFilePath ( './no-unused-modules/file-a.js' ) ,
115
+ } ) ,
116
+ test ( {
117
+ options : unusedExportsOptions ,
116
118
code : 'export const b = 2' ,
117
- filename : testFilePath ( './no-unused-modules/file-b.js' ) } ) ,
118
- test ( { options : unusedExportsOptions ,
119
+ filename : testFilePath ( './no-unused-modules/file-b.js' ) ,
120
+ } ) ,
121
+ test ( {
122
+ options : unusedExportsOptions ,
119
123
code : 'const c1 = 3; function c2() { return 3 }; export { c1, c2 }' ,
120
- filename : testFilePath ( './no-unused-modules/file-c.js' ) } ) ,
121
- test ( { options : unusedExportsOptions ,
124
+ filename : testFilePath ( './no-unused-modules/file-c.js' ) ,
125
+ } ) ,
126
+ test ( {
127
+ options : unusedExportsOptions ,
122
128
code : 'export function d() { return 4 }' ,
123
- filename : testFilePath ( './no-unused-modules/file-d.js' ) } ) ,
124
- test ( { options : unusedExportsOptions ,
129
+ filename : testFilePath ( './no-unused-modules/file-d.js' ) ,
130
+ } ) ,
131
+ test ( {
132
+ options : unusedExportsOptions ,
125
133
code : 'export class q { q0() {} }' ,
126
- filename : testFilePath ( './no-unused-modules/file-q.js' ) } ) ,
127
- test ( { options : unusedExportsOptions ,
134
+ filename : testFilePath ( './no-unused-modules/file-q.js' ) ,
135
+ } ) ,
136
+ test ( {
137
+ options : unusedExportsOptions ,
128
138
code : 'const e0 = 5; export { e0 as e }' ,
129
- filename : testFilePath ( './no-unused-modules/file-e.js' ) } ) ,
130
- test ( { options : unusedExportsOptions ,
139
+ filename : testFilePath ( './no-unused-modules/file-e.js' ) ,
140
+ } ) ,
141
+ test ( {
142
+ options : unusedExportsOptions ,
131
143
code : 'const l0 = 5; const l = 10; export { l0 as l1, l }; export default () => {}' ,
132
- filename : testFilePath ( './no-unused-modules/file-l.js' ) } ) ,
133
- test ( { options : unusedExportsOptions ,
144
+ filename : testFilePath ( './no-unused-modules/file-l.js' ) ,
145
+ } ) ,
146
+ test ( {
147
+ options : unusedExportsOptions ,
134
148
code : 'const o0 = 0; const o1 = 1; export { o0, o1 as o2 }; export default () => {}' ,
135
- filename : testFilePath ( './no-unused-modules/file-o.js' ) } ) ,
149
+ filename : testFilePath ( './no-unused-modules/file-o.js' ) ,
150
+ } ) ,
136
151
] ,
137
152
invalid : [
138
- test ( { options : unusedExportsOptions ,
153
+ test ( {
154
+ options : unusedExportsOptions ,
139
155
code : `import eslint from 'eslint'
140
156
import fileA from './file-a'
141
157
import { b } from './file-b'
@@ -155,319 +171,413 @@ ruleTester.run('no-unused-modules', rule, {
155
171
error ( `exported declaration 'o0' not used within other modules` ) ,
156
172
error ( `exported declaration 'o3' not used within other modules` ) ,
157
173
error ( `exported declaration 'p' not used within other modules` ) ,
158
- ] } ) ,
159
- test ( { options : unusedExportsOptions ,
174
+ ] ,
175
+ } ) ,
176
+ test ( {
177
+ options : unusedExportsOptions ,
160
178
code : `const n0 = 'n0'; const n1 = 42; export { n0, n1 }; export default () => {}` ,
161
179
filename : testFilePath ( './no-unused-modules/file-n.js' ) ,
162
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
180
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
181
+ } ) ,
163
182
] ,
164
183
} ) ;
165
184
166
185
// test for unused exports
167
186
ruleTester . run ( 'no-unused-modules' , rule , {
168
187
valid : [ ] ,
169
188
invalid : [
170
- test ( { options : unusedExportsOptions ,
189
+ test ( {
190
+ options : unusedExportsOptions ,
171
191
code : 'export default () => 13' ,
172
192
filename : testFilePath ( './no-unused-modules/file-f.js' ) ,
173
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
174
- test ( { options : unusedExportsOptions ,
193
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
194
+ } ) ,
195
+ test ( {
196
+ options : unusedExportsOptions ,
175
197
code : 'export const g = 2' ,
176
198
filename : testFilePath ( './no-unused-modules/file-g.js' ) ,
177
- errors : [ error ( `exported declaration 'g' not used within other modules` ) ] } ) ,
178
- test ( { options : unusedExportsOptions ,
199
+ errors : [ error ( `exported declaration 'g' not used within other modules` ) ] ,
200
+ } ) ,
201
+ test ( {
202
+ options : unusedExportsOptions ,
179
203
code : 'const h1 = 3; function h2() { return 3 }; const h3 = true; export { h1, h2, h3 }' ,
180
204
filename : testFilePath ( './no-unused-modules/file-h.js' ) ,
181
- errors : [ error ( `exported declaration 'h1' not used within other modules` ) ] } ) ,
182
- test ( { options : unusedExportsOptions ,
205
+ errors : [ error ( `exported declaration 'h1' not used within other modules` ) ] ,
206
+ } ) ,
207
+ test ( {
208
+ options : unusedExportsOptions ,
183
209
code : 'const i1 = 3; function i2() { return 3 }; export { i1, i2 }' ,
184
210
filename : testFilePath ( './no-unused-modules/file-i.js' ) ,
185
211
errors : [
186
212
error ( `exported declaration 'i1' not used within other modules` ) ,
187
213
error ( `exported declaration 'i2' not used within other modules` ) ,
188
- ] } ) ,
189
- test ( { options : unusedExportsOptions ,
214
+ ] ,
215
+ } ) ,
216
+ test ( {
217
+ options : unusedExportsOptions ,
190
218
code : 'export function j() { return 4 }' ,
191
219
filename : testFilePath ( './no-unused-modules/file-j.js' ) ,
192
- errors : [ error ( `exported declaration 'j' not used within other modules` ) ] } ) ,
193
- test ( { options : unusedExportsOptions ,
220
+ errors : [ error ( `exported declaration 'j' not used within other modules` ) ] ,
221
+ } ) ,
222
+ test ( {
223
+ options : unusedExportsOptions ,
194
224
code : 'export class q { q0() {} }' ,
195
225
filename : testFilePath ( './no-unused-modules/file-q.js' ) ,
196
- errors : [ error ( `exported declaration 'q' not used within other modules` ) ] } ) ,
197
- test ( { options : unusedExportsOptions ,
226
+ errors : [ error ( `exported declaration 'q' not used within other modules` ) ] ,
227
+ } ) ,
228
+ test ( {
229
+ options : unusedExportsOptions ,
198
230
code : 'const k0 = 5; export { k0 as k }' ,
199
231
filename : testFilePath ( './no-unused-modules/file-k.js' ) ,
200
- errors : [ error ( `exported declaration 'k' not used within other modules` ) ] } ) ,
232
+ errors : [ error ( `exported declaration 'k' not used within other modules` ) ] ,
233
+ } ) ,
201
234
] ,
202
235
} ) ;
203
236
204
- // // test for export from
237
+ // test for export from
205
238
ruleTester . run ( 'no-unused-modules' , rule , {
206
239
valid : [
207
- test ( { options : unusedExportsOptions ,
240
+ test ( {
241
+ options : unusedExportsOptions ,
208
242
code : `export { default } from './file-o'` ,
209
- filename : testFilePath ( './no-unused-modules/file-s.js' ) } ) ,
243
+ filename : testFilePath ( './no-unused-modules/file-s.js' ) ,
244
+ } ) ,
210
245
] ,
211
246
invalid : [
212
- test ( { options : unusedExportsOptions ,
247
+ test ( {
248
+ options : unusedExportsOptions ,
213
249
code : `export { k } from '${ testFilePath ( './no-unused-modules/file-k.js' ) } '` ,
214
250
filename : testFilePath ( './no-unused-modules/file-j.js' ) ,
215
- errors : [ error ( `exported declaration 'k' not used within other modules` ) ] } ) ,
251
+ errors : [ error ( `exported declaration 'k' not used within other modules` ) ] ,
252
+ } ) ,
216
253
] ,
217
254
} ) ;
218
255
219
256
ruleTester . run ( 'no-unused-modules' , rule , {
220
257
valid : [
221
- test ( { options : unusedExportsOptions ,
258
+ test ( {
259
+ options : unusedExportsOptions ,
222
260
code : 'const k0 = 5; export { k0 as k }' ,
223
- filename : testFilePath ( './no-unused-modules/file-k.js' ) } ) ,
261
+ filename : testFilePath ( './no-unused-modules/file-k.js' ) ,
262
+ } ) ,
224
263
] ,
225
264
invalid : [ ] ,
226
265
} ) ;
227
266
228
267
// test for ignored files
229
268
ruleTester . run ( 'no-unused-modules' , rule , {
230
269
valid : [
231
- test ( { options : unusedExportsOptions ,
270
+ test ( {
271
+ options : unusedExportsOptions ,
232
272
code : 'export default () => 14' ,
233
- filename : testFilePath ( './no-unused-modules/file-ignored-a.js' ) } ) ,
234
- test ( { options : unusedExportsOptions ,
273
+ filename : testFilePath ( './no-unused-modules/file-ignored-a.js' ) ,
274
+ } ) ,
275
+ test ( {
276
+ options : unusedExportsOptions ,
235
277
code : 'export const b = 2' ,
236
- filename : testFilePath ( './no-unused-modules/file-ignored-b.js' ) } ) ,
237
- test ( { options : unusedExportsOptions ,
278
+ filename : testFilePath ( './no-unused-modules/file-ignored-b.js' ) ,
279
+ } ) ,
280
+ test ( {
281
+ options : unusedExportsOptions ,
238
282
code : 'const c1 = 3; function c2() { return 3 }; export { c1, c2 }' ,
239
- filename : testFilePath ( './no-unused-modules/file-ignored-c.js' ) } ) ,
240
- test ( { options : unusedExportsOptions ,
283
+ filename : testFilePath ( './no-unused-modules/file-ignored-c.js' ) ,
284
+ } ) ,
285
+ test ( {
286
+ options : unusedExportsOptions ,
241
287
code : 'export function d() { return 4 }' ,
242
- filename : testFilePath ( './no-unused-modules/file-ignored-d.js' ) } ) ,
243
- test ( { options : unusedExportsOptions ,
288
+ filename : testFilePath ( './no-unused-modules/file-ignored-d.js' ) ,
289
+ } ) ,
290
+ test ( {
291
+ options : unusedExportsOptions ,
244
292
code : 'const f = 5; export { f as e }' ,
245
- filename : testFilePath ( './no-unused-modules/file-ignored-e.js' ) } ) ,
246
- test ( { options : unusedExportsOptions ,
293
+ filename : testFilePath ( './no-unused-modules/file-ignored-e.js' ) ,
294
+ } ) ,
295
+ test ( {
296
+ options : unusedExportsOptions ,
247
297
code : 'const l0 = 5; const l = 10; export { l0 as l1, l }; export default () => {}' ,
248
- filename : testFilePath ( './no-unused-modules/file-ignored-l.js' ) } ) ,
298
+ filename : testFilePath ( './no-unused-modules/file-ignored-l.js' ) ,
299
+ } ) ,
249
300
] ,
250
301
invalid : [ ] ,
251
302
} ) ;
252
303
253
304
// add named import for file with default export
254
305
ruleTester . run ( 'no-unused-modules' , rule , {
255
306
valid : [
256
- test ( { options : unusedExportsOptions ,
307
+ test ( {
308
+ options : unusedExportsOptions ,
257
309
code : `import { f } from '${ testFilePath ( './no-unused-modules/file-f.js' ) } '` ,
258
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
310
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
311
+ } ) ,
259
312
] ,
260
313
invalid : [
261
- test ( { options : unusedExportsOptions ,
314
+ test ( {
315
+ options : unusedExportsOptions ,
262
316
code : 'export default () => 15' ,
263
317
filename : testFilePath ( './no-unused-modules/file-f.js' ) ,
264
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
318
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
319
+ } ) ,
265
320
] ,
266
321
} ) ;
267
322
268
323
// add default import for file with default export
269
324
ruleTester . run ( 'no-unused-modules' , rule , {
270
325
valid : [
271
- test ( { options : unusedExportsOptions ,
326
+ test ( {
327
+ options : unusedExportsOptions ,
272
328
code : `import f from '${ testFilePath ( './no-unused-modules/file-f.js' ) } '` ,
273
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
274
- test ( { options : unusedExportsOptions ,
329
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
330
+ } ) ,
331
+ test ( {
332
+ options : unusedExportsOptions ,
275
333
code : 'export default () => 16' ,
276
- filename : testFilePath ( './no-unused-modules/file-f.js' ) } ) ,
334
+ filename : testFilePath ( './no-unused-modules/file-f.js' ) ,
335
+ } ) ,
277
336
] ,
278
337
invalid : [ ] ,
279
338
} ) ;
280
339
281
340
// add default import for file with named export
282
341
ruleTester . run ( 'no-unused-modules' , rule , {
283
342
valid : [
284
- test ( { options : unusedExportsOptions ,
343
+ test ( {
344
+ options : unusedExportsOptions ,
285
345
code : `import g from '${ testFilePath ( './no-unused-modules/file-g.js' ) } ';import {h} from '${ testFilePath ( './no-unused-modules/file-gg.js' ) } '` ,
286
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
346
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
347
+ } ) ,
287
348
] ,
288
349
invalid : [
289
- test ( { options : unusedExportsOptions ,
350
+ test ( {
351
+ options : unusedExportsOptions ,
290
352
code : 'export const g = 2' ,
291
353
filename : testFilePath ( './no-unused-modules/file-g.js' ) ,
292
- errors : [ error ( `exported declaration 'g' not used within other modules` ) ] } ) ] ,
354
+ errors : [ error ( `exported declaration 'g' not used within other modules` ) ] ,
355
+ } ) ] ,
293
356
} ) ;
294
357
295
358
// add named import for file with named export
296
359
ruleTester . run ( 'no-unused-modules' , rule , {
297
360
valid : [
298
- test ( { options : unusedExportsOptions ,
361
+ test ( {
362
+ options : unusedExportsOptions ,
299
363
code : `import { g } from '${ testFilePath ( './no-unused-modules/file-g.js' ) } '; import eslint from 'eslint'` ,
300
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
301
- test ( { options : unusedExportsOptions ,
364
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
365
+ } ) ,
366
+ test ( {
367
+ options : unusedExportsOptions ,
302
368
code : 'export const g = 2' ,
303
- filename : testFilePath ( './no-unused-modules/file-g.js' ) } ) ,
369
+ filename : testFilePath ( './no-unused-modules/file-g.js' ) ,
370
+ } ) ,
304
371
] ,
305
372
invalid : [ ] ,
306
373
} ) ;
307
374
308
375
// add different named import for file with named export
309
376
ruleTester . run ( 'no-unused-modules' , rule , {
310
377
valid : [
311
- test ( { options : unusedExportsOptions ,
378
+ test ( {
379
+ options : unusedExportsOptions ,
312
380
code : `import { c } from '${ testFilePath ( './no-unused-modules/file-b.js' ) } '` ,
313
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
381
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
382
+ } ) ,
314
383
] ,
315
384
invalid : [
316
- test ( { options : unusedExportsOptions ,
385
+ test ( {
386
+ options : unusedExportsOptions ,
317
387
code : 'export const b = 2' ,
318
388
filename : testFilePath ( './no-unused-modules/file-b.js' ) ,
319
- errors : [ error ( `exported declaration 'b' not used within other modules` ) ] } ) ,
389
+ errors : [ error ( `exported declaration 'b' not used within other modules` ) ] ,
390
+ } ) ,
320
391
] ,
321
392
} ) ;
322
393
323
394
// add renamed named import for file with named export
324
395
ruleTester . run ( 'no-unused-modules' , rule , {
325
396
valid : [
326
- test ( { options : unusedExportsOptions ,
397
+ test ( {
398
+ options : unusedExportsOptions ,
327
399
code : `import { g as g1 } from '${ testFilePath ( './no-unused-modules/file-g.js' ) } '; import eslint from 'eslint'` ,
328
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
329
- test ( { options : unusedExportsOptions ,
400
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
401
+ } ) ,
402
+ test ( {
403
+ options : unusedExportsOptions ,
330
404
code : 'export const g = 2' ,
331
- filename : testFilePath ( './no-unused-modules/file-g.js' ) } ) ,
405
+ filename : testFilePath ( './no-unused-modules/file-g.js' ) ,
406
+ } ) ,
332
407
] ,
333
408
invalid : [ ] ,
334
409
} ) ;
335
410
336
411
// add different renamed named import for file with named export
337
412
ruleTester . run ( 'no-unused-modules' , rule , {
338
413
valid : [
339
- test ( { options : unusedExportsOptions ,
414
+ test ( {
415
+ options : unusedExportsOptions ,
340
416
code : `import { g1 as g } from '${ testFilePath ( './no-unused-modules/file-g.js' ) } '` ,
341
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
417
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
418
+ } ) ,
342
419
] ,
343
420
invalid : [
344
- test ( { options : unusedExportsOptions ,
421
+ test ( {
422
+ options : unusedExportsOptions ,
345
423
code : 'export const g = 2' ,
346
424
filename : testFilePath ( './no-unused-modules/file-g.js' ) ,
347
- errors : [ error ( `exported declaration 'g' not used within other modules` ) ] } ) ,
425
+ errors : [ error ( `exported declaration 'g' not used within other modules` ) ] ,
426
+ } ) ,
348
427
] ,
349
428
} ) ;
350
429
351
430
// remove default import for file with default export
352
431
ruleTester . run ( 'no-unused-modules' , rule , {
353
432
valid : [
354
- test ( { options : unusedExportsOptions ,
433
+ test ( {
434
+ options : unusedExportsOptions ,
355
435
code : `import { a1, a2 } from '${ testFilePath ( './no-unused-modules/file-a.js' ) } '` ,
356
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
436
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
437
+ } ) ,
357
438
] ,
358
439
invalid : [
359
- test ( { options : unusedExportsOptions ,
440
+ test ( {
441
+ options : unusedExportsOptions ,
360
442
code : 'export default () => 17' ,
361
443
filename : testFilePath ( './no-unused-modules/file-a.js' ) ,
362
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
444
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
445
+ } ) ,
363
446
] ,
364
447
} ) ;
365
448
366
449
// add namespace import for file with unused exports
367
450
ruleTester . run ( 'no-unused-modules' , rule , {
368
451
valid : [ ] ,
369
452
invalid : [
370
- test ( { options : unusedExportsOptions ,
453
+ test ( {
454
+ options : unusedExportsOptions ,
371
455
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
372
456
filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
373
457
errors : [
374
458
error ( `exported declaration 'm1' not used within other modules` ) ,
375
459
error ( `exported declaration 'm' not used within other modules` ) ,
376
460
error ( `exported declaration 'default' not used within other modules` ) ,
377
- ] } ) ,
461
+ ] ,
462
+ } ) ,
378
463
] ,
379
464
} ) ;
380
465
ruleTester . run ( 'no-unused-modules' , rule , {
381
466
valid : [
382
- test ( { options : unusedExportsOptions ,
467
+ test ( {
468
+ options : unusedExportsOptions ,
383
469
code : `import * as m from '${ testFilePath ( './no-unused-modules/file-m.js' ) } '; import unknown from 'unknown-module'` ,
384
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
385
- test ( { options : unusedExportsOptions ,
470
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
471
+ } ) ,
472
+ test ( {
473
+ options : unusedExportsOptions ,
386
474
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
387
- filename : testFilePath ( './no-unused-modules/file-m.js' ) } ) ,
475
+ filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
476
+ } ) ,
388
477
] ,
389
478
invalid : [ ] ,
390
479
} ) ;
391
480
392
481
// remove all exports
393
482
ruleTester . run ( 'no-unused-modules' , rule , {
394
483
valid : [
395
- test ( { options : unusedExportsOptions ,
484
+ test ( {
485
+ options : unusedExportsOptions ,
396
486
code : `/* import * as m from '${ testFilePath ( './no-unused-modules/file-m.js' ) } ' */` ,
397
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
487
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
488
+ } ) ,
398
489
] ,
399
490
invalid : [
400
- test ( { options : unusedExportsOptions ,
491
+ test ( {
492
+ options : unusedExportsOptions ,
401
493
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
402
494
filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
403
495
errors : [
404
496
error ( `exported declaration 'm1' not used within other modules` ) ,
405
497
error ( `exported declaration 'm' not used within other modules` ) ,
406
498
error ( `exported declaration 'default' not used within other modules` ) ,
407
- ] } ) ,
499
+ ] ,
500
+ } ) ,
408
501
] ,
409
502
} ) ;
410
503
411
504
ruleTester . run ( 'no-unused-modules' , rule , {
412
505
valid : [
413
- test ( { options : unusedExportsOptions ,
506
+ test ( {
507
+ options : unusedExportsOptions ,
414
508
code : `export * from '${ testFilePath ( './no-unused-modules/file-m.js' ) } ';` ,
415
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
509
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
510
+ } ) ,
416
511
] ,
417
512
invalid : [ ] ,
418
513
} ) ;
419
514
ruleTester . run ( 'no-unused-modules' , rule , {
420
515
valid : [ ] ,
421
516
invalid : [
422
- test ( { options : unusedExportsOptions ,
517
+ test ( {
518
+ options : unusedExportsOptions ,
423
519
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
424
520
filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
425
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
521
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
522
+ } ) ,
426
523
] ,
427
524
} ) ;
428
525
429
526
ruleTester . run ( 'no-unused-modules' , rule , {
430
527
valid : [ ] ,
431
528
invalid : [
432
- test ( { options : unusedExportsOptions ,
529
+ test ( {
530
+ options : unusedExportsOptions ,
433
531
code : `export { m1, m} from '${ testFilePath ( './no-unused-modules/file-m.js' ) } ';` ,
434
532
filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
435
533
errors : [
436
534
error ( `exported declaration 'm1' not used within other modules` ) ,
437
535
error ( `exported declaration 'm' not used within other modules` ) ,
438
- ] } ) ,
439
- test ( { options : unusedExportsOptions ,
536
+ ] ,
537
+ } ) ,
538
+ test ( {
539
+ options : unusedExportsOptions ,
440
540
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
441
541
filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
442
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
542
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
543
+ } ) ,
443
544
] ,
444
545
} ) ;
445
546
446
547
ruleTester . run ( 'no-unused-modules' , rule , {
447
548
valid : [
448
- // test({ options: unusedExportsOptions,
449
- // code: `export { default, m1 } from '${testFilePath('./no-unused-modules/file-m.js')}';`,
450
- // filename: testFilePath('./no-unused-modules/file-0.js') }),
549
+ /* TODO:
550
+ test({
551
+ options: unusedExportsOptions,
552
+ code: `export { default, m1 } from '${testFilePath('./no-unused-modules/file-m.js')}';`,
553
+ filename: testFilePath('./no-unused-modules/file-0.js')
554
+ }),
555
+ */
451
556
] ,
452
557
invalid : [
453
- test ( { options : unusedExportsOptions ,
558
+ test ( {
559
+ options : unusedExportsOptions ,
454
560
code : `export { default, m1 } from '${ testFilePath ( './no-unused-modules/file-m.js' ) } ';` ,
455
561
filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
456
562
errors : [
457
563
error ( `exported declaration 'default' not used within other modules` ) ,
458
564
error ( `exported declaration 'm1' not used within other modules` ) ,
459
- ] } ) ,
460
- test ( { options : unusedExportsOptions ,
565
+ ] ,
566
+ } ) ,
567
+ test ( {
568
+ options : unusedExportsOptions ,
461
569
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
462
570
filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
463
- errors : [ error ( `exported declaration 'm' not used within other modules` ) ] } ) ,
571
+ errors : [ error ( `exported declaration 'm' not used within other modules` ) ] ,
572
+ } ) ,
464
573
] ,
465
574
} ) ;
466
575
467
576
// Test that import and export in the same file both counts as usage
468
577
ruleTester . run ( 'no-unused-modules' , rule , {
469
578
valid : [
470
- test ( { options : unusedExportsOptions ,
579
+ test ( {
580
+ options : unusedExportsOptions ,
471
581
code : `export const a = 5;export const b = 't1'` ,
472
582
filename : testFilePath ( './no-unused-modules/import-export-1.js' ) ,
473
583
} ) ,
@@ -478,23 +588,31 @@ ruleTester.run('no-unused-modules', rule, {
478
588
describe ( 'renameDefault' , ( ) => {
479
589
ruleTester . run ( 'no-unused-modules' , rule , {
480
590
valid : [
481
- test ( { options : unusedExportsOptions ,
591
+ test ( {
592
+ options : unusedExportsOptions ,
482
593
code : 'export { default as Component } from "./Component"' ,
483
- filename : testFilePath ( './no-unused-modules/renameDefault/components.js' ) } ) ,
484
- test ( { options : unusedExportsOptions ,
594
+ filename : testFilePath ( './no-unused-modules/renameDefault/components.js' ) ,
595
+ } ) ,
596
+ test ( {
597
+ options : unusedExportsOptions ,
485
598
code : 'export default function Component() {}' ,
486
- filename : testFilePath ( './no-unused-modules/renameDefault/Component.js' ) } ) ,
599
+ filename : testFilePath ( './no-unused-modules/renameDefault/Component.js' ) ,
600
+ } ) ,
487
601
] ,
488
602
invalid : [ ] ,
489
603
} ) ;
490
604
ruleTester . run ( 'no-unused-modules' , rule , {
491
605
valid : [
492
- test ( { options : unusedExportsOptions ,
606
+ test ( {
607
+ options : unusedExportsOptions ,
493
608
code : 'export { default as ComponentA } from "./ComponentA";export { default as ComponentB } from "./ComponentB";' ,
494
- filename : testFilePath ( './no-unused-modules/renameDefault-2/components.js' ) } ) ,
495
- test ( { options : unusedExportsOptions ,
609
+ filename : testFilePath ( './no-unused-modules/renameDefault-2/components.js' ) ,
610
+ } ) ,
611
+ test ( {
612
+ options : unusedExportsOptions ,
496
613
code : 'export default function ComponentA() {};' ,
497
- filename : testFilePath ( './no-unused-modules/renameDefault-2/ComponentA.js' ) } ) ,
614
+ filename : testFilePath ( './no-unused-modules/renameDefault-2/ComponentA.js' ) ,
615
+ } ) ,
498
616
] ,
499
617
invalid : [ ] ,
500
618
} ) ;
@@ -508,12 +626,16 @@ describe('test behavior for new file', () => {
508
626
// add import in newly created file
509
627
ruleTester . run ( 'no-unused-modules' , rule , {
510
628
valid : [
511
- test ( { options : unusedExportsOptions ,
629
+ test ( {
630
+ options : unusedExportsOptions ,
512
631
code : `import * as m from '${ testFilePath ( './no-unused-modules/file-m.js' ) } '` ,
513
- filename : testFilePath ( './no-unused-modules/file-added-0.js' ) } ) ,
514
- test ( { options : unusedExportsOptions ,
632
+ filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
633
+ } ) ,
634
+ test ( {
635
+ options : unusedExportsOptions ,
515
636
code : 'const m0 = 5; const m = 10; export { m0 as m1, m }; export default () => {}' ,
516
- filename : testFilePath ( './no-unused-modules/file-m.js' ) } ) ,
637
+ filename : testFilePath ( './no-unused-modules/file-m.js' ) ,
638
+ } ) ,
517
639
] ,
518
640
invalid : [ ] ,
519
641
} ) ;
@@ -522,49 +644,62 @@ describe('test behavior for new file', () => {
522
644
ruleTester . run ( 'no-unused-modules' , rule , {
523
645
valid : [ ] ,
524
646
invalid : [
525
- test ( { options : unusedExportsOptions ,
647
+ test ( {
648
+ options : unusedExportsOptions ,
526
649
code : `export default () => {2}` ,
527
650
filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
528
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
651
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
652
+ } ) ,
529
653
] ,
530
654
} ) ;
531
655
532
656
ruleTester . run ( 'no-unused-modules' , rule , {
533
657
valid : [
534
- test ( { options : unusedExportsOptions ,
658
+ test ( {
659
+ options : unusedExportsOptions ,
535
660
code : `import def from '${ testFilePath ( './no-unused-modules/file-added-0.js' ) } '` ,
536
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
537
- test ( { options : unusedExportsOptions ,
661
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
662
+ } ) ,
663
+ test ( {
664
+ options : unusedExportsOptions ,
538
665
code : `export default () => {}` ,
539
- filename : testFilePath ( './no-unused-modules/file-added-0.js' ) } ) ,
666
+ filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
667
+ } ) ,
540
668
] ,
541
669
invalid : [ ] ,
542
670
} ) ;
543
671
544
672
// export * only considers named imports. default imports still need to be reported
545
673
ruleTester . run ( 'no-unused-modules' , rule , {
546
674
valid : [
547
- test ( { options : unusedExportsOptions ,
675
+ test ( {
676
+ options : unusedExportsOptions ,
548
677
code : `export * from '${ testFilePath ( './no-unused-modules/file-added-0.js' ) } '` ,
549
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
678
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
679
+ } ) ,
550
680
// Test export * from 'external-compiled-library'
551
- test ( { options : unusedExportsOptions ,
681
+ test ( {
682
+ options : unusedExportsOptions ,
552
683
code : `export * from 'external-compiled-library'` ,
553
684
filename : testFilePath ( './no-unused-modules/file-r.js' ) ,
554
685
} ) ,
555
686
] ,
556
687
invalid : [
557
- test ( { options : unusedExportsOptions ,
688
+ test ( {
689
+ options : unusedExportsOptions ,
558
690
code : `export const z = 'z';export default () => {}` ,
559
691
filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
560
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
692
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
693
+ } ) ,
561
694
] ,
562
695
} ) ;
563
696
ruleTester . run ( 'no-unused-modules' , rule , {
564
697
valid : [
565
- test ( { options : unusedExportsOptions ,
698
+ test ( {
699
+ options : unusedExportsOptions ,
566
700
code : `export const a = 2` ,
567
- filename : testFilePath ( './no-unused-modules/file-added-0.js' ) } ) ,
701
+ filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
702
+ } ) ,
568
703
] ,
569
704
invalid : [ ] ,
570
705
} ) ;
@@ -573,17 +708,21 @@ describe('test behavior for new file', () => {
573
708
ruleTester . run ( 'no-unused-modules' , rule , {
574
709
valid : [ ] ,
575
710
invalid : [
576
- test ( { options : unusedExportsOptions ,
711
+ test ( {
712
+ options : unusedExportsOptions ,
577
713
code : `export { a } from '${ testFilePath ( './no-unused-modules/file-added-0.js' ) } '` ,
578
714
filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
579
- errors : [ error ( `exported declaration 'a' not used within other modules` ) ] } ) ,
580
- test ( { options : unusedExportsOptions ,
715
+ errors : [ error ( `exported declaration 'a' not used within other modules` ) ] ,
716
+ } ) ,
717
+ test ( {
718
+ options : unusedExportsOptions ,
581
719
code : `export const z = 'z';export default () => {}` ,
582
720
filename : testFilePath ( './no-unused-modules/file-added-0.js' ) ,
583
721
errors : [
584
722
error ( `exported declaration 'z' not used within other modules` ) ,
585
723
error ( `exported declaration 'default' not used within other modules` ) ,
586
- ] } ) ,
724
+ ] ,
725
+ } ) ,
587
726
] ,
588
727
} ) ;
589
728
@@ -594,15 +733,19 @@ describe('test behavior for new file', () => {
594
733
} ) ;
595
734
ruleTester . run ( 'no-unused-modules' , rule , {
596
735
valid : [
597
- test ( { options : unusedExportsOptions ,
736
+ test ( {
737
+ options : unusedExportsOptions ,
598
738
code : `export * from '${ testFilePath ( './no-unused-modules/file-added-1.js' ) } '` ,
599
- filename : testFilePath ( './no-unused-modules/file-0.js' ) } ) ,
739
+ filename : testFilePath ( './no-unused-modules/file-0.js' ) ,
740
+ } ) ,
600
741
] ,
601
742
invalid : [
602
- test ( { options : unusedExportsOptions ,
743
+ test ( {
744
+ options : unusedExportsOptions ,
603
745
code : `export const z = 'z';export default () => {}` ,
604
746
filename : testFilePath ( './no-unused-modules/file-added-1.js' ) ,
605
- errors : [ error ( `exported declaration 'default' not used within other modules` ) ] } ) ,
747
+ errors : [ error ( `exported declaration 'default' not used within other modules` ) ] ,
748
+ } ) ,
606
749
] ,
607
750
} ) ;
608
751
after ( ( ) => {
@@ -625,12 +768,16 @@ describe('test behavior for new file', () => {
625
768
} ) ;
626
769
ruleTester . run ( 'no-unused-modules' , rule , {
627
770
valid : [
628
- test ( { options : unusedExportsOptions ,
771
+ test ( {
772
+ options : unusedExportsOptions ,
629
773
code : `import added from '${ testFilePath ( './no-unused-modules/file-added-2.js' ) } '` ,
630
- filename : testFilePath ( './no-unused-modules/file-added-1.js' ) } ) ,
631
- test ( { options : unusedExportsOptions ,
774
+ filename : testFilePath ( './no-unused-modules/file-added-1.js' ) ,
775
+ } ) ,
776
+ test ( {
777
+ options : unusedExportsOptions ,
632
778
code : `export default () => {}` ,
633
- filename : testFilePath ( './no-unused-modules/file-added-2.js' ) } ) ,
779
+ filename : testFilePath ( './no-unused-modules/file-added-2.js' ) ,
780
+ } ) ,
634
781
] ,
635
782
invalid : [ ] ,
636
783
} ) ;
@@ -647,12 +794,16 @@ describe('test behavior for new file', () => {
647
794
} ) ;
648
795
ruleTester . run ( 'no-unused-modules' , rule , {
649
796
valid : [
650
- test ( { options : unusedExportsOptions ,
797
+ test ( {
798
+ options : unusedExportsOptions ,
651
799
code : `import { added } from '${ testFilePath ( './no-unused-modules/file-added-3.js' ) } '` ,
652
- filename : testFilePath ( './no-unused-modules/file-added-1.js' ) } ) ,
653
- test ( { options : unusedExportsOptions ,
800
+ filename : testFilePath ( './no-unused-modules/file-added-1.js' ) ,
801
+ } ) ,
802
+ test ( {
803
+ options : unusedExportsOptions ,
654
804
code : `export const added = () => {}` ,
655
- filename : testFilePath ( './no-unused-modules/file-added-3.js' ) } ) ,
805
+ filename : testFilePath ( './no-unused-modules/file-added-3.js' ) ,
806
+ } ) ,
656
807
] ,
657
808
invalid : [ ] ,
658
809
} ) ;
@@ -666,18 +817,24 @@ describe('test behavior for new file', () => {
666
817
describe ( 'test behavior for destructured exports' , ( ) => {
667
818
ruleTester . run ( 'no-unused-modules' , rule , {
668
819
valid : [
669
- test ( { options : unusedExportsOptions ,
820
+ test ( {
821
+ options : unusedExportsOptions ,
670
822
code : `import { destructured } from '${ testFilePath ( './no-unused-modules/file-destructured-1.js' ) } '` ,
671
- filename : testFilePath ( './no-unused-modules/file-destructured-2.js' ) } ) ,
672
- test ( { options : unusedExportsOptions ,
823
+ filename : testFilePath ( './no-unused-modules/file-destructured-2.js' ) ,
824
+ } ) ,
825
+ test ( {
826
+ options : unusedExportsOptions ,
673
827
code : `export const { destructured } = {};` ,
674
- filename : testFilePath ( './no-unused-modules/file-destructured-1.js' ) } ) ,
828
+ filename : testFilePath ( './no-unused-modules/file-destructured-1.js' ) ,
829
+ } ) ,
675
830
] ,
676
831
invalid : [
677
- test ( { options : unusedExportsOptions ,
832
+ test ( {
833
+ options : unusedExportsOptions ,
678
834
code : `export const { destructured2 } = {};` ,
679
835
filename : testFilePath ( './no-unused-modules/file-destructured-1.js' ) ,
680
- errors : [ `exported declaration 'destructured2' not used within other modules` ] } ) ,
836
+ errors : [ `exported declaration 'destructured2' not used within other modules` ] ,
837
+ } ) ,
681
838
] ,
682
839
} ) ;
683
840
} ) ;
@@ -688,12 +845,16 @@ describe('test behavior for new file', () => {
688
845
} ) ;
689
846
ruleTester . run ( 'no-unused-modules' , rule , {
690
847
valid : [
691
- test ( { options : unusedExportsOptions ,
848
+ test ( {
849
+ options : unusedExportsOptions ,
692
850
code : `import * as added from '${ testFilePath ( './no-unused-modules/file-added-4.js.js' ) } '` ,
693
- filename : testFilePath ( './no-unused-modules/file-added-1.js' ) } ) ,
694
- test ( { options : unusedExportsOptions ,
851
+ filename : testFilePath ( './no-unused-modules/file-added-1.js' ) ,
852
+ } ) ,
853
+ test ( {
854
+ options : unusedExportsOptions ,
695
855
code : `export const added = () => {}; export default () => {}` ,
696
- filename : testFilePath ( './no-unused-modules/file-added-4.js.js' ) } ) ,
856
+ filename : testFilePath ( './no-unused-modules/file-added-4.js.js' ) ,
857
+ } ) ,
697
858
] ,
698
859
invalid : [ ] ,
699
860
} ) ;
@@ -707,13 +868,15 @@ describe('test behavior for new file', () => {
707
868
describe ( 'do not report missing export for ignored file' , ( ) => {
708
869
ruleTester . run ( 'no-unused-modules' , rule , {
709
870
valid : [
710
- test ( { options : [ {
711
- src : [ testFilePath ( './no-unused-modules/**/*.js' ) ] ,
712
- ignoreExports : [ testFilePath ( './no-unused-modules/*ignored*.js' ) ] ,
713
- missingExports : true ,
714
- } ] ,
715
- code : 'export const test = true' ,
716
- filename : testFilePath ( './no-unused-modules/file-ignored-a.js' ) } ) ,
871
+ test ( {
872
+ options : [ {
873
+ src : [ testFilePath ( './no-unused-modules/**/*.js' ) ] ,
874
+ ignoreExports : [ testFilePath ( './no-unused-modules/*ignored*.js' ) ] ,
875
+ missingExports : true ,
876
+ } ] ,
877
+ code : 'export const test = true' ,
878
+ filename : testFilePath ( './no-unused-modules/file-ignored-a.js' ) ,
879
+ } ) ,
717
880
] ,
718
881
invalid : [ ] ,
719
882
} ) ;
@@ -722,47 +885,63 @@ describe('do not report missing export for ignored file', () => {
722
885
// lint file not available in `src`
723
886
ruleTester . run ( 'no-unused-modules' , rule , {
724
887
valid : [
725
- test ( { options : unusedExportsOptions ,
888
+ test ( {
889
+ options : unusedExportsOptions ,
726
890
code : `export const jsxFoo = 'foo'; export const jsxBar = 'bar'` ,
727
- filename : testFilePath ( '../jsx/named.jsx' ) } ) ,
891
+ filename : testFilePath ( '../jsx/named.jsx' ) ,
892
+ } ) ,
728
893
] ,
729
894
invalid : [ ] ,
730
895
} ) ;
731
896
732
897
describe ( 'do not report unused export for files mentioned in package.json' , ( ) => {
733
898
ruleTester . run ( 'no-unused-modules' , rule , {
734
899
valid : [
735
- test ( { options : unusedExportsOptions ,
900
+ test ( {
901
+ options : unusedExportsOptions ,
736
902
code : 'export const bin = "bin"' ,
737
- filename : testFilePath ( './no-unused-modules/bin.js' ) } ) ,
738
- test ( { options : unusedExportsOptions ,
903
+ filename : testFilePath ( './no-unused-modules/bin.js' ) ,
904
+ } ) ,
905
+ test ( {
906
+ options : unusedExportsOptions ,
739
907
code : 'export const binObject = "binObject"' ,
740
- filename : testFilePath ( './no-unused-modules/binObject/index.js' ) } ) ,
741
- test ( { options : unusedExportsOptions ,
908
+ filename : testFilePath ( './no-unused-modules/binObject/index.js' ) ,
909
+ } ) ,
910
+ test ( {
911
+ options : unusedExportsOptions ,
742
912
code : 'export const browser = "browser"' ,
743
- filename : testFilePath ( './no-unused-modules/browser.js' ) } ) ,
744
- test ( { options : unusedExportsOptions ,
913
+ filename : testFilePath ( './no-unused-modules/browser.js' ) ,
914
+ } ) ,
915
+ test ( {
916
+ options : unusedExportsOptions ,
745
917
code : 'export const browserObject = "browserObject"' ,
746
- filename : testFilePath ( './no-unused-modules/browserObject/index.js' ) } ) ,
747
- test ( { options : unusedExportsOptions ,
918
+ filename : testFilePath ( './no-unused-modules/browserObject/index.js' ) ,
919
+ } ) ,
920
+ test ( {
921
+ options : unusedExportsOptions ,
748
922
code : 'export const main = "main"' ,
749
- filename : testFilePath ( './no-unused-modules/main/index.js' ) } ) ,
923
+ filename : testFilePath ( './no-unused-modules/main/index.js' ) ,
924
+ } ) ,
750
925
] ,
751
926
invalid : [
752
- test ( { options : unusedExportsOptions ,
927
+ test ( {
928
+ options : unusedExportsOptions ,
753
929
code : 'export const privatePkg = "privatePkg"' ,
754
930
filename : testFilePath ( './no-unused-modules/privatePkg/index.js' ) ,
755
- errors : [ error ( `exported declaration 'privatePkg' not used within other modules` ) ] } ) ,
931
+ errors : [ error ( `exported declaration 'privatePkg' not used within other modules` ) ] ,
932
+ } ) ,
756
933
] ,
757
934
} ) ;
758
935
} ) ;
759
936
760
937
describe ( 'Avoid errors if re-export all from umd compiled library' , ( ) => {
761
938
ruleTester . run ( 'no-unused-modules' , rule , {
762
939
valid : [
763
- test ( { options : unusedExportsOptions ,
940
+ test ( {
941
+ options : unusedExportsOptions ,
764
942
code : `export * from '${ testFilePath ( './no-unused-modules/bin.js' ) } '` ,
765
- filename : testFilePath ( './no-unused-modules/main/index.js' ) } ) ,
943
+ filename : testFilePath ( './no-unused-modules/main/index.js' ) ,
944
+ } ) ,
766
945
] ,
767
946
invalid : [ ] ,
768
947
} ) ;
0 commit comments