eslint-plugin-perfectionist 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +29 -4
- package/dist/rules/sort-array-includes.js +118 -60
- package/dist/rules/sort-array-includes.mjs +106 -58
- package/dist/rules/sort-astro-attributes.js +18 -44
- package/dist/rules/sort-astro-attributes.mjs +9 -31
- package/dist/rules/sort-classes.js +56 -35
- package/dist/rules/sort-classes.mjs +56 -35
- package/dist/rules/sort-enums.js +69 -39
- package/dist/rules/sort-enums.mjs +66 -37
- package/dist/rules/sort-exports.js +88 -12
- package/dist/rules/sort-exports.mjs +85 -12
- package/dist/rules/sort-interfaces.js +82 -106
- package/dist/rules/sort-interfaces.mjs +66 -89
- package/dist/rules/sort-intersection-types.js +151 -119
- package/dist/rules/sort-intersection-types.mjs +147 -113
- package/dist/rules/sort-jsx-props.js +18 -44
- package/dist/rules/sort-jsx-props.mjs +9 -31
- package/dist/rules/sort-maps.js +78 -22
- package/dist/rules/sort-maps.mjs +74 -22
- package/dist/rules/sort-named-exports.js +87 -31
- package/dist/rules/sort-named-exports.mjs +81 -28
- package/dist/rules/sort-named-imports.js +87 -31
- package/dist/rules/sort-named-imports.mjs +81 -28
- package/dist/rules/sort-object-types.js +80 -119
- package/dist/rules/sort-object-types.mjs +72 -104
- package/dist/rules/sort-objects.js +48 -50
- package/dist/rules/sort-objects.mjs +48 -43
- package/dist/rules/sort-svelte-attributes.js +18 -44
- package/dist/rules/sort-svelte-attributes.mjs +9 -31
- package/dist/rules/sort-union-types.js +151 -119
- package/dist/rules/sort-union-types.mjs +147 -113
- package/dist/rules/sort-variable-declarations.js +97 -24
- package/dist/rules/sort-variable-declarations.mjs +95 -25
- package/dist/rules/sort-vue-attributes.js +18 -45
- package/dist/rules/sort-vue-attributes.mjs +9 -32
- package/dist/utils/get-node-range.js +4 -6
- package/dist/utils/get-node-range.mjs +4 -8
- package/dist/utils/sort-nodes-by-dependencies.js +16 -0
- package/dist/utils/sort-nodes-by-dependencies.mjs +16 -1
- package/dist/utils/sort-nodes-by-groups.js +22 -0
- package/dist/utils/sort-nodes-by-groups.mjs +20 -0
- package/package.json +3 -3
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { minimatch } from 'minimatch'
|
|
2
2
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
|
|
3
|
+
import { hasPartitionComment } from '../utils/is-partition-comment.mjs'
|
|
4
|
+
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.mjs'
|
|
5
|
+
import { getCommentsBefore } from '../utils/get-comments-before.mjs'
|
|
3
6
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
4
7
|
import { isMemberOptional } from '../utils/is-member-optional.mjs'
|
|
5
8
|
import { getLinesBetween } from '../utils/get-lines-between.mjs'
|
|
@@ -8,13 +11,10 @@ import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
|
8
11
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
9
12
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
10
13
|
import { getSettings } from '../utils/get-settings.mjs'
|
|
11
|
-
import { isPositive } from '../utils/is-positive.mjs'
|
|
12
14
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
13
|
-
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
14
15
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
15
16
|
import { complete } from '../utils/complete.mjs'
|
|
16
17
|
import { pairwise } from '../utils/pairwise.mjs'
|
|
17
|
-
import { compare } from '../utils/compare.mjs'
|
|
18
18
|
const sortInterfaces = createEslintRule({
|
|
19
19
|
name: 'sort-interfaces',
|
|
20
20
|
meta: {
|
|
@@ -51,6 +51,24 @@ const sortInterfaces = createEslintRule({
|
|
|
51
51
|
},
|
|
52
52
|
type: 'array',
|
|
53
53
|
},
|
|
54
|
+
partitionByComment: {
|
|
55
|
+
description:
|
|
56
|
+
'Allows you to use comments to separate the interface properties into logical groups.',
|
|
57
|
+
anyOf: [
|
|
58
|
+
{
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'string',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
54
72
|
partitionByNewLine: {
|
|
55
73
|
description:
|
|
56
74
|
'Allows to use spaces to separate the nodes into logical groups.',
|
|
@@ -112,6 +130,7 @@ const sortInterfaces = createEslintRule({
|
|
|
112
130
|
order: 'asc',
|
|
113
131
|
ignoreCase: true,
|
|
114
132
|
ignorePattern: [],
|
|
133
|
+
partitionByComment: false,
|
|
115
134
|
partitionByNewLine: false,
|
|
116
135
|
groupKind: 'mixed',
|
|
117
136
|
groups: [],
|
|
@@ -123,6 +142,7 @@ const sortInterfaces = createEslintRule({
|
|
|
123
142
|
if (node.body.body.length > 1) {
|
|
124
143
|
let settings = getSettings(context.settings)
|
|
125
144
|
let options = complete(context.options.at(0), settings, {
|
|
145
|
+
partitionByComment: false,
|
|
126
146
|
partitionByNewLine: false,
|
|
127
147
|
type: 'alphabetical',
|
|
128
148
|
groupKind: 'mixed',
|
|
@@ -138,6 +158,7 @@ const sortInterfaces = createEslintRule({
|
|
|
138
158
|
Object.keys(options.customGroups),
|
|
139
159
|
)
|
|
140
160
|
let sourceCode = getSourceCode(context)
|
|
161
|
+
let partitionComment = options.partitionByComment
|
|
141
162
|
if (
|
|
142
163
|
!options.ignorePattern.some(pattern =>
|
|
143
164
|
minimatch(node.id.name, pattern, {
|
|
@@ -184,84 +205,60 @@ const sortInterfaces = createEslintRule({
|
|
|
184
205
|
: _d.range.at(0)) ?? element.range.at(1)
|
|
185
206
|
name = sourceCode.text.slice(element.range.at(0), endIndex)
|
|
186
207
|
}
|
|
208
|
+
setCustomGroups(options.customGroups, name)
|
|
209
|
+
if (element.loc.start.line !== element.loc.end.line) {
|
|
210
|
+
defineGroup('multiline')
|
|
211
|
+
}
|
|
187
212
|
let elementSortingNode = {
|
|
188
213
|
size: rangeToDiff(element.range),
|
|
189
214
|
node: element,
|
|
215
|
+
group: getGroup(),
|
|
190
216
|
name,
|
|
191
217
|
}
|
|
192
218
|
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
219
|
+
(partitionComment &&
|
|
220
|
+
hasPartitionComment(
|
|
221
|
+
partitionComment,
|
|
222
|
+
getCommentsBefore(element, sourceCode),
|
|
223
|
+
)) ||
|
|
224
|
+
(options.partitionByNewLine &&
|
|
225
|
+
lastElement &&
|
|
226
|
+
getLinesBetween(sourceCode, lastElement, elementSortingNode))
|
|
196
227
|
) {
|
|
197
228
|
accumulator.push([])
|
|
198
229
|
}
|
|
199
|
-
|
|
200
|
-
if (element.loc.start.line !== element.loc.end.line) {
|
|
201
|
-
defineGroup('multiline')
|
|
202
|
-
}
|
|
203
|
-
accumulator.at(-1).push({
|
|
204
|
-
...elementSortingNode,
|
|
205
|
-
group: getGroup(),
|
|
206
|
-
})
|
|
230
|
+
accumulator.at(-1).push(elementSortingNode)
|
|
207
231
|
return accumulator
|
|
208
232
|
},
|
|
209
233
|
[[]],
|
|
210
234
|
)
|
|
211
|
-
let toSorted = nodes => {
|
|
212
|
-
let grouped = {}
|
|
213
|
-
for (let currentNode of nodes) {
|
|
214
|
-
let groupNum = getGroupNumber(options.groups, currentNode)
|
|
215
|
-
if (!(groupNum in grouped)) {
|
|
216
|
-
grouped[groupNum] = [currentNode]
|
|
217
|
-
} else {
|
|
218
|
-
grouped[groupNum] = sortNodes(
|
|
219
|
-
[...grouped[groupNum], currentNode],
|
|
220
|
-
options,
|
|
221
|
-
)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
let sortedNodes = []
|
|
225
|
-
for (let group of Object.keys(grouped).sort(
|
|
226
|
-
(a, b) => Number(a) - Number(b),
|
|
227
|
-
)) {
|
|
228
|
-
sortedNodes.push(...sortNodes(grouped[group], options))
|
|
229
|
-
}
|
|
230
|
-
return sortedNodes
|
|
231
|
-
}
|
|
232
|
-
let checkGroupSort = (left, right) => {
|
|
233
|
-
let leftNum = getGroupNumber(options.groups, left)
|
|
234
|
-
let rightNum = getGroupNumber(options.groups, right)
|
|
235
|
-
return (
|
|
236
|
-
leftNum > rightNum ||
|
|
237
|
-
(leftNum === rightNum &&
|
|
238
|
-
isPositive(compare(left, right, options)))
|
|
239
|
-
)
|
|
240
|
-
}
|
|
241
235
|
let { groupKind } = options
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
isMemberOptional(
|
|
250
|
-
isMemberOptional(members[i].node),
|
|
251
|
-
)
|
|
252
|
-
if (iteration < switchIndex && iteration + 1 !== switchIndex) {
|
|
253
|
-
return checkGroupSort(left, right)
|
|
254
|
-
}
|
|
255
|
-
if (isMemberOptional(left.node) !== isMemberOptional(right.node)) {
|
|
256
|
-
return (
|
|
257
|
-
isMemberOptional(left.node) !== (groupKind === 'optional-first')
|
|
236
|
+
for (let nodes of formattedMembers) {
|
|
237
|
+
let sortedNodes
|
|
238
|
+
if (groupKind !== 'mixed') {
|
|
239
|
+
let optionalNodes = nodes.filter(member =>
|
|
240
|
+
isMemberOptional(member.node),
|
|
241
|
+
)
|
|
242
|
+
let requiredNodes = nodes.filter(
|
|
243
|
+
member => !isMemberOptional(member.node),
|
|
258
244
|
)
|
|
245
|
+
sortedNodes =
|
|
246
|
+
groupKind === 'optional-first'
|
|
247
|
+
? [
|
|
248
|
+
...sortNodesByGroups(optionalNodes, options),
|
|
249
|
+
...sortNodesByGroups(requiredNodes, options),
|
|
250
|
+
]
|
|
251
|
+
: [
|
|
252
|
+
...sortNodesByGroups(requiredNodes, options),
|
|
253
|
+
...sortNodesByGroups(optionalNodes, options),
|
|
254
|
+
]
|
|
255
|
+
} else {
|
|
256
|
+
sortedNodes = sortNodesByGroups(nodes, options)
|
|
259
257
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (checkOrder(nodes, left, right, iteration)) {
|
|
258
|
+
pairwise(nodes, (left, right) => {
|
|
259
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
260
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
261
|
+
if (indexOfLeft > indexOfRight) {
|
|
265
262
|
let leftNum = getGroupNumber(options.groups, left)
|
|
266
263
|
let rightNum = getGroupNumber(options.groups, right)
|
|
267
264
|
context.report({
|
|
@@ -276,30 +273,10 @@ const sortInterfaces = createEslintRule({
|
|
|
276
273
|
rightGroup: right.group,
|
|
277
274
|
},
|
|
278
275
|
node: right.node,
|
|
279
|
-
fix: fixer =>
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
isMemberOptional(member.node),
|
|
284
|
-
)
|
|
285
|
-
let requiredNodes = nodes.filter(
|
|
286
|
-
member => !isMemberOptional(member.node),
|
|
287
|
-
)
|
|
288
|
-
sortedNodes =
|
|
289
|
-
groupKind === 'optional-first'
|
|
290
|
-
? [
|
|
291
|
-
...toSorted(optionalNodes),
|
|
292
|
-
...toSorted(requiredNodes),
|
|
293
|
-
]
|
|
294
|
-
: [
|
|
295
|
-
...toSorted(requiredNodes),
|
|
296
|
-
...toSorted(optionalNodes),
|
|
297
|
-
]
|
|
298
|
-
} else {
|
|
299
|
-
sortedNodes = toSorted(nodes)
|
|
300
|
-
}
|
|
301
|
-
return makeFixes(fixer, nodes, sortedNodes, sourceCode)
|
|
302
|
-
},
|
|
276
|
+
fix: fixer =>
|
|
277
|
+
makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
278
|
+
partitionComment,
|
|
279
|
+
}),
|
|
303
280
|
})
|
|
304
281
|
}
|
|
305
282
|
})
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
3
|
+
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
4
|
+
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
5
|
+
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
3
6
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
7
|
+
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
4
8
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
5
9
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
10
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
7
11
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
8
12
|
const getSettings = require('../utils/get-settings.js')
|
|
9
|
-
const isPositive = require('../utils/is-positive.js')
|
|
10
|
-
const sortNodes = require('../utils/sort-nodes.js')
|
|
11
13
|
const useGroups = require('../utils/use-groups.js')
|
|
12
14
|
const makeFixes = require('../utils/make-fixes.js')
|
|
13
15
|
const complete = require('../utils/complete.js')
|
|
14
16
|
const pairwise = require('../utils/pairwise.js')
|
|
15
|
-
const compare = require('../utils/compare.js')
|
|
16
17
|
const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
17
18
|
name: 'sort-intersection-types',
|
|
18
19
|
meta: {
|
|
@@ -58,6 +59,29 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
58
59
|
],
|
|
59
60
|
},
|
|
60
61
|
},
|
|
62
|
+
partitionByComment: {
|
|
63
|
+
description:
|
|
64
|
+
'Allows you to use comments to separate the intersection types members into logical groups.',
|
|
65
|
+
anyOf: [
|
|
66
|
+
{
|
|
67
|
+
type: 'array',
|
|
68
|
+
items: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'string',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
partitionByNewLine: {
|
|
81
|
+
description:
|
|
82
|
+
'Allows to use spaces to separate the nodes into logical groups.',
|
|
83
|
+
type: 'boolean',
|
|
84
|
+
},
|
|
61
85
|
},
|
|
62
86
|
additionalProperties: false,
|
|
63
87
|
},
|
|
@@ -74,6 +98,8 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
74
98
|
type: 'alphabetical',
|
|
75
99
|
order: 'asc',
|
|
76
100
|
ignoreCase: true,
|
|
101
|
+
partitionByNewLine: false,
|
|
102
|
+
partitionByComment: false,
|
|
77
103
|
groups: [],
|
|
78
104
|
},
|
|
79
105
|
],
|
|
@@ -84,6 +110,8 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
84
110
|
type: 'alphabetical',
|
|
85
111
|
ignoreCase: true,
|
|
86
112
|
order: 'asc',
|
|
113
|
+
partitionByComment: false,
|
|
114
|
+
partitionByNewLine: false,
|
|
87
115
|
groups: [],
|
|
88
116
|
})
|
|
89
117
|
validateGroupsConfiguration.validateGroupsConfiguration(
|
|
@@ -106,122 +134,126 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
106
134
|
[],
|
|
107
135
|
)
|
|
108
136
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
137
|
+
let partitionComment = options.partitionByComment
|
|
138
|
+
let formattedMembers = node.types.reduce(
|
|
139
|
+
(accumulator, type) => {
|
|
140
|
+
var _a, _b
|
|
141
|
+
let { getGroup, defineGroup } = useGroups.useGroups(options.groups)
|
|
142
|
+
switch (type.type) {
|
|
143
|
+
case 'TSConditionalType':
|
|
144
|
+
defineGroup('conditional')
|
|
145
|
+
break
|
|
146
|
+
case 'TSConstructorType':
|
|
147
|
+
case 'TSFunctionType':
|
|
148
|
+
defineGroup('function')
|
|
149
|
+
break
|
|
150
|
+
case 'TSImportType':
|
|
151
|
+
defineGroup('import')
|
|
152
|
+
break
|
|
153
|
+
case 'TSIntersectionType':
|
|
154
|
+
defineGroup('intersection')
|
|
155
|
+
break
|
|
156
|
+
case 'TSAnyKeyword':
|
|
157
|
+
case 'TSBigIntKeyword':
|
|
158
|
+
case 'TSBooleanKeyword':
|
|
159
|
+
case 'TSNeverKeyword':
|
|
160
|
+
case 'TSNumberKeyword':
|
|
161
|
+
case 'TSObjectKeyword':
|
|
162
|
+
case 'TSStringKeyword':
|
|
163
|
+
case 'TSSymbolKeyword':
|
|
164
|
+
case 'TSThisType':
|
|
165
|
+
case 'TSUnknownKeyword':
|
|
166
|
+
case 'TSIntrinsicKeyword':
|
|
167
|
+
defineGroup('keyword')
|
|
168
|
+
break
|
|
169
|
+
case 'TSLiteralType':
|
|
170
|
+
case 'TSTemplateLiteralType':
|
|
171
|
+
defineGroup('literal')
|
|
172
|
+
break
|
|
173
|
+
case 'TSArrayType':
|
|
174
|
+
case 'TSIndexedAccessType':
|
|
175
|
+
case 'TSInferType':
|
|
176
|
+
case 'TSTypeReference':
|
|
177
|
+
case 'TSQualifiedName':
|
|
178
|
+
defineGroup('named')
|
|
179
|
+
break
|
|
180
|
+
case 'TSMappedType':
|
|
181
|
+
case 'TSTypeLiteral':
|
|
182
|
+
defineGroup('object')
|
|
183
|
+
break
|
|
184
|
+
case 'TSTypeQuery':
|
|
185
|
+
case 'TSTypeOperator':
|
|
186
|
+
defineGroup('operator')
|
|
187
|
+
break
|
|
188
|
+
case 'TSTupleType':
|
|
189
|
+
defineGroup('tuple')
|
|
190
|
+
break
|
|
191
|
+
case 'TSUnionType':
|
|
192
|
+
defineGroup('union')
|
|
193
|
+
break
|
|
194
|
+
case 'TSNullKeyword':
|
|
195
|
+
case 'TSUndefinedKeyword':
|
|
196
|
+
case 'TSVoidKeyword':
|
|
197
|
+
defineGroup('nullish')
|
|
198
|
+
break
|
|
199
|
+
}
|
|
200
|
+
let lastSortingNode =
|
|
201
|
+
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
202
|
+
let sortingNode = {
|
|
203
|
+
name: sourceCode.text.slice(...type.range),
|
|
204
|
+
size: rangeToDiff.rangeToDiff(type.range),
|
|
205
|
+
group: getGroup(),
|
|
206
|
+
node: type,
|
|
207
|
+
}
|
|
208
|
+
if (
|
|
209
|
+
(partitionComment &&
|
|
210
|
+
isPartitionComment.hasPartitionComment(
|
|
211
|
+
partitionComment,
|
|
212
|
+
getCommentsBefore.getCommentsBefore(type, sourceCode),
|
|
213
|
+
)) ||
|
|
214
|
+
(options.partitionByNewLine &&
|
|
215
|
+
lastSortingNode &&
|
|
216
|
+
getLinesBetween.getLinesBetween(
|
|
217
|
+
sourceCode,
|
|
218
|
+
lastSortingNode,
|
|
219
|
+
sortingNode,
|
|
220
|
+
))
|
|
221
|
+
) {
|
|
222
|
+
accumulator.push([])
|
|
223
|
+
}
|
|
224
|
+
;(_b = accumulator.at(-1)) == null ? void 0 : _b.push(sortingNode)
|
|
225
|
+
return accumulator
|
|
226
|
+
},
|
|
227
|
+
[[]],
|
|
228
|
+
)
|
|
229
|
+
for (let nodes of formattedMembers) {
|
|
230
|
+
let sortedNodes = sortNodesByGroups.sortNodesByGroups(nodes, options)
|
|
231
|
+
pairwise.pairwise(nodes, (left, right) => {
|
|
232
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
233
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
234
|
+
if (indexOfLeft > indexOfRight) {
|
|
235
|
+
let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
|
|
236
|
+
let rightNum = getGroupNumber.getGroupNumber(options.groups, right)
|
|
237
|
+
context.report({
|
|
238
|
+
messageId:
|
|
239
|
+
leftNum !== rightNum
|
|
240
|
+
? 'unexpectedIntersectionTypesGroupOrder'
|
|
241
|
+
: 'unexpectedIntersectionTypesOrder',
|
|
242
|
+
data: {
|
|
243
|
+
left: toSingleLine.toSingleLine(left.name),
|
|
244
|
+
leftGroup: left.group,
|
|
245
|
+
right: toSingleLine.toSingleLine(right.name),
|
|
246
|
+
rightGroup: right.group,
|
|
247
|
+
},
|
|
248
|
+
node: right.node,
|
|
249
|
+
fix: fixer =>
|
|
250
|
+
makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
251
|
+
partitionComment,
|
|
252
|
+
}),
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
}
|
|
225
257
|
},
|
|
226
258
|
}),
|
|
227
259
|
})
|