@@ -6,6 +6,7 @@ import type { PartitionComment, SortingNode } from '../typings'
6
6
import { isPartitionComment } from '../utils/is-partition-comment'
7
7
import { getCommentBefore } from '../utils/get-comment-before'
8
8
import { createEslintRule } from '../utils/create-eslint-rule'
9
+ import { getLinesBetween } from '../utils/get-lines-between'
9
10
import { getGroupNumber } from '../utils/get-group-number'
10
11
import { toSingleLine } from '../utils/to-single-line'
11
12
import { rangeToDiff } from '../utils/range-to-diff'
@@ -33,6 +34,7 @@ type Options = [
33
34
Partial < {
34
35
'custom-groups' : { [ key : string ] : string [ ] | string }
35
36
'partition-by-comment' : PartitionComment
37
+ 'partition-by-new-line' : boolean
36
38
groups : ( string [ ] | string ) [ ]
37
39
'styled-components' : boolean
38
40
'ignore-case' : boolean
@@ -62,6 +64,10 @@ export default createEslintRule<Options, MESSAGE_ID>({
62
64
type : [ 'boolean' , 'string' , 'array' ] ,
63
65
default : false ,
64
66
} ,
67
+ 'partition-by-new-line' : {
68
+ type : 'boolean' ,
69
+ default : false ,
70
+ } ,
65
71
'styled-components' : {
66
72
type : 'boolean' ,
67
73
default : true ,
@@ -107,6 +113,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
107
113
) => {
108
114
if ( node . properties . length > 1 ) {
109
115
let options = complete ( context . options . at ( 0 ) , {
116
+ 'partition-by-new-line' : false ,
110
117
'partition-by-comment' : false ,
111
118
type : SortType . alphabetical ,
112
119
'styled-components' : true ,
@@ -158,6 +165,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
158
165
}
159
166
160
167
let comment = getCommentBefore ( prop , source )
168
+ let lastProp = accumulator . at ( - 1 ) ?. at ( - 1 )
161
169
162
170
if (
163
171
options [ 'partition-by-comment' ] &&
@@ -184,6 +192,20 @@ export default createEslintRule<Options, MESSAGE_ID>({
184
192
name = source . text . slice ( ...prop . key . range )
185
193
}
186
194
195
+ let propSortingNode = {
196
+ size : rangeToDiff ( prop . range ) ,
197
+ node : prop ,
198
+ name,
199
+ }
200
+
201
+ if (
202
+ options [ 'partition-by-new-line' ] &&
203
+ lastProp &&
204
+ getLinesBetween ( source , lastProp , propSortingNode )
205
+ ) {
206
+ accumulator . push ( [ ] )
207
+ }
208
+
187
209
if ( prop . value . type === 'AssignmentPattern' ) {
188
210
let addDependencies = ( value : TSESTree . AssignmentPattern ) => {
189
211
if ( value . right . type === 'Identifier' ) {
@@ -252,12 +274,10 @@ export default createEslintRule<Options, MESSAGE_ID>({
252
274
setCustomGroups ( options [ 'custom-groups' ] , name )
253
275
254
276
let value = {
255
- size : rangeToDiff ( prop . range ) ,
277
+ ... propSortingNode ,
256
278
group : getGroup ( ) ,
257
279
dependencies,
258
- node : prop ,
259
280
position,
260
- name,
261
281
}
262
282
263
283
accumulator . at ( - 1 ) ! . push ( value )
0 commit comments