@@ -330,6 +330,22 @@ ruleTester.run('extensions', rule, {
330
330
options : [ 'never' , { ignorePackages : true } ] ,
331
331
} ) ,
332
332
333
+ test ( {
334
+ code : `
335
+ import foo from './foo.js'
336
+ import bar from './bar.json'
337
+ import Component from './Component.jsx'
338
+ ` ,
339
+ errors : [
340
+ {
341
+ message : 'Unexpected use of file extension "jsx" for "./Component.jsx"' ,
342
+ line : 4 ,
343
+ column : 31 ,
344
+ } ,
345
+ ] ,
346
+ options : [ 'always' , { pattern : { jsx : 'never' } } ] ,
347
+ } ) ,
348
+
333
349
// export (#964)
334
350
test ( {
335
351
code : [
@@ -359,5 +375,95 @@ ruleTester.run('extensions', rule, {
359
375
} ,
360
376
] ,
361
377
} ) ,
378
+
379
+ // require (#1230)
380
+ test ( {
381
+ code : [
382
+ 'const { foo } = require("./foo")' ,
383
+ 'export { bar }' ,
384
+ ] . join ( '\n' ) ,
385
+ options : [ 'always' ] ,
386
+ errors : [
387
+ {
388
+ message : 'Missing file extension for "./foo"' ,
389
+ line : 1 ,
390
+ column : 25 ,
391
+ } ,
392
+ ] ,
393
+ } ) ,
394
+ test ( {
395
+ code : [
396
+ 'const { foo } = require("./foo.js")' ,
397
+ 'export { bar }' ,
398
+ ] . join ( '\n' ) ,
399
+ options : [ 'never' ] ,
400
+ errors : [
401
+ {
402
+ message : 'Unexpected use of file extension "js" for "./foo.js"' ,
403
+ line : 1 ,
404
+ column : 25 ,
405
+ } ,
406
+ ] ,
407
+ } ) ,
408
+
409
+ // export { } from
410
+ test ( {
411
+ code : [
412
+ 'export { foo } from "./foo"' ,
413
+ 'export { bar }' ,
414
+ ] . join ( '\n' ) ,
415
+ options : [ 'always' ] ,
416
+ errors : [
417
+ {
418
+ message : 'Missing file extension for "./foo"' ,
419
+ line : 1 ,
420
+ column : 21 ,
421
+ } ,
422
+ ] ,
423
+ } ) ,
424
+ test ( {
425
+ code : [
426
+ 'export { foo } from "./foo.js"' ,
427
+ 'export { bar }' ,
428
+ ] . join ( '\n' ) ,
429
+ options : [ 'never' ] ,
430
+ errors : [
431
+ {
432
+ message : 'Unexpected use of file extension "js" for "./foo.js"' ,
433
+ line : 1 ,
434
+ column : 21 ,
435
+ } ,
436
+ ] ,
437
+ } ) ,
438
+
439
+ // export * from
440
+ test ( {
441
+ code : [
442
+ 'export * from "./foo"' ,
443
+ 'export { bar }' ,
444
+ ] . join ( '\n' ) ,
445
+ options : [ 'always' ] ,
446
+ errors : [
447
+ {
448
+ message : 'Missing file extension for "./foo"' ,
449
+ line : 1 ,
450
+ column : 15 ,
451
+ } ,
452
+ ] ,
453
+ } ) ,
454
+ test ( {
455
+ code : [
456
+ 'export * from "./foo.js"' ,
457
+ 'export { bar }' ,
458
+ ] . join ( '\n' ) ,
459
+ options : [ 'never' ] ,
460
+ errors : [
461
+ {
462
+ message : 'Unexpected use of file extension "js" for "./foo.js"' ,
463
+ line : 1 ,
464
+ column : 15 ,
465
+ } ,
466
+ ] ,
467
+ } ) ,
362
468
] ,
363
469
} )
0 commit comments