eslint-plugin-perfectionist 4.14.0 → 4.15.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/package.json.js +1 -1
- package/dist/rules/sort-array-includes.js +5 -2
- package/dist/rules/sort-classes.js +6 -3
- package/dist/rules/sort-decorators.js +5 -2
- package/dist/rules/sort-enums.js +6 -3
- package/dist/rules/sort-exports.js +8 -4
- package/dist/rules/sort-heritage-clauses.js +2 -1
- package/dist/rules/sort-imports.js +28 -18
- package/dist/rules/sort-jsx-props.js +5 -2
- package/dist/rules/sort-maps.js +5 -2
- package/dist/rules/sort-modules.js +7 -2
- package/dist/rules/sort-named-exports.js +5 -2
- package/dist/rules/sort-named-imports.js +5 -2
- package/dist/rules/sort-object-types/get-custom-groups-compare-options.js +3 -3
- package/dist/rules/sort-object-types.js +3 -2
- package/dist/rules/sort-objects.js +5 -2
- package/dist/rules/sort-switch-case.js +4 -0
- package/dist/rules/sort-union-types.js +7 -2
- package/dist/rules/sort-variable-declarations.js +7 -2
- package/dist/utils/common-json-schemas.js +23 -7
- package/dist/utils/compare.js +15 -18
- package/dist/utils/get-custom-groups-compare-options.js +6 -6
- package/dist/utils/get-eslint-disabled-lines.js +12 -10
- package/dist/utils/get-newlines-between-errors.js +16 -16
- package/dist/utils/get-newlines-between-option.js +64 -30
- package/dist/utils/make-fixes.js +4 -1
- package/dist/utils/make-newlines-between-fixes.js +49 -23
- package/dist/utils/pairwise.js +1 -2
- package/dist/utils/report-all-errors.js +1 -1
- package/dist/utils/sort-nodes-by-groups.js +9 -9
- package/dist/utils/unreachable-case-error.js +9 -0
- package/package.json +5 -3
package/dist/package.json.js
CHANGED
|
@@ -199,7 +199,10 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
199
199
|
) {
|
|
200
200
|
accumulator.push([])
|
|
201
201
|
}
|
|
202
|
-
accumulator.at(-1).push(
|
|
202
|
+
accumulator.at(-1).push({
|
|
203
|
+
...sortingNode,
|
|
204
|
+
partitionId: accumulator.length,
|
|
205
|
+
})
|
|
203
206
|
return accumulator
|
|
204
207
|
},
|
|
205
208
|
[[]],
|
|
@@ -222,7 +225,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
222
225
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
223
226
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
224
227
|
sortNodesByGroups.sortNodesByGroups({
|
|
225
|
-
|
|
228
|
+
getOptionsByGroupIndex:
|
|
226
229
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
227
230
|
options,
|
|
228
231
|
),
|
|
@@ -465,7 +465,10 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
465
465
|
) {
|
|
466
466
|
accumulator.push([])
|
|
467
467
|
}
|
|
468
|
-
accumulator.at(-1).push(
|
|
468
|
+
accumulator.at(-1).push({
|
|
469
|
+
...sortingNode,
|
|
470
|
+
partitionId: accumulator.length,
|
|
471
|
+
})
|
|
469
472
|
return accumulator
|
|
470
473
|
},
|
|
471
474
|
[[]],
|
|
@@ -476,7 +479,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
476
479
|
isNodeIgnored: sortingNode =>
|
|
477
480
|
getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
|
|
478
481
|
options.groups.length,
|
|
479
|
-
|
|
482
|
+
getOptionsByGroupIndex:
|
|
480
483
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
481
484
|
options,
|
|
482
485
|
),
|
|
@@ -503,7 +506,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
503
506
|
left.overloadSignaturesGroupId !== null &&
|
|
504
507
|
left.overloadSignaturesGroupId === right.overloadSignaturesGroupId
|
|
505
508
|
) {
|
|
506
|
-
return
|
|
509
|
+
return 0
|
|
507
510
|
}
|
|
508
511
|
return computedNewlinesBetween
|
|
509
512
|
},
|
|
@@ -194,7 +194,10 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
194
194
|
) {
|
|
195
195
|
accumulator.push([])
|
|
196
196
|
}
|
|
197
|
-
accumulator.at(-1).push(
|
|
197
|
+
accumulator.at(-1).push({
|
|
198
|
+
...sortingNode,
|
|
199
|
+
partitionId: accumulator.length,
|
|
200
|
+
})
|
|
198
201
|
return accumulator
|
|
199
202
|
},
|
|
200
203
|
[[]],
|
|
@@ -202,7 +205,7 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
202
205
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
203
206
|
formattedMembers.flatMap(nodes2 =>
|
|
204
207
|
sortNodesByGroups.sortNodesByGroups({
|
|
205
|
-
|
|
208
|
+
getOptionsByGroupIndex: () => ({ options }),
|
|
206
209
|
ignoreEslintDisabledNodes,
|
|
207
210
|
groups: options.groups,
|
|
208
211
|
nodes: nodes2,
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -155,7 +155,10 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
155
155
|
) {
|
|
156
156
|
accumulator.push([])
|
|
157
157
|
}
|
|
158
|
-
accumulator.at(-1).push(
|
|
158
|
+
accumulator.at(-1).push({
|
|
159
|
+
...sortingNode,
|
|
160
|
+
partitionId: accumulator.length,
|
|
161
|
+
})
|
|
159
162
|
return accumulator
|
|
160
163
|
},
|
|
161
164
|
[[]],
|
|
@@ -180,11 +183,11 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
180
183
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
181
184
|
let nodesSortedByGroups = formattedMembers.flatMap(sortingNodes =>
|
|
182
185
|
sortNodesByGroups.sortNodesByGroups({
|
|
183
|
-
|
|
186
|
+
getOptionsByGroupIndex: groupIndex => ({
|
|
184
187
|
options:
|
|
185
188
|
getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions({
|
|
186
189
|
options: overriddenOptions,
|
|
187
|
-
|
|
190
|
+
groupIndex,
|
|
188
191
|
}),
|
|
189
192
|
nodeValueGetter,
|
|
190
193
|
}),
|
|
@@ -95,10 +95,11 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
95
95
|
name,
|
|
96
96
|
node,
|
|
97
97
|
}
|
|
98
|
-
let
|
|
98
|
+
let lastSortingNode =
|
|
99
|
+
(_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
|
|
99
100
|
if (
|
|
100
101
|
shouldPartition.shouldPartition({
|
|
101
|
-
lastSortingNode
|
|
102
|
+
lastSortingNode,
|
|
102
103
|
sortingNode,
|
|
103
104
|
sourceCode,
|
|
104
105
|
options,
|
|
@@ -106,7 +107,10 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
106
107
|
) {
|
|
107
108
|
formattedMembers.push([])
|
|
108
109
|
}
|
|
109
|
-
formattedMembers.at(-1).push(
|
|
110
|
+
formattedMembers.at(-1).push({
|
|
111
|
+
...sortingNode,
|
|
112
|
+
partitionId: formattedMembers.length,
|
|
113
|
+
})
|
|
110
114
|
}
|
|
111
115
|
return {
|
|
112
116
|
'Program:exit': () => {
|
|
@@ -128,7 +132,7 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
128
132
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
129
133
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
130
134
|
sortNodesByGroups.sortNodesByGroups({
|
|
131
|
-
|
|
135
|
+
getOptionsByGroupIndex:
|
|
132
136
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
133
137
|
options,
|
|
134
138
|
),
|
|
@@ -95,13 +95,14 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
|
|
|
95
95
|
),
|
|
96
96
|
size: rangeToDiff.rangeToDiff(heritageClause, sourceCode),
|
|
97
97
|
node: heritageClause,
|
|
98
|
+
partitionId: 0,
|
|
98
99
|
group,
|
|
99
100
|
name,
|
|
100
101
|
}
|
|
101
102
|
})
|
|
102
103
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
103
104
|
sortNodesByGroups.sortNodesByGroups({
|
|
104
|
-
|
|
105
|
+
getOptionsByGroupIndex: () => ({ options }),
|
|
105
106
|
ignoreEslintDisabledNodes,
|
|
106
107
|
groups: options.groups,
|
|
107
108
|
nodes,
|
|
@@ -41,11 +41,11 @@ let defaultOptions = {
|
|
|
41
41
|
fallbackSort: { type: 'unsorted' },
|
|
42
42
|
partitionByComment: false,
|
|
43
43
|
partitionByNewLine: false,
|
|
44
|
-
newlinesBetween: 'always',
|
|
45
44
|
specialCharacters: 'keep',
|
|
46
45
|
sortSideEffects: false,
|
|
47
46
|
type: 'alphabetical',
|
|
48
47
|
environment: 'node',
|
|
48
|
+
newlinesBetween: 1,
|
|
49
49
|
customGroups: [],
|
|
50
50
|
ignoreCase: true,
|
|
51
51
|
locales: 'en-US',
|
|
@@ -96,7 +96,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
96
96
|
ruleName: id,
|
|
97
97
|
sourceCode,
|
|
98
98
|
})
|
|
99
|
-
let
|
|
99
|
+
let sortingNodesWithoutPartitionId = []
|
|
100
100
|
let flatGroups = new Set(options.groups.flat())
|
|
101
101
|
let shouldRegroupSideEffectNodes = flatGroups.has('side-effect')
|
|
102
102
|
let shouldRegroupSideEffectStyleNodes = flatGroups.has('side-effect-style')
|
|
@@ -196,7 +196,16 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
196
196
|
options,
|
|
197
197
|
name,
|
|
198
198
|
}) ?? 'unknown')
|
|
199
|
-
|
|
199
|
+
let hasMultipleImportDeclarations = isSortable.isSortable(node.specifiers)
|
|
200
|
+
let size = rangeToDiff.rangeToDiff(node, sourceCode)
|
|
201
|
+
if (
|
|
202
|
+
hasMultipleImportDeclarations &&
|
|
203
|
+
options.maxLineLength &&
|
|
204
|
+
size > options.maxLineLength
|
|
205
|
+
) {
|
|
206
|
+
size = name.length + 10
|
|
207
|
+
}
|
|
208
|
+
sortingNodesWithoutPartitionId.push({
|
|
200
209
|
isIgnored:
|
|
201
210
|
!options.sortSideEffects &&
|
|
202
211
|
isSideEffect &&
|
|
@@ -208,30 +217,28 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
208
217
|
),
|
|
209
218
|
dependencyNames: computeDependencyNames({ sourceCode, node }),
|
|
210
219
|
dependencies: computeDependencies(node),
|
|
211
|
-
size: rangeToDiff.rangeToDiff(node, sourceCode),
|
|
212
220
|
addSafetySemicolonWhenInline: true,
|
|
213
221
|
group,
|
|
222
|
+
size,
|
|
214
223
|
name,
|
|
215
224
|
node,
|
|
216
|
-
...(options.type === 'line-length' &&
|
|
217
|
-
options.maxLineLength && {
|
|
218
|
-
hasMultipleImportDeclarations: isSortable.isSortable(
|
|
219
|
-
node.specifiers,
|
|
220
|
-
),
|
|
221
|
-
}),
|
|
222
225
|
})
|
|
223
226
|
}
|
|
224
227
|
return {
|
|
225
228
|
'Program:exit': () => {
|
|
226
229
|
let contentSeparatedSortingNodeGroups = [[[]]]
|
|
227
|
-
for (let
|
|
230
|
+
for (let sortingNodeWithoutPartitionId of sortingNodesWithoutPartitionId) {
|
|
228
231
|
let lastGroupWithNoContentBetween =
|
|
229
232
|
contentSeparatedSortingNodeGroups.at(-1)
|
|
230
233
|
let lastGroup = lastGroupWithNoContentBetween.at(-1)
|
|
231
234
|
let lastSortingNode = lastGroup.at(-1)
|
|
232
235
|
if (
|
|
233
236
|
lastSortingNode &&
|
|
234
|
-
hasContentBetweenNodes(
|
|
237
|
+
hasContentBetweenNodes(
|
|
238
|
+
sourceCode,
|
|
239
|
+
lastSortingNode,
|
|
240
|
+
sortingNodeWithoutPartitionId,
|
|
241
|
+
)
|
|
235
242
|
) {
|
|
236
243
|
lastGroup = []
|
|
237
244
|
lastGroupWithNoContentBetween = [lastGroup]
|
|
@@ -240,8 +247,8 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
240
247
|
)
|
|
241
248
|
} else if (
|
|
242
249
|
shouldPartition.shouldPartition({
|
|
250
|
+
sortingNode: sortingNodeWithoutPartitionId,
|
|
243
251
|
lastSortingNode,
|
|
244
|
-
sortingNode,
|
|
245
252
|
sourceCode,
|
|
246
253
|
options,
|
|
247
254
|
})
|
|
@@ -249,13 +256,16 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
249
256
|
lastGroup = []
|
|
250
257
|
lastGroupWithNoContentBetween.push(lastGroup)
|
|
251
258
|
}
|
|
252
|
-
lastGroup.push(
|
|
259
|
+
lastGroup.push({
|
|
260
|
+
...sortingNodeWithoutPartitionId,
|
|
261
|
+
partitionId: lastGroupWithNoContentBetween.length,
|
|
262
|
+
})
|
|
253
263
|
}
|
|
254
264
|
for (let sortingNodeGroups of contentSeparatedSortingNodeGroups) {
|
|
255
265
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
256
266
|
let nodesSortedByGroups = sortingNodeGroups.flatMap(nodes2 =>
|
|
257
267
|
sortNodesByGroups.sortNodesByGroups({
|
|
258
|
-
|
|
268
|
+
getOptionsByGroupIndex: groupIndex => {
|
|
259
269
|
let customGroupOverriddenOptions =
|
|
260
270
|
getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions(
|
|
261
271
|
{
|
|
@@ -265,7 +275,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
265
275
|
? options.customGroups
|
|
266
276
|
: [],
|
|
267
277
|
},
|
|
268
|
-
|
|
278
|
+
groupIndex,
|
|
269
279
|
},
|
|
270
280
|
)
|
|
271
281
|
if (options.sortSideEffects) {
|
|
@@ -284,9 +294,9 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
284
294
|
options: {
|
|
285
295
|
...overriddenOptions,
|
|
286
296
|
type:
|
|
287
|
-
overriddenOptions.groups[
|
|
297
|
+
overriddenOptions.groups[groupIndex] &&
|
|
288
298
|
isSideEffectOnlyGroup.isSideEffectOnlyGroup(
|
|
289
|
-
overriddenOptions.groups[
|
|
299
|
+
overriddenOptions.groups[groupIndex],
|
|
290
300
|
)
|
|
291
301
|
? 'unsorted'
|
|
292
302
|
: overriddenOptions.type,
|
|
@@ -166,7 +166,10 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
166
166
|
) {
|
|
167
167
|
accumulator.push([])
|
|
168
168
|
}
|
|
169
|
-
accumulator.at(-1).push(
|
|
169
|
+
accumulator.at(-1).push({
|
|
170
|
+
...sortingNode,
|
|
171
|
+
partitionId: accumulator.length,
|
|
172
|
+
})
|
|
170
173
|
return accumulator
|
|
171
174
|
},
|
|
172
175
|
[[]],
|
|
@@ -174,7 +177,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
174
177
|
for (let nodes of formattedMembers) {
|
|
175
178
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
176
179
|
sortNodesByGroups.sortNodesByGroups({
|
|
177
|
-
|
|
180
|
+
getOptionsByGroupIndex:
|
|
178
181
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
179
182
|
options,
|
|
180
183
|
),
|
package/dist/rules/sort-maps.js
CHANGED
|
@@ -129,12 +129,15 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
129
129
|
) {
|
|
130
130
|
formattedMembers.push([])
|
|
131
131
|
}
|
|
132
|
-
formattedMembers.at(-1).push(
|
|
132
|
+
formattedMembers.at(-1).push({
|
|
133
|
+
...sortingNode,
|
|
134
|
+
partitionId: formattedMembers.length,
|
|
135
|
+
})
|
|
133
136
|
}
|
|
134
137
|
for (let nodes of formattedMembers) {
|
|
135
138
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
136
139
|
sortNodesByGroups.sortNodesByGroups({
|
|
137
|
-
|
|
140
|
+
getOptionsByGroupIndex:
|
|
138
141
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
139
142
|
options,
|
|
140
143
|
),
|
|
@@ -278,7 +278,12 @@ let analyzeModule = ({
|
|
|
278
278
|
) {
|
|
279
279
|
formattedNodes.push([])
|
|
280
280
|
}
|
|
281
|
-
;(_b = formattedNodes.at(-1)) == null
|
|
281
|
+
;(_b = formattedNodes.at(-1)) == null
|
|
282
|
+
? void 0
|
|
283
|
+
: _b.push({
|
|
284
|
+
...sortingNode,
|
|
285
|
+
partitionId: formattedNodes.length,
|
|
286
|
+
})
|
|
282
287
|
}
|
|
283
288
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
284
289
|
let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
|
|
@@ -286,7 +291,7 @@ let analyzeModule = ({
|
|
|
286
291
|
isNodeIgnored: sortingNode =>
|
|
287
292
|
getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
|
|
288
293
|
options.groups.length,
|
|
289
|
-
|
|
294
|
+
getOptionsByGroupIndex:
|
|
290
295
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
291
296
|
options,
|
|
292
297
|
),
|
|
@@ -128,7 +128,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
128
128
|
) {
|
|
129
129
|
formattedMembers.push([])
|
|
130
130
|
}
|
|
131
|
-
formattedMembers.at(-1).push(
|
|
131
|
+
formattedMembers.at(-1).push({
|
|
132
|
+
...sortingNode,
|
|
133
|
+
partitionId: formattedMembers.length,
|
|
134
|
+
})
|
|
132
135
|
}
|
|
133
136
|
let groupKindOrder
|
|
134
137
|
if (options.groupKind === 'values-first') {
|
|
@@ -148,7 +151,7 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
148
151
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
149
152
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
150
153
|
sortNodesByGroups.sortNodesByGroups({
|
|
151
|
-
|
|
154
|
+
getOptionsByGroupIndex:
|
|
152
155
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
153
156
|
options,
|
|
154
157
|
),
|
|
@@ -132,7 +132,10 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
132
132
|
) {
|
|
133
133
|
formattedMembers.push([])
|
|
134
134
|
}
|
|
135
|
-
formattedMembers.at(-1).push(
|
|
135
|
+
formattedMembers.at(-1).push({
|
|
136
|
+
...sortingNode,
|
|
137
|
+
partitionId: formattedMembers.length,
|
|
138
|
+
})
|
|
136
139
|
}
|
|
137
140
|
let groupKindOrder
|
|
138
141
|
if (options.groupKind === 'values-first') {
|
|
@@ -152,7 +155,7 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
152
155
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
153
156
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
154
157
|
sortNodesByGroups.sortNodesByGroups({
|
|
155
|
-
|
|
158
|
+
getOptionsByGroupIndex:
|
|
156
159
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
157
160
|
options,
|
|
158
161
|
),
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const getCustomGroupsCompareOptions$1 = require('../../utils/get-custom-groups-compare-options.js')
|
|
4
4
|
const buildNodeValueGetter = require('./build-node-value-getter.js')
|
|
5
|
-
let getCustomGroupsCompareOptions = (options,
|
|
5
|
+
let getCustomGroupsCompareOptions = (options, groupIndex) => {
|
|
6
6
|
var _a
|
|
7
7
|
let baseCompareOptions =
|
|
8
8
|
getCustomGroupsCompareOptions$1.getCustomGroupsCompareOptions(
|
|
9
9
|
options,
|
|
10
|
-
|
|
10
|
+
groupIndex,
|
|
11
11
|
)
|
|
12
12
|
let { fallbackSort, customGroups, sortBy, groups } = options
|
|
13
13
|
let fallbackSortBy = fallbackSort.sortBy
|
|
14
14
|
if (Array.isArray(customGroups)) {
|
|
15
|
-
let group = groups[
|
|
15
|
+
let group = groups[groupIndex]
|
|
16
16
|
let customGroup =
|
|
17
17
|
typeof group === 'string'
|
|
18
18
|
? customGroups.find(currentGroup => group === currentGroup.groupName)
|
|
@@ -256,6 +256,7 @@ let sortObjectTypeElements = ({
|
|
|
256
256
|
: 'required',
|
|
257
257
|
size: rangeToDiff.rangeToDiff(typeElement, sourceCode),
|
|
258
258
|
addSafetySemicolonWhenInline: true,
|
|
259
|
+
partitionId: accumulator.length,
|
|
259
260
|
node: typeElement,
|
|
260
261
|
group,
|
|
261
262
|
value,
|
|
@@ -295,14 +296,14 @@ let sortObjectTypeElements = ({
|
|
|
295
296
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
296
297
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
297
298
|
sortNodesByGroups.sortNodesByGroups({
|
|
298
|
-
|
|
299
|
+
getOptionsByGroupIndex: groupIndex => {
|
|
299
300
|
let {
|
|
300
301
|
fallbackSortNodeValueGetter,
|
|
301
302
|
options: overriddenOptions,
|
|
302
303
|
nodeValueGetter,
|
|
303
304
|
} = getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
|
|
304
305
|
options,
|
|
305
|
-
|
|
306
|
+
groupIndex,
|
|
306
307
|
)
|
|
307
308
|
return {
|
|
308
309
|
options: {
|
|
@@ -297,7 +297,10 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
297
297
|
) {
|
|
298
298
|
accumulator.push([])
|
|
299
299
|
}
|
|
300
|
-
accumulator.at(-1).push(
|
|
300
|
+
accumulator.at(-1).push({
|
|
301
|
+
...sortingNode,
|
|
302
|
+
partitionId: accumulator.length,
|
|
303
|
+
})
|
|
301
304
|
return accumulator
|
|
302
305
|
},
|
|
303
306
|
[[]],
|
|
@@ -319,7 +322,7 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
319
322
|
nodes: nodes2,
|
|
320
323
|
})
|
|
321
324
|
: sortNodesByGroups.sortNodesByGroups({
|
|
322
|
-
|
|
325
|
+
getOptionsByGroupIndex:
|
|
323
326
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
324
327
|
options,
|
|
325
328
|
),
|
|
@@ -48,8 +48,10 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
48
48
|
accumulator.at(-1).push({
|
|
49
49
|
size: rangeToDiff.rangeToDiff(caseNode.test, sourceCode),
|
|
50
50
|
name: getCaseName(sourceCode, caseNode),
|
|
51
|
+
partitionId: accumulator.length,
|
|
51
52
|
isEslintDisabled: false,
|
|
52
53
|
node: caseNode.test,
|
|
54
|
+
group: 'unknown',
|
|
53
55
|
})
|
|
54
56
|
}
|
|
55
57
|
if (
|
|
@@ -104,6 +106,8 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
104
106
|
addSafetySemicolonWhenInline: true,
|
|
105
107
|
isDefaultClause: !caseNode.test,
|
|
106
108
|
isEslintDisabled: false,
|
|
109
|
+
group: 'unknown',
|
|
110
|
+
partitionId: 0,
|
|
107
111
|
node: caseNode,
|
|
108
112
|
}))
|
|
109
113
|
let sortingNodeGroupsForDefaultSort = reduceCaseSortingNodes(
|
|
@@ -217,7 +217,12 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
217
217
|
lastGroup = []
|
|
218
218
|
accumulator.push(lastGroup)
|
|
219
219
|
}
|
|
220
|
-
lastGroup == null
|
|
220
|
+
lastGroup == null
|
|
221
|
+
? void 0
|
|
222
|
+
: lastGroup.push({
|
|
223
|
+
...sortingNode,
|
|
224
|
+
partitionId: accumulator.length,
|
|
225
|
+
})
|
|
221
226
|
return accumulator
|
|
222
227
|
},
|
|
223
228
|
[[]],
|
|
@@ -225,7 +230,7 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
225
230
|
for (let nodes of formattedMembers) {
|
|
226
231
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
227
232
|
sortNodesByGroups.sortNodesByGroups({
|
|
228
|
-
|
|
233
|
+
getOptionsByGroupIndex:
|
|
229
234
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
230
235
|
options,
|
|
231
236
|
),
|
|
@@ -115,7 +115,12 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
115
115
|
) {
|
|
116
116
|
accumulator.push([])
|
|
117
117
|
}
|
|
118
|
-
;(_b = accumulator.at(-1)) == null
|
|
118
|
+
;(_b = accumulator.at(-1)) == null
|
|
119
|
+
? void 0
|
|
120
|
+
: _b.push({
|
|
121
|
+
...sortingNode,
|
|
122
|
+
partitionId: accumulator.length,
|
|
123
|
+
})
|
|
119
124
|
return accumulator
|
|
120
125
|
},
|
|
121
126
|
[[]],
|
|
@@ -123,7 +128,7 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
123
128
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
124
129
|
let nodesSortedByGroups = formattedMembers.flatMap(nodes2 =>
|
|
125
130
|
sortNodesByGroups.sortNodesByGroups({
|
|
126
|
-
|
|
131
|
+
getOptionsByGroupIndex:
|
|
127
132
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
128
133
|
options,
|
|
129
134
|
),
|
|
@@ -64,9 +64,17 @@ let buildCommonJsonSchemas = ({ additionalFallbackSortProperties } = {}) => ({
|
|
|
64
64
|
})
|
|
65
65
|
let commonJsonSchemas = buildCommonJsonSchemas()
|
|
66
66
|
let newlinesBetweenJsonSchema = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
oneOf: [
|
|
68
|
+
{
|
|
69
|
+
description: 'Specifies how to handle newlines between groups.',
|
|
70
|
+
enum: ['ignore', 'always', 'never'],
|
|
71
|
+
type: 'string',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'number',
|
|
75
|
+
minimum: 0,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
70
78
|
}
|
|
71
79
|
let commentAboveJsonSchema = {
|
|
72
80
|
description: 'Specifies a comment to enforce above the group.',
|
|
@@ -198,10 +206,18 @@ let buildCommonCustomGroupJsonSchemas = ({
|
|
|
198
206
|
additionalFallbackSortProperties,
|
|
199
207
|
} = {}) => ({
|
|
200
208
|
newlinesInside: {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
oneOf: [
|
|
210
|
+
{
|
|
211
|
+
description:
|
|
212
|
+
'Specifies how to handle newlines between members of the custom group.',
|
|
213
|
+
enum: ['always', 'never'],
|
|
214
|
+
type: 'string',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: 'number',
|
|
218
|
+
minimum: 0,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
205
221
|
},
|
|
206
222
|
fallbackSort: buildFallbackSortJsonSchema({
|
|
207
223
|
additionalProperties: additionalFallbackSortProperties,
|
package/dist/utils/compare.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const naturalOrderby = require('natural-orderby')
|
|
4
4
|
const convertBooleanToSign = require('./convert-boolean-to-sign.js')
|
|
5
|
+
const unreachableCaseError = require('./unreachable-case-error.js')
|
|
5
6
|
let alphabetCache = /* @__PURE__ */ new Map()
|
|
6
7
|
let compare = ({
|
|
7
8
|
fallbackSortNodeValueGetter,
|
|
@@ -42,7 +43,7 @@ let computeCompareValue = ({ nodeValueGetter, options, a, b }) => {
|
|
|
42
43
|
sortingFunction = getAlphabeticalSortingFunction(options, nodeValueGetter)
|
|
43
44
|
break
|
|
44
45
|
case 'line-length':
|
|
45
|
-
sortingFunction = getLineLengthSortingFunction(
|
|
46
|
+
sortingFunction = getLineLengthSortingFunction()
|
|
46
47
|
break
|
|
47
48
|
case 'unsorted':
|
|
48
49
|
return 0
|
|
@@ -52,6 +53,9 @@ let computeCompareValue = ({ nodeValueGetter, options, a, b }) => {
|
|
|
52
53
|
case 'custom':
|
|
53
54
|
sortingFunction = getCustomSortingFunction(options, nodeValueGetter)
|
|
54
55
|
break
|
|
56
|
+
/* v8 ignore next 2 */
|
|
57
|
+
default:
|
|
58
|
+
throw new unreachableCaseError.UnreachableCaseError(options.type)
|
|
55
59
|
}
|
|
56
60
|
return (
|
|
57
61
|
convertBooleanToSign.convertBooleanToSign(options.order === 'asc') *
|
|
@@ -121,23 +125,11 @@ let getCustomSortingFunction = (
|
|
|
121
125
|
)
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
|
-
let getLineLengthSortingFunction =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (maxLineLength) {
|
|
130
|
-
let isTooLong = (size, node) =>
|
|
131
|
-
size > maxLineLength && node.hasMultipleImportDeclarations
|
|
132
|
-
if (isTooLong(aSize, aNode)) {
|
|
133
|
-
aSize = nodeValueGetter(aNode).length + 10
|
|
134
|
-
}
|
|
135
|
-
if (isTooLong(bSize, bNode)) {
|
|
136
|
-
bSize = nodeValueGetter(bNode).length + 10
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return aSize - bSize
|
|
140
|
-
}
|
|
128
|
+
let getLineLengthSortingFunction = () => (aNode, bNode) => {
|
|
129
|
+
let aSize = aNode.size
|
|
130
|
+
let bSize = bNode.size
|
|
131
|
+
return aSize - bSize
|
|
132
|
+
}
|
|
141
133
|
let getFormatStringFunction = (ignoreCase, specialCharacters) => value => {
|
|
142
134
|
let valueToCompare = value
|
|
143
135
|
if (ignoreCase) {
|
|
@@ -156,6 +148,11 @@ let getFormatStringFunction = (ignoreCase, specialCharacters) => value => {
|
|
|
156
148
|
'',
|
|
157
149
|
)
|
|
158
150
|
break
|
|
151
|
+
case 'keep':
|
|
152
|
+
break
|
|
153
|
+
/* v8 ignore next 2 */
|
|
154
|
+
default:
|
|
155
|
+
throw new unreachableCaseError.UnreachableCaseError(specialCharacters)
|
|
159
156
|
}
|
|
160
157
|
return valueToCompare.replaceAll(/\s/gu, '')
|
|
161
158
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
-
let getCustomGroupsCompareOptions = (options,
|
|
3
|
+
let getCustomGroupsCompareOptions = (options, groupIndex) => {
|
|
4
4
|
var _a, _b
|
|
5
5
|
let { customGroups, fallbackSort, groups, order, type } = options
|
|
6
6
|
if (Array.isArray(customGroups)) {
|
|
7
|
-
let group = groups[
|
|
7
|
+
let group = groups[groupIndex]
|
|
8
8
|
let customGroup =
|
|
9
9
|
typeof group === 'string'
|
|
10
10
|
? customGroups.find(currentGroup => group === currentGroup.groupName)
|
|
@@ -31,15 +31,15 @@ let getCustomGroupsCompareOptions = (options, groupNumber) => {
|
|
|
31
31
|
type,
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
let buildGetCustomGroupOverriddenOptionsFunction = options =>
|
|
34
|
+
let buildGetCustomGroupOverriddenOptionsFunction = options => groupIndex => ({
|
|
35
35
|
options: getCustomGroupOverriddenOptions({
|
|
36
|
-
|
|
36
|
+
groupIndex,
|
|
37
37
|
options,
|
|
38
38
|
}),
|
|
39
39
|
})
|
|
40
|
-
let getCustomGroupOverriddenOptions = ({
|
|
40
|
+
let getCustomGroupOverriddenOptions = ({ groupIndex, options }) => ({
|
|
41
41
|
...options,
|
|
42
|
-
...getCustomGroupsCompareOptions(options,
|
|
42
|
+
...getCustomGroupsCompareOptions(options, groupIndex),
|
|
43
43
|
})
|
|
44
44
|
exports.buildGetCustomGroupOverriddenOptionsFunction =
|
|
45
45
|
buildGetCustomGroupOverriddenOptionsFunction
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const getEslintDisabledRules = require('./get-eslint-disabled-rules.js')
|
|
4
|
+
const unreachableCaseError = require('./unreachable-case-error.js')
|
|
4
5
|
let getEslintDisabledLines = props => {
|
|
5
6
|
let { sourceCode, ruleName } = props
|
|
6
7
|
let returnValue = []
|
|
@@ -9,20 +10,16 @@ let getEslintDisabledLines = props => {
|
|
|
9
10
|
let eslintDisabledRules = getEslintDisabledRules.getEslintDisabledRules(
|
|
10
11
|
comment.value,
|
|
11
12
|
)
|
|
13
|
+
if (!eslintDisabledRules) {
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
12
16
|
let includesRule =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(eslintDisabledRules == null
|
|
16
|
-
? void 0
|
|
17
|
-
: eslintDisabledRules.rules.includes(ruleName))
|
|
17
|
+
eslintDisabledRules.rules === 'all' ||
|
|
18
|
+
eslintDisabledRules.rules.includes(ruleName)
|
|
18
19
|
if (!includesRule) {
|
|
19
20
|
continue
|
|
20
21
|
}
|
|
21
|
-
switch (
|
|
22
|
-
eslintDisabledRules == null
|
|
23
|
-
? void 0
|
|
24
|
-
: eslintDisabledRules.eslintDisableDirective
|
|
25
|
-
) {
|
|
22
|
+
switch (eslintDisabledRules.eslintDisableDirective) {
|
|
26
23
|
case 'eslint-disable-next-line':
|
|
27
24
|
returnValue.push(comment.loc.end.line + 1)
|
|
28
25
|
continue
|
|
@@ -45,6 +42,11 @@ let getEslintDisabledLines = props => {
|
|
|
45
42
|
)
|
|
46
43
|
lineRulePermanentlyDisabled = null
|
|
47
44
|
break
|
|
45
|
+
/* v8 ignore next 4 */
|
|
46
|
+
default:
|
|
47
|
+
throw new unreachableCaseError.UnreachableCaseError(
|
|
48
|
+
eslintDisabledRules.eslintDisableDirective,
|
|
49
|
+
)
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
return returnValue
|
|
@@ -13,9 +13,15 @@ let getNewlinesBetweenErrors = ({
|
|
|
13
13
|
right,
|
|
14
14
|
left,
|
|
15
15
|
}) => {
|
|
16
|
+
if (
|
|
17
|
+
leftGroupIndex > rightGroupIndex ||
|
|
18
|
+
left.partitionId !== right.partitionId
|
|
19
|
+
) {
|
|
20
|
+
return []
|
|
21
|
+
}
|
|
16
22
|
let newlinesBetween = getNewlinesBetweenOption.getNewlinesBetweenOption({
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
nextNodeGroupIndex: rightGroupIndex,
|
|
24
|
+
nodeGroupIndex: leftGroupIndex,
|
|
19
25
|
options,
|
|
20
26
|
})
|
|
21
27
|
newlinesBetween =
|
|
@@ -26,25 +32,19 @@ let getNewlinesBetweenErrors = ({
|
|
|
26
32
|
right,
|
|
27
33
|
left,
|
|
28
34
|
})) ?? newlinesBetween
|
|
29
|
-
if (leftGroupIndex > rightGroupIndex) {
|
|
30
|
-
return []
|
|
31
|
-
}
|
|
32
35
|
let numberOfEmptyLinesBetween = getLinesBetween.getLinesBetween(
|
|
33
36
|
sourceCode,
|
|
34
37
|
left,
|
|
35
38
|
right,
|
|
36
39
|
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else if (numberOfEmptyLinesBetween > 1) {
|
|
46
|
-
return [extraSpacingError]
|
|
47
|
-
}
|
|
40
|
+
if (newlinesBetween === 'ignore') {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
if (numberOfEmptyLinesBetween < newlinesBetween) {
|
|
44
|
+
return [missedSpacingError]
|
|
45
|
+
}
|
|
46
|
+
if (numberOfEmptyLinesBetween > newlinesBetween) {
|
|
47
|
+
return [extraSpacingError]
|
|
48
48
|
}
|
|
49
49
|
return []
|
|
50
50
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const isNewlinesBetweenOption = require('./is-newlines-between-option.js')
|
|
4
|
-
const
|
|
5
|
-
let getNewlinesBetweenOption = ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
4
|
+
const unreachableCaseError = require('./unreachable-case-error.js')
|
|
5
|
+
let getNewlinesBetweenOption = ({
|
|
6
|
+
nextNodeGroupIndex,
|
|
7
|
+
nodeGroupIndex,
|
|
8
|
+
options,
|
|
9
|
+
}) => {
|
|
11
10
|
let globalNewlinesBetweenOption = getGlobalNewlinesBetweenOption({
|
|
12
11
|
newlinesBetween: options.newlinesBetween,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
nextNodeGroupIndex,
|
|
13
|
+
nodeGroupIndex,
|
|
15
14
|
})
|
|
16
|
-
let nodeGroup = options.groups[
|
|
17
|
-
let nextNodeGroup = options.groups[
|
|
15
|
+
let nodeGroup = options.groups[nodeGroupIndex]
|
|
16
|
+
let nextNodeGroup = options.groups[nextNodeGroupIndex]
|
|
18
17
|
if (
|
|
19
18
|
Array.isArray(options.customGroups) &&
|
|
20
19
|
typeof nodeGroup === 'string' &&
|
|
@@ -32,19 +31,26 @@ let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
|
|
|
32
31
|
nextNodeCustomGroup &&
|
|
33
32
|
nodeCustomGroup.groupName === nextNodeCustomGroup.groupName
|
|
34
33
|
) {
|
|
35
|
-
|
|
34
|
+
if (nodeCustomGroup.newlinesInside !== void 0) {
|
|
35
|
+
return convertNewlinesBetweenOptionToNumber(
|
|
36
|
+
nodeCustomGroup.newlinesInside,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
return globalNewlinesBetweenOption
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
if (
|
|
39
|
-
if (
|
|
40
|
-
let groupBetween = options.groups[
|
|
42
|
+
if (nextNodeGroupIndex >= nodeGroupIndex + 2) {
|
|
43
|
+
if (nextNodeGroupIndex === nodeGroupIndex + 2) {
|
|
44
|
+
let groupBetween = options.groups[nodeGroupIndex + 1]
|
|
41
45
|
if (isNewlinesBetweenOption.isNewlinesBetweenOption(groupBetween)) {
|
|
42
|
-
return
|
|
46
|
+
return convertNewlinesBetweenOptionToNumber(
|
|
47
|
+
groupBetween.newlinesBetween,
|
|
48
|
+
)
|
|
43
49
|
}
|
|
44
50
|
} else {
|
|
45
51
|
let relevantGroups = options.groups.slice(
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
nodeGroupIndex,
|
|
53
|
+
nextNodeGroupIndex + 1,
|
|
48
54
|
)
|
|
49
55
|
let groupsWithAllNewlinesBetween = buildGroupsWithAllNewlinesBetween(
|
|
50
56
|
relevantGroups,
|
|
@@ -53,33 +59,43 @@ let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
|
|
|
53
59
|
let newlinesBetweenOptions = new Set(
|
|
54
60
|
groupsWithAllNewlinesBetween
|
|
55
61
|
.filter(isNewlinesBetweenOption.isNewlinesBetweenOption)
|
|
56
|
-
.map(group => group.newlinesBetween)
|
|
62
|
+
.map(group => group.newlinesBetween)
|
|
63
|
+
.map(convertNewlinesBetweenOptionToNumber),
|
|
64
|
+
)
|
|
65
|
+
let numberNewlinesBetween = [...newlinesBetweenOptions].filter(
|
|
66
|
+
option => typeof option === 'number',
|
|
57
67
|
)
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
let maxNewlinesBetween =
|
|
69
|
+
numberNewlinesBetween.length > 0
|
|
70
|
+
? Math.max(...numberNewlinesBetween)
|
|
71
|
+
: null
|
|
72
|
+
if (maxNewlinesBetween !== null && maxNewlinesBetween >= 1) {
|
|
73
|
+
return maxNewlinesBetween
|
|
60
74
|
}
|
|
61
75
|
if (newlinesBetweenOptions.has('ignore')) {
|
|
62
76
|
return 'ignore'
|
|
63
77
|
}
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
78
|
+
if (maxNewlinesBetween === 0) {
|
|
79
|
+
return 0
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
82
|
}
|
|
69
83
|
return globalNewlinesBetweenOption
|
|
70
84
|
}
|
|
71
85
|
let getGlobalNewlinesBetweenOption = ({
|
|
72
|
-
|
|
86
|
+
nextNodeGroupIndex,
|
|
73
87
|
newlinesBetween,
|
|
74
|
-
|
|
88
|
+
nodeGroupIndex,
|
|
75
89
|
}) => {
|
|
76
|
-
|
|
90
|
+
let numberNewlinesBetween =
|
|
91
|
+
convertNewlinesBetweenOptionToNumber(newlinesBetween)
|
|
92
|
+
if (numberNewlinesBetween === 'ignore') {
|
|
77
93
|
return 'ignore'
|
|
78
94
|
}
|
|
79
|
-
if (
|
|
80
|
-
return
|
|
95
|
+
if (nodeGroupIndex === nextNodeGroupIndex) {
|
|
96
|
+
return 0
|
|
81
97
|
}
|
|
82
|
-
return
|
|
98
|
+
return numberNewlinesBetween
|
|
83
99
|
}
|
|
84
100
|
let buildGroupsWithAllNewlinesBetween = (
|
|
85
101
|
groups,
|
|
@@ -94,11 +110,29 @@ let buildGroupsWithAllNewlinesBetween = (
|
|
|
94
110
|
previousGroup &&
|
|
95
111
|
!isNewlinesBetweenOption.isNewlinesBetweenOption(previousGroup)
|
|
96
112
|
) {
|
|
97
|
-
returnValue.push({
|
|
113
|
+
returnValue.push({
|
|
114
|
+
newlinesBetween: globalNewlinesBetweenOption,
|
|
115
|
+
})
|
|
98
116
|
}
|
|
99
117
|
}
|
|
100
118
|
returnValue.push(group)
|
|
101
119
|
}
|
|
102
120
|
return returnValue
|
|
103
121
|
}
|
|
122
|
+
let convertNewlinesBetweenOptionToNumber = newlinesBetween => {
|
|
123
|
+
if (typeof newlinesBetween === 'number') {
|
|
124
|
+
return newlinesBetween
|
|
125
|
+
}
|
|
126
|
+
switch (newlinesBetween) {
|
|
127
|
+
case 'ignore':
|
|
128
|
+
return 'ignore'
|
|
129
|
+
case 'always':
|
|
130
|
+
return 1
|
|
131
|
+
case 'never':
|
|
132
|
+
return 0
|
|
133
|
+
/* v8 ignore next 2 */
|
|
134
|
+
default:
|
|
135
|
+
throw new unreachableCaseError.UnreachableCaseError(newlinesBetween)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
104
138
|
exports.getNewlinesBetweenOption = getNewlinesBetweenOption
|
package/dist/utils/make-fixes.js
CHANGED
|
@@ -31,7 +31,10 @@ let makeFixes = ({
|
|
|
31
31
|
if (commentAfterFixes.length > 0) {
|
|
32
32
|
return [...orderFixes, ...commentAfterFixes]
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (
|
|
35
|
+
(options == null ? void 0 : options.groups) &&
|
|
36
|
+
options.newlinesBetween !== void 0
|
|
37
|
+
) {
|
|
35
38
|
let newlinesFixes = makeNewlinesBetweenFixes.makeNewlinesBetweenFixes({
|
|
36
39
|
options: {
|
|
37
40
|
...options,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const getNewlinesBetweenOption = require('./get-newlines-between-option.js')
|
|
4
4
|
const getLinesBetween = require('./get-lines-between.js')
|
|
5
|
+
const getGroupIndex = require('./get-group-index.js')
|
|
5
6
|
const getNodeRange = require('./get-node-range.js')
|
|
6
7
|
let makeNewlinesBetweenFixes = ({
|
|
7
8
|
newlinesBetweenValueGetter,
|
|
@@ -17,9 +18,23 @@ let makeNewlinesBetweenFixes = ({
|
|
|
17
18
|
let nextSortingNode = nodes.at(i + 1)
|
|
18
19
|
let sortedSortingNode = sortedNodes.at(i)
|
|
19
20
|
let nextSortedSortingNode = sortedNodes.at(i + 1)
|
|
21
|
+
if (sortedSortingNode.partitionId !== nextSortedSortingNode.partitionId) {
|
|
22
|
+
continue
|
|
23
|
+
}
|
|
24
|
+
let nodeGroupIndex = getGroupIndex.getGroupIndex(
|
|
25
|
+
options.groups,
|
|
26
|
+
sortedSortingNode,
|
|
27
|
+
)
|
|
28
|
+
let nextNodeGroupIndex = getGroupIndex.getGroupIndex(
|
|
29
|
+
options.groups,
|
|
30
|
+
nextSortedSortingNode,
|
|
31
|
+
)
|
|
32
|
+
if (nodeGroupIndex > nextNodeGroupIndex) {
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
20
35
|
let newlinesBetween = getNewlinesBetweenOption.getNewlinesBetweenOption({
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
nextNodeGroupIndex,
|
|
37
|
+
nodeGroupIndex,
|
|
23
38
|
options,
|
|
24
39
|
})
|
|
25
40
|
newlinesBetween =
|
|
@@ -43,39 +58,50 @@ let makeNewlinesBetweenFixes = ({
|
|
|
43
58
|
sourceCode,
|
|
44
59
|
})
|
|
45
60
|
.at(0)
|
|
46
|
-
let rangeToReplace = [currentNodeRange.at(1), nextNodeRangeStart]
|
|
47
|
-
let textBetweenNodes = sourceCode.text.slice(
|
|
48
|
-
currentNodeRange.at(1),
|
|
49
|
-
nextNodeRangeStart,
|
|
50
|
-
)
|
|
51
61
|
let linesBetweenMembers = getLinesBetween.getLinesBetween(
|
|
52
62
|
sourceCode,
|
|
53
63
|
sortingNode,
|
|
54
64
|
nextSortingNode,
|
|
55
65
|
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rangeReplacement = getStringWithoutInvalidNewlines(textBetweenNodes)
|
|
59
|
-
}
|
|
60
|
-
if (newlinesBetween === 'always' && linesBetweenMembers !== 1) {
|
|
61
|
-
rangeReplacement = addNewlineBeforeFirstNewline(
|
|
62
|
-
linesBetweenMembers > 1
|
|
63
|
-
? getStringWithoutInvalidNewlines(textBetweenNodes)
|
|
64
|
-
: textBetweenNodes,
|
|
65
|
-
)
|
|
66
|
-
let isOnSameLine =
|
|
67
|
-
linesBetweenMembers === 0 &&
|
|
68
|
-
sortingNode.node.loc.end.line === nextSortingNode.node.loc.start.line
|
|
69
|
-
if (isOnSameLine) {
|
|
70
|
-
rangeReplacement = addNewlineBeforeFirstNewline(rangeReplacement)
|
|
71
|
-
}
|
|
66
|
+
if (linesBetweenMembers === newlinesBetween) {
|
|
67
|
+
continue
|
|
72
68
|
}
|
|
69
|
+
let rangeToReplace = [currentNodeRange.at(1), nextNodeRangeStart]
|
|
70
|
+
let textBetweenNodes = sourceCode.text.slice(
|
|
71
|
+
currentNodeRange.at(1),
|
|
72
|
+
nextNodeRangeStart,
|
|
73
|
+
)
|
|
74
|
+
let rangeReplacement = computeRangeReplacement({
|
|
75
|
+
isOnSameLine:
|
|
76
|
+
sortingNode.node.loc.end.line === nextSortingNode.node.loc.start.line,
|
|
77
|
+
textBetweenNodes,
|
|
78
|
+
newlinesBetween,
|
|
79
|
+
})
|
|
73
80
|
if (rangeReplacement) {
|
|
74
81
|
fixes.push(fixer.replaceTextRange(rangeToReplace, rangeReplacement))
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
return fixes
|
|
78
85
|
}
|
|
86
|
+
let computeRangeReplacement = ({
|
|
87
|
+
textBetweenNodes,
|
|
88
|
+
newlinesBetween,
|
|
89
|
+
isOnSameLine,
|
|
90
|
+
}) => {
|
|
91
|
+
let textBetweenNodesWithoutInvalidNewlines =
|
|
92
|
+
getStringWithoutInvalidNewlines(textBetweenNodes)
|
|
93
|
+
if (newlinesBetween === 0) {
|
|
94
|
+
return textBetweenNodesWithoutInvalidNewlines
|
|
95
|
+
}
|
|
96
|
+
let rangeReplacement = textBetweenNodesWithoutInvalidNewlines
|
|
97
|
+
for (let index = 0; index < newlinesBetween; index++) {
|
|
98
|
+
rangeReplacement = addNewlineBeforeFirstNewline(rangeReplacement)
|
|
99
|
+
}
|
|
100
|
+
if (!isOnSameLine) {
|
|
101
|
+
return rangeReplacement
|
|
102
|
+
}
|
|
103
|
+
return addNewlineBeforeFirstNewline(rangeReplacement)
|
|
104
|
+
}
|
|
79
105
|
let getStringWithoutInvalidNewlines = value =>
|
|
80
106
|
value.replaceAll(/\n\s*\n/gu, '\n').replaceAll(/\n+/gu, '\n')
|
|
81
107
|
let addNewlineBeforeFirstNewline = value => {
|
package/dist/utils/pairwise.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
-
const isSortable = require('./is-sortable.js')
|
|
4
3
|
let pairwise = (nodes, callback) => {
|
|
5
|
-
if (
|
|
4
|
+
if (nodes.length === 0) {
|
|
6
5
|
return
|
|
7
6
|
}
|
|
8
7
|
callback(null, nodes.at(0))
|
|
@@ -4,13 +4,13 @@ const getGroupIndex = require('./get-group-index.js')
|
|
|
4
4
|
const sortNodes = require('./sort-nodes.js')
|
|
5
5
|
let sortNodesByGroups = ({
|
|
6
6
|
ignoreEslintDisabledNodes,
|
|
7
|
-
|
|
7
|
+
getOptionsByGroupIndex,
|
|
8
8
|
isNodeIgnoredForGroup,
|
|
9
9
|
isNodeIgnored,
|
|
10
10
|
groups,
|
|
11
11
|
nodes,
|
|
12
12
|
}) => {
|
|
13
|
-
let
|
|
13
|
+
let nodesByNonIgnoredGroupIndex = {}
|
|
14
14
|
let ignoredNodeIndices = []
|
|
15
15
|
for (let [index, sortingNode] of nodes.entries()) {
|
|
16
16
|
if (
|
|
@@ -20,18 +20,18 @@ let sortNodesByGroups = ({
|
|
|
20
20
|
ignoredNodeIndices.push(index)
|
|
21
21
|
continue
|
|
22
22
|
}
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
23
|
+
let groupIndex = getGroupIndex.getGroupIndex(groups, sortingNode)
|
|
24
|
+
nodesByNonIgnoredGroupIndex[groupIndex] ??
|
|
25
|
+
(nodesByNonIgnoredGroupIndex[groupIndex] = [])
|
|
26
|
+
nodesByNonIgnoredGroupIndex[groupIndex].push(sortingNode)
|
|
27
27
|
}
|
|
28
28
|
let sortedNodes = []
|
|
29
|
-
for (let
|
|
29
|
+
for (let groupIndex of Object.keys(nodesByNonIgnoredGroupIndex).sort(
|
|
30
30
|
(a, b) => Number(a) - Number(b),
|
|
31
31
|
)) {
|
|
32
32
|
let { fallbackSortNodeValueGetter, nodeValueGetter, options } =
|
|
33
|
-
|
|
34
|
-
let nodesToPush =
|
|
33
|
+
getOptionsByGroupIndex(Number(groupIndex))
|
|
34
|
+
let nodesToPush = nodesByNonIgnoredGroupIndex[Number(groupIndex)]
|
|
35
35
|
let groupIgnoredNodes = new Set(
|
|
36
36
|
nodesToPush.filter(node =>
|
|
37
37
|
isNodeIgnoredForGroup == null
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
class UnreachableCaseError extends Error {
|
|
4
|
+
constructor(value) {
|
|
5
|
+
super(`Unreachable case: ${value}`)
|
|
6
|
+
this.name = 'UnreachableCaseError'
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.UnreachableCaseError = UnreachableCaseError
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -23,12 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
26
28
|
"files": [
|
|
27
29
|
"./dist"
|
|
28
30
|
],
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@typescript-eslint/types": "^8.
|
|
31
|
-
"@typescript-eslint/utils": "^8.
|
|
32
|
+
"@typescript-eslint/types": "^8.34.1",
|
|
33
|
+
"@typescript-eslint/utils": "^8.34.1",
|
|
32
34
|
"natural-orderby": "^5.0.0"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|