Skip to content

Commit 513d13e

Browse files
authored
feat: allow type overrides in groups option
1 parent d0b38b9 commit 513d13e

File tree

61 files changed

+1427
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1427
-248
lines changed

docs/content/rules/sort-array-includes.mdx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Enforce sorted array values if the `includes` method is immediately called after
2020

2121
By keeping arrays sorted, developers can quickly scan and verify the values, making the code more predictable and reducing the likelihood of errors. This practice simplifies debugging and enhances the overall clarity of the codebase.
2222

23-
2423
## Try it out
2524

2625
<CodeExample
@@ -316,6 +315,10 @@ Example configuration:
316315
| string
317316
| string[]
318317
| { newlinesBetween: number }
318+
| {
319+
group: string | string[];
320+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
321+
}
319322
>
320323
```
321324
</sub>
@@ -338,6 +341,21 @@ Predefined groups are characterized by a selector.
338341
- `literal` — Array elements that are not spread values.
339342
- `spread` — Array elements that are spread values.
340343

344+
#### Group with overridden settings
345+
346+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
347+
348+
- `type` — Overrides the [`type`](#type) option for that group.
349+
350+
```ts
351+
{
352+
groups: [
353+
'literal',
354+
{ group: 'spread', type: 'unsorted' }, // Elements from this group will not be sorted
355+
]
356+
}
357+
```
358+
341359
#### Newlines between groups
342360

343361
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

docs/content/rules/sort-classes.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ Without `ignoreCallbackDependenciesPatterns: ['^computed$']`, `role` and `userna
330330
| string
331331
| string[]
332332
| { newlinesBetween: number }
333+
| {
334+
group: string | string[];
335+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
336+
}
333337
>
334338
```
335339
</sub>
@@ -598,6 +602,21 @@ abstract class Example extends BaseExample {
598602
}
599603
```
600604

