eslint-plugin-perfectionist 3.3.0 → 3.5.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.
Files changed (45) hide show
  1. package/dist/index.d.ts +243 -21
  2. package/dist/index.js +3 -1
  3. package/dist/index.mjs +2 -0
  4. package/dist/rules/sort-array-includes.js +108 -107
  5. package/dist/rules/sort-array-includes.mjs +100 -100
  6. package/dist/rules/sort-astro-attributes.js +6 -0
  7. package/dist/rules/sort-astro-attributes.mjs +6 -0
  8. package/dist/rules/sort-classes-utils.js +71 -0
  9. package/dist/rules/sort-classes-utils.mjs +75 -1
  10. package/dist/rules/sort-classes.js +234 -79
  11. package/dist/rules/sort-classes.mjs +232 -69
  12. package/dist/rules/sort-classes.types.js +71 -0
  13. package/dist/rules/sort-classes.types.mjs +71 -0
  14. package/dist/rules/sort-enums.js +11 -15
  15. package/dist/rules/sort-enums.mjs +11 -11
  16. package/dist/rules/sort-imports.js +46 -5
  17. package/dist/rules/sort-imports.mjs +46 -5
  18. package/dist/rules/sort-interfaces.js +6 -0
  19. package/dist/rules/sort-interfaces.mjs +6 -0
  20. package/dist/rules/sort-intersection-types.js +20 -0
  21. package/dist/rules/sort-intersection-types.mjs +20 -0
  22. package/dist/rules/sort-jsx-props.js +6 -0
  23. package/dist/rules/sort-jsx-props.mjs +6 -0
  24. package/dist/rules/sort-object-types.js +6 -0
  25. package/dist/rules/sort-object-types.mjs +6 -0
  26. package/dist/rules/sort-objects.js +34 -43
  27. package/dist/rules/sort-objects.mjs +28 -30
  28. package/dist/rules/sort-sets.js +48 -0
  29. package/dist/rules/sort-sets.mjs +47 -0
  30. package/dist/rules/sort-svelte-attributes.js +6 -0
  31. package/dist/rules/sort-svelte-attributes.mjs +6 -0
  32. package/dist/rules/sort-union-types.js +20 -0
  33. package/dist/rules/sort-union-types.mjs +20 -0
  34. package/dist/rules/sort-variable-declarations.js +43 -14
  35. package/dist/rules/sort-variable-declarations.mjs +41 -10
  36. package/dist/rules/sort-vue-attributes.js +6 -0
  37. package/dist/rules/sort-vue-attributes.mjs +6 -0
  38. package/dist/utils/compare.js +0 -6
  39. package/dist/utils/compare.mjs +0 -6
  40. package/dist/utils/sort-nodes-by-dependencies.js +30 -0
  41. package/dist/utils/sort-nodes-by-dependencies.mjs +28 -0
  42. package/dist/utils/validate-groups-configuration.js +19 -0
  43. package/dist/utils/validate-groups-configuration.mjs +17 -0
  44. package/package.json +4 -4
  45. package/readme.md +1 -0
@@ -1,7 +1,15 @@
1
1
  import {
2
2
  getOverloadSignatureGroups,
3
3
  generateOfficialGroups,
4
+ customGroupMatches,
5
+ getCompareOptions,
4
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'
5
13
  import { isPartitionComment } from '../utils/is-partition-comment.mjs'
6
14
  import { getCommentBefore } from '../utils/get-comment-before.mjs'
7
15
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
@@ -10,13 +18,11 @@ import { getSourceCode } from '../utils/get-source-code.mjs'
10
18
  import { toSingleLine } from '../utils/to-single-line.mjs'
11
19
  import { rangeToDiff } from '../utils/range-to-diff.mjs'
12
20
  import { getSettings } from '../utils/get-settings.mjs'
13
- import { isPositive } from '../utils/is-positive.mjs'
14
21
  import { useGroups } from '../utils/use-groups.mjs'
15
22
  import { sortNodes } from '../utils/sort-nodes.mjs'
16
23
  import { makeFixes } from '../utils/make-fixes.mjs'
17
24
  import { complete } from '../utils/complete.mjs'
18
25
  import { pairwise } from '../utils/pairwise.mjs'
19
- import { compare } from '../utils/compare.mjs'
20
26
  const sortClasses = createEslintRule({
21
27
  name: 'sort-classes',
22
28
  meta: {
@@ -82,20 +88,62 @@ const sortClasses = createEslintRule({
82
88
  },
83
89
  customGroups: {
84
90
  description: 'Specifies custom groups.',
85
- type: 'object',
86
- additionalProperties: {
87
- oneOf: [
88
- {
89
- type: 'string',
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
+ ],
90
106
  },
91
- {
92
- type: 'array',
93
- items: {
94
- type: 'string',
95
- },
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
+ ],
96
144
  },
97
- ],
98
- },
145
+ },
146
+ ],
99
147
  },
100
148
  },
