eslint-plugin-perfectionist 3.6.0 → 3.7.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 +29 -4
- package/dist/rules/sort-array-includes.js +118 -60
- package/dist/rules/sort-array-includes.mjs +106 -58
- package/dist/rules/sort-astro-attributes.js +18 -44
- package/dist/rules/sort-astro-attributes.mjs +9 -31
- package/dist/rules/sort-classes.js +56 -35
- package/dist/rules/sort-classes.mjs +56 -35
- package/dist/rules/sort-enums.js +69 -39
- package/dist/rules/sort-enums.mjs +66 -37
- package/dist/rules/sort-exports.js +88 -12
- package/dist/rules/sort-exports.mjs +85 -12
- package/dist/rules/sort-interfaces.js +82 -106
- package/dist/rules/sort-interfaces.mjs +66 -89
- package/dist/rules/sort-intersection-types.js +151 -119
- package/dist/rules/sort-intersection-types.mjs +147 -113
- package/dist/rules/sort-jsx-props.js +18 -44
- package/dist/rules/sort-jsx-props.mjs +9 -31
- package/dist/rules/sort-maps.js +78 -22
- package/dist/rules/sort-maps.mjs +74 -22
- package/dist/rules/sort-named-exports.js +87 -31
- package/dist/rules/sort-named-exports.mjs +81 -28
- package/dist/rules/sort-named-imports.js +87 -31
- package/dist/rules/sort-named-imports.mjs +81 -28
- package/dist/rules/sort-object-types.js +80 -119
- package/dist/rules/sort-object-types.mjs +72 -104
- package/dist/rules/sort-objects.js +48 -50
- package/dist/rules/sort-objects.mjs +48 -43
- package/dist/rules/sort-svelte-attributes.js +18 -44
- package/dist/rules/sort-svelte-attributes.mjs +9 -31
- package/dist/rules/sort-union-types.js +151 -119
- package/dist/rules/sort-union-types.mjs +147 -113
- package/dist/rules/sort-variable-declarations.js +97 -24
- package/dist/rules/sort-variable-declarations.mjs +95 -25
- package/dist/rules/sort-vue-attributes.js +18 -45
- package/dist/rules/sort-vue-attributes.mjs +9 -32
- package/dist/utils/get-node-range.js +4 -6
- package/dist/utils/get-node-range.mjs +4 -8
- package/dist/utils/sort-nodes-by-dependencies.js +16 -0
- package/dist/utils/sort-nodes-by-dependencies.mjs +16 -1
- package/dist/utils/sort-nodes-by-groups.js +22 -0
- package/dist/utils/sort-nodes-by-groups.mjs +20 -0
- package/package.json +3 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
3
|
+
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
2
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
5
|
+
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
3
6
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
4
7
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
5
8
|
const getSettings = require('../utils/get-settings.js')
|
|
6
|
-
const isPositive = require('../utils/is-positive.js')
|
|
7
9
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
8
10
|
const makeFixes = require('../utils/make-fixes.js')
|
|
9
11
|
const complete = require('../utils/complete.js')
|
|
10
12
|
const pairwise = require('../utils/pairwise.js')
|
|
11
|
-
const compare = require('../utils/compare.js')
|
|
12
13
|
const sortExports = createEslintRule.createEslintRule({
|
|
13
14
|
name: 'sort-exports',
|
|
14
15
|
meta: {
|
|
@@ -37,6 +38,34 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
37
38
|
'Controls whether sorting should be case-sensitive or not.',
|
|
38
39
|
type: 'boolean',
|
|
39
40
|
},
|
|
41
|
+
partitionByComment: {
|
|
42
|
+
description:
|
|
43
|
+
'Allows you to use comments to separate the exports into logical groups.',
|
|
44
|
+
anyOf: [
|
|
45
|
+
{
|
|
46
|
+
type: 'array',
|
|
47
|
+
items: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'boolean',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'string',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
partitionByNewLine: {
|
|
60
|
+
description:
|
|
61
|
+
'Allows to use spaces to separate the nodes into logical groups.',
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
},
|
|
64
|
+
groupKind: {
|
|
65
|
+
description: 'Specifies top-level groups.',
|
|
66
|
+
type: 'string',
|
|
67
|
+
enum: ['mixed', 'values-first', 'types-first'],
|
|
68
|
+
},
|
|
40
69
|
},
|
|
41
70
|
additionalProperties: false,
|
|
42
71
|
},
|
|
@@ -50,6 +79,9 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
50
79
|
type: 'alphabetical',
|
|
51
80
|
order: 'asc',
|
|
52
81
|
ignoreCase: true,
|
|
82
|
+
partitionByComment: false,
|
|
83
|
+
partitionByNewLine: false,
|
|
84
|
+
groupKind: 'mixed',
|
|
53
85
|
},
|
|
54
86
|
],
|
|
55
87
|
create: context => {
|
|
@@ -58,14 +90,34 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
58
90
|
type: 'alphabetical',
|
|
59
91
|
ignoreCase: true,
|
|
60
92
|
order: 'asc',
|
|
93
|
+
partitionByComment: false,
|
|
94
|
+
partitionByNewLine: false,
|
|
95
|
+
groupKind: 'mixed',
|
|
61
96
|
})
|
|
97
|
+
let sourceCode = getSourceCode.getSourceCode(context)
|
|
98
|
+
let partitionComment = options.partitionByComment
|
|
62
99
|
let parts = [[]]
|
|
63
100
|
let registerNode = node => {
|
|
64
|
-
|
|
101
|
+
var _a
|
|
102
|
+
let sortingNode = {
|
|
65
103
|
size: rangeToDiff.rangeToDiff(node.range),
|
|
66
104
|
name: node.source.value,
|
|
67
105
|
node,
|
|
68
|
-
}
|
|
106
|
+
}
|
|
107
|
+
let lastNode = (_a = parts.at(-1)) == null ? void 0 : _a.at(-1)
|
|
108
|
+
if (
|
|
109
|
+
(partitionComment &&
|
|
110
|
+
isPartitionComment.hasPartitionComment(
|
|
111
|
+
partitionComment,
|
|
112
|
+
getCommentsBefore.getCommentsBefore(node, sourceCode),
|
|
113
|
+
)) ||
|
|
114
|
+
(options.partitionByNewLine &&
|
|
115
|
+
lastNode &&
|
|
116
|
+
getLinesBetween.getLinesBetween(sourceCode, lastNode, sortingNode))
|
|
117
|
+
) {
|
|
118
|
+
parts.push([])
|
|
119
|
+
}
|
|
120
|
+
parts.at(-1).push(sortingNode)
|
|
69
121
|
}
|
|
70
122
|
return {
|
|
71
123
|
ExportAllDeclaration: registerNode,
|
|
@@ -75,10 +127,37 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
75
127
|
}
|
|
76
128
|
},
|
|
77
129
|
'Program:exit': () => {
|
|
78
|
-
let sourceCode = getSourceCode.getSourceCode(context)
|
|
79
130
|
for (let nodes of parts) {
|
|
131
|
+
let groupedByKind
|
|
132
|
+
if (options.groupKind !== 'mixed') {
|
|
133
|
+
groupedByKind = nodes.reduce(
|
|
134
|
+
(accumulator, currentNode) => {
|
|
135
|
+
let exportTypeIndex =
|
|
136
|
+
options.groupKind === 'types-first' ? 0 : 1
|
|
137
|
+
let exportIndex = options.groupKind === 'types-first' ? 1 : 0
|
|
138
|
+
if (currentNode.node.exportKind === 'value') {
|
|
139
|
+
accumulator[exportIndex].push(currentNode)
|
|
140
|
+
} else {
|
|
141
|
+
accumulator[exportTypeIndex].push(currentNode)
|
|
142
|
+
}
|
|
143
|
+
return accumulator
|
|
144
|
+
},
|
|
145
|
+
[[], []],
|
|
146
|
+
)
|
|
147
|
+
} else {
|
|
148
|
+
groupedByKind = [nodes]
|
|
149
|
+
}
|
|
150
|
+
let sortedNodes = []
|
|
151
|
+
for (let nodesByKind of groupedByKind) {
|
|
152
|
+
sortedNodes = [
|
|
153
|
+
...sortedNodes,
|
|
154
|
+
...sortNodes.sortNodes(nodesByKind, options),
|
|
155
|
+
]
|
|
156
|
+
}
|
|
80
157
|
pairwise.pairwise(nodes, (left, right) => {
|
|
81
|
-
|
|
158
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
159
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
160
|
+
if (indexOfLeft > indexOfRight) {
|
|
82
161
|
context.report({
|
|
83
162
|
messageId: 'unexpectedExportsOrder',
|
|
84
163
|
data: {
|
|
@@ -87,12 +166,9 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
87
166
|
},
|
|
88
167
|
node: right.node,
|
|
89
168
|
fix: fixer =>
|
|
90
|
-
makeFixes.makeFixes(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
sortNodes.sortNodes(nodes, options),
|
|
94
|
-
sourceCode,
|
|
95
|
-
),
|
|
169
|
+
makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
170
|
+
partitionComment,
|
|
171
|
+
}),
|
|
96
172
|
})
|
|
97
173
|
}
|
|
98
174
|
})
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { hasPartitionComment } from '../utils/is-partition-comment.mjs'
|
|
2
|
+
import { getCommentsBefore } from '../utils/get-comments-before.mjs'
|
|
1
3
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
4
|
+
import { getLinesBetween } from '../utils/get-lines-between.mjs'
|
|
2
5
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
3
6
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
4
7
|
import { getSettings } from '../utils/get-settings.mjs'
|
|
5
|
-
import { isPositive } from '../utils/is-positive.mjs'
|
|
6
8
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
7
9
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
8
10
|
import { complete } from '../utils/complete.mjs'
|
|
9
11
|
import { pairwise } from '../utils/pairwise.mjs'
|
|
10
|
-
import { compare } from '../utils/compare.mjs'
|
|
11
12
|
const sortExports = createEslintRule({
|
|
12
13
|
name: 'sort-exports',
|
|
13
14
|
meta: {
|
|
@@ -36,6 +37,34 @@ const sortExports = createEslintRule({
|
|
|
36
37
|
'Controls whether sorting should be case-sensitive or not.',
|
|
37
38
|
type: 'boolean',
|
|
38
39
|
},
|
|
40
|
+
partitionByComment: {
|
|
41
|
+
description:
|
|
42
|
+
'Allows you to use comments to separate the exports into logical groups.',
|
|
43
|
+
anyOf: [
|
|
44
|
+
{
|
|
45
|
+
type: 'array',
|
|
46
|
+
items: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'string',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
partitionByNewLine: {
|
|
59
|
+
description:
|
|
60
|
+
'Allows to use spaces to separate the nodes into logical groups.',
|
|
61
|
+
type: 'boolean',
|
|
62
|
+
},
|
|
63
|
+
groupKind: {
|
|
64
|
+
description: 'Specifies top-level groups.',
|
|
65
|
+
type: 'string',
|
|
66
|
+
enum: ['mixed', 'values-first', 'types-first'],
|
|
67
|
+
},
|
|
39
68
|
},
|
|
40
69
|
additionalProperties: false,
|
|
41
70
|
},
|
|
@@ -49,6 +78,9 @@ const sortExports = createEslintRule({
|
|
|
49
78
|
type: 'alphabetical',
|
|
50
79
|
order: 'asc',
|
|
51
80
|
ignoreCase: true,
|
|
81
|
+
partitionByComment: false,
|
|
82
|
+
partitionByNewLine: false,
|
|
83
|
+
groupKind: 'mixed',
|
|
52
84
|
},
|
|
53
85
|
],
|
|
54
86
|
create: context => {
|
|
@@ -57,14 +89,34 @@ const sortExports = createEslintRule({
|
|
|
57
89
|
type: 'alphabetical',
|
|
58
90
|
ignoreCase: true,
|
|
59
91
|
order: 'asc',
|
|
92
|
+
partitionByComment: false,
|
|
93
|
+
partitionByNewLine: false,
|
|
94
|
+
groupKind: 'mixed',
|
|
60
95
|
})
|
|
96
|
+
let sourceCode = getSourceCode(context)
|
|
97
|
+
let partitionComment = options.partitionByComment
|
|
61
98
|
let parts = [[]]
|
|
62
99
|
let registerNode = node => {
|
|
63
|
-
|
|
100
|
+
var _a
|
|
101
|
+
let sortingNode = {
|
|
64
102
|
size: rangeToDiff(node.range),
|
|
65
103
|
name: node.source.value,
|
|
66
104
|
node,
|
|
67
|
-
}
|
|
105
|
+
}
|
|
106
|
+
let lastNode = (_a = parts.at(-1)) == null ? void 0 : _a.at(-1)
|
|
107
|
+
if (
|
|
108
|
+
(partitionComment &&
|
|
109
|
+
hasPartitionComment(
|
|
110
|
+
partitionComment,
|
|
111
|
+
getCommentsBefore(node, sourceCode),
|
|
112
|
+
)) ||
|
|
113
|
+
(options.partitionByNewLine &&
|
|
114
|
+
lastNode &&
|
|
115
|
+
getLinesBetween(sourceCode, lastNode, sortingNode))
|
|
116
|
+
) {
|
|
117
|
+
parts.push([])
|
|
118
|
+
}
|
|
119
|
+
parts.at(-1).push(sortingNode)
|
|
68
120
|
}
|
|
69
121
|
return {
|
|
70
122
|
ExportAllDeclaration: registerNode,
|
|
@@ -74,10 +126,34 @@ const sortExports = createEslintRule({
|
|
|
74
126
|
}
|
|
75
127
|
},
|
|
76
128
|
'Program:exit': () => {
|
|
77
|
-
let sourceCode = getSourceCode(context)
|
|
78
129
|
for (let nodes of parts) {
|
|
130
|
+
let groupedByKind
|
|
131
|
+
if (options.groupKind !== 'mixed') {
|
|
132
|
+
groupedByKind = nodes.reduce(
|
|
133
|
+
(accumulator, currentNode) => {
|
|
134
|
+
let exportTypeIndex =
|
|
135
|
+
options.groupKind === 'types-first' ? 0 : 1
|
|
136
|
+
let exportIndex = options.groupKind === 'types-first' ? 1 : 0
|
|
137
|
+
if (currentNode.node.exportKind === 'value') {
|
|
138
|
+
accumulator[exportIndex].push(currentNode)
|
|
139
|
+
} else {
|
|
140
|
+
accumulator[exportTypeIndex].push(currentNode)
|
|
141
|
+
}
|
|
142
|
+
return accumulator
|
|
143
|
+
},
|
|
144
|
+
[[], []],
|
|
145
|
+
)
|
|
146
|
+
} else {
|
|
147
|
+
groupedByKind = [nodes]
|
|
148
|
+
}
|
|
149
|
+
let sortedNodes = []
|
|
150
|
+
for (let nodesByKind of groupedByKind) {
|
|
151
|
+
sortedNodes = [...sortedNodes, ...sortNodes(nodesByKind, options)]
|
|
152
|
+
}
|
|
79
153
|
pairwise(nodes, (left, right) => {
|
|
80
|
-
|
|
154
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
155
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
156
|
+
if (indexOfLeft > indexOfRight) {
|
|
81
157
|
context.report({
|
|
82
158
|
messageId: 'unexpectedExportsOrder',
|
|
83
159
|
data: {
|
|
@@ -86,12 +162,9 @@ const sortExports = createEslintRule({
|
|
|
86
162
|
},
|
|
87
163
|
node: right.node,
|
|
88
164
|
fix: fixer =>
|
|
89
|
-
makeFixes(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
sortNodes(nodes, options),
|
|
93
|
-
sourceCode,
|
|
94
|
-
),
|
|
165
|
+
makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
166
|
+
partitionComment,
|
|
167
|
+
}),
|
|
95
168
|
})
|
|
96
169
|
}
|
|
97
170
|
})
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const minimatch = require('minimatch')
|
|
3
3
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
4
|
+
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
5
|
+
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
6
|
+
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
4
7
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
5
8
|
const isMemberOptional = require('../utils/is-member-optional.js')
|
|
6
9
|
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
@@ -9,13 +12,10 @@ const getSourceCode = require('../utils/get-source-code.js')
|
|
|
9
12
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
10
13
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
11
14
|
const getSettings = require('../utils/get-settings.js')
|
|
12
|
-
const isPositive = require('../utils/is-positive.js')
|
|
13
15
|
const useGroups = require('../utils/use-groups.js')
|
|
14
|
-
const sortNodes = require('../utils/sort-nodes.js')
|
|
15
16
|
const makeFixes = require('../utils/make-fixes.js')
|
|
16
17
|
const complete = require('../utils/complete.js')
|
|
17
18
|
const pairwise = require('../utils/pairwise.js')
|
|
18
|
-
const compare = require('../utils/compare.js')
|
|
19
19
|
const sortInterfaces = createEslintRule.createEslintRule({
|
|
20
20
|
name: 'sort-interfaces',
|
|
21
21
|
meta: {
|
|
@@ -52,6 +52,24 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
52
52
|
},
|
|
53
53
|
type: 'array',
|
|
54
54
|
},
|
|
55
|
+
partitionByComment: {
|
|
56
|
+
description:
|
|
57
|
+
'Allows you to use comments to separate the interface properties into logical groups.',
|
|
58
|
+
anyOf: [
|
|
59
|
+
{
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'string',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'array',
|
|
67
|
+
items: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
55
73
|
partitionByNewLine: {
|
|
56
74
|
description:
|
|
57
75
|
'Allows to use spaces to separate the nodes into logical groups.',
|
|
@@ -113,6 +131,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
113
131
|
order: 'asc',
|
|
114
132
|
ignoreCase: true,
|
|
115
133
|
ignorePattern: [],
|
|
134
|
+
partitionByComment: false,
|
|
116
135
|
partitionByNewLine: false,
|
|
117
136
|
groupKind: 'mixed',
|
|
118
137
|
groups: [],
|
|
@@ -124,6 +143,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
124
143
|
if (node.body.body.length > 1) {
|
|
125
144
|
let settings = getSettings.getSettings(context.settings)
|
|
126
145
|
let options = complete.complete(context.options.at(0), settings, {
|
|
146
|
+
partitionByComment: false,
|
|
127
147
|
partitionByNewLine: false,
|
|
128
148
|
type: 'alphabetical',
|
|
129
149
|
groupKind: 'mixed',
|
|
@@ -139,6 +159,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
139
159
|
Object.keys(options.customGroups),
|
|
140
160
|
)
|
|
141
161
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
162
|
+
let partitionComment = options.partitionByComment
|
|
142
163
|
if (
|
|
143
164
|
!options.ignorePattern.some(pattern =>
|
|
144
165
|
minimatch.minimatch(node.id.name, pattern, {
|
|
@@ -184,95 +205,76 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
184
205
|
: _d.range.at(0)) ?? element.range.at(1)
|
|
185
206
|
name = sourceCode.text.slice(element.range.at(0), endIndex)
|
|
186
207
|
}
|
|
208
|
+
setCustomGroups(options.customGroups, name)
|
|
209
|
+
if (element.loc.start.line !== element.loc.end.line) {
|
|
210
|
+
defineGroup('multiline')
|
|
211
|
+
}
|
|
187
212
|
let elementSortingNode = {
|
|
188
213
|
size: rangeToDiff.rangeToDiff(element.range),
|
|
189
214
|
node: element,
|
|
215
|
+
group: getGroup(),
|
|
190
216
|
name,
|
|
191
217
|
}
|
|
192
218
|
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
219
|
+
(partitionComment &&
|
|
220
|
+
isPartitionComment.hasPartitionComment(
|
|
221
|
+
partitionComment,
|
|
222
|
+
getCommentsBefore.getCommentsBefore(element, sourceCode),
|
|
223
|
+
)) ||
|
|
224
|
+
(options.partitionByNewLine &&
|
|
225
|
+
lastElement &&
|
|
226
|
+
getLinesBetween.getLinesBetween(
|
|
227
|
+
sourceCode,
|
|
228
|
+
lastElement,
|
|
229
|
+
elementSortingNode,
|
|
230
|
+
))
|
|
200
231
|
) {
|
|
201
232
|
accumulator.push([])
|
|
202
233
|
}
|
|
203
|
-
|
|
204
|
-
if (element.loc.start.line !== element.loc.end.line) {
|
|
205
|
-
defineGroup('multiline')
|
|
206
|
-
}
|
|
207
|
-
accumulator.at(-1).push({
|
|
208
|
-
...elementSortingNode,
|
|
209
|
-
group: getGroup(),
|
|
210
|
-
})
|
|
234
|
+
accumulator.at(-1).push(elementSortingNode)
|
|
211
235
|
return accumulator
|
|
212
236
|
},
|
|
213
237
|
[[]],
|
|
214
238
|
)
|
|
215
|
-
let toSorted = nodes => {
|
|
216
|
-
let grouped = {}
|
|
217
|
-
for (let currentNode of nodes) {
|
|
218
|
-
let groupNum = getGroupNumber.getGroupNumber(
|
|
219
|
-
options.groups,
|
|
220
|
-
currentNode,
|
|
221
|
-
)
|
|
222
|
-
if (!(groupNum in grouped)) {
|
|
223
|
-
grouped[groupNum] = [currentNode]
|
|
224
|
-
} else {
|
|
225
|
-
grouped[groupNum] = sortNodes.sortNodes(
|
|
226
|
-
[...grouped[groupNum], currentNode],
|
|
227
|
-
options,
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
let sortedNodes = []
|
|
232
|
-
for (let group of Object.keys(grouped).sort(
|
|
233
|
-
(a, b) => Number(a) - Number(b),
|
|
234
|
-
)) {
|
|
235
|
-
sortedNodes.push(...sortNodes.sortNodes(grouped[group], options))
|
|
236
|
-
}
|
|
237
|
-
return sortedNodes
|
|
238
|
-
}
|
|
239
|
-
let checkGroupSort = (left, right) => {
|
|
240
|
-
let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
|
|
241
|
-
let rightNum = getGroupNumber.getGroupNumber(options.groups, right)
|
|
242
|
-
return (
|
|
243
|
-
leftNum > rightNum ||
|
|
244
|
-
(leftNum === rightNum &&
|
|
245
|
-
isPositive.isPositive(compare.compare(left, right, options)))
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
239
|
let { groupKind } = options
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
isMemberOptional.isMemberOptional(
|
|
257
|
-
isMemberOptional.isMemberOptional(members[i].node),
|
|
258
|
-
)
|
|
259
|
-
if (iteration < switchIndex && iteration + 1 !== switchIndex) {
|
|
260
|
-
return checkGroupSort(left, right)
|
|
261
|
-
}
|
|
262
|
-
if (
|
|
263
|
-
isMemberOptional.isMemberOptional(left.node) !==
|
|
264
|
-
isMemberOptional.isMemberOptional(right.node)
|
|
265
|
-
) {
|
|
266
|
-
return (
|
|
267
|
-
isMemberOptional.isMemberOptional(left.node) !==
|
|
268
|
-
(groupKind === 'optional-first')
|
|
240
|
+
for (let nodes of formattedMembers) {
|
|
241
|
+
let sortedNodes
|
|
242
|
+
if (groupKind !== 'mixed') {
|
|
243
|
+
let optionalNodes = nodes.filter(member =>
|
|
244
|
+
isMemberOptional.isMemberOptional(member.node),
|
|
245
|
+
)
|
|
246
|
+
let requiredNodes = nodes.filter(
|
|
247
|
+
member => !isMemberOptional.isMemberOptional(member.node),
|
|
269
248
|
)
|
|
249
|
+
sortedNodes =
|
|
250
|
+
groupKind === 'optional-first'
|
|
251
|
+
? [
|
|
252
|
+
...sortNodesByGroups.sortNodesByGroups(
|
|
253
|
+
optionalNodes,
|
|
254
|
+
options,
|
|
255
|
+
),
|
|
256
|
+
...sortNodesByGroups.sortNodesByGroups(
|
|
257
|
+
requiredNodes,
|
|
258
|
+
options,
|
|
259
|
+
),
|
|
260
|
+
]
|
|
261
|
+
: [
|
|
262
|
+
...sortNodesByGroups.sortNodesByGroups(
|
|
263
|
+
requiredNodes,
|
|
264
|
+
options,
|
|
265
|
+
),
|
|
266
|
+
...sortNodesByGroups.sortNodesByGroups(
|
|
267
|
+
optionalNodes,
|
|
268
|
+
options,
|
|
269
|
+
),
|
|
270
|
+
]
|
|
271
|
+
} else {
|
|
272
|
+
sortedNodes = sortNodesByGroups.sortNodesByGroups(nodes, options)
|
|
270
273
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (checkOrder(nodes, left, right, iteration)) {
|
|
274
|
+
pairwise.pairwise(nodes, (left, right) => {
|
|
275
|
+
let indexOfLeft = sortedNodes.indexOf(left)
|
|
276
|
+
let indexOfRight = sortedNodes.indexOf(right)
|
|
277
|
+
if (indexOfLeft > indexOfRight) {
|
|
276
278
|
let leftNum = getGroupNumber.getGroupNumber(
|
|
277
279
|
options.groups,
|
|
278
280
|
left,
|
|
@@ -293,36 +295,10 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
293
295
|
rightGroup: right.group,
|
|
294
296
|
},
|
|
295
297
|
node: right.node,
|
|
296
|
-
fix: fixer =>
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
isMemberOptional.isMemberOptional(member.node),
|
|
301
|
-
)
|
|
302
|
-
let requiredNodes = nodes.filter(
|
|
303
|
-
member =>
|
|
304
|
-
!isMemberOptional.isMemberOptional(member.node),
|
|
305
|
-
)
|
|
306
|
-
sortedNodes =
|
|
307
|
-
groupKind === 'optional-first'
|
|
308
|
-
? [
|
|
309
|
-
...toSorted(optionalNodes),
|
|
310
|
-
...toSorted(requiredNodes),
|
|
311
|
-
]
|
|
312
|
-
: [
|
|
313
|
-
...toSorted(requiredNodes),
|
|
314
|
-
...toSorted(optionalNodes),
|
|
315
|
-
]
|
|
316
|
-
} else {
|
|
317
|
-
sortedNodes = toSorted(nodes)
|
|
318
|
-
}
|
|
319
|
-
return makeFixes.makeFixes(
|
|
320
|
-
fixer,
|
|
321
|
-
nodes,
|
|
322
|
-
sortedNodes,
|
|
323
|
-
sourceCode,
|
|
324
|
-
)
|
|
325
|
-
},
|
|
298
|
+
fix: fixer =>
|
|
299
|
+
makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
300
|
+
partitionComment,
|
|
301
|
+
}),
|
|
326
302
|
})
|
|
327
303
|
}
|
|
328
304
|
})
|