@@ -225,5 +225,104 @@ describe('order', () => {
225
225
] ,
226
226
invalid : [ ] ,
227
227
} )
228
+
229
+ ruleTester . run ( 'starts a new grouping context after non-import nodes' , orderRule , {
230
+ valid : [
231
+ {
232
+ name : 'without errors' ,
233
+ code : dedent `
234
+ import { b1, b2 } from 'b'
235
+ import d from 'd'
236
+
237
+ export { e } from 'e'
238
+
239
+ import { a } from 'a'
240
+ import { c } from 'c'
241
+ ` ,
242
+ } ,
243
+ ] ,
244
+ invalid : [
245
+ {
246
+ name : 'sorts import blocks separately' ,
247
+ code : dedent `
248
+ import d from 'd'
249
+ import { b1, b2 } from 'b'
250
+
251
+ export { e } from 'e'
252
+
253
+ import { c } from 'c'
254
+ import { a } from 'a'
255
+ ` ,
256
+ output : dedent `
257
+ import { b1, b2 } from 'b'
258
+ import d from 'd'
259
+
260
+ export { e } from 'e'
261
+
262
+ import { a } from 'a'
263
+ import { c } from 'c'
264
+ ` ,
265
+ errors : [ { messageId : 'out-of-order' } , { messageId : 'out-of-order' } ] ,
266
+ } ,
267
+ ] ,
268
+ } )
269
+
270
+ ruleTester . run ( 'ignores comments when counting lines between imports' , orderRule , {
271
+ valid : [
272
+ {
273
+ name : 'without errors' ,
274
+ code : dedent `
275
+ import { a } from 'a'
276
+ // @ts-expect-error missing types
277
+ import { c } from 'c'
278
+ ` ,
279
+ } ,
280
+ ] ,
281
+ invalid : [
282
+ {
283
+ name : 'preserves block comments' ,
284
+ code : dedent `
285
+ import fs from 'node:fs'
286
+
287
+ import { b } from 'b'
288
+ /* Comment */
289
+ import { c } from '~/c'
290
+ import { a } from 'a'
291
+ ` ,
292
+ output : dedent `
293
+ import fs from 'node:fs'
294
+
295
+ import { a } from 'a'
296
+ import { b } from 'b'
297
+
298
+ /* Comment */
299
+ import { c } from '~/c'
300
+ ` ,
301
+ errors : [ { messageId : 'needs-newline' } , { messageId : 'out-of-order' } ] ,
302
+ } ,
303
+
304
+ {
305
+ name : 'preserves line comments' ,
306
+ code : dedent `
307
+ import fs from 'node:fs'
308
+
309
+ import { b } from 'b'
310
+ // Comment
311
+ import { c } from '~/c'
312
+ import { a } from 'a'
313
+ ` ,
314
+ output : dedent `
315
+ import fs from 'node:fs'
316
+
317
+ import { a } from 'a'
318
+ import { b } from 'b'
319
+
320
+ // Comment
321
+ import { c } from '~/c'
322
+ ` ,
323
+ errors : [ { messageId : 'needs-newline' } , { messageId : 'out-of-order' } ] ,
324
+ } ,
325
+ ] ,
326
+ } )
228
327
} )
229
328
} )
0 commit comments