101
149
  additionalProperties: false,
@@ -114,9 +162,9 @@ const sortClasses = createEslintRule({
114
162
  ignoreCase: true,
115
163
  partitionByComment: false,
116
164
  groups: [
117
- 'static-block',
118
165
  'index-signature',
119
166
  'static-property',
167
+ 'static-block',
120
168
  ['protected-property', 'protected-accessor-property'],
121
169
  ['private-property', 'private-accessor-property'],
122
170
  ['property', 'accessor-property'],
@@ -128,18 +176,19 @@ const sortClasses = createEslintRule({
128
176
  ['get-method', 'set-method'],
129
177
  'unknown',
130
178
  ],
131
- customGroups: {},
179
+ customGroups: [],
132
180
  },
133
181
  ],
134
182
  create: context => ({
135
183
  ClassBody: node => {
184
+ var _a
136
185
  if (node.body.length > 1) {
137
186
  let settings = getSettings(context.settings)
138
187
  let options = complete(context.options.at(0), settings, {
139
188
  groups: [
140
- 'static-block',
141
189
  'index-signature',
142
190
  'static-property',
191
+ 'static-block',
143
192
  ['protected-property', 'protected-accessor-property'],
144
193
  ['private-property', 'private-accessor-property'],
145
194
  ['property', 'accessor-property'],
@@ -154,19 +203,76 @@ const sortClasses = createEslintRule({
154
203
  partitionByComment: false,
155
204
  type: 'alphabetical',
156
205
  ignoreCase: true,
157
- customGroups: {},
206
+ customGroups: [],
158
207
  order: 'asc',
159
208
  })
160
209
  let sourceCode = getSourceCode(context)
161
- let extractDependencies = expression => {
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) => {
162
228
  let dependencies = []
163
229
  let checkNode = nodeValue => {
230
+ if (
231
+ nodeValue.type === 'ArrowFunctionExpression' ||
232
+ nodeValue.type === 'FunctionExpression'
233
+ ) {
234
+ return
235
+ }
164
236
  if (
165
237
  nodeValue.type === 'MemberExpression' &&
166
- nodeValue.object.type === 'ThisExpression' &&
238
+ (nodeValue.object.type === 'ThisExpression' ||
239
+ (nodeValue.object.type === 'Identifier' &&
240
+ nodeValue.object.name === className)) &&
167
241
  nodeValue.property.type === 'Identifier'
168
242
  ) {
169
- dependencies.push(nodeValue.property.name)
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)
170
276
  }
171
277
  if ('body' in nodeValue && nodeValue.body) {
172
278
  traverseNode(nodeValue.body)
@@ -182,9 +288,21 @@ const sortClasses = createEslintRule({
182
288
  .filter(currentNode => currentNode !== null)
183
289
  .forEach(traverseNode)
184
290
  }
291
+ if ('argument' in nodeValue && nodeValue.argument) {
292
+ traverseNode(nodeValue.argument)
293
+ }
185
294
  if ('arguments' in nodeValue) {
186
295
  nodeValue.arguments.forEach(traverseNode)
187
296
  }
297
+ if ('declarations' in nodeValue) {
298
+ nodeValue.declarations.forEach(traverseNode)
299
+ }
300
+ if ('properties' in nodeValue) {
301
+ nodeValue.properties.forEach(traverseNode)
302
+ }
303
+ if ('expressions' in nodeValue) {
304
+ nodeValue.expressions.forEach(traverseNode)
305
+ }
188
306
  }
189
307
  let traverseNode = nodeValue => {
190
308
  if (Array.isArray(nodeValue)) {
@@ -199,7 +317,7 @@ const sortClasses = createEslintRule({
199
317
  let overloadSignatureGroups = getOverloadSignatureGroups(node.body)
200
318
  let formattedNodes = node.body.reduce(
201
319
  (accumulator, member) => {
202
- var _a, _b, _c, _d
320
+ var _a2, _b, _c, _d
203
321
  let comment = getCommentBefore(member, sourceCode)
204
322
  if (
205
323
  options.partitionByComment &&
@@ -218,9 +336,9 @@ const sortClasses = createEslintRule({
218
336
  } else if (member.type === 'TSIndexSignature') {
219
337
  name = sourceCode.text.slice(
220
338
  member.range.at(0),
221
- ((_a = member.typeAnnotation) == null
339
+ ((_a2 = member.typeAnnotation) == null
222
340
  ? void 0
223
- : _a.range.at(0)) ?? member.range.at(1),
341
+ : _a2.range.at(0)) ?? member.range.at(1),
224
342
  )
225
343
  } else {
226
344
  if (member.key.type === 'Identifier') {
@@ -231,8 +349,21 @@ const sortClasses = createEslintRule({
231
349
  }
232
350
  let isPrivateHash =
233
351
  'key' in member && member.key.type === 'PrivateIdentifier'
234
- let decorated =
235
- 'decorators' in member && member.decorators.length > 0
352
+ let decorated = false
353
+ let decorators = []
354
+ if ('decorators' in member) {
355
+ decorated = member.decorators.length > 0
356
+ for (let decorator of member.decorators) {
357
+ if (decorator.expression.type === 'Identifier') {
358
+ decorators.push(decorator.expression.name)
359
+ } else if (
360
+ decorator.expression.type === 'CallExpression' &&
361
+ decorator.expression.callee.type === 'Identifier'
362
+ ) {
363
+ decorators.push(decorator.expression.callee.name)
364
+ }
365
+ }
366
+ }
236
367
  let modifiers = []
237
368
  let selectors = []
238
369
  if (
@@ -281,6 +412,7 @@ const sortClasses = createEslintRule({
281
412
  selectors.push('index-signature')
282
413
  } else if (member.type === 'StaticBlock') {
283
414
  selectors.push('static-block')
415
+ dependencies = extractDependencies(member, true)
284
416
  } else if (
285
417
  member.type === 'AccessorProperty' ||
286
418
  member.type === 'TSAbstractAccessorProperty'
@@ -334,15 +466,22 @@ const sortClasses = createEslintRule({
334
466
  if (member.optional) {
335
467
  modifiers.push('optional')
336
468
  }
337
- if (
469
+ let isFunctionProperty =
338
470
  ((_b = member.value) == null ? void 0 : _b.type) ===
339
471
  'ArrowFunctionExpression' ||
340
472
  ((_c = member.value) == null ? void 0 : _c.type) ===
341
473
  'FunctionExpression'
342
- ) {
474
+ if (isFunctionProperty) {
343
475
  selectors.push('function-property')
344
476
  }
345
477
  selectors.push('property')
478
+ if (
479
+ member.type === 'PropertyDefinition' &&
480
+ member.value &&
481
+ !isFunctionProperty
482
+ ) {
483
+ dependencies = extractDependencies(member.value, member.static)
484
+ }
346
485
  }
347
486
  for (let officialGroup of generateOfficialGroups(
348
487
  modifiers,
@@ -350,11 +489,27 @@ const sortClasses = createEslintRule({
350
489
  )) {
351
490
  defineGroup(officialGroup)
352
491
  }
353
- setCustomGroups(options.customGroups, name, {
354
- override: true,
355
- })
356
- if (member.type === 'PropertyDefinition' && member.value) {
357
- dependencies = extractDependencies(member.value)
492
+ if (Array.isArray(options.customGroups)) {
493
+ for (let customGroup of options.customGroups) {
494
+ if (
495
+ customGroupMatches({
496
+ customGroup,
497
+ elementName: name,
498
+ modifiers,
499
+ selectors,
500
+ decorators,
501
+ })
502
+ ) {
503
+ defineGroup(customGroup.groupName, true)
504
+ if (getGroup() === customGroup.groupName) {
505
+ break
506
+ }
507
+ }
508
+ }
509
+ } else {
510
+ setCustomGroups(options.customGroups, name, {
511
+ override: true,
512
+ })
358
513
  }
359
514
  let overloadSignatureGroupMember =
360
515
  (_d = overloadSignatureGroups.find(overloadSignatures =>
@@ -370,6 +525,10 @@ const sortClasses = createEslintRule({
370
525
  node: member,
371
526
  dependencies,
372
527
  name,
528
+ dependencyName: getDependencyName(
529
+ name,
530
+ modifiers.includes('static'),
531
+ ),
373
532
  }
374
533
  accumulator.at(-1).push(value)
375
534
  return accumulator
@@ -377,18 +536,49 @@ const sortClasses = createEslintRule({
377
536
  [[]],
378
537
  )
379
538
  for (let nodes of formattedNodes) {
539
+ let nodesByNonIgnoredGroupNumber = {}
540
+ let ignoredNodeIndices = []
541
+ for (let [index, sortingNode] of nodes.entries()) {
542
+ let groupNum = getGroupNumber(options.groups, sortingNode)
543
+ if (groupNum === options.groups.length) {
544
+ ignoredNodeIndices.push(index)
545
+ continue
546
+ }
547
+ nodesByNonIgnoredGroupNumber[groupNum] =
548
+ nodesByNonIgnoredGroupNumber[groupNum] ?? []
549
+ nodesByNonIgnoredGroupNumber[groupNum].push(sortingNode)
550
+ }
551
+ let sortedNodes = []
552
+ for (let groupNumber of Object.keys(
553
+ nodesByNonIgnoredGroupNumber,
554
+ ).sort((a, b) => Number(a) - Number(b))) {
555
+ let compareOptions = getCompareOptions(options, Number(groupNumber))
556
+ if (!compareOptions) {
557
+ sortedNodes.push(
558
+ ...nodesByNonIgnoredGroupNumber[Number(groupNumber)],
559
+ )
560
+ } else {
561
+ sortedNodes.push(
562
+ ...sortNodes(
563
+ nodesByNonIgnoredGroupNumber[Number(groupNumber)],
564
+ compareOptions,
565
+ ),
566
+ )
567
+ }
568
+ }
569
+ for (let ignoredIndex of ignoredNodeIndices) {
570
+ sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
571
+ }
572
+ sortedNodes = sortNodesByDependencies(sortedNodes)
380
573
  pairwise(nodes, (left, right) => {
381
574
  let leftNum = getGroupNumber(options.groups, left)
382
575
  let rightNum = getGroupNumber(options.groups, right)
383
576
  let isLeftOrRightIgnored =
384
577
  leftNum === options.groups.length ||
385
578
  rightNum === options.groups.length
386
- if (
387
- !isLeftOrRightIgnored &&
388
- (leftNum > rightNum ||
389
- (leftNum === rightNum &&
390
- isPositive(compare(left, right, options))))
391
- ) {
579
+ let indexOfLeft = sortedNodes.indexOf(left)
580
+ let indexOfRight = sortedNodes.indexOf(right)
581
+ if (!isLeftOrRightIgnored && indexOfLeft > indexOfRight) {
392
582
  context.report({
393
583
  messageId:
394
584
  leftNum !== rightNum
@@ -401,37 +591,10 @@ const sortClasses = createEslintRule({
401
591
  rightGroup: right.group,
402
592
  },
403
593
  node: right.node,
404
- fix: fixer => {
405
- let nodesByNonIgnoredGroupNumber = {}
406
- let ignoredNodeIndices = []
407
- for (let [index, sortingNode] of nodes.entries()) {
408
- let groupNum = getGroupNumber(options.groups, sortingNode)
409
- if (groupNum === options.groups.length) {
410
- ignoredNodeIndices.push(index)
411
- continue
412
- }
413
- nodesByNonIgnoredGroupNumber[groupNum] =
414
- nodesByNonIgnoredGroupNumber[groupNum] ?? []
415
- nodesByNonIgnoredGroupNumber[groupNum].push(sortingNode)
416
- }
417
- let sortedNodes = []
418
- for (let groupNumber of Object.keys(
419
- nodesByNonIgnoredGroupNumber,
420
- ).sort((a, b) => Number(a) - Number(b))) {
421
- sortedNodes.push(
422
- ...sortNodes(
423
- nodesByNonIgnoredGroupNumber[Number(groupNumber)],
424
- options,
425
- ),
426
- )
427
- }
428
- for (let ignoredIndex of ignoredNodeIndices) {
429
- sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
430
- }
431
- return makeFixes(fixer, nodes, sortedNodes, sourceCode, {
594
+ fix: fixer =>
595
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, {
432
596
  partitionComment: options.partitionByComment,
433
- })
434
- },
597
+ }),
435
598
  })
436
599
  }
437
600
  })
@@ -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
+ }
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
2
3
  const isPartitionComment = require('../utils/is-partition-comment.js')
3
4
  const createEslintRule = require('../utils/create-eslint-rule.js')
4
5
  const getCommentBefore = require('../utils/get-comment-before.js')
@@ -6,12 +7,10 @@ const getSourceCode = require('../utils/get-source-code.js')
6
7
  const toSingleLine = require('../utils/to-single-line.js')
7
8
  const rangeToDiff = require('../utils/range-to-diff.js')
8
9
  const getSettings = require('../utils/get-settings.js')
9
- const isPositive = require('../utils/is-positive.js')
10
10
  const sortNodes = require('../utils/sort-nodes.js')
11
11
  const makeFixes = require('../utils/make-fixes.js')
12
12
  const complete = require('../utils/complete.js')
13
13
  const pairwise = require('../utils/pairwise.js')
14
- const compare = require('../utils/compare.js')
15
14
  const sortEnums = createEslintRule.createEslintRule({
16
15
  name: 'sort-enums',
17
16
  meta: {
@@ -153,7 +152,7 @@ const sortEnums = createEslintRule.createEslintRule({
153
152
  member.id.type === 'Literal'
154
153
  ? `${member.id.value}`
155
154
  : `${sourceCode.text.slice(...member.id.range)}`
156
- let dependencies
155
+ let dependencies = []
157
156
  if (member.initializer) {
158
157
  dependencies = extractDependencies(
159
158
  member.initializer,
@@ -208,12 +207,13 @@ const sortEnums = createEslintRule.createEslintRule({
208
207
  : void 0,
209
208
  }
210
209
  for (let nodes of formattedMembers) {
210
+ let sortedNodes = sortNodesByDependencies.sortNodesByDependencies(
211
+ sortNodes.sortNodes(nodes, compareOptions),
212
+ )
211
213
  pairwise.pairwise(nodes, (left, right) => {
212
- if (
213
- isPositive.isPositive(
214
- compare.compare(left, right, compareOptions),
215
- )
216
- ) {
214
+ let indexOfLeft = sortedNodes.indexOf(left)
215
+ let indexOfRight = sortedNodes.indexOf(right)
216
+ if (indexOfLeft > indexOfRight) {
217
217
  context.report({
218
218
  messageId: 'unexpectedEnumsOrder',
219
219
  data: {
@@ -222,13 +222,9 @@ const sortEnums = createEslintRule.createEslintRule({
222
222
  },
223
223
  node: right.node,
224
224
  fix: fixer =>
225
- makeFixes.makeFixes(
226
- fixer,
227
- nodes,
228
- sortNodes.sortNodes(nodes, compareOptions),
229
- sourceCode,
230
- { partitionComment },
231
- ),
225
+ makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
226
+ partitionComment,
227
+ }),
232
228
  })
233
229
  }
234
230
  })