File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -356,4 +356,32 @@ run(
356
356
]
357
357
` ,
358
358
} ,
359
+ {
360
+ description : 'With satisfies' ,
361
+ code : $ `
362
+ // @keep-sorted
363
+ const a = {
364
+ foo,
365
+ bar,
366
+ apple
367
+ } satisfies Record<string, any>
368
+ ` ,
369
+ output : $ `
370
+ // @keep-sorted
371
+ const a = {
372
+ apple,
373
+ bar,
374
+ foo,
375
+ } satisfies Record<string, any>
376
+ ` ,
377
+ errors : [ 'command-fix' ] ,
378
+ } ,
379
+ {
380
+ description : 'With satisfies' ,
381
+ code : $ `
382
+ // @keep-sorted
383
+ const a = bar satisfies Record<string, any>
384
+ ` ,
385
+ errors : [ 'command-error' ] ,
386
+ } ,
359
387
)
Original file line number Diff line number Diff line change @@ -22,15 +22,27 @@ export const keepSorted: Command = {
22
22
return ctx . reportError ( `Failed to parse options: ${ optionsRaw } ` )
23
23
}
24
24
25
- const node = ctx . findNodeBelow (
25
+ let node = ctx . findNodeBelow (
26
26
'ObjectExpression' ,
27
27
'ObjectPattern' ,
28
28
'ArrayExpression' ,
29
29
'TSInterfaceBody' ,
30
30
'TSTypeLiteral' ,
31
+ 'TSSatisfiesExpression' ,
31
32
) || ctx . findNodeBelow (
32
33
'ExportNamedDeclaration' ,
33
34
)
35
+
36
+ // Unwrap TSSatisfiesExpression
37
+ if ( node ?. type === 'TSSatisfiesExpression' ) {
38
+ if ( node . expression . type !== 'ArrayExpression' && node . expression . type !== 'ObjectExpression' ) {
39
+ node = undefined
40
+ }
41
+ else {
42
+ node = node . expression
43
+ }
44
+ }
45
+
34
46
if ( ! node )
35
47
return ctx . reportError ( 'Unable to find object/array/interface to sort' )
36
48
You can’t perform that action at this time.
0 commit comments