@@ -33,6 +33,14 @@ ruleTester.run('named', rule, {
33
33
'// eslint-disable-line named' } ) ,
34
34
35
35
test ( { code : 'import { foo, bar } from "./re-export-names"' } ) ,
36
+ test ( {
37
+ code : 'import { foo, bar } from "./re-export-names-es5"' ,
38
+ options : [ { commonjs : { exports : true } } ] ,
39
+ } ) ,
40
+ test ( {
41
+ code : 'import { foo, bar } from "./re-export-names-es5"' ,
42
+ options : [ { commonjs : true } ] ,
43
+ } ) ,
36
44
37
45
test ( { code : 'import { foo, bar } from "./common"'
38
46
, settings : { 'import/ignore' : [ 'common' ] } } ) ,
@@ -65,6 +73,11 @@ ruleTester.run('named', rule, {
65
73
test ( { code : 'import { destructuredProp } from "./named-exports"' } ) ,
66
74
test ( { code : 'import { arrayKeyProp } from "./named-exports"' } ) ,
67
75
test ( { code : 'import { deepProp } from "./named-exports"' } ) ,
76
+ test ( { code : 'import { deepProp, deepSparseElement } from "./named-exports-es5"' } ) ,
77
+ test ( {
78
+ code : 'import { deepProp, deepSparseElement } from "./named-exports-es5"' ,
79
+ options : [ { commonjs : { exports : true } } ] ,
80
+ } ) ,
68
81
test ( { code : 'import { deepSparseElement } from "./named-exports"' } ) ,
69
82
70
83
// should ignore imported flow types, even if they don’t exist
@@ -154,6 +167,10 @@ ruleTester.run('named', rule, {
154
167
test ( {
155
168
code : '/*jsnext*/ import { createStore } from "redux"' ,
156
169
} ) ,
170
+ test ( {
171
+ code : 'import { createStore } from "redux/lib/index"' ,
172
+ options : [ { commonjs : true } ] ,
173
+ } ) ,
157
174
158
175
// ignore is ignored if exports are found
159
176
test ( { code : 'import { foo } from "es6-module"' } ) ,
@@ -178,6 +195,17 @@ ruleTester.run('named', rule, {
178
195
code : 'import { common } from "./re-export-default"' ,
179
196
} ) ,
180
197
198
+ // direct module exports cases
199
+ test ( {
200
+ code : 'import { a, c } from "./module-exports-direct"' ,
201
+ options : [ { commonjs : true } ] ,
202
+ } ) ,
203
+
204
+ test ( {
205
+ code : 'import { default as n } from "./module-exports-number"' ,
206
+ options : [ { commonjs : true } ] ,
207
+ } ) ,
208
+
181
209
...SYNTAX_CASES ,
182
210
] ,
183
211
@@ -207,10 +235,16 @@ ruleTester.run('named', rule, {
207
235
208
236
test ( {
209
237
code : 'import { a } from "./re-export-names"' ,
210
- options : [ 2 , 'es6-only' ] ,
238
+ options : [ { commonjs : true } ] ,
211
239
errors : [ error ( 'a' , './re-export-names' ) ] ,
212
240
} ) ,
213
241
242
+ test ( {
243
+ code : 'import { a } from "./re-export-names-es5"' ,
244
+ options : [ { commonjs : true } ] ,
245
+ errors : [ error ( 'a' , './re-export-names-es5' ) ] ,
246
+ } ) ,
247
+
214
248
// export tests
215
249
test ( {
216
250
code : 'export { bar } from "./bar"' ,
@@ -282,11 +316,23 @@ ruleTester.run('named', rule, {
282
316
settings : { 'import/ignore' : [ ] } ,
283
317
errors : [ "createSnorlax not found in 'redux'" ] ,
284
318
} ) ,
319
+ test ( {
320
+ code : 'import { createSnorlax } from "redux/lib/index"' ,
321
+ settings : { 'import/ignore' : [ ] } ,
322
+ options : [ { commonjs : true } ] ,
323
+ errors : [ "createSnorlax not found in 'redux/lib/index'" ] ,
324
+ } ) ,
285
325
// should work without ignore
286
326
test ( {
287
327
code : '/*jsnext*/ import { createSnorlax } from "redux"' ,
288
328
errors : [ "createSnorlax not found in 'redux'" ] ,
289
329
} ) ,
330
+ test ( {
331
+ code : 'import { createSnorlax } from "redux/lib/index"' ,
332
+ options : [ { commonjs : { exports : true } } ] ,
333
+ errors : [ "createSnorlax not found in 'redux/lib/index'" ] ,
334
+ } ) ,
335
+
290
336
291
337
// ignore is ignored if exports are found
292
338
test ( {
@@ -306,6 +352,19 @@ ruleTester.run('named', rule, {
306
352
code : 'import { default as barDefault } from "./re-export"' ,
307
353
errors : [ `default not found in './re-export'` ] ,
308
354
} ) ,
355
+
356
+ // direct module.exports assignment
357
+ test ( {
358
+ code : 'import { b } from "./module-exports-direct"' ,
359
+ options : [ { commonjs : true } ] ,
360
+ errors : [ error ( 'b' , './module-exports-direct' ) ] ,
361
+ } ) ,
362
+
363
+ test ( {
364
+ code : 'import { noExports } from "./module-exports-number"' ,
365
+ options : [ { commonjs : true } ] ,
366
+ errors : [ error ( 'noExports' , './module-exports-number' ) ] ,
367
+ } ) ,
309
368
] ,
310
369
} )
311
370
0 commit comments