605+
##### Group with overridden settings
606+
607+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
608+
609+
- `type` — Overrides the [`type`](#type) option for that group.
610+
611+
```ts
612+
{
613+
groups: [
614+
'property',
615+
{ group: 'method', type: 'unsorted' }, // Elements from this group will not be sorted
616+
]
617+
}
618+
```
619+
601620
##### Newlines between groups
602621

603622
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

docs/content/rules/sort-decorators.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
276276
| string
277277
| string[]
278278
| { newlinesBetween: number }
279+
| {
280+
group: string | string[];
281+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
282+
}
279283
>
280284
```
281285
</sub>
@@ -297,6 +301,21 @@ Within a given group, members will be sorted according to the `type`, `order`, `
297301
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
298302
All members of the groups in the array will be sorted together as if they were part of a single group.
299303

304+
##### Group with overridden settings
305+
306+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
307+
308+
- `type` — Overrides the [`type`](#type) option for that group.
309+
310+
```ts
311+
{
312+
groups: [
313+
'myCustomGroup1',
314+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
315+
]
316+
}
317+
```
318+
300319
#### Newlines between groups
301320

302321
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

docs/content/rules/sort-enums.mdx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
239239
| string
240240
| string[]
241241
| { newlinesBetween: number }
242+
| {
243+
group: string | string[];
244+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
245+
}
242246
>
243247
```
244248
</sub>
@@ -254,6 +258,21 @@ Within a given group, members will be sorted according to the `type`, `order`, `
254258
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
255259
All members of the groups in the array will be sorted together as if they were part of a single group.
256260

261+
##### Group with overridden settings
262+
263+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
264+
265+
- `type` — Overrides the [`type`](#type) option for that group.
266+
267+
```ts
268+
{
269+
groups: [
270+
'myCustomGroup1',
271+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
272+
]
273+
}
274+
```
275+
257276
#### Newlines between groups
258277

259278
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
@@ -412,4 +431,4 @@ This rule was introduced in [v0.8.0](https://github.com/azat-io/eslint-plugin-pe
412431
## Resources
413432

414433
- [Rule source](https://github.com/azat-io/eslint-plugin-perfectionist/blob/main/rules/sort-enums.ts)
415-
- [Test source](https://github.com/azat-io/eslint-plugin-perfectionist/blob/main/test/sort-enums.test.ts)
434+
- [Test source](https://github.com/azat-io/eslint-plugin-perfectionist/blob/main/test/rules/sort-enums.test.ts)

docs/content/rules/sort-export-attributes.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Controls newlines between groups:
164164
| string
165165
| string[]
166166
| { newlinesBetween: number }
167+
| {
168+
group: string | string[];
169+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
170+
}
167171
>
168172
```
169173
</sub>
@@ -183,6 +187,40 @@ customGroups: [
183187
newlinesBetween: 'always'
184188
```
185189

190+
#### Group with overridden settings
191+
192+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
193+
194+
- `type` — Overrides the [`type`](#type) option for that group.
195+
196+
```ts
197+
{
198+
groups: [
199+
'myCustomGroup1',
200+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
201+
]
202+
}
203+
```
204+
205+
#### Newlines between groups
206+
207+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
208+
209+
See the [`newlinesBetween`](#newlinesbetween) option.
210+
211+
This feature is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
212+
213+
```ts
214+
{
215+
newlinesBetween: 1,
216+
groups: [
217+
'a',
218+
{ newlinesBetween: 0 }, // Overrides the global newlinesBetween option
219+
'b',
220+
]
221+
}
222+
```
223+
186224
### customGroups
187225

188226
Define custom attribute groups with optional per-group sort overrides.

docs/content/rules/sort-exports.mdx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
219219
| string
220220
| string[]
221221
| { newlinesBetween: number }
222-
| { group: string | string[]; commentAbove: string }
222+
| {
223+
group: string | string[];
224+
commentAbove?: string;
225+
type?: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
226+
}
223227
>
224228
```
225229
</sub>
@@ -255,45 +259,47 @@ Example: `type-export`.
255259
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,
256260
it will automatically be added to the end of the list.
257261

258-
##### Newlines between groups
259-
260-
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
262+
##### Group with overridden settings
261263

262-
See the [`newlinesBetween`](#newlinesbetween) option.
264+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
263265

264-
This feature is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
266+
- `type` — Overrides the [`type`](#type) option for that group.
267+
- `commentAbove` — Enforces the presence of a comment containing the content of `commentAbove` above the top element of the group.
268+
- An error will be raised if no comment containing the content of `commentAbove` is found above the top element of the
269+
group.
270+
- Auto-fixing will add a comment containing the content of `commentAbove` above the top element of the group.
271+
- Auto-fixing will also remove invalid auto-added comments (only comments existing in `commentAbove` objects are
272+
considered as auto-removable).
265273

266274
```ts
267275
{
268-
newlinesBetween: 1,
269276
groups: [
270-
'a',
271-
{ newlinesBetween: 0 }, // Overrides the global newlinesBetween option
272-
'b',
277+
{ group: 'type-export', commentAbove: 'Type exports' },
278+
'myCustomGroup1',
279+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
273280
]
274281
}
275282
```
276283

277-
#### Comment above groups
284+
##### Newlines between groups
278285

279-
You may place `commentAbove` objects alongside their related group(s) to enforce the presence of a comment containing the
280-
content of `commentAbove`.
286+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
287+
288+
See the [`newlinesBetween`](#newlinesbetween) option.
289+
290+
This feature is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
281291

282292
```ts
283293
{
294+
newlinesBetween: 1,
284295
groups: [
285-
{ group: 'type-export', commentAbove: 'Type exports' },
286-
{ group: 'value-export', commentAbove: 'Value exports' },
296+
'a',
297+
{ newlinesBetween: 0 }, // Overrides the global newlinesBetween option
298+
'b',
287299
]
288300
}
289301
```
290302

291-
- An error will be raised if no comment containing the content of `commentAbove` is found above the top element of the
292-
group.
293-
- Auto-fixing will add a comment containing the content of `commentAbove` above the top element of the group.
294-
- Auto-fixing will also remove invalid auto-added comments (only comments existing in `commentAbove`
295-
objects are considered as auto-removable).
296-
297303
### customGroups
298304

299305
<sub>

docs/content/rules/sort-heritage-clauses.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
189189
| string
190190
| string[]
191191
| { newlinesBetween: number }
192+
| {
193+
group: string | string[];
194+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
195+
}
192196
>
193197
```
194198
</sub>
@@ -210,6 +214,21 @@ Within a given group, members will be sorted according to the `type`, `order`, `
210214
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
211215
All members of the groups in the array will be sorted together as if they were part of a single group.
212216

217+
#### Group with overridden settings
218+
219+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
220+
221+
- `type` — Overrides the [`type`](#type) option for that group.
222+
223+
```ts
224+
{
225+
groups: [
226+
'myCustomGroup1',
227+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
228+
]
229+
}
230+
```
231+
213232
#### Newlines between groups
214233

215234
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

docs/content/rules/sort-import-attributes.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Controls newlines between groups:
164164
| string
165165
| string[]
166166
| { newlinesBetween: number }
167+
| {
168+
group: string | string[];
169+
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
170+
}
167171
>
168172
```
169173
</sub>
@@ -183,6 +187,40 @@ customGroups: [
183187
newlinesBetween: 'always'
184188
```
185189

190+
#### Group with overridden settings
191+
192+
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
193+
194+
- `type` — Overrides the [`type`](#type) option for that group.
195+
196+
```ts
197+
{
198+
groups: [
199+
'myCustomGroup1',
200+
{ group: 'myCustomGroup2', type: 'unsorted' }, // Elements from this group will not be sorted
201+
]
202+
}
203+
```
204+
205+
#### Newlines between groups
206+
207+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
208+
209+
See the [`newlinesBetween`](#newlinesbetween) option.
210+
211+
This feature is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
212+
213+
```ts
214+
{
215+
newlinesBetween: 1,
216+
groups: [
217+
'a',
218+
{ newlinesBetween: 0 }, // Overrides the global newlinesBetween option
219+
'b',
220+
]
221+
}
222+
```
223+
186224
### customGroups
187225

188226
Define custom attribute groups with optional per-group sort overrides.

0 commit comments

Comments
 (0)