1
- import { parsers , test as _test , testFilePath } from '../utils' ;
1
+ import { parsers , test as _test , testFilePath , testVersion as _testVersion } from '../utils' ;
2
2
3
3
import { RuleTester } from 'eslint' ;
4
4
import flatMap from 'array.prototype.flatmap' ;
@@ -11,6 +11,9 @@ const error = message => ({ message });
11
11
const test = def => _test ( Object . assign ( def , {
12
12
filename : testFilePath ( './cycles/depth-zero.js' ) ,
13
13
} ) ) ;
14
+ const testVersion = ( specifier , t ) => _testVersion ( specifier , ( ) => Object . assign ( t ( ) , {
15
+ filename : testFilePath ( './cycles/depth-zero.js' ) ,
16
+ } ) ) ;
14
17
15
18
const testDialects = [ 'es6' ] ;
16
19
@@ -73,7 +76,28 @@ ruleTester.run('no-cycle', rule, {
73
76
code : `import type { FooType, BarType } from "./${ testDialect } /depth-one"` ,
74
77
parser : parsers . BABEL_OLD ,
75
78
} ) ,
76
- ] ) ,
79
+ test ( {
80
+ code : `function bar(){ return import("./${ testDialect } /depth-one"); } // #2265 1` ,
81
+ options : [ { allowUnsafeDynamicCyclicDependency : true } ] ,
82
+ parser : parsers . BABEL_OLD ,
83
+ } ) ,
84
+ test ( {
85
+ code : `import { foo } from "./${ testDialect } /depth-one-dynamic"; // #2265 2` ,
86
+ options : [ { allowUnsafeDynamicCyclicDependency : true } ] ,
87
+ parser : parsers . BABEL_OLD ,
88
+ } ) ,
89
+ ] . concat ( parsers . TS_NEW ? [
90
+ test ( {
91
+ code : `function bar(){ return import("./${ testDialect } /depth-one"); } // #2265 3` ,
92
+ options : [ { allowUnsafeDynamicCyclicDependency : true } ] ,
93
+ parser : parsers . TS_NEW ,
94
+ } ) ,
95
+ test ( {
96
+ code : `import { foo } from "./${ testDialect } /depth-one-dynamic"; // #2265 4` ,
97
+ options : [ { allowUnsafeDynamicCyclicDependency : true } ] ,
98
+ parser : parsers . TS_NEW ,
99
+ } ) ,
100
+ ] : [ ] ) ) ,
77
101
78
102
test ( {
79
103
code : 'import { bar } from "./flow-types"' ,
@@ -112,62 +136,83 @@ ruleTester.run('no-cycle', rule, {
112
136
} ,
113
137
} ) ,
114
138
115
- flatMap ( testDialects , ( testDialect ) => [
139
+ // Ensure behavior does not change for those tests, with or without `
140
+ flatMap ( testDialects , ( testDialect ) => flatMap ( [
141
+ { } ,
142
+ { allowUnsafeDynamicCyclicDependency : true } ,
143
+ ] , ( opts ) => [
116
144
test ( {
117
145
code : `import { foo } from "./${ testDialect } /depth-one"` ,
146
+ options : [ { ...opts } ] ,
118
147
errors : [ error ( `Dependency cycle detected.` ) ] ,
119
148
} ) ,
120
149
test ( {
121
150
code : `import { foo } from "./${ testDialect } /depth-one"` ,
122
- options : [ { maxDepth : 1 } ] ,
151
+ options : [ { ... opts , maxDepth : 1 } ] ,
123
152
errors : [ error ( `Dependency cycle detected.` ) ] ,
124
153
} ) ,
125
154
test ( {
126
155
code : `const { foo } = require("./${ testDialect } /depth-one")` ,
127
156
errors : [ error ( `Dependency cycle detected.` ) ] ,
128
- options : [ { commonjs : true } ] ,
157
+ options : [ { ... opts , commonjs : true } ] ,
129
158
} ) ,
130
159
test ( {
131
160
code : `require(["./${ testDialect } /depth-one"], d1 => {})` ,
132
161
errors : [ error ( `Dependency cycle detected.` ) ] ,
133
- options : [ { amd : true } ] ,
162
+ options : [ { ... opts , amd : true } ] ,
134
163
} ) ,
135
164
test ( {
136
165
code : `define(["./${ testDialect } /depth-one"], d1 => {})` ,
137
166
errors : [ error ( `Dependency cycle detected.` ) ] ,
138
- options : [ { amd : true } ] ,
167
+ options : [ { ... opts , amd : true } ] ,
139
168
} ) ,
140
169
test ( {
141
170
code : `import { foo } from "./${ testDialect } /depth-two"` ,
171
+ options : [ { ...opts } ] ,
142
172
errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
143
173
} ) ,
144
174
test ( {
145
175
code : `import { foo } from "./${ testDialect } /depth-two"` ,
146
- options : [ { maxDepth : 2 } ] ,
176
+ options : [ { ... opts , maxDepth : 2 } ] ,
147
177
errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
148
178
} ) ,
149
179
test ( {
150
180
code : `const { foo } = require("./${ testDialect } /depth-two")` ,
151
181
errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
152
- options : [ { commonjs : true } ] ,
182
+ options : [ { ... opts , commonjs : true } ] ,
153
183
} ) ,
154
184
test ( {
155
185
code : `import { two } from "./${ testDialect } /depth-three-star"` ,
186
+ options : [ { ...opts } ] ,
156
187
errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
157
188
} ) ,
158
189
test ( {
159
190
code : `import one, { two, three } from "./${ testDialect } /depth-three-star"` ,
191
+ options : [ { ...opts } ] ,
160
192
errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
161
193
} ) ,
162
194
test ( {
163
195
code : `import { bar } from "./${ testDialect } /depth-three-indirect"` ,
196
+ options : [ { ...opts } ] ,
164
197
errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
165
198
} ) ,
166
199
test ( {
167
200
code : `import { bar } from "./${ testDialect } /depth-three-indirect"` ,
201
+ options : [ { ...opts } ] ,
168
202
errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
169
203
parser : parsers . BABEL_OLD ,
170
204
} ) ,
205
+ test ( {
206
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
207
+ options : [ { ...opts , maxDepth : Infinity } ] ,
208
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
209
+ } ) ,
210
+ test ( {
211
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
212
+ options : [ { ...opts , maxDepth : '∞' } ] ,
213
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
214
+ } ) ,
215
+ ] ) . concat ( [
171
216
test ( {
172
217
code : `import("./${ testDialect } /depth-three-star")` ,
173
218
errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
@@ -188,7 +233,29 @@ ruleTester.run('no-cycle', rule, {
188
233
options : [ { maxDepth : '∞' } ] ,
189
234
errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
190
235
} ) ,
191
- ] ) ,
236
+ test ( {
237
+ code : `function bar(){ return import("./${ testDialect } /depth-one"); } // #2265 5` ,
238
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
239
+ parser : parsers . BABEL_OLD ,
240
+ } ) ,
241
+ ] ) . concat (
242
+ testVersion ( '> 3' , ( ) => ( { // Dynamic import is not properly caracterized with eslint < 4
243
+ code : `import { foo } from "./${ testDialect } /depth-one-dynamic"; // #2265 6` ,
244
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
245
+ parser : parsers . BABEL_OLD ,
246
+ } ) ) ,
247
+ ) . concat ( parsers . TS_NEW ? [
248
+ test ( {
249
+ code : `function bar(){ return import("./${ testDialect } /depth-one"); } // #2265 7` ,
250
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
251
+ parser : parsers . TS_NEW ,
252
+ } ) ,
253
+ test ( {
254
+ code : `import { foo } from "./${ testDialect } /depth-one-dynamic"; // #2265 8` ,
255
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
256
+ parser : parsers . TS_NEW ,
257
+ } ) ,
258
+ ] : [ ] ) ) ,
192
259
193
260
test ( {
194
261
code : 'import { bar } from "./flow-types-depth-one"' ,
0 commit comments