Skip to content

Commit 231af42

Browse files
authoredJan 18, 2025··
feat: add newlines-between to some rules
1 parent c705547 commit 231af42

18 files changed

+1352
-95
lines changed
 

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

+37
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ if ([
232232

233233
Each group of elements (separated by empty lines) is treated independently, and the order within each group is preserved.
234234

235+
### newlinesBetween
236+
237+
<sub>default: `'ignore'`</sub>
238+
239+
Specifies how new lines should be handled between groups.
240+
241+
- `ignore` — Do not report errors related to new lines.
242+
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
243+
- `never` — No new lines are allowed.
244+
245+
You can also enforce the newline behavior between two specific groups through the `groups` options.
246+
247+
See the [`groups`](#newlines-between-groups) option.
248+
249+
This option is only applicable when `partitionByNewLine` is `false`.
250+
235251
### useConfigurationIf
236252

237253
<sub>
@@ -301,6 +317,25 @@ Predefined groups are characterized by a selector.
301317
- `literal`: Array elements that are not spread values.
302318
- `spread`: Array elements that are spread values.
303319

320+
#### Newlines between groups
321+
322+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
323+
324+
See the [`newlinesBetween`](#newlinesbetween) option.
325+
326+
This feature is only applicable when `partitionByNewLine` is false.
327+
328+
```ts
329+
{
330+
newlinesBetween: 'always',
331+
groups: [
332+
'a',
333+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
334+
'b',
335+
]
336+
}
337+
```
338+
304339
### customGroups
305340

306341
<sub>
@@ -379,6 +414,7 @@ Custom groups have a higher priority than any predefined group.
379414
specialCharacters: 'keep',
380415
groupKind: 'literals-first',
381416
partitionByNewLine: false,
417+
newlinesBetween: 'ignore',
382418
useConfigurationIf: {},
383419
groups: [],
384420
customGroups: [],
@@ -408,6 +444,7 @@ Custom groups have a higher priority than any predefined group.
408444
specialCharacters: 'keep',
409445
groupKind: 'literals-first',
410446
partitionByNewLine: false,
447+
newlinesBetween: 'ignore',
411448
useConfigurationIf: {},
412449
groups: [],
413450
customGroups: [],

‎docs/content/rules/sort-classes.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ Specifies how new lines should be handled between class member groups.
266266
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
267267
- `never` — No new lines are allowed in object types.
268268

269+
You can also enforce the newline behavior between two specific groups through the `groups` options.
270+
271+
See the [`groups`](#newlines-between-groups) option.
272+
269273
This option is only applicable when `partitionByNewLine` is `false`.
270274

271275
### ignoreCallbackDependenciesPatterns
@@ -556,6 +560,25 @@ abstract class Example extends BaseExample {
556560
}
557561
```
558562

563+
#### Newlines between groups
564+
565+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
566+
567+
See the [`newlinesBetween`](#newlinesbetween) option.
568+
569+
This feature is only applicable when `partitionByNewLine` is false.
570+
571+
```ts
572+
{
573+
newlinesBetween: 'always',
574+
groups: [
575+
'a',
576+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
577+
'b',
578+
]
579+
}
580+
```
581+
559582
### customGroups
560583

561584
<Important title="Migrating from the old API">

‎docs/content/rules/sort-interfaces.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ Specifies how new lines should be handled between interface groups.
248248
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
249249
- `never` — No new lines are allowed between interface members.
250250

251+
You can also enforce the newline behavior between two specific groups through the `groups` options.
252+
253+
See the [`groups`](#newlines-between-groups) option.
254+
251255
This option is only applicable when `partitionByNewLine` is `false`.
252256

253257
### [DEPRECATED] groupKind
@@ -433,6 +437,25 @@ interface Interface {
433437
method(): string
434438
```
435439
440+
#### Newlines between groups
441+
442+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
443+
444+
See the [`newlinesBetween`](#newlinesbetween) option.
445+
446+
This feature is only applicable when `partitionByNewLine` is false.
447+
448+
```ts
449+
{
450+
newlinesBetween: 'always',
451+
groups: [
452+
'a',
453+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
454+
'b',
455+
]
456+
}
457+
```
458+
436459
### customGroups
437460
438461
<Important title="Migrating from the old API">

‎docs/content/rules/sort-intersection-types.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ Specifies how new lines should be handled between intersection type groups.
176176
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
177177
- `never` — No new lines are allowed in intersection types.
178178
179+
You can also enforce the newline behavior between two specific groups through the `groups` options.
180+
181+
See the [`groups`](#newlines-between-groups) option.
182+
179183
This option is only applicable when `partitionByNewLine` is `false`.
180184
181185
### groups
@@ -296,6 +300,25 @@ type Example =
296300
}
297301
```
298302

303+
#### Newlines between groups
304+
305+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
306+
307+
See the [`newlinesBetween`](#newlinesbetween) option.
308+
309+
This feature is only applicable when `partitionByNewLine` is false.
310+
311+
```ts
312+
{
313+
newlinesBetween: 'always',
314+
groups: [
315+
'a',
316+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
317+
'b',
318+
]
319+
}
320+
```
321+
299322
## Usage
300323

301324
<CodeTabs

‎docs/content/rules/sort-jsx-props.mdx

+29
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ Allows you to specify names or patterns for JSX elements that should be ignored
200200

201201
You can specify their names or a regexp pattern to ignore, for example: `'^Table.+'` to ignore all object types whose names begin with the word Table.
202202

203+
### partitionByNewLine
204+
205+
<sub>default: `false`</sub>
206+
207+
When `true`, the rule will not sort members if there is an empty line between them. This can be useful for keeping logically separated groups of members in their defined order.
208+
203209
### groups
204210

205211
<sub>
@@ -225,6 +231,25 @@ Within a given group, members will be sorted according to the `type`, `order`, `
225231
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
226232
All members of the groups in the array will be sorted together as if they were part of a single group.
227233

234+
#### Newlines between groups
235+
236+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
237+
238+
See the [`newlinesBetween`](#newlinesbetween) option.
239+
240+
This feature is only applicable when `partitionByNewLine` is false.
241+
242+
```ts
243+
{
244+
newlinesBetween: 'always',
245+
groups: [
246+
'a',
247+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
248+
'b',
249+
]
250+
}
251+
```
252+
228253
### customGroups
229254

230255
<sub>
@@ -280,6 +305,8 @@ Custom group matching takes precedence over predefined group matching.
280305
ignoreCase: true,
281306
specialCharacters: 'keep',
282307
ignorePattern: [],
308+
partitionByNewLine: false,
309+
newlinesBetween: 'ignore',
283310
groups: [],
284311
customGroups: {},
285312
},
@@ -307,6 +334,8 @@ Custom group matching takes precedence over predefined group matching.
307334
ignoreCase: true,
308335
specialCharacters: 'keep',
309336
ignorePattern: [],
337+
partitionByNewLine: false,
338+
newlinesBetween: 'ignore',
310339
groups: [],
311340
customGroups: {},
312341
},

‎docs/content/rules/sort-modules.mdx

+22
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ Specifies how new lines should be handled between module member groups.
290290
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
291291
- `never` — No new lines are allowed in object types.
292292

293+
You can also enforce the newline behavior between two specific groups through the `groups` options.
294+
295+
See the [`groups`](#newlines-between-groups) option.
296+
293297
This option is only applicable when `partitionByNewLine` is `false`.
294298

295299
### groups
@@ -496,6 +500,24 @@ Example:
496500
}
497501
```
498502

503+
#### Newlines between groups
504+
505+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
506+
507+
See the [`newlinesBetween`](#newlinesbetween) option.
508+
509+
This feature is only applicable when `partitionByNewLine` is false.
510+
511+
```ts
512+
{
513+
newlinesBetween: 'always',
514+
groups: [
515+
'a',
516+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
517+
'b',
518+
]
519+
}
520+
```
499521

500522
## Usage
501523

‎docs/content/rules/sort-object-types.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ Specifies how new lines should be handled between object type groups.
213213
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
214214
- `never` — No new lines are allowed in object types.
215215

216+
You can also enforce the newline behavior between two specific groups through the `groups` options.
217+
218+
See the [`groups`](#newlines-between-groups) option.
219+
216220
This option is only applicable when `partitionByNewLine` is `false`.
217221

218222
### [DEPRECATED] groupKind
@@ -529,6 +533,25 @@ type User = {
529533
}
530534
```
531535
536+
#### Newlines between groups
537+
538+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
539+
540+
See the [`newlinesBetween`](#newlinesbetween) option.
541+
542+
This feature is only applicable when `partitionByNewLine` is false.
543+
544+
```ts
545+
{
546+
newlinesBetween: 'always',
547+
groups: [
548+
'a',
549+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
550+
'b',
551+
]
552+
}
553+
```
554+
532555
## Usage
533556
534557
<CodeTabs

‎docs/content/rules/sort-sets.mdx

+37
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ let items = new Set([
235235

236236
Each group of elements (separated by empty lines) is treated independently, and the order within each group is preserved.
237237

238+
### newlinesBetween
239+
240+
<sub>default: `'ignore'`</sub>
241+
242+
Specifies how new lines should be handled between groups.
243+
244+
- `ignore` — Do not report errors related to new lines.
245+
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
246+
- `never` — No new lines are allowed.
247+
248+
You can also enforce the newline behavior between two specific groups through the `groups` options.
249+
250+
See the [`groups`](#newlines-between-groups) option.
251+
252+
This option is only applicable when `partitionByNewLine` is `false`.
253+
238254
### groups
239255

240256
<sub>
@@ -259,6 +275,25 @@ Predefined groups are characterized by a selector.
259275
- `literal`: Array elements that are not spread values.
260276
- `spread`: Array elements that are spread values.
261277

278+
#### Newlines between groups
279+
280+
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
281+
282+
See the [`newlinesBetween`](#newlinesbetween) option.
283+
284+
This feature is only applicable when `partitionByNewLine` is false.
285+
286+
```ts
287+
{
288+
newlinesBetween: 'always',
289+
groups: [
290+
'a',
291+
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
292+
'b',
293+
]
294+
}
295+
```
296+
262297
### customGroups
263298

264299
<sub>
@@ -337,6 +372,7 @@ Custom groups have a higher priority than any predefined group.
337372
specialCharacters: 'keep',
338373
groupKind: 'literals-first',
339374
partitionByNewLine: false,
375+
newlinesBetween: 'ignore',
340376
useConfigurationIf: {},
341377
groups: [],
342378
customGroups: [],
@@ -366,6 +402,7 @@ Custom groups have a higher priority than any predefined group.
366402
specialCharacters: 'keep',
367403
groupKind: 'literals-first',
368404
partitionByNewLine: false,
405+
newlinesBetween: 'ignore',
369406
useConfigurationIf: {},
370407
groups: [],
371408
customGroups: [],

0 commit comments

Comments
 (0)
Please sign in to comment.