@@ -177,10 +177,12 @@ Specifies the sorting locales. See [String.prototype.localeCompare() - locales](
177
177
- ` string ` — A BCP 47 language tag (e.g. ` 'en' ` , ` 'en-US' ` , ` 'zh-CN' ` ).
178
178
- ` string[] ` — An array of BCP 47 language tags.
179
179
180
- ### groupKind
180
+ ### [ DEPRECATED ] groupKind
181
181
182
182
<sub >default: ` 'literals-first' ` </sub >
183
183
184
+ Use the [ groups] ( #groups ) option with the ` literal ` and ` spread ` selectors instead. Make sure to set this option to ` mixed ` .
185
+
184
186
Allows you to group array elements by their kind, determining whether spread values should come before or after literal values.
185
187
186
188
- ` mixed ` — Do not group array elements by their kind; spread values are sorted together with literal values.
@@ -228,6 +230,129 @@ if ([
228
230
229
231
Each group of elements (separated by empty lines) is treated independently, and the order within each group is preserved.
230
232
233
+ ### useConfigurationIf
234
+
235
+ <sub >
236
+ type: ` { allNamesMatchPattern?: string } `
237
+ </sub >
238
+ <sub >default: ` {} ` </sub >
239
+
240
+ Allows you to specify filters to match a particular options configuration for a given object.
241
+
242
+ The first matching options configuration will be used. If no configuration matches, the default options configuration will be used.
243
+
244
+ - ` allNamesMatchPattern ` — A regexp pattern that all object keys must match.
245
+
246
+ Example configuration:
247
+ ``` ts
248
+ {
249
+ ' perfectionist/sort-array-includes' : [
250
+ ' error' ,
251
+ {
252
+ groups: [' r' , ' g' , ' b' ], // Sort colors by RGB
253
+ customGroups: [
254
+ {
255
+ elementNamePattern: ' ^r$' ,
256
+ groupName: ' r' ,
257
+ },
258
+ {
259
+ elementNamePattern: ' ^g$' ,
260
+ groupName: ' g' ,
261
+ },
262
+ {
263
+ elementNamePattern: ' ^b$' ,
264
+ groupName: ' b' ,
265
+ },
266
+ ],
267
+ useConfigurationIf: {
268
+ allNamesMatchPattern: ' ^r|g|b$' ,
269
+ },
270
+ },
271
+ {
272
+ type: ' alphabetical' // Fallback configuration
273
+ }
274
+ ],
275
+ }
276
+ ```
277
+
278
+ ### groups
279
+
280
+ <sub >
281
+ type: ` Array<string | string[]> `
282
+ </sub >
283
+ <sub >default: ` [] ` </sub >
284
+
285
+ Allows you to specify a list of groups for sorting. Groups help organize elements into categories.
286
+
287
+ Each element will be assigned a single group specified in the ` groups ` option (or the ` unknown ` group if no match is found).
288
+ The order of items in the ` groups ` option determines how groups are ordered.
289
+
290
+ Within a given group, members will be sorted according to the ` type ` , ` order ` , ` ignoreCase ` , etc. options.
291
+
292
+ Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
293
+ All members of the groups in the array will be sorted together as if they were part of a single group.
294
+
295
+ Predefined groups are characterized by a selector.
296
+
297
+ ##### List of selectors
298
+
299
+ - ` literal ` : Array elements that are not spread values.
300
+ - ` spread ` : Array elements that are spread values.
301
+
302
+ ### customGroups
303
+
304
+ <sub >
305
+ type: ` Array<CustomGroupDefinition | CustomGroupAnyOfDefinition> `
306
+ </sub >
307
+ <sub >default: ` {} ` </sub >
308
+
309
+ You can define your own groups and use regexp pattern to match specific object type members.
310
+
311
+ A custom group definition may follow one of the two following interfaces:
312
+
313
+ ``` ts
314
+ interface CustomGroupDefinition {
315
+ groupName: string
316
+ type? : ' alphabetical' | ' natural' | ' line-length' | ' unsorted'
317
+ order? : ' asc' | ' desc'
318
+ selector? : string
319
+ elementNamePattern? : string
320
+ }
321
+
322
+ ```
323
+ An array element will match a ` CustomGroupDefinition ` group if it matches all the filters of the custom group's definition.
324
+
325
+ or:
326
+
327
+ ``` ts
328
+ interface CustomGroupAnyOfDefinition {
329
+ groupName: string
330
+ type? : ' alphabetical' | ' natural' | ' line-length' | ' unsorted'
331
+ order? : ' asc' | ' desc'
332
+ anyOf: Array <{
333
+ selector? : string
334
+ elementNamePattern? : string
335
+ }>
336
+ }
337
+ ```
338
+
339
+ An array element will match a ` CustomGroupAnyOfDefinition ` group if it matches all the filters of at least one of the ` anyOf ` items.
340
+
341
+ #### Attributes
342
+
343
+ - ` groupName ` : The group's name, which needs to be put in the ` groups ` option.
344
+ - ` selector ` : Filter on the ` selector ` of the element.
345
+ - ` elementNamePattern ` : If entered, will check that the name of the element matches the pattern entered.
346
+ - ` type ` : Overrides the sort type for that custom group. ` unsorted ` will not sort the group.
347
+ - ` order ` : Overrides the sort order for that custom group
348
+
349
+ #### Match importance
350
+
351
+ The ` customGroups ` list is ordered:
352
+ The first custom group definition that matches an element will be used.
353
+
354
+ Custom groups have a higher priority than any predefined group.
355
+
231
356
## Usage
232
357
233
358
<CodeTabs
@@ -252,6 +377,9 @@ Each group of elements (separated by empty lines) is treated independently, and
252
377
specialCharacters: 'keep',
253
378
groupKind: 'literals-first',
254
379
partitionByNewLine: false,
380
+ useConfigurationIf: {},
381
+ groups: [],
382
+ customGroups: [],
255
383
},
256
384
],
257
385
},
@@ -278,6 +406,9 @@ Each group of elements (separated by empty lines) is treated independently, and
278
406
specialCharacters: 'keep',
279
407
groupKind: 'literals-first',
280
408
partitionByNewLine: false,
409
+ useConfigurationIf: {},
410
+ groups: [],
411
+ customGroups: [],
281
412
},
282
413
],
283
414
},
0 commit comments