You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -288,36 +288,13 @@ Specifies the directory of the root `tsconfig.json` file (ex: `.`). This is use
288
288
'internal',
289
289
['parent-type', 'sibling-type', 'index-type'],
290
290
['parent', 'sibling', 'index'],
291
-
'object',
292
291
'unknown',
293
292
]
294
293
```
295
294
</sub>
296
295
297
296
Specifies a list of import groups for sorting. Groups help organize imports into meaningful categories, making your code more readable and maintainable.
298
297
299
-
Predefined groups:
300
-
301
-
-`'builtin'` — Node.js Built-in Modules.
302
-
-`'external'` — External modules installed in the project.
303
-
-`'internal'` — Your internal modules.
304
-
-`'parent'` — Modules from the parent directory.
305
-
-`'sibling'` — Modules from the same directory.
306
-
-`'side-effect'` — Side effect imports.
307
-
-`'side-effect-style'` — Side effect style imports.
308
-
-`'index'` — Main file from the current directory.
309
-
-`'object'` — TypeScript object imports.
310
-
-`'style'` — Styles.
311
-
-`'external-type'` — TypeScript type imports from external modules.
312
-
-`'builtin-type'` — TypeScript type imports from built-in modules.
313
-
-`'internal-type'` — TypeScript type imports from your internal modules.
314
-
-`'parent-type'` — TypeScript type imports from the parent directory.
315
-
-`'sibling-type'` — TypeScript type imports from the same directory.
316
-
-`'index-type'` — TypeScript type imports from the main directory file.
317
-
-`'unknown'` — Imports that don’t fit into any group specified in the `groups` option.
318
-
319
-
If the `unknown` group is not specified in the `groups` option, it will automatically be added to the end of the list.
320
-
321
298
Each import will be assigned a single group specified in the `groups` option (or the `unknown` group if no match is found).
322
299
The order of items in the `groups` option determines how groups are ordered.
323
300
@@ -326,7 +303,54 @@ Within a given group, members will be sorted according to the `type`, `order`, `
326
303
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
327
304
All members of the groups in the array will be sorted together as if they were part of a single group.
328
305
329
-
#### Example
306
+
Predefined groups are characterized by a single selector and potentially multiple modifiers. You may enter modifiers in any order, but the selector must always come at the end.
307
+
308
+
#### Selectors
309
+
310
+
The list of selectors is sorted from most to least important:
311
+
312
+
-`'type'` — TypeScript type imports.
313
+
-`'side-effect-style'` — Side effect style imports.
314
+
-`'side-effect'` — Side effect imports.
315
+
-`'style'` — Styles.
316
+
-`'index'` — Main file from the current directory.
317
+
-`'sibling'` — Modules from the same directory.
318
+
-`'parent'` — Modules from the parent directory.
319
+
-`'internal'` — Your internal modules.
320
+
-`'builtin'` — Node.js Built-in Modules.
321
+
-`'external'` — External modules installed in the project.
322
+
323
+
#### Modifiers
324
+
325
+
-`'type'` — Typescript time imports.
326
+
327
+
#### Important notes
328
+
329
+
##### The `unknown` group
330
+
331
+
Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
332
+
the members will remain in their original order.
333
+
334
+
##### Behavior when multiple groups match an element
335
+
336
+
The lists of selectors and modifiers above are both sorted by importance, from most to least important.
337
+
In case of multiple groups matching an element, the following rules will be applied:
338
+
339
+
1. Selector priority: `type`, `index`, ... will take precedence over `external` groups for example.
340
+
2. If the selector is the same, the group with the most modifiers matching will be selected.
341
+
342
+
Example 1:
343
+
344
+
```ts
345
+
importtype { FC } from'react'
346
+
```
347
+
348
+
`react` can be matched by the following groups, from most to least important:
349
+
-`type` (`type` selector).
350
+
-`type-external` (`type` modifier).
351
+
-`external`.
352
+
353
+
Example 2 (The most important group is written in the comments):
An import will match a `CustomGroupAnyOfDefinition` group if it matches all the filters of at least one of the `anyOf` items.
494
+
495
+
#### Attributes
496
+
497
+
-`groupName` — The group's name, which needs to be put in the [`groups`](#groups) option.
498
+
-`selector` — Filter on the `selector` of the element.
499
+
-`modifiers` — Filter on the `modifiers` of the element. (All the modifiers of the element must be present in that list)
500
+
-`elementNamePattern` — If entered, will check that the name of the element matches the pattern entered.
501
+
-`type` — Overrides the [`type`](#type) option for that custom group. `unsorted` will not sort the group.
502
+
-`order` — Overrides the [`order`](#order) option for that custom group.
503
+
-`fallbackSort` — Overrides the [`fallbackSort`](#fallbacksort) option for that custom group.
504
+
-`newlinesInside` — Enforces a specific newline behavior between elements of the group.
397
505
398
-
Defines custom groups to match specific imports.
506
+
#### Match importance
399
507
400
-
Each key of the `value` or `type` fields represents a group name which you can then use in the `groups` option. The value for each key can either be of type:
401
-
-`string` — An import matching the value will be marked as part of the group referenced by the key.
402
-
-`string[]` — An import matching any of the values of the array will be marked as part of the group referenced by the key.
403
-
The order of values in the array does not matter.
508
+
The `customGroups` list is ordered:
509
+
The first custom group definition that matches an element will be used.
404
510
405
-
Custom group matching takes precedence over predefined group matching.
511
+
Custom groups have a higher priority than any predefined group. If you want a predefined group to take precedence over a custom group,
512
+
you must write a custom group definition that does the same as what the predefined group does (using `selector` and `modifiers` filters), and put it first in the list.
406
513
407
514
#### Example
408
515
@@ -416,18 +523,18 @@ Custom group matching takes precedence over predefined group matching.
0 commit comments