eslint-plugin-perfectionist 3.2.0 → 3.4.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 +242 -21
- package/dist/index.js +3 -1
- package/dist/index.mjs +2 -0
- package/dist/rules/sort-array-includes.js +108 -107
- package/dist/rules/sort-array-includes.mjs +100 -100
- package/dist/rules/sort-astro-attributes.js +6 -0
- package/dist/rules/sort-astro-attributes.mjs +6 -0
- package/dist/rules/sort-classes-utils.js +102 -0
- package/dist/rules/sort-classes-utils.mjs +105 -1
- package/dist/rules/sort-classes.js +263 -83
- package/dist/rules/sort-classes.mjs +263 -71
- package/dist/rules/sort-classes.types.js +71 -0
- package/dist/rules/sort-classes.types.mjs +71 -0
- package/dist/rules/sort-enums.js +41 -14
- package/dist/rules/sort-enums.mjs +41 -10
- package/dist/rules/sort-imports.js +28 -0
- package/dist/rules/sort-imports.mjs +28 -0
- package/dist/rules/sort-interfaces.js +6 -0
- package/dist/rules/sort-interfaces.mjs +6 -0
- package/dist/rules/sort-intersection-types.js +20 -0
- package/dist/rules/sort-intersection-types.mjs +20 -0
- package/dist/rules/sort-jsx-props.js +6 -0
- package/dist/rules/sort-jsx-props.mjs +6 -0
- package/dist/rules/sort-object-types.js +6 -0
- package/dist/rules/sort-object-types.mjs +6 -0
- package/dist/rules/sort-objects.js +34 -43
- package/dist/rules/sort-objects.mjs +28 -30
- package/dist/rules/sort-sets.js +48 -0
- package/dist/rules/sort-sets.mjs +47 -0
- package/dist/rules/sort-svelte-attributes.js +6 -0
- package/dist/rules/sort-svelte-attributes.mjs +6 -0
- package/dist/rules/sort-switch-case.js +6 -3
- package/dist/rules/sort-switch-case.mjs +6 -3
- package/dist/rules/sort-union-types.js +20 -0
- package/dist/rules/sort-union-types.mjs +20 -0
- package/dist/rules/sort-variable-declarations.js +8 -9
- package/dist/rules/sort-variable-declarations.mjs +6 -5
- package/dist/rules/sort-vue-attributes.js +6 -0
- package/dist/rules/sort-vue-attributes.mjs +6 -0
- package/dist/utils/compare.js +0 -6
- package/dist/utils/compare.mjs +0 -6
- package/dist/utils/sort-nodes-by-dependencies.js +30 -0
- package/dist/utils/sort-nodes-by-dependencies.mjs +28 -0
- package/dist/utils/validate-groups-configuration.js +19 -0
- package/dist/utils/validate-groups-configuration.mjs +17 -0
- package/package.json +4 -4
|
@@ -1,19 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOverloadSignatureGroups,
|
|
3
|
+
generateOfficialGroups,
|
|
4
|
+
customGroupMatches,
|
|
5
|
+
getCompareOptions,
|
|
6
|
+
} from './sort-classes-utils.mjs'
|
|
7
|
+
import {
|
|
8
|
+
customGroupNameJsonSchema,
|
|
9
|
+
customGroupSortJsonSchema,
|
|
10
|
+
singleCustomGroupJsonSchema,
|
|
11
|
+
} from './sort-classes.types.mjs'
|
|
12
|
+
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.mjs'
|
|
1
13
|
import { isPartitionComment } from '../utils/is-partition-comment.mjs'
|
|
2
14
|
import { getCommentBefore } from '../utils/get-comment-before.mjs'
|
|
3
15
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
4
|
-
import { generateOfficialGroups } from './sort-classes-utils.mjs'
|
|
5
16
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
6
17
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
7
18
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
8
19
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
9
20
|
import { getSettings } from '../utils/get-settings.mjs'
|
|
10
|
-
import { isPositive } from '../utils/is-positive.mjs'
|
|
11
21
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
12
22
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
13
23
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
14
24
|
import { complete } from '../utils/complete.mjs'
|
|
15
25
|
import { pairwise } from '../utils/pairwise.mjs'
|
|
16
|
-
import { compare } from '../utils/compare.mjs'
|
|
17
26
|
const sortClasses = createEslintRule({
|
|
18
27
|
name: 'sort-classes',
|
|
19
28
|
meta: {
|
|
@@ -79,20 +88,62 @@ const sortClasses = createEslintRule({
|
|
|
79
88
|
},
|
|
80
89
|
customGroups: {
|
|
81
90
|
description: 'Specifies custom groups.',
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
|
|
91
|
+
oneOf: [
|
|
92
|
+
{
|
|
93
|
+
type: 'object',
|
|
94
|
+
additionalProperties: {
|
|
95
|
+
oneOf: [
|
|
96
|
+
{
|
|
97
|
+
type: 'string',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'array',
|
|
101
|
+
items: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
],
|
|
87
106
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: {
|
|
111
|
+
description: 'Advanced custom groups.',
|
|
112
|
+
oneOf: [
|
|
113
|
+
{
|
|
114
|
+
description: 'Custom group block.',
|
|
115
|
+
type: 'object',
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
properties: {
|
|
118
|
+
...customGroupNameJsonSchema,
|
|
119
|
+
...customGroupSortJsonSchema,
|
|
120
|
+
anyOf: {
|
|
121
|
+
type: 'array',
|
|
122
|
+
items: {
|
|
123
|
+
description: 'Custom group.',
|
|
124
|
+
type: 'object',
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
properties: {
|
|
127
|
+
...singleCustomGroupJsonSchema,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
description: 'Custom group.',
|
|
135
|
+
type: 'object',
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
properties: {
|
|
138
|
+
...customGroupNameJsonSchema,
|
|
139
|
+
...customGroupSortJsonSchema,
|
|
140
|
+
...singleCustomGroupJsonSchema,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
93
144
|
},
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
},
|
|
146
|
+
],
|
|
96
147
|
},
|
|
97
148
|
},
|
|
98
149
|
additionalProperties: false,
|
|
@@ -113,9 +164,10 @@ const sortClasses = createEslintRule({
|
|
|
113
164
|
groups: [
|
|
114
165
|
'index-signature',
|
|
115
166
|
'static-property',
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'property',
|
|
167
|
+
'static-block',
|
|
168
|
+
['protected-property', 'protected-accessor-property'],
|
|
169
|
+
['private-property', 'private-accessor-property'],
|
|
170
|
+
['property', 'accessor-property'],
|
|
119
171
|
'constructor',
|
|
120
172
|
'static-method',
|
|
121
173
|
'protected-method',
|
|
@@ -124,20 +176,22 @@ const sortClasses = createEslintRule({
|
|
|
124
176
|
['get-method', 'set-method'],
|
|
125
177
|
'unknown',
|
|
126
178
|
],
|
|
127
|
-
customGroups:
|
|
179
|
+
customGroups: [],
|
|
128
180
|
},
|
|
129
181
|
],
|
|
130
182
|
create: context => ({
|
|
131
183
|
ClassBody: node => {
|
|
184
|
+
var _a
|
|
132
185
|
if (node.body.length > 1) {
|
|
133
186
|
let settings = getSettings(context.settings)
|
|
134
187
|
let options = complete(context.options.at(0), settings, {
|
|
135
188
|
groups: [
|
|
136
189
|
'index-signature',
|
|
137
190
|
'static-property',
|
|
138
|
-
'
|
|
139
|
-
'
|
|
140
|
-
'property',
|
|
191
|
+
'static-block',
|
|
192
|
+
['protected-property', 'protected-accessor-property'],
|
|
193
|
+
['private-property', 'private-accessor-property'],
|
|
194
|
+
['property', 'accessor-property'],
|
|
141
195
|
'constructor',
|
|
142
196
|
'static-method',
|
|
143
197
|
'protected-method',
|
|
@@ -149,19 +203,76 @@ const sortClasses = createEslintRule({
|
|
|
149
203
|
partitionByComment: false,
|
|
150
204
|
type: 'alphabetical',
|
|
151
205
|
ignoreCase: true,
|
|
152
|
-
customGroups:
|
|
206
|
+
customGroups: [],
|
|
153
207
|
order: 'asc',
|
|
154
208
|
})
|
|
155
209
|
let sourceCode = getSourceCode(context)
|
|
156
|
-
let
|
|
210
|
+
let className = (_a = node.parent.id) == null ? void 0 : _a.name
|
|
211
|
+
let getDependencyName = (nodeName, isStatic) =>
|
|
212
|
+
`${isStatic ? 'static ' : ''}${nodeName}`
|
|
213
|
+
let classMethodsDependencyNames = new Set(
|
|
214
|
+
node.body
|
|
215
|
+
.map(member => {
|
|
216
|
+
if (
|
|
217
|
+
(member.type === 'MethodDefinition' ||
|
|
218
|
+
member.type === 'TSAbstractMethodDefinition') &&
|
|
219
|
+
'name' in member.key
|
|
220
|
+
) {
|
|
221
|
+
return getDependencyName(member.key.name, member.static)
|
|
222
|
+
}
|
|
223
|
+
return null
|
|
224
|
+
})
|
|
225
|
+
.filter(m => m !== null),
|
|
226
|
+
)
|
|
227
|
+
let extractDependencies = (expression, isMemberStatic) => {
|
|
157
228
|
let dependencies = []
|
|
158
229
|
let checkNode = nodeValue => {
|
|
230
|
+
if (
|
|
231
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
232
|
+
nodeValue.type === 'FunctionExpression'
|
|
233
|
+
) {
|
|
234
|
+
return
|
|
235
|
+
}
|
|
159
236
|
if (
|
|
160
237
|
nodeValue.type === 'MemberExpression' &&
|
|
161
|
-
nodeValue.object.type === 'ThisExpression'
|
|
238
|
+
(nodeValue.object.type === 'ThisExpression' ||
|
|
239
|
+
(nodeValue.object.type === 'Identifier' &&
|
|
240
|
+
nodeValue.object.name === className)) &&
|
|
162
241
|
nodeValue.property.type === 'Identifier'
|
|
163
242
|
) {
|
|
164
|
-
|
|
243
|
+
let isStaticDependency =
|
|
244
|
+
isMemberStatic || nodeValue.object.type === 'Identifier'
|
|
245
|
+
let dependencyName = getDependencyName(
|
|
246
|
+
nodeValue.property.name,
|
|
247
|
+
isStaticDependency,
|
|
248
|
+
)
|
|
249
|
+
if (!classMethodsDependencyNames.has(dependencyName)) {
|
|
250
|
+
dependencies.push(dependencyName)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (nodeValue.type === 'Property') {
|
|
254
|
+
traverseNode(nodeValue.key)
|
|
255
|
+
traverseNode(nodeValue.value)
|
|
256
|
+
}
|
|
257
|
+
if (nodeValue.type === 'ConditionalExpression') {
|
|
258
|
+
traverseNode(nodeValue.test)
|
|
259
|
+
traverseNode(nodeValue.consequent)
|
|
260
|
+
traverseNode(nodeValue.alternate)
|
|
261
|
+
}
|
|
262
|
+
if (
|
|
263
|
+
'expression' in nodeValue &&
|
|
264
|
+
typeof nodeValue.expression !== 'boolean'
|
|
265
|
+
) {
|
|
266
|
+
traverseNode(nodeValue.expression)
|
|
267
|
+
}
|
|
268
|
+
if ('object' in nodeValue) {
|
|
269
|
+
traverseNode(nodeValue.object)
|
|
270
|
+
}
|
|
271
|
+
if ('callee' in nodeValue) {
|
|
272
|
+
traverseNode(nodeValue.callee)
|
|
273
|
+
}
|
|
274
|
+
if ('init' in nodeValue && nodeValue.init) {
|
|
275
|
+
traverseNode(nodeValue.init)
|
|
165
276
|
}
|
|
166
277
|
if ('body' in nodeValue && nodeValue.body) {
|
|
167
278
|
traverseNode(nodeValue.body)
|
|
@@ -177,9 +288,18 @@ const sortClasses = createEslintRule({
|
|
|
177
288
|
.filter(currentNode => currentNode !== null)
|
|
178
289
|
.forEach(traverseNode)
|
|
179
290
|
}
|
|
291
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
292
|
+
traverseNode(nodeValue.argument)
|
|
293
|
+
}
|
|
180
294
|
if ('arguments' in nodeValue) {
|
|
181
295
|
nodeValue.arguments.forEach(traverseNode)
|
|
182
296
|
}
|
|
297
|
+
if ('declarations' in nodeValue) {
|
|
298
|
+
nodeValue.declarations.forEach(traverseNode)
|
|
299
|
+
}
|
|
300
|
+
if ('properties' in nodeValue) {
|
|
301
|
+
nodeValue.properties.forEach(traverseNode)
|
|
302
|
+
}
|
|
183
303
|
}
|
|
184
304
|
let traverseNode = nodeValue => {
|
|
185
305
|
if (Array.isArray(nodeValue)) {
|
|
@@ -191,9 +311,10 @@ const sortClasses = createEslintRule({
|
|
|
191
311
|
traverseNode(expression)
|
|
192
312
|
return dependencies
|
|
193
313
|
}
|
|
314
|
+
let overloadSignatureGroups = getOverloadSignatureGroups(node.body)
|
|
194
315
|
let formattedNodes = node.body.reduce(
|
|
195
316
|
(accumulator, member) => {
|
|
196
|
-
var
|
|
317
|
+
var _a2, _b, _c, _d
|
|
197
318
|
let comment = getCommentBefore(member, sourceCode)
|
|
198
319
|
if (
|
|
199
320
|
options.partitionByComment &&
|
|
@@ -212,9 +333,9 @@ const sortClasses = createEslintRule({
|
|
|
212
333
|
} else if (member.type === 'TSIndexSignature') {
|
|
213
334
|
name = sourceCode.text.slice(
|
|
214
335
|
member.range.at(0),
|
|
215
|
-
((
|
|
336
|
+
((_a2 = member.typeAnnotation) == null
|
|
216
337
|
? void 0
|
|
217
|
-
:
|
|
338
|
+
: _a2.range.at(0)) ?? member.range.at(1),
|
|
218
339
|
)
|
|
219
340
|
} else {
|
|
220
341
|
if (member.key.type === 'Identifier') {
|
|
@@ -223,9 +344,23 @@ const sortClasses = createEslintRule({
|
|
|
223
344
|
name = sourceCode.text.slice(...member.key.range)
|
|
224
345
|
}
|
|
225
346
|
}
|
|
226
|
-
let
|
|
227
|
-
|
|
228
|
-
|
|
347
|
+
let isPrivateHash =
|
|
348
|
+
'key' in member && member.key.type === 'PrivateIdentifier'
|
|
349
|
+
let decorated = false
|
|
350
|
+
let decorators = []
|
|
351
|
+
if ('decorators' in member) {
|
|
352
|
+
decorated = member.decorators.length > 0
|
|
353
|
+
for (let decorator of member.decorators) {
|
|
354
|
+
if (decorator.expression.type === 'Identifier') {
|
|
355
|
+
decorators.push(decorator.expression.name)
|
|
356
|
+
} else if (
|
|
357
|
+
decorator.expression.type === 'CallExpression' &&
|
|
358
|
+
decorator.expression.callee.type === 'Identifier'
|
|
359
|
+
) {
|
|
360
|
+
decorators.push(decorator.expression.callee.name)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
229
364
|
let modifiers = []
|
|
230
365
|
let selectors = []
|
|
231
366
|
if (
|
|
@@ -246,11 +381,14 @@ const sortClasses = createEslintRule({
|
|
|
246
381
|
}
|
|
247
382
|
if (member.accessibility === 'protected') {
|
|
248
383
|
modifiers.push('protected')
|
|
249
|
-
} else if (member.accessibility === 'private' ||
|
|
384
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
250
385
|
modifiers.push('private')
|
|
251
386
|
} else {
|
|
252
387
|
modifiers.push('public')
|
|
253
388
|
}
|
|
389
|
+
if (member.optional) {
|
|
390
|
+
modifiers.push('optional')
|
|
391
|
+
}
|
|
254
392
|
if (member.kind === 'constructor') {
|
|
255
393
|
selectors.push('constructor')
|
|
256
394
|
}
|
|
@@ -271,6 +409,7 @@ const sortClasses = createEslintRule({
|
|
|
271
409
|
selectors.push('index-signature')
|
|
272
410
|
} else if (member.type === 'StaticBlock') {
|
|
273
411
|
selectors.push('static-block')
|
|
412
|
+
dependencies = extractDependencies(member, true)
|
|
274
413
|
} else if (
|
|
275
414
|
member.type === 'AccessorProperty' ||
|
|
276
415
|
member.type === 'TSAbstractAccessorProperty'
|
|
@@ -289,7 +428,7 @@ const sortClasses = createEslintRule({
|
|
|
289
428
|
}
|
|
290
429
|
if (member.accessibility === 'protected') {
|
|
291
430
|
modifiers.push('protected')
|
|
292
|
-
} else if (member.accessibility === 'private' ||
|
|
431
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
293
432
|
modifiers.push('private')
|
|
294
433
|
} else {
|
|
295
434
|
modifiers.push('public')
|
|
@@ -316,20 +455,30 @@ const sortClasses = createEslintRule({
|
|
|
316
455
|
}
|
|
317
456
|
if (member.accessibility === 'protected') {
|
|
318
457
|
modifiers.push('protected')
|
|
319
|
-
} else if (member.accessibility === 'private' ||
|
|
458
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
320
459
|
modifiers.push('private')
|
|
321
460
|
} else {
|
|
322
461
|
modifiers.push('public')
|
|
323
462
|
}
|
|
324
|
-
if (
|
|
463
|
+
if (member.optional) {
|
|
464
|
+
modifiers.push('optional')
|
|
465
|
+
}
|
|
466
|
+
let isFunctionProperty =
|
|
325
467
|
((_b = member.value) == null ? void 0 : _b.type) ===
|
|
326
468
|
'ArrowFunctionExpression' ||
|
|
327
469
|
((_c = member.value) == null ? void 0 : _c.type) ===
|
|
328
470
|
'FunctionExpression'
|
|
329
|
-
) {
|
|
471
|
+
if (isFunctionProperty) {
|
|
330
472
|
selectors.push('function-property')
|
|
331
473
|
}
|
|
332
474
|
selectors.push('property')
|
|
475
|
+
if (
|
|
476
|
+
member.type === 'PropertyDefinition' &&
|
|
477
|
+
member.value &&
|
|
478
|
+
!isFunctionProperty
|
|
479
|
+
) {
|
|
480
|
+
dependencies = extractDependencies(member.value, member.static)
|
|
481
|
+
}
|
|
333
482
|
}
|
|
334
483
|
for (let officialGroup of generateOfficialGroups(
|
|
335
484
|
modifiers,
|
|
@@ -337,18 +486,46 @@ const sortClasses = createEslintRule({
|
|
|
337
486
|
)) {
|
|
338
487
|
defineGroup(officialGroup)
|
|
339
488
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
489
|
+
if (Array.isArray(options.customGroups)) {
|
|
490
|
+
for (let customGroup of options.customGroups) {
|
|
491
|
+
if (
|
|
492
|
+
customGroupMatches({
|
|
493
|
+
customGroup,
|
|
494
|
+
elementName: name,
|
|
495
|
+
modifiers,
|
|
496
|
+
selectors,
|
|
497
|
+
decorators,
|
|
498
|
+
})
|
|
499
|
+
) {
|
|
500
|
+
defineGroup(customGroup.groupName, true)
|
|
501
|
+
if (getGroup() === customGroup.groupName) {
|
|
502
|
+
break
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
setCustomGroups(options.customGroups, name, {
|
|
508
|
+
override: true,
|
|
509
|
+
})
|
|
345
510
|
}
|
|
511
|
+
let overloadSignatureGroupMember =
|
|
512
|
+
(_d = overloadSignatureGroups.find(overloadSignatures =>
|
|
513
|
+
overloadSignatures.includes(member),
|
|
514
|
+
)) == null
|
|
515
|
+
? void 0
|
|
516
|
+
: _d.at(-1)
|
|
346
517
|
let value = {
|
|
347
|
-
size:
|
|
518
|
+
size: overloadSignatureGroupMember
|
|
519
|
+
? rangeToDiff(overloadSignatureGroupMember.range)
|
|
520
|
+
: rangeToDiff(member.range),
|
|
348
521
|
group: getGroup(),
|
|
349
522
|
node: member,
|
|
350
523
|
dependencies,
|
|
351
524
|
name,
|
|
525
|
+
dependencyName: getDependencyName(
|
|
526
|
+
name,
|
|
527
|
+
modifiers.includes('static'),
|
|
528
|
+
),
|
|
352
529
|
}
|
|
353
530
|
accumulator.at(-1).push(value)
|
|
354
531
|
return accumulator
|
|
@@ -356,15 +533,49 @@ const sortClasses = createEslintRule({
|
|
|
356
533
|
[[]],
|
|
357
534
|
)
|
|
358
535
|
for (let nodes of formattedNodes) {
|
|
536
|
+
let nodesByNonIgnoredGroupNumber = {}
|
|
537
|
+
let ignoredNodeIndices = []
|
|
538
|
+
for (let [index, sortingNode] of nodes.entries()) {
|
|
539
|
+
let groupNum = getGroupNumber(options.groups, sortingNode)
|
|
540
|
+
if (groupNum === options.groups.length) {
|
|
541
|
+
ignoredNodeIndices.push(index)
|
|
542
|
+
continue
|
|
543
|
+
}
|
|
544
|
+
nodesByNonIgnoredGroupNumber[groupNum] =
|
|
545
|
+
nodesByNonIgnoredGroupNumber[groupNum] ?? []
|
|
546
|
+
nodesByNonIgnoredGroupNumber[groupNum].push(sortingNode)
|
|
547
|
+
}
|
|
548
|
+
let sortedNodes = []
|
|
549
|
+
for (let groupNumber of Object.keys(
|
|
550
|
+
nodesByNonIgnoredGroupNumber,
|
|
551
|
+
).sort((a, b) => Number(a) - Number(b))) {
|
|
552
|
+
let compareOptions = getCompareOptions(options, Number(groupNumber))
|
|
553
|
+
if (!compareOptions) {
|
|
554
|
+
sortedNodes.push(
|
|
555
|
+
...nodesByNonIgnoredGroupNumber[Number(groupNumber)],
|
|
556
|
+
)
|
|
557
|
+
} else {
|
|
558
|
+
sortedNodes.push(
|
|
559
|
+
...sortNodes(
|
|
560
|
+
nodesByNonIgnoredGroupNumber[Number(groupNumber)],
|
|
561
|
+
compareOptions,
|
|
562
|
+
),
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
for (let ignoredIndex of ignoredNodeIndices) {
|
|
567
|
+
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
|
|
568
|
+
}
|
|
569
|
+
sortedNodes = sortNodesByDependencies(sortedNodes)
|
|
359
570
|
pairwise(nodes, (left, right) => {
|
|
360
571
|
let leftNum = getGroupNumber(options.groups, left)
|
|
361
572
|
let rightNum = getGroupNumber(options.groups, right)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
) {
|
|
573
|
+
let isLeftOrRightIgnored =
|
|
574
|
+
leftNum === options.groups.length ||
|
|
575
|
+
rightNum === options.groups.length
|
|
576
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
577
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
578
|
+
if (!isLeftOrRightIgnored && indexOfLeft > indexOfRight) {
|
|
368
579
|
context.report({
|
|
369
580
|
messageId:
|
|
370
581
|
leftNum !== rightNum
|
|
@@ -377,29 +588,10 @@ const sortClasses = createEslintRule({
|
|
|
377
588
|
rightGroup: right.group,
|
|
378
589
|
},
|
|
379
590
|
node: right.node,
|
|
380
|
-
fix: fixer =>
|
|
381
|
-
|
|
382
|
-
let groupNum = getGroupNumber(options.groups, sortingNode)
|
|
383
|
-
if (!(groupNum in accumulator)) {
|
|
384
|
-
accumulator[groupNum] = [sortingNode]
|
|
385
|
-
} else {
|
|
386
|
-
accumulator[groupNum] = sortNodes(
|
|
387
|
-
[...accumulator[groupNum], sortingNode],
|
|
388
|
-
options,
|
|
389
|
-
)
|
|
390
|
-
}
|
|
391
|
-
return accumulator
|
|
392
|
-
}, {})
|
|
393
|
-
let sortedNodes = []
|
|
394
|
-
for (let group of Object.keys(grouped).sort(
|
|
395
|
-
(a, b) => Number(a) - Number(b),
|
|
396
|
-
)) {
|
|
397
|
-
sortedNodes.push(...sortNodes(grouped[group], options))
|
|
398
|
-
}
|
|
399
|
-
return makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
591
|
+
fix: fixer =>
|
|
592
|
+
makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
400
593
|
partitionComment: options.partitionByComment,
|
|
401
|
-
})
|
|
402
|
-
},
|
|
594
|
+
}),
|
|
403
595
|
})
|
|
404
596
|
}
|
|
405
597
|
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const allSelectors = [
|
|
4
|
+
'accessor-property',
|
|
5
|
+
'index-signature',
|
|
6
|
+
'constructor',
|
|
7
|
+
'static-block',
|
|
8
|
+
'get-method',
|
|
9
|
+
'set-method',
|
|
10
|
+
'function-property',
|
|
11
|
+
'property',
|
|
12
|
+
'method',
|
|
13
|
+
]
|
|
14
|
+
const allModifiers = [
|
|
15
|
+
'protected',
|
|
16
|
+
'private',
|
|
17
|
+
'public',
|
|
18
|
+
'static',
|
|
19
|
+
'abstract',
|
|
20
|
+
'override',
|
|
21
|
+
'readonly',
|
|
22
|
+
'decorated',
|
|
23
|
+
'declare',
|
|
24
|
+
'optional',
|
|
25
|
+
]
|
|
26
|
+
const customGroupSortJsonSchema = {
|
|
27
|
+
type: {
|
|
28
|
+
description: 'Custom group sort type.',
|
|
29
|
+
type: 'string',
|
|
30
|
+
enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
|
|
31
|
+
},
|
|
32
|
+
order: {
|
|
33
|
+
description: 'Custom group sort order.',
|
|
34
|
+
type: 'string',
|
|
35
|
+
enum: ['desc', 'asc'],
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
const customGroupNameJsonSchema = {
|
|
39
|
+
groupName: {
|
|
40
|
+
description: 'Custom group name.',
|
|
41
|
+
type: 'string',
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
const singleCustomGroupJsonSchema = {
|
|
45
|
+
selector: {
|
|
46
|
+
description: 'Selector filter.',
|
|
47
|
+
type: 'string',
|
|
48
|
+
enum: allSelectors,
|
|
49
|
+
},
|
|
50
|
+
modifiers: {
|
|
51
|
+
description: 'Modifier filters.',
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
enum: allModifiers,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
elementNamePattern: {
|
|
59
|
+
description: 'Element name pattern filter.',
|
|
60
|
+
type: 'string',
|
|
61
|
+
},
|
|
62
|
+
decoratorNamePattern: {
|
|
63
|
+
description: 'Decorator name pattern filter.',
|
|
64
|
+
type: 'string',
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
exports.allModifiers = allModifiers
|
|
68
|
+
exports.allSelectors = allSelectors
|
|
69
|
+
exports.customGroupNameJsonSchema = customGroupNameJsonSchema
|
|
70
|
+
exports.customGroupSortJsonSchema = customGroupSortJsonSchema
|
|
71
|
+
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const allSelectors = [
|
|
2
|
+
'accessor-property',
|
|
3
|
+
'index-signature',
|
|
4
|
+
'constructor',
|
|
5
|
+
'static-block',
|
|
6
|
+
'get-method',
|
|
7
|
+
'set-method',
|
|
8
|
+
'function-property',
|
|
9
|
+
'property',
|
|
10
|
+
'method',
|
|
11
|
+
]
|
|
12
|
+
const allModifiers = [
|
|
13
|
+
'protected',
|
|
14
|
+
'private',
|
|
15
|
+
'public',
|
|
16
|
+
'static',
|
|
17
|
+
'abstract',
|
|
18
|
+
'override',
|
|
19
|
+
'readonly',
|
|
20
|
+
'decorated',
|
|
21
|
+
'declare',
|
|
22
|
+
'optional',
|
|
23
|
+
]
|
|
24
|
+
const customGroupSortJsonSchema = {
|
|
25
|
+
type: {
|
|
26
|
+
description: 'Custom group sort type.',
|
|
27
|
+
type: 'string',
|
|
28
|
+
enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
|
|
29
|
+
},
|
|
30
|
+
order: {
|
|
31
|
+
description: 'Custom group sort order.',
|
|
32
|
+
type: 'string',
|
|
33
|
+
enum: ['desc', 'asc'],
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
const customGroupNameJsonSchema = {
|
|
37
|
+
groupName: {
|
|
38
|
+
description: 'Custom group name.',
|
|
39
|
+
type: 'string',
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
const singleCustomGroupJsonSchema = {
|
|
43
|
+
selector: {
|
|
44
|
+
description: 'Selector filter.',
|
|
45
|
+
type: 'string',
|
|
46
|
+
enum: allSelectors,
|
|
47
|
+
},
|
|
48
|
+
modifiers: {
|
|
49
|
+
description: 'Modifier filters.',
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
enum: allModifiers,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
elementNamePattern: {
|
|
57
|
+
description: 'Element name pattern filter.',
|
|
58
|
+
type: 'string',
|
|
59
|
+
},
|
|
60
|
+
decoratorNamePattern: {
|
|
61
|
+
description: 'Decorator name pattern filter.',
|
|
62
|
+
type: 'string',
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
allModifiers,
|
|
67
|
+
allSelectors,
|
|
68
|
+
customGroupNameJsonSchema,
|
|
69
|
+
customGroupSortJsonSchema,
|
|
70
|
+
singleCustomGroupJsonSchema,
|
|
71
|
+
}
|