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
package/dist/index.d.ts CHANGED
@@ -3,6 +3,100 @@ import { FlatConfig } from '@typescript-eslint/utils/ts-eslint'
3
3
  import { RuleListener } from '@typescript-eslint/utils/ts-eslint'
4
4
  import { RuleModule } from '@typescript-eslint/utils/ts-eslint'
5
5
 
6
+ declare type AbstractModifier = 'abstract'
7
+
8
+ declare type AccessorPropertyGroup =
9
+ `${PublicOrProtectedOrPrivateModifierPrefix}${StaticOrAbstractModifierPrefix}${OverrideModifierPrefix}${DecoratedModifierPrefix}${AccessorPropertySelector}`
10
+
11
+ declare type AccessorPropertySelector = 'accessor-property'
12
+
13
+ declare type AdvancedSingleCustomGroup<T extends Selector> = {
14
+ decoratorNamePattern?: string
15
+ elementNamePattern?: string
16
+ } & BaseSingleCustomGroup<T>
17
+
18
+ /**
19
+ * Only used in code as well
20
+ */
21
+ declare interface AllowedModifiersPerSelector {
22
+ property:
23
+ | PublicOrProtectedOrPrivateModifier
24
+ | DecoratedModifier
25
+ | AbstractModifier
26
+ | OverrideModifier
27
+ | ReadonlyModifier
28
+ | OptionalModifier
29
+ | DeclareModifier
30
+ | StaticModifier
31
+ method:
32
+ | PublicOrProtectedOrPrivateModifier
33
+ | DecoratedModifier
34
+ | AbstractModifier
35
+ | OverrideModifier
36
+ | OptionalModifier
37
+ | StaticModifier
38
+ 'accessor-property':
39
+ | PublicOrProtectedOrPrivateModifier
40
+ | DecoratedModifier
41
+ | AbstractModifier
42
+ | OverrideModifier
43
+ | StaticModifier
44
+ 'function-property':
45
+ | PublicOrProtectedOrPrivateModifier
46
+ | DecoratedModifier
47
+ | OverrideModifier
48
+ | ReadonlyModifier
49
+ | StaticModifier
50
+ 'set-method':
51
+ | PublicOrProtectedOrPrivateModifier
52
+ | DecoratedModifier
53
+ | AbstractModifier
54
+ | OverrideModifier
55
+ | StaticModifier
56
+ 'get-method': AllowedModifiersPerSelector['set-method']
57
+ 'index-signature': ReadonlyModifier | StaticModifier
58
+ constructor: PublicOrProtectedOrPrivateModifier
59
+ 'static-block': never
60
+ }
61
+
62
+ declare interface BaseSingleCustomGroup<T extends Selector> {
63
+ modifiers?: AllowedModifiersPerSelector[T][]
64
+ selector?: T
65
+ }
66
+
67
+ declare type ConstructorGroup =
68
+ `${PublicOrProtectedOrPrivateModifierPrefix}${ConstructorSelector}`
69
+
70
+ declare type ConstructorSelector = 'constructor'
71
+
72
+ declare type CustomGroup = (
73
+ | {
74
+ order?: SortClassesOptions[0]['order']
75
+ type?: SortClassesOptions[0]['type']
76
+ }
77
+ | {
78
+ type?: 'unsorted'
79
+ }
80
+ ) &
81
+ (SingleCustomGroup | CustomGroupBlock) & {
82
+ groupName: string
83
+ }
84
+
85
+ declare interface CustomGroupBlock {
86
+ anyOf: SingleCustomGroup[]
87
+ }
88
+
89
+ declare type DeclareModifier = 'declare'
90
+
91
+ declare type DeclareModifierPrefix = WithDashSuffixOrEmpty<DeclareModifier>
92
+
93
+ declare type DeclarePropertyGroup =
94
+ `${DeclareModifierPrefix}${PublicOrProtectedOrPrivateModifierPrefix}${StaticOrAbstractModifierPrefix}${ReadonlyModifierPrefix}${OptionalModifierPrefix}${PropertySelector}`
95
+
96
+ declare type DecoratedModifier = 'decorated'
97
+
98
+ declare type DecoratedModifierPrefix = WithDashSuffixOrEmpty<DecoratedModifier>
99
+
6
100
  declare const _default: {
7
101
  configs: {
8
102
  'recommended-alphabetical-legacy': ClassicConfig.Config
@@ -119,14 +213,7 @@ declare const _default: {
119
213
  >
120
214
  'sort-array-includes': RuleModule<
121
215
  'unexpectedArrayIncludesOrder',
122
- [
123
- Partial<{
124
- groupKind: 'literals-first' | 'spreads-first' | 'mixed'
125
- type: 'alphabetical' | 'line-length' | 'natural'
126
- order: 'desc' | 'asc'
127
- ignoreCase: boolean
128
- }>,
129
- ],
216
+ Options,
130
217
  unknown,
131
218
  RuleListener
132
219
  >
@@ -162,12 +249,14 @@ declare const _default: {
162
249
  [
163
250
  Partial<{
164
251
  groupKind: 'required-first' | 'optional-first' | 'mixed'
252
+ customGroups: {
253
+ [x: string]: string | string[]
254
+ }
165
255
  type: 'alphabetical' | 'line-length' | 'natural'
166
256
  groups: (string | string[])[]
167
257
  partitionByNewLine: boolean
168
258
  order: 'desc' | 'asc'
169
259
  ignoreCase: boolean
170
- customGroups: {}
171
260
  }>,
172
261
  ],
173
262
  unknown,
@@ -267,18 +356,7 @@ declare const _default: {
267
356
  >
268
357
  'sort-classes': RuleModule<
269
358
  'unexpectedClassesGroupOrder' | 'unexpectedClassesOrder',
270
- [
271
- Partial<{
272
- customGroups: {
273
- [key: string]: string[] | string
274
- }
275
- type: 'alphabetical' | 'line-length' | 'natural'
276
- partitionByComment: string[] | boolean | string
277
- groups: (string[] | string)[]
278
- order: 'desc' | 'asc'
279
- ignoreCase: boolean
280
- }>,
281
- ],
359
+ SortClassesOptions,
282
360
  unknown,
283
361
  RuleListener
284
362
  >
@@ -348,6 +426,12 @@ declare const _default: {
348
426
  >
349
427
  'sort-enums': RuleModule<
350
428
  'unexpectedEnumsOrder',
429
+ Options_2,
430
+ unknown,
431
+ RuleListener
432
+ >
433
+ 'sort-sets': RuleModule<
434
+ 'unexpectedSetsOrder',
351
435
  Options,
352
436
  unknown,
353
437
  RuleListener
@@ -368,7 +452,66 @@ declare const _default: {
368
452
  name: string
369
453
  }
370
454
 
455
+ declare type FunctionPropertyGroup =
456
+ `${PublicOrProtectedOrPrivateModifierPrefix}${StaticModifierPrefix}${OverrideModifierPrefix}${ReadonlyModifierPrefix}${DecoratedModifierPrefix}${FunctionPropertySelector}`
457
+
458
+ declare type FunctionPropertySelector = 'function-property'
459
+
460
+ declare type GetMethodOrSetMethodGroup =
461
+ `${PublicOrProtectedOrPrivateModifierPrefix}${StaticOrAbstractModifierPrefix}${OverrideModifierPrefix}${DecoratedModifierPrefix}${GetMethodOrSetMethodSelector}`
462
+
463
+ declare type GetMethodOrSetMethodSelector =
464
+ | GetMethodSelector
465
+ | SetMethodSelector
466
+
467
+ declare type GetMethodSelector = 'get-method'
468
+
469
+ /**
470
+ * Some invalid combinations are still handled by this type, such as
471
+ * - private abstract X
472
+ * - abstract decorated X
473
+ * Only used in code, so I don't know if it's worth maintaining this.
474
+ */
475
+ declare type Group =
476
+ | GetMethodOrSetMethodGroup
477
+ | NonDeclarePropertyGroup
478
+ | AccessorPropertyGroup
479
+ | FunctionPropertyGroup
480
+ | DeclarePropertyGroup
481
+ | IndexSignatureGroup
482
+ | ConstructorGroup
483
+ | StaticBlockGroup
484
+ | MethodGroup
485
+ | 'unknown'
486
+ | string
487
+
488
+ declare type IndexSignatureGroup =
489
+ `${StaticModifierPrefix}${ReadonlyModifierPrefix}${IndexSignatureSelector}`
490
+
491
+ declare type IndexSignatureSelector = 'index-signature'
492
+
493
+ declare type MethodGroup =
494
+ `${PublicOrProtectedOrPrivateModifierPrefix}${StaticOrAbstractModifierPrefix}${OverrideModifierPrefix}${DecoratedModifierPrefix}${OptionalModifierPrefix}${MethodSelector}`
495
+
496
+ declare type MethodSelector = 'method'
497
+
498
+ declare type NonDeclarePropertyGroup =
499
+ `${PublicOrProtectedOrPrivateModifierPrefix}${StaticOrAbstractModifierPrefix}${OverrideModifierPrefix}${ReadonlyModifierPrefix}${DecoratedModifierPrefix}${OptionalModifierPrefix}${PropertySelector}`
500
+
501
+ declare type OptionalModifier = 'optional'
502
+
503
+ declare type OptionalModifierPrefix = WithDashSuffixOrEmpty<OptionalModifier>
504
+
371
505
  declare type Options = [
506
+ Partial<{
507
+ groupKind: 'literals-first' | 'spreads-first' | 'mixed'
508
+ type: 'alphabetical' | 'line-length' | 'natural'
509
+ order: 'desc' | 'asc'
510
+ ignoreCase: boolean
511
+ }>,
512
+ ]
513
+
514
+ declare type Options_2 = [
372
515
  Partial<{
373
516
  type: 'alphabetical' | 'line-length' | 'natural'
374
517
  partitionByComment: string[] | boolean | string
@@ -379,5 +522,83 @@ declare type Options = [
379
522
  }>,
380
523
  ]
381
524
 
525
+ declare type OverrideModifier = 'override'
526
+
527
+ declare type OverrideModifierPrefix = WithDashSuffixOrEmpty<OverrideModifier>
528
+
529
+ declare type PrivateModifier = 'private'
530
+
531
+ declare type PropertySelector = 'property'
532
+
533
+ declare type ProtectedModifier = 'protected'
534
+
535
+ declare type PublicModifier = 'public'
536
+
537
+ declare type PublicOrProtectedOrPrivateModifier =
538
+ | ProtectedModifier
539
+ | PrivateModifier
540
+ | PublicModifier
541
+
542
+ declare type PublicOrProtectedOrPrivateModifierPrefix = WithDashSuffixOrEmpty<
543
+ ProtectedModifier | PrivateModifier | PublicModifier
544
+ >
545
+
546
+ declare type ReadonlyModifier = 'readonly'
547
+
548
+ declare type ReadonlyModifierPrefix = WithDashSuffixOrEmpty<ReadonlyModifier>
549
+
550
+ declare type Selector =
551
+ | AccessorPropertySelector
552
+ | FunctionPropertySelector
553
+ | IndexSignatureSelector
554
+ | ConstructorSelector
555
+ | StaticBlockSelector
556
+ | GetMethodSelector
557
+ | SetMethodSelector
558
+ | PropertySelector
559
+ | MethodSelector
560
+
561
+ declare type SetMethodSelector = 'set-method'
562
+
563
+ declare type SingleCustomGroup =
564
+ | AdvancedSingleCustomGroup<FunctionPropertySelector>
565
+ | AdvancedSingleCustomGroup<AccessorPropertySelector>
566
+ | BaseSingleCustomGroup<IndexSignatureSelector>
567
+ | AdvancedSingleCustomGroup<GetMethodSelector>
568
+ | AdvancedSingleCustomGroup<SetMethodSelector>
569
+ | AdvancedSingleCustomGroup<PropertySelector>
570
+ | BaseSingleCustomGroup<StaticBlockSelector>
571
+ | BaseSingleCustomGroup<ConstructorSelector>
572
+ | AdvancedSingleCustomGroup<MethodSelector>
573
+
574
+ declare type SortClassesOptions = [
575
+ Partial<{
576
+ customGroups:
577
+ | {
578
+ [key: string]: string[] | string
579
+ }
580
+ | CustomGroup[]
581
+ type: 'alphabetical' | 'line-length' | 'natural'
582
+ partitionByComment: string[] | boolean | string
583
+ groups: (Group[] | Group)[]
584
+ order: 'desc' | 'asc'
585
+ ignoreCase: boolean
586
+ }>,
587
+ ]
588
+
589
+ declare type StaticBlockGroup = `${StaticBlockSelector}`
590
+
591
+ declare type StaticBlockSelector = 'static-block'
592
+
593
+ declare type StaticModifier = 'static'
594
+
595
+ declare type StaticModifierPrefix = WithDashSuffixOrEmpty<StaticModifier>
596
+
597
+ declare type StaticOrAbstractModifierPrefix = WithDashSuffixOrEmpty<
598
+ AbstractModifier | StaticModifier
599
+ >
600
+
601
+ declare type WithDashSuffixOrEmpty<T extends string> = `${T}-` | ''
602
+
382
603
  export {}
383
604
  export = _default
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ const sortExports = require('./rules/sort-exports.js')
18
18
  const sortObjects = require('./rules/sort-objects.js')
19
19
  const sortEnums = require('./rules/sort-enums.js')
20
20
  const sortMaps = require('./rules/sort-maps.js')
21
+ const sortSets = require('./rules/sort-sets.js')
21
22
  let name = 'perfectionist'
22
23
  let plugin = {
23
24
  rules: {
@@ -26,7 +27,7 @@ let plugin = {
26
27
  'sort-svelte-attributes': sortSvelteAttributes,
27
28
  'sort-astro-attributes': sortAstroAttributes,
28
29
  'sort-vue-attributes': sortVueAttributes,
29
- 'sort-array-includes': sortArrayIncludes,
30
+ 'sort-array-includes': sortArrayIncludes.default,
30
31
  'sort-named-imports': sortNamedImports,
31
32
  'sort-named-exports': sortNamedExports,
32
33
  'sort-object-types': sortObjectTypes,
@@ -39,6 +40,7 @@ let plugin = {
39
40
  'sort-exports': sortExports,
40
41
  'sort-objects': sortObjects,
41
42
  'sort-enums': sortEnums,
43
+ 'sort-sets': sortSets,
42
44
  'sort-maps': sortMaps,
43
45
  },
44
46
  name,
package/dist/index.mjs CHANGED
@@ -17,6 +17,7 @@ import sortExports from './rules/sort-exports.mjs'
17
17
  import sortObjects from './rules/sort-objects.mjs'
18
18
  import sortEnums from './rules/sort-enums.mjs'
19
19
  import sortMaps from './rules/sort-maps.mjs'
20
+ import sortSets from './rules/sort-sets.mjs'
20
21
  let name = 'perfectionist'
21
22
  let plugin = {
22
23
  rules: {
@@ -38,6 +39,7 @@ let plugin = {
38
39
  'sort-exports': sortExports,
39
40
  'sort-objects': sortObjects,
40
41
  'sort-enums': sortEnums,
42
+ 'sort-sets': sortSets,
41
43
  'sort-maps': sortMaps,
42
44
  },
43
45
  name,
@@ -1,4 +1,8 @@
1
1
  'use strict'
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: 'Module' },
5
+ })
2
6
  const createEslintRule = require('../utils/create-eslint-rule.js')
3
7
  const getGroupNumber = require('../utils/get-group-number.js')
4
8
  const getSourceCode = require('../utils/get-source-code.js')
@@ -11,6 +15,32 @@ const makeFixes = require('../utils/make-fixes.js')
11
15
  const complete = require('../utils/complete.js')
12
16
  const pairwise = require('../utils/pairwise.js')
13
17
  const compare = require('../utils/compare.js')
18
+ let jsonSchema = {
19
+ type: 'object',
20
+ properties: {
21
+ type: {
22
+ description: 'Specifies the sorting method.',
23
+ type: 'string',
24
+ enum: ['alphabetical', 'natural', 'line-length'],
25
+ },
26
+ order: {
27
+ description:
28
+ 'Determines whether the sorted items should be in ascending or descending order.',
29
+ type: 'string',
30
+ enum: ['asc', 'desc'],
31
+ },
32
+ ignoreCase: {
33
+ description: 'Controls whether sorting should be case-sensitive or not.',
34
+ type: 'boolean',
35
+ },
36
+ groupKind: {
37
+ description: 'Specifies top-level groups.',
38
+ enum: ['mixed', 'literals-first', 'spreads-first'],
39
+ type: 'string',
40
+ },
41
+ },
42
+ additionalProperties: false,
43
+ }
14
44
  const sortArrayIncludes = createEslintRule.createEslintRule({
15
45
  name: 'sort-array-includes',
16
46
  meta: {
@@ -19,35 +49,7 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
19
49
  description: 'Enforce sorted arrays before include method.',
20
50
  },
21
51
  fixable: 'code',
22
- schema: [
23
- {
24
- type: 'object',
25
- properties: {
26
- type: {
27
- description: 'Specifies the sorting method.',
28
- type: 'string',
29
- enum: ['alphabetical', 'natural', 'line-length'],
30
- },
31
- order: {
32
- description:
33
- 'Determines whether the sorted items should be in ascending or descending order.',
34
- type: 'string',
35
- enum: ['asc', 'desc'],
36
- },
37
- ignoreCase: {
38
- description:
39
- 'Controls whether sorting should be case-sensitive or not.',
40
- type: 'boolean',
41
- },
42
- groupKind: {
43
- description: 'Specifies top-level groups.',
44
- enum: ['mixed', 'literals-first', 'spreads-first'],
45
- type: 'string',
46
- },
47
- },
48
- additionalProperties: false,
49
- },
50
- ],
52
+ schema: [jsonSchema],
51
53
  messages: {
52
54
  unexpectedArrayIncludesOrder:
53
55
  'Expected "{{right}}" to come before "{{left}}".',
@@ -73,85 +75,84 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
73
75
  node.object.type === 'ArrayExpression'
74
76
  ? node.object.elements
75
77
  : node.object.arguments
76
- let settings = getSettings.getSettings(context.settings)
77
- if (elements.length > 1) {
78
- let options = complete.complete(context.options.at(0), settings, {
79
- groupKind: 'literals-first',
80
- type: 'alphabetical',
81
- ignoreCase: true,
82
- order: 'asc',
83
- })
84
- let sourceCode = getSourceCode.getSourceCode(context)
85
- let nodes = elements
86
- .reduce(
87
- (accumulator, element) => {
88
- if (element !== null) {
89
- let group = 'unknown'
90
- if (typeof options.groupKind === 'string') {
91
- group =
92
- element.type === 'SpreadElement' ? 'spread' : 'literal'
93
- }
94
- accumulator.at(0).push({
95
- name:
96
- element.type === 'Literal'
97
- ? `${element.value}`
98
- : sourceCode.text.slice(...element.range),
99
- size: rangeToDiff.rangeToDiff(element.range),
100
- type: element.type,
101
- node: element,
102
- group,
103
- })
104
- }
105
- return accumulator
106
- },
107
- [[], []],
108
- )
109
- .flat()
110
- pairwise.pairwise(nodes, (left, right) => {
111
- let groupKindOrder = ['unknown']
112
- if (typeof options.groupKind === 'string') {
113
- groupKindOrder =
114
- options.groupKind === 'literals-first'
115
- ? ['literal', 'spread']
116
- : ['spread', 'literal']
117
- }
118
- let leftNum = getGroupNumber.getGroupNumber(groupKindOrder, left)
119
- let rightNum = getGroupNumber.getGroupNumber(groupKindOrder, right)
120
- if (
121
- (options.groupKind !== 'mixed' && leftNum > rightNum) ||
122
- ((options.groupKind === 'mixed' || leftNum === rightNum) &&
123
- isPositive.isPositive(compare.compare(left, right, options)))
124
- ) {
125
- context.report({
126
- messageId: 'unexpectedArrayIncludesOrder',
127
- data: {
128
- left: toSingleLine.toSingleLine(left.name),
129
- right: toSingleLine.toSingleLine(right.name),
130
- },
131
- node: right.node,
132
- fix: fixer => {
133
- let sortedNodes =
134
- options.groupKind !== 'mixed'
135
- ? groupKindOrder
136
- .map(group => nodes.filter(n => n.group === group))
137
- .map(groupedNodes =>
138
- sortNodes.sortNodes(groupedNodes, options),
139
- )
140
- .flat()
141
- : sortNodes.sortNodes(nodes, options)
142
- return makeFixes.makeFixes(
143
- fixer,
144
- nodes,
145
- sortedNodes,
146
- sourceCode,
147
- )
148
- },
149
- })
150
- }
151
- })
152
- }
78
+ sortArray(context, 'unexpectedArrayIncludesOrder', elements)
153
79
  }
154
80
  },
155
81
  }),
156
82
  })
157
- module.exports = sortArrayIncludes
83
+ let sortArray = (context, messageId, elements) => {
84
+ let settings = getSettings.getSettings(context.settings)
85
+ if (elements.length > 1) {
86
+ let options = complete.complete(context.options.at(0), settings, {
87
+ groupKind: 'literals-first',
88
+ type: 'alphabetical',
89
+ ignoreCase: true,
90
+ order: 'asc',
91
+ })
92
+ let sourceCode = getSourceCode.getSourceCode(context)
93
+ let nodes = elements
94
+ .reduce(
95
+ (accumulator, element) => {
96
+ if (element !== null) {
97
+ let group = 'unknown'
98
+ if (typeof options.groupKind === 'string') {
99
+ group = element.type === 'SpreadElement' ? 'spread' : 'literal'
100
+ }
101
+ accumulator.at(0).push({
102
+ name:
103
+ element.type === 'Literal'
104
+ ? `${element.value}`
105
+ : sourceCode.text.slice(...element.range),
106
+ size: rangeToDiff.rangeToDiff(element.range),
107
+ type: element.type,
108
+ node: element,
109
+ group,
110
+ })
111
+ }
112
+ return accumulator
113
+ },
114
+ [[], []],
115
+ )
116
+ .flat()
117
+ pairwise.pairwise(nodes, (left, right) => {
118
+ let groupKindOrder = ['unknown']
119
+ if (typeof options.groupKind === 'string') {
120
+ groupKindOrder =
121
+ options.groupKind === 'literals-first'
122
+ ? ['literal', 'spread']
123
+ : ['spread', 'literal']
124
+ }
125
+ let leftNum = getGroupNumber.getGroupNumber(groupKindOrder, left)
126
+ let rightNum = getGroupNumber.getGroupNumber(groupKindOrder, right)
127
+ if (
128
+ (options.groupKind !== 'mixed' && leftNum > rightNum) ||
129
+ ((options.groupKind === 'mixed' || leftNum === rightNum) &&
130
+ isPositive.isPositive(compare.compare(left, right, options)))
131
+ ) {
132
+ context.report({
133
+ messageId,
134
+ data: {
135
+ left: toSingleLine.toSingleLine(left.name),
136
+ right: toSingleLine.toSingleLine(right.name),
137
+ },
138
+ node: right.node,
139
+ fix: fixer => {
140
+ let sortedNodes =
141
+ options.groupKind !== 'mixed'
142
+ ? groupKindOrder
143
+ .map(group => nodes.filter(n => n.group === group))
144
+ .map(groupedNodes =>
145
+ sortNodes.sortNodes(groupedNodes, options),
146
+ )
147
+ .flat()
148
+ : sortNodes.sortNodes(nodes, options)
149
+ return makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode)
150
+ },
151
+ })
152
+ }
153
+ })
154
+ }
155
+ }
156
+ exports.default = sortArrayIncludes
157
+ exports.jsonSchema = jsonSchema
158
+ exports.sortArray = sortArray