@@ -2243,6 +2243,50 @@ context('TypeScript', function () {
2243
2243
// #1667: typescript type import support
2244
2244
2245
2245
// Option alphabetize: {order: 'asc'}
2246
+ test (
2247
+ {
2248
+ code : `
2249
+ import c from 'Bar';
2250
+ import type { C } from 'Bar';
2251
+ import b from 'bar';
2252
+ import a from 'foo';
2253
+ import type { A } from 'foo';
2254
+
2255
+ import index from './';
2256
+ ` ,
2257
+ parser,
2258
+ options : [
2259
+ {
2260
+ groups : [ 'external' , 'index' ] ,
2261
+ alphabetize : { order : 'asc' } ,
2262
+ } ,
2263
+ ] ,
2264
+ } ,
2265
+ parserConfig ,
2266
+ ) ,
2267
+ // Option alphabetize: {order: 'desc'}
2268
+ test (
2269
+ {
2270
+ code : `
2271
+ import a from 'foo';
2272
+ import type { A } from 'foo';
2273
+ import b from 'bar';
2274
+ import c from 'Bar';
2275
+ import type { C } from 'Bar';
2276
+
2277
+ import index from './';
2278
+ ` ,
2279
+ parser,
2280
+ options : [
2281
+ {
2282
+ groups : [ 'external' , 'index' ] ,
2283
+ alphabetize : { order : 'desc' } ,
2284
+ } ,
2285
+ ] ,
2286
+ } ,
2287
+ parserConfig ,
2288
+ ) ,
2289
+ // Option alphabetize: {order: 'asc'} with type group
2246
2290
test (
2247
2291
{
2248
2292
code : `
@@ -2258,14 +2302,14 @@ context('TypeScript', function () {
2258
2302
parser,
2259
2303
options : [
2260
2304
{
2261
- groups : [ 'external' , 'index' ] ,
2305
+ groups : [ 'external' , 'index' , 'type' ] ,
2262
2306
alphabetize : { order : 'asc' } ,
2263
2307
} ,
2264
2308
] ,
2265
2309
} ,
2266
2310
parserConfig ,
2267
2311
) ,
2268
- // Option alphabetize: {order: 'desc'}
2312
+ // Option alphabetize: {order: 'desc'} with type group
2269
2313
test (
2270
2314
{
2271
2315
code : `
@@ -2281,7 +2325,7 @@ context('TypeScript', function () {
2281
2325
parser,
2282
2326
options : [
2283
2327
{
2284
- groups : [ 'external' , 'index' ] ,
2328
+ groups : [ 'external' , 'index' , 'type' ] ,
2285
2329
alphabetize : { order : 'desc' } ,
2286
2330
} ,
2287
2331
] ,
@@ -2303,35 +2347,130 @@ context('TypeScript', function () {
2303
2347
} ,
2304
2348
parserConfig ,
2305
2349
) ,
2350
+ test (
2351
+ {
2352
+ code : `
2353
+ import { serialize, parse, mapFieldErrors } from '@vtaits/form-schema';
2354
+ import type { GetFieldSchema } from '@vtaits/form-schema';
2355
+ import { useMemo, useCallback } from 'react';
2356
+ import type { ReactElement, ReactNode } from 'react';
2357
+ import { Form } from 'react-final-form';
2358
+ import type { FormProps as FinalFormProps } from 'react-final-form';
2359
+ ` ,
2360
+ parser,
2361
+ options : [
2362
+ {
2363
+ alphabetize : { order : 'asc' } ,
2364
+ } ,
2365
+ ] ,
2366
+ } ,
2367
+ parserConfig ,
2368
+ ) ,
2306
2369
] ,
2307
2370
invalid : [
2308
2371
// Option alphabetize: {order: 'asc'}
2309
2372
test (
2310
2373
{
2311
2374
code : `
2312
- import b from 'bar';
2313
- import c from 'Bar';
2314
- import a from 'foo ';
2315
-
2316
- import index from './ ';
2375
+ import b from 'bar';
2376
+ import c from 'Bar';
2377
+ import type { C } from 'Bar ';
2378
+ import a from 'foo';
2379
+ import type { A } from 'foo ';
2317
2380
2318
- import type { A } from 'foo';
2319
- import type { C } from 'Bar';
2320
- ` ,
2381
+ import index from './';
2382
+ ` ,
2321
2383
output : `
2322
- import c from 'Bar';
2323
- import b from 'bar';
2324
- import a from 'foo';
2384
+ import c from 'Bar';
2385
+ import type { C } from 'Bar';
2386
+ import b from 'bar';
2387
+ import a from 'foo';
2388
+ import type { A } from 'foo';
2325
2389
2326
- import index from './';
2390
+ import index from './';
2391
+ ` ,
2392
+ parser,
2393
+ options : [
2394
+ {
2395
+ groups : [ 'external' , 'index' ] ,
2396
+ alphabetize : { order : 'asc' } ,
2397
+ } ,
2398
+ ] ,
2399
+ errors : [
2400
+ {
2401
+ message : semver . satisfies ( eslintPkg . version , '< 3' )
2402
+ ? '`bar` import should occur after import of `Bar`'
2403
+ : / ( ` b a r ` i m p o r t s h o u l d o c c u r a f t e r i m p o r t o f ` B a r ` ) | ( ` B a r ` i m p o r t s h o u l d o c c u r b e f o r e i m p o r t o f ` b a r ` ) / ,
2404
+ } ,
2405
+ ] ,
2406
+ } ,
2407
+ parserConfig ,
2408
+ ) ,
2409
+ // Option alphabetize: {order: 'desc'}
2410
+ test (
2411
+ {
2412
+ code : `
2413
+ import a from 'foo';
2414
+ import type { A } from 'foo';
2415
+ import c from 'Bar';
2416
+ import type { C } from 'Bar';
2417
+ import b from 'bar';
2327
2418
2328
- import type { C } from 'Bar';
2329
- import type { A } from 'foo';
2330
- ` ,
2419
+ import index from './';
2420
+ ` ,
2421
+ output : `
2422
+ import a from 'foo';
2423
+ import type { A } from 'foo';
2424
+ import b from 'bar';
2425
+ import c from 'Bar';
2426
+ import type { C } from 'Bar';
2427
+
2428
+ import index from './';
2429
+ ` ,
2331
2430
parser,
2332
2431
options : [
2333
2432
{
2334
2433
groups : [ 'external' , 'index' ] ,
2434
+ alphabetize : { order : 'desc' } ,
2435
+ } ,
2436
+ ] ,
2437
+ errors : [
2438
+ {
2439
+ message : semver . satisfies ( eslintPkg . version , '< 3' )
2440
+ ? '`bar` import should occur before import of `Bar`'
2441
+ : / ( ` b a r ` i m p o r t s h o u l d o c c u r b e f o r e i m p o r t o f ` B a r ` ) | ( ` B a r ` i m p o r t s h o u l d o c c u r a f t e r i m p o r t o f ` b a r ` ) / ,
2442
+ } ,
2443
+ ] ,
2444
+ } ,
2445
+ parserConfig ,
2446
+ ) ,
2447
+ // Option alphabetize: {order: 'asc'} with type group
2448
+ test (
2449
+ {
2450
+ code : `
2451
+ import b from 'bar';
2452
+ import c from 'Bar';
2453
+ import a from 'foo';
2454
+
2455
+ import index from './';
2456
+
2457
+ import type { A } from 'foo';
2458
+ import type { C } from 'Bar';
2459
+ ` ,
2460
+ output : `
2461
+ import c from 'Bar';
2462
+ import b from 'bar';
2463
+ import a from 'foo';
2464
+
2465
+ import index from './';
2466
+
2467
+ import type { C } from 'Bar';
2468
+ import type { A } from 'foo';
2469
+ ` ,
2470
+ parser,
2471
+ options : [
2472
+ {
2473
+ groups : [ 'external' , 'index' , 'type' ] ,
2335
2474
alphabetize : { order : 'asc' } ,
2336
2475
} ,
2337
2476
] ,
@@ -2345,33 +2484,33 @@ context('TypeScript', function () {
2345
2484
} ,
2346
2485
parserConfig ,
2347
2486
) ,
2348
- // Option alphabetize: {order: 'desc'}
2487
+ // Option alphabetize: {order: 'desc'} with type group
2349
2488
test (
2350
2489
{
2351
2490
code : `
2352
- import a from 'foo';
2353
- import c from 'Bar';
2354
- import b from 'bar';
2491
+ import a from 'foo';
2492
+ import c from 'Bar';
2493
+ import b from 'bar';
2355
2494
2356
- import index from './';
2495
+ import index from './';
2357
2496
2358
- import type { C } from 'Bar';
2359
- import type { A } from 'foo';
2360
- ` ,
2497
+ import type { C } from 'Bar';
2498
+ import type { A } from 'foo';
2499
+ ` ,
2361
2500
output : `
2362
- import a from 'foo';
2363
- import b from 'bar';
2364
- import c from 'Bar';
2501
+ import a from 'foo';
2502
+ import b from 'bar';
2503
+ import c from 'Bar';
2365
2504
2366
- import index from './';
2505
+ import index from './';
2367
2506
2368
- import type { A } from 'foo';
2369
- import type { C } from 'Bar';
2370
- ` ,
2507
+ import type { A } from 'foo';
2508
+ import type { C } from 'Bar';
2509
+ ` ,
2371
2510
parser,
2372
2511
options : [
2373
2512
{
2374
- groups : [ 'external' , 'index' ] ,
2513
+ groups : [ 'external' , 'index' , 'type' ] ,
2375
2514
alphabetize : { order : 'desc' } ,
2376
2515
} ,
2377
2516
] ,
0 commit comments