eslint-plugin-perfectionist 3.3.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.
Files changed (44) hide show
  1. package/dist/index.d.ts +242 -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 +231 -79
  11. package/dist/rules/sort-classes.mjs +229 -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 +28 -0
  17. package/dist/rules/sort-imports.mjs +28 -0
  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 +8 -9
  35. package/dist/rules/sort-variable-declarations.mjs +6 -5
  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
@@ -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,18 @@ 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
+ }
188
303
  }
189
304
  let traverseNode = nodeValue => {
190
305
  if (Array.isArray(nodeValue)) {
@@ -199,7 +314,7 @@ const sortClasses = createEslintRule({
199
314
  let overloadSignatureGroups = getOverloadSignatureGroups(node.body)
200
315
  let formattedNodes = node.body.reduce(
201
316
  (accumulator, member) => {
202
- var _a, _b, _c, _d
317
+ var _a2, _b, _c, _d
203
318
  let comment = getCommentBefore(member, sourceCode)
204
319
  if (
205
320
  options.partitionByComment &&
@@ -218,9 +333,9 @@ const sortClasses = createEslintRule({
218
333
  } else if (member.type === 'TSIndexSignature') {
219
334
  name = sourceCode.text.slice(
220
335
  member.range.at(0),
221
- ((_a = member.typeAnnotation) == null
336
+ ((_a2 = member.typeAnnotation) == null
222
337
  ? void 0
223
- : _a.range.at(0)) ?? member.range.at(1),
338
+ : _a2.range.at(0)) ?? member.range.at(1),
224
339
  )
225
340
  } else {
226
341
  if (member.key.type === 'Identifier') {
@@ -231,8 +346,21 @@ const sortClasses = createEslintRule({
231
346
  }
232
347
  let isPrivateHash =
233
348
  'key' in member && member.key.type === 'PrivateIdentifier'
234
- let decorated =
235
- 'decorators' in member && member.decorators.length > 0
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
+ }
236
364
  let modifiers = []
237
365
  let selectors = []
238
366
  if (
@@ -281,6 +409,7 @@ const sortClasses = createEslintRule({
281
409
  selectors.push('index-signature')
282
410
  } else if (member.type === 'StaticBlock') {
283
411
  selectors.push('static-block')
412
+ dependencies = extractDependencies(member, true)
284
413
  } else if (
285
414
  member.type === 'AccessorProperty' ||
286
415
  member.type === 'TSAbstractAccessorProperty'
@@ -334,15 +463,22 @@ const sortClasses = createEslintRule({
334
463
  if (member.optional) {
335
464
  modifiers.push('optional')
336
465
  }
337
- if (
466
+ let isFunctionProperty =
338
467
  ((_b = member.value) == null ? void 0 : _b.type) ===
339
468
  'ArrowFunctionExpression' ||
340
469
  ((_c = member.value) == null ? void 0 : _c.type) ===
341
470
  'FunctionExpression'
342
- ) {
471
+ if (isFunctionProperty) {
343
472
  selectors.push('function-property')
344
473
  }
345
474
  selectors.push('property')
475
+ if (
476
+ member.type === 'PropertyDefinition' &&
477
+ member.value &&
478
+ !isFunctionProperty
479
+ ) {
480
+ dependencies = extractDependencies(member.value, member.static)
481
+ }
346
482
  }
347
483
  for (let officialGroup of generateOfficialGroups(
348
484
  modifiers,
@@ -350,11 +486,27 @@ const sortClasses = createEslintRule({
350
486
  )) {
351
487
  defineGroup(officialGroup)
352
488
  }
353
- setCustomGroups(options.customGroups, name, {
354
- override: true,
355
- })
356
- if (member.type === 'PropertyDefinition' && member.value) {
357
- dependencies = extractDependencies(member.value)
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
+ })
358
510
  }
359
511
  let overloadSignatureGroupMember =
360
512
  (_d = overloadSignatureGroups.find(overloadSignatures =>
@@ -370,6 +522,10 @@ const sortClasses = createEslintRule({
370
522
  node: member,
371
523
  dependencies,
372
524
  name,
525
+ dependencyName: getDependencyName(
526
+ name,
527
+ modifiers.includes('static'),
528
+ ),
373
529
  }
374
530
  accumulator.at(-1).push(value)
375
531
  return accumulator
@@ -377,18 +533,49 @@ const sortClasses = createEslintRule({
377
533
  [[]],
378
534
  )
379
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)
380
570
  pairwise(nodes, (left, right) => {
381
571
  let leftNum = getGroupNumber(options.groups, left)
382
572
  let rightNum = getGroupNumber(options.groups, right)
383
573
  let isLeftOrRightIgnored =
384
574
  leftNum === options.groups.length ||
385
575
  rightNum === options.groups.length
386
- if (
387
- !isLeftOrRightIgnored &&
388
- (leftNum > rightNum ||
389
- (leftNum === rightNum &&
390
- isPositive(compare(left, right, options))))
391
- ) {
576
+ let indexOfLeft = sortedNodes.indexOf(left)
577
+ let indexOfRight = sortedNodes.indexOf(right)
578
+ if (!isLeftOrRightIgnored && indexOfLeft > indexOfRight) {
392
579
  context.report({
393
580
  messageId:
394
581
  leftNum !== rightNum
@@ -401,37 +588,10 @@ const sortClasses = createEslintRule({
401
588
  rightGroup: right.group,
402
589
  },
403
590
  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, {
591
+ fix: fixer =>
592
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, {
432
593
  partitionComment: options.partitionByComment,
433
- })
434
- },
594
+ }),
435
595
  })
436
596
  }
437
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
+ }
@@ -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
  })