Skip to content

Commit 1430b19

Browse files
authored
feat: add new lines inside at rule options and settings level
1 parent ae36860 commit 1430b19

File tree

73 files changed

+3181
-1076
lines changed

Some content is hidden

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

73 files changed

+3181
-1076
lines changed

docs/content/guide/getting-started.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ In settings, you can set the following options:
150150
- `partitionByComment` — Partition the sorted elements by comments. Values can be `true`, `false` or regexp pattern.
151151
- `partitionByNewLine` — Partition the sorted elements by newlines. Values can be `true` or `false`.
152152
- `newlinesBetween` — Specifies how to handle newlines between groups. Values can be `'ignore'` or a number.
153+
- `newlinesInside` — Specifies how to handle newlines between elements of each group. Values can be `'ignore'`, `'newlinesBetween'` or a number.
153154

154155
Example:
155156

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,38 @@ Each group of elements (separated by empty lines) is treated independently, and
245245

246246
### newlinesBetween
247247

248-
<sub>type: `number | 'ignore'`</sub>
248+
<sub>
249+
type: `number | 'ignore'`
250+
</sub>
249251
<sub>default: `'ignore'`</sub>
250252

251253
Specifies how to handle newlines between groups.
252254

253255
- `'ignore'` — Do not report errors related to newlines.
254256
- `0` — No newlines are allowed.
255-
- Any other number — Enforce this number of newlines between each group, and forbid newlines inside groups.
257+
- Any other number — Enforce this number of newlines between each group.
258+
259+
You can also enforce the newline behavior between two specific groups through the [`groups`](#newlines-between-groups)
260+
option.
261+
262+
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
263+
264+
### newlinesInside
256265

257-
You can also enforce the newline behavior between two specific groups through the `groups` options.
266+
<sub>
267+
type: `number | 'ignore' | 'newlinesBetween'`
268+
</sub>
269+
<sub>default: `'newlinesBetween'`</sub>
270+
271+
Specifies how to handle newlines inside groups.
272+
273+
- `'ignore'` — Do not report errors related to newlines.
274+
- `'newlinesBetween'`[DEPRECATED] If [`newlinesBetween`](#newlinesbetween) is `'ignore'`, then `'ignore'`, otherwise `0`.
275+
- `0` — No newlines are allowed.
276+
- Any other number — Enforce this number of newlines between each element of the same group.
258277

259-
See the [`groups`](#newlines-between-groups) option.
278+
You can also enforce the newline behavior inside a given group through the [`groups`](#group-with-overridden-settings)
279+
or [`customGroups`](#customgroups) options.
260280

261281
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
262282

@@ -322,12 +342,12 @@ Example configuration:
322342
Array<
323343
| string
324344
| string[]
325-
| { newlinesBetween: number }
345+
| { newlinesBetween: number | 'ignore' }
326346
| {
327347
group: string | string[];
328348
type?: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
329349
order?: 'asc' | 'desc';
330-
newlinesInside?: number;
350+
newlinesInside?: number | 'ignore';
331351
}
332352
>
333353
```
@@ -404,7 +424,7 @@ interface CustomGroupDefinition {
404424
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
405425
order?: 'asc' | 'desc'
406426
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
407-
newlinesInside?: number
427+
newlinesInside?: number | 'ignore'
408428
selector?: string
409429
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
410430
}
@@ -420,7 +440,7 @@ interface CustomGroupAnyOfDefinition {
420440
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
421441
order?: 'asc' | 'desc'
422442
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
423-
newlinesInside?: number
443+
newlinesInside?: number | 'ignore'
424444
anyOf: Array<{
425445
selector?: string
426446
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
@@ -472,6 +492,7 @@ Custom groups have a higher priority than any predefined group.
472492
specialCharacters: 'keep',
473493
partitionByNewLine: false,
474494
newlinesBetween: 'ignore',
495+
newlinesInside: 'ignore',
475496
useConfigurationIf: {},
476497
groups: ["literal"],
477498
customGroups: [],
@@ -502,6 +523,7 @@ Custom groups have a higher priority than any predefined group.
502523
specialCharacters: 'keep',
503524
partitionByNewLine: false,
504525
newlinesBetween: 'ignore',
526+
newlinesInside: 'ignore',
505527
useConfigurationIf: {},
506528
groups: ["literal"],
507529
customGroups: [],

docs/content/rules/sort-classes.mdx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,38 @@ class User {
284284

285285
### newlinesBetween
286286

287-
<sub>type: `number | 'ignore'`</sub>
287+
<sub>
288+
type: `number | 'ignore'`
289+
</sub>
288290
<sub>default: `'ignore'`</sub>
289291

290292
Specifies how to handle newlines between groups.
291293

292294
- `'ignore'` — Do not report errors related to newlines.
293295
- `0` — No newlines are allowed.
294-
- Any other number — Enforce this number of newlines between each group, and forbid newlines inside groups.
296+
- Any other number — Enforce this number of newlines between each group.
297+
298+
You can also enforce the newline behavior between two specific groups through the [`groups`](#newlines-between-groups)
299+
option.
300+
301+
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
302+
303+
### newlinesInside
295304

296-
You can also enforce the newline behavior between two specific groups through the `groups` options.
305+
<sub>
306+
type: `number | 'ignore' | 'newlinesBetween'`
307+
</sub>
308+
<sub>default: `'newlinesBetween'`</sub>
309+
310+
Specifies how to handle newlines inside groups.
311+
312+
- `'ignore'` — Do not report errors related to newlines.
313+
- `'newlinesBetween'`[DEPRECATED] If [`newlinesBetween`](#newlinesbetween) is `'ignore'`, then `'ignore'`, otherwise `0`.
314+
- `0` — No newlines are allowed.
315+
- Any other number — Enforce this number of newlines between each element of the same group.
297316

298-
See the [`groups`](#newlines-between-groups) option.
317+
You can also enforce the newline behavior inside a given group through the [`groups`](#group-with-overridden-settings)
318+
or [`customGroups`](#customgroups) options.
299319

300320
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
301321

@@ -328,12 +348,12 @@ Without `ignoreCallbackDependenciesPatterns: ['^computed$']`, `role` and `userna
328348
Array<
329349
| string
330350
| string[]
331-
| { newlinesBetween: number }
351+
| { newlinesBetween: number | 'ignore' }
332352
| {
333353
group: string | string[];
334354
type?: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
335355
order?: 'asc' | 'desc';
336-
newlinesInside?: number;
356+
newlinesInside?: number | 'ignore';
337357
}
338358
>
339359
```
@@ -684,7 +704,7 @@ interface CustomGroupDefinition {
684704
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
685705
order?: 'asc' | 'desc'
686706
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
687-
newlinesInside?: number
707+
newlinesInside?: number | 'ignore'
688708
selector?: string
689709
modifiers?: string[]
690710
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
@@ -702,7 +722,7 @@ interface CustomGroupAnyOfDefinition {
702722
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
703723
order?: 'asc' | 'desc'
704724
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
705-
newlinesInside?: number
725+
newlinesInside?: number | 'ignore'
706726
anyOf: Array<{
707727
selector?: string
708728
modifiers?: string[]
@@ -813,6 +833,7 @@ Example:
813833
partitionByComment: false,
814834
partitionByNewLine: false,
815835
newlinesBetween: 'ignore',
836+
newlinesInside: 'ignore',
816837
ignoreCallbackDependenciesPatterns: [],
817838
groups: [
818839
'index-signature',
@@ -867,6 +888,7 @@ Example:
867888
partitionByComment: false,
868889
partitionByNewLine: false,
869890
newlinesBetween: 'ignore',
891+
newlinesInside: 'ignore',
870892
ignoreCallbackDependenciesPatterns: [],
871893
groups: [
872894
'index-signature',

docs/content/rules/sort-decorators.mdx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,38 @@ When `true`, the rule will not sort the decorators if there is an empty line bet
251251

252252
### newlinesBetween
253253

254-
<sub>type: `number | 'ignore'`</sub>
254+
<sub>
255+
type: `number | 'ignore'`
256+
</sub>
255257
<sub>default: `'ignore'`</sub>
256258

257259
Specifies how to handle newlines between groups.
258260

259261
- `'ignore'` — Do not report errors related to newlines.
260262
- `0` — No newlines are allowed.
261-
- Any other number — Enforce this number of newlines between each group, and forbid newlines inside groups.
263+
- Any other number — Enforce this number of newlines between each group.
264+
265+
You can also enforce the newline behavior between two specific groups through the [`groups`](#newlines-between-groups)
266+
option.
267+
268+
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
269+
270+
### newlinesInside
262271

263-
You can also enforce the newline behavior between two specific groups through the `groups` options.
272+
<sub>
273+
type: `number | 'ignore' | 'newlinesBetween'`
274+
</sub>
275+
<sub>default: `'newlinesBetween'`</sub>
276+
277+
Specifies how to handle newlines inside groups.
278+
279+
- `'ignore'` — Do not report errors related to newlines.
280+
- `'newlinesBetween'`[DEPRECATED] If [`newlinesBetween`](#newlinesbetween) is `'ignore'`, then `'ignore'`, otherwise `0`.
281+
- `0` — No newlines are allowed.
282+
- Any other number — Enforce this number of newlines between each element of the same group.
264283

265-
See the [`groups`](#newlines-between-groups) option.
284+
You can also enforce the newline behavior inside a given group through the [`groups`](#group-with-overridden-settings)
285+
or [`customGroups`](#customgroups) options.
266286

267287
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
268288

@@ -274,12 +294,12 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
274294
Array<
275295
| string
276296
| string[]
277-
| { newlinesBetween: number }
297+
| { newlinesBetween: number | 'ignore' }
278298
| {
279299
group: string | string[];
280300
type?: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
281301
order?: 'asc' | 'desc';
282-
newlinesInside?: number;
302+
newlinesInside?: number | 'ignore';
283303
}
284304
>
285305
```
@@ -383,7 +403,7 @@ interface CustomGroupDefinition {
383403
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
384404
order?: 'asc' | 'desc'
385405
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
386-
newlinesInside?: number
406+
newlinesInside?: number | 'ignore'
387407
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
388408
}
389409

@@ -398,7 +418,7 @@ interface CustomGroupAnyOfDefinition {
398418
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
399419
order?: 'asc' | 'desc'
400420
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
401-
newlinesInside?: number
421+
newlinesInside?: number | 'ignore'
402422
anyOf: Array<{
403423
selector?: string
404424
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
@@ -482,6 +502,7 @@ class MyClass {
482502
partitionByNewLine: false,
483503
partitionByComment: false,
484504
newlinesBetween: 'ignore',
505+
newlinesInside: 'ignore',
485506
groups: [],
486507
customGroups: [],
487508
sortOnClasses: true,
@@ -517,6 +538,7 @@ class MyClass {
517538
partitionByNewLine: false,
518539
partitionByComment: false,
519540
newlinesBetween: 'ignore',
541+
newlinesInside: 'ignore',
520542
groups: [],
521543
customGroups: [],
522544
sortOnClasses: true,

docs/content/rules/sort-enums.mdx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,38 @@ Each group of enum members (separated by empty lines) is treated independently,
214214

215215
### newlinesBetween
216216

217-
<sub>type: `number | 'ignore'`</sub>
217+
<sub>
218+
type: `number | 'ignore'`
219+
</sub>
218220
<sub>default: `'ignore'`</sub>
219221

220222
Specifies how to handle newlines between groups.
221223

222224
- `'ignore'` — Do not report errors related to newlines.
223225
- `0` — No newlines are allowed.
224-
- Any other number — Enforce this number of newlines between each group, and forbid newlines inside groups.
226+
- Any other number — Enforce this number of newlines between each group.
227+
228+
You can also enforce the newline behavior between two specific groups through the [`groups`](#newlines-between-groups)
229+
option.
230+
231+
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
232+
233+
### newlinesInside
225234

226-
You can also enforce the newline behavior between two specific groups through the `groups` options.
235+
<sub>
236+
type: `number | 'ignore' | 'newlinesBetween'`
237+
</sub>
238+
<sub>default: `'newlinesBetween'`</sub>
239+
240+
Specifies how to handle newlines inside groups.
241+
242+
- `'ignore'` — Do not report errors related to newlines.
243+
- `'newlinesBetween'`[DEPRECATED] If [`newlinesBetween`](#newlinesbetween) is `'ignore'`, then `'ignore'`, otherwise `0`.
244+
- `0` — No newlines are allowed.
245+
- Any other number — Enforce this number of newlines between each element of the same group.
227246

228-
See the [`groups`](#newlines-between-groups) option.
247+
You can also enforce the newline behavior inside a given group through the [`groups`](#group-with-overridden-settings)
248+
or [`customGroups`](#customgroups) options.
229249

230250
This option is only applicable when [`partitionByNewLine`](#partitionbynewline) is `false`.
231251

@@ -237,12 +257,12 @@ This option is only applicable when [`partitionByNewLine`](#partitionbynewline)
237257
Array<
238258
| string
239259
| string[]
240-
| { newlinesBetween: number }
260+
| { newlinesBetween: number | 'ignore' }
241261
| {
242262
group: string | string[];
243263
type?: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted';
244264
order?: 'asc' | 'desc';
245-
newlinesInside?: number;
265+
newlinesInside?: number | 'ignore';
246266
}
247267
>
248268
```
@@ -312,7 +332,7 @@ interface CustomGroupDefinition {
312332
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
313333
order?: 'asc' | 'desc'
314334
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
315-
newlinesInside?: number
335+
newlinesInside?: number | 'ignore'
316336
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
317337
}
318338

@@ -327,7 +347,7 @@ interface CustomGroupAnyOfDefinition {
327347
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
328348
order?: 'asc' | 'desc'
329349
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
330-
newlinesInside?: number
350+
newlinesInside?: number | 'ignore'
331351
anyOf: Array<{
332352
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
333353
}>
@@ -379,6 +399,7 @@ Custom groups have a higher priority than any predefined group.
379399
partitionByComment: false,
380400
partitionByNewLine: false,
381401
newlinesBetween: 'ignore',
402+
newlinesInside: 'ignore',
382403
sortByValue: "ifNumericEnum",
383404
groups: [],
384405
customGroups: [],
@@ -410,6 +431,7 @@ Custom groups have a higher priority than any predefined group.
410431
partitionByComment: false,
411432
partitionByNewLine: false,
412433
newlinesBetween: 'ignore',
434+
newlinesInside: 'ignore',
413435
sortByValue: "ifNumericEnum",
414436
groups: [],
415437
customGroups: [],

0 commit comments

Comments
 (0)