eslint-plugin-perfectionist 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rules/sort-array-includes-utils.js +30 -0
- package/dist/rules/sort-array-includes.js +149 -55
- package/dist/rules/sort-array-includes.types.js +10 -0
- package/dist/rules/sort-classes.js +13 -14
- package/dist/rules/sort-decorators.js +7 -6
- package/dist/rules/sort-enums.js +34 -31
- package/dist/rules/sort-exports.js +7 -5
- package/dist/rules/sort-heritage-clauses.js +8 -6
- package/dist/rules/sort-imports.js +29 -21
- package/dist/rules/sort-interfaces.js +2 -1
- package/dist/rules/sort-intersection-types.js +20 -19
- package/dist/rules/sort-jsx-props.js +8 -7
- package/dist/rules/sort-maps.js +14 -13
- package/dist/rules/sort-modules.js +17 -16
- package/dist/rules/sort-named-exports.js +14 -13
- package/dist/rules/sort-named-imports.js +14 -13
- package/dist/rules/sort-object-types.js +142 -95
- package/dist/rules/sort-objects.js +114 -57
- package/dist/rules/sort-sets.js +14 -5
- package/dist/rules/sort-switch-case.js +12 -14
- package/dist/rules/sort-union-types.js +20 -19
- package/dist/rules/sort-variable-declarations.js +14 -13
- package/dist/utils/common-json-schemas.js +15 -8
- package/dist/utils/create-node-index-map.js +10 -0
- package/dist/utils/{get-node-parent.js → get-first-node-parent-with-type.js} +3 -4
- package/dist/utils/get-matching-context-options.js +1 -1
- package/dist/utils/is-partition-comment.js +4 -1
- package/dist/utils/pairwise.js +1 -3
- package/dist/utils/validate-groups-configuration.js +11 -5
- package/package.json +3 -3
|
@@ -9,6 +9,7 @@ const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-group
|
|
|
9
9
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
10
10
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
11
11
|
const getTypescriptImport = require('../utils/get-typescript-import.js')
|
|
12
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
12
13
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
13
14
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
14
15
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
@@ -132,11 +133,18 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
132
133
|
node.specifiers.length ===
|
|
133
134
|
0 /* Avoid matching on named imports without specifiers */ &&
|
|
134
135
|
!/\}\s*from\s+/u.test(sourceCode.getText(node))
|
|
136
|
+
let styleExtensions = [
|
|
137
|
+
'.less',
|
|
138
|
+
'.scss',
|
|
139
|
+
'.sass',
|
|
140
|
+
'.styl',
|
|
141
|
+
'.pcss',
|
|
142
|
+
'.css',
|
|
143
|
+
'.sss',
|
|
144
|
+
]
|
|
135
145
|
let isStyle = value => {
|
|
136
146
|
let [cleanedValue] = value.split('?')
|
|
137
|
-
return
|
|
138
|
-
extension => cleanedValue.endsWith(extension),
|
|
139
|
-
)
|
|
147
|
+
return styleExtensions.some(extension => cleanedValue.endsWith(extension))
|
|
140
148
|
}
|
|
141
149
|
let flatGroups = new Set(options.groups.flat())
|
|
142
150
|
let shouldRegroupSideEffectNodes = flatGroups.has('side-effect')
|
|
@@ -330,24 +338,22 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
330
338
|
}
|
|
331
339
|
return {
|
|
332
340
|
'Program:exit': () => {
|
|
333
|
-
var _a
|
|
334
341
|
let hasContentBetweenNodes = (left, right) =>
|
|
335
342
|
!!sourceCode.getTokensBetween(left.node, right.node, {
|
|
336
343
|
includeComments: false,
|
|
337
344
|
}).length
|
|
338
345
|
let formattedMembers = [[]]
|
|
339
346
|
for (let sortingNode of nodes) {
|
|
340
|
-
let
|
|
341
|
-
|
|
347
|
+
let lastGroup = formattedMembers.at(-1)
|
|
348
|
+
let lastSortingNode = lastGroup == null ? void 0 : lastGroup.at(-1)
|
|
342
349
|
if (
|
|
343
|
-
(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
)) ||
|
|
350
|
+
isPartitionComment.hasPartitionComment(
|
|
351
|
+
options.partitionByComment,
|
|
352
|
+
getCommentsBefore.getCommentsBefore({
|
|
353
|
+
node: sortingNode.node,
|
|
354
|
+
sourceCode,
|
|
355
|
+
}),
|
|
356
|
+
) ||
|
|
351
357
|
(options.partitionByNewLine &&
|
|
352
358
|
lastSortingNode &&
|
|
353
359
|
getLinesBetween.getLinesBetween(
|
|
@@ -358,9 +364,10 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
358
364
|
(lastSortingNode &&
|
|
359
365
|
hasContentBetweenNodes(lastSortingNode, sortingNode))
|
|
360
366
|
) {
|
|
361
|
-
|
|
367
|
+
lastGroup = []
|
|
368
|
+
formattedMembers.push(lastGroup)
|
|
362
369
|
}
|
|
363
|
-
|
|
370
|
+
lastGroup.push(sortingNode)
|
|
364
371
|
}
|
|
365
372
|
for (let nodeList of formattedMembers) {
|
|
366
373
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
@@ -378,20 +385,21 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
378
385
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
379
386
|
let sortedNodesExcludingEslintDisabled =
|
|
380
387
|
sortNodesExcludingEslintDisabled(true)
|
|
388
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
381
389
|
pairwise.pairwise(nodeList, (left, right) => {
|
|
382
390
|
let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
|
|
383
391
|
let rightNumber = getGroupNumber.getGroupNumber(
|
|
384
392
|
options.groups,
|
|
385
393
|
right,
|
|
386
394
|
)
|
|
387
|
-
let
|
|
388
|
-
let
|
|
395
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
396
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
389
397
|
let indexOfRightExcludingEslintDisabled =
|
|
390
398
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
391
399
|
let messageIds = []
|
|
392
400
|
if (
|
|
393
|
-
|
|
394
|
-
|
|
401
|
+
leftIndex > rightIndex ||
|
|
402
|
+
leftIndex >= indexOfRightExcludingEslintDisabled
|
|
395
403
|
) {
|
|
396
404
|
messageIds.push(
|
|
397
405
|
leftNumber === rightNumber
|
|
@@ -517,10 +525,10 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
517
525
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
518
526
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
519
527
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
528
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
520
529
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
521
530
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
522
531
|
order: commonJsonSchemas.orderJsonSchema,
|
|
523
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
524
532
|
},
|
|
525
533
|
definitions: {
|
|
526
534
|
'max-line-length-requires-line-length-type': {
|
|
@@ -6,6 +6,7 @@ let defaultOptions = {
|
|
|
6
6
|
partitionByNewLine: false,
|
|
7
7
|
newlinesBetween: 'ignore',
|
|
8
8
|
specialCharacters: 'keep',
|
|
9
|
+
useConfigurationIf: {},
|
|
9
10
|
type: 'alphabetical',
|
|
10
11
|
groupKind: 'mixed',
|
|
11
12
|
ignorePattern: [],
|
|
@@ -33,7 +34,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
33
34
|
description: 'Enforce sorted interface properties.',
|
|
34
35
|
recommended: true,
|
|
35
36
|
},
|
|
36
|
-
schema:
|
|
37
|
+
schema: sortObjectTypes.jsonSchema,
|
|
37
38
|
type: 'suggestion',
|
|
38
39
|
fixable: 'code',
|
|
39
40
|
},
|
|
@@ -5,6 +5,7 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
|
|
|
5
5
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
6
6
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
7
7
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
8
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
8
9
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
9
10
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
10
11
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
@@ -72,7 +73,6 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
72
73
|
})
|
|
73
74
|
let formattedMembers = node.types.reduce(
|
|
74
75
|
(accumulator, type) => {
|
|
75
|
-
var _a, _b
|
|
76
76
|
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
77
77
|
switch (type.type) {
|
|
78
78
|
case 'TSTemplateLiteralType':
|
|
@@ -131,8 +131,8 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
131
131
|
defineGroup('union')
|
|
132
132
|
break
|
|
133
133
|
}
|
|
134
|
-
let
|
|
135
|
-
|
|
134
|
+
let lastGroup = accumulator.at(-1)
|
|
135
|
+
let lastSortingNode = lastGroup == null ? void 0 : lastGroup.at(-1)
|
|
136
136
|
let sortingNode = {
|
|
137
137
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
138
138
|
type,
|
|
@@ -144,15 +144,14 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
144
144
|
node: type,
|
|
145
145
|
}
|
|
146
146
|
if (
|
|
147
|
-
(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)) ||
|
|
147
|
+
isPartitionComment.hasPartitionComment(
|
|
148
|
+
options.partitionByComment,
|
|
149
|
+
getCommentsBefore.getCommentsBefore({
|
|
150
|
+
tokenValueToIgnoreBefore: '&',
|
|
151
|
+
node: type,
|
|
152
|
+
sourceCode,
|
|
153
|
+
}),
|
|
154
|
+
) ||
|
|
156
155
|
(options.partitionByNewLine &&
|
|
157
156
|
lastSortingNode &&
|
|
158
157
|
getLinesBetween.getLinesBetween(
|
|
@@ -161,9 +160,10 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
161
160
|
sortingNode,
|
|
162
161
|
))
|
|
163
162
|
) {
|
|
164
|
-
|
|
163
|
+
lastGroup = []
|
|
164
|
+
accumulator.push(lastGroup)
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
lastGroup == null ? void 0 : lastGroup.push(sortingNode)
|
|
167
167
|
return accumulator
|
|
168
168
|
},
|
|
169
169
|
[[]],
|
|
@@ -176,17 +176,18 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
176
176
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
177
177
|
let sortedNodesExcludingEslintDisabled =
|
|
178
178
|
sortNodesExcludingEslintDisabled(true)
|
|
179
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
179
180
|
pairwise.pairwise(nodes, (left, right) => {
|
|
180
181
|
let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
|
|
181
182
|
let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
|
|
182
|
-
let
|
|
183
|
-
let
|
|
183
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
184
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
184
185
|
let indexOfRightExcludingEslintDisabled =
|
|
185
186
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
186
187
|
let messageIds = []
|
|
187
188
|
if (
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
leftIndex > rightIndex ||
|
|
190
|
+
leftIndex >= indexOfRightExcludingEslintDisabled
|
|
190
191
|
) {
|
|
191
192
|
messageIds.push(
|
|
192
193
|
leftNumber === rightNumber
|
|
@@ -253,10 +254,10 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
253
254
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
254
255
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
255
256
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
257
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
256
258
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
257
259
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
258
260
|
order: commonJsonSchemas.orderJsonSchema,
|
|
259
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
260
261
|
},
|
|
261
262
|
additionalProperties: false,
|
|
262
263
|
type: 'object',
|
|
@@ -4,6 +4,7 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
|
|
|
4
4
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
5
5
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
6
6
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
7
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
7
8
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
9
10
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
@@ -78,8 +79,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
78
79
|
setCustomGroups(options.customGroups, name)
|
|
79
80
|
if (attribute.value === null) {
|
|
80
81
|
defineGroup('shorthand')
|
|
81
|
-
}
|
|
82
|
-
if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
82
|
+
} else if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
83
83
|
defineGroup('multiline')
|
|
84
84
|
}
|
|
85
85
|
let jsxNode = {
|
|
@@ -105,14 +105,15 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
105
105
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
106
106
|
let sortedNodesExcludingEslintDisabled =
|
|
107
107
|
sortNodesExcludingEslintDisabled(true)
|
|
108
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
108
109
|
pairwise.pairwise(nodes, (left, right) => {
|
|
109
|
-
let
|
|
110
|
-
let
|
|
110
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
111
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
111
112
|
let indexOfRightExcludingEslintDisabled =
|
|
112
113
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
113
114
|
if (
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
leftIndex < rightIndex &&
|
|
116
|
+
leftIndex < indexOfRightExcludingEslintDisabled
|
|
116
117
|
) {
|
|
117
118
|
return
|
|
118
119
|
}
|
|
@@ -158,10 +159,10 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
158
159
|
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
159
160
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
160
161
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
162
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
161
163
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
162
164
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
163
165
|
order: commonJsonSchemas.orderJsonSchema,
|
|
164
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
165
166
|
},
|
|
166
167
|
additionalProperties: false,
|
|
167
168
|
type: 'object',
|
package/dist/rules/sort-maps.js
CHANGED
|
@@ -3,6 +3,7 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
|
3
3
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
4
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
5
5
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
6
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
6
7
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
7
8
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -94,14 +95,13 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
94
95
|
name,
|
|
95
96
|
}
|
|
96
97
|
if (
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
)) ||
|
|
98
|
+
isPartitionComment.hasPartitionComment(
|
|
99
|
+
options.partitionByComment,
|
|
100
|
+
getCommentsBefore.getCommentsBefore({
|
|
101
|
+
node: element,
|
|
102
|
+
sourceCode,
|
|
103
|
+
}),
|
|
104
|
+
) ||
|
|
105
105
|
(options.partitionByNewLine &&
|
|
106
106
|
lastSortingNode &&
|
|
107
107
|
getLinesBetween.getLinesBetween(
|
|
@@ -120,14 +120,15 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
120
120
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
121
121
|
let sortedNodesExcludingEslintDisabled =
|
|
122
122
|
sortNodesExcludingEslintDisabled(true)
|
|
123
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
123
124
|
pairwise.pairwise(nodes, (left, right) => {
|
|
124
|
-
let
|
|
125
|
-
let
|
|
125
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
126
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
126
127
|
let indexOfRightExcludingEslintDisabled =
|
|
127
128
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
128
129
|
if (
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
leftIndex < rightIndex &&
|
|
131
|
+
leftIndex < indexOfRightExcludingEslintDisabled
|
|
131
132
|
) {
|
|
132
133
|
return
|
|
133
134
|
}
|
|
@@ -165,9 +166,9 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
165
166
|
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
166
167
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
167
168
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
169
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
168
170
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
169
171
|
order: commonJsonSchemas.orderJsonSchema,
|
|
170
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
171
172
|
},
|
|
172
173
|
additionalProperties: false,
|
|
173
174
|
type: 'object',
|
|
@@ -10,6 +10,7 @@ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compar
|
|
|
10
10
|
const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
|
|
11
11
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
12
12
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
13
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
13
14
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
14
15
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
15
16
|
const getNewlinesErrors = require('../utils/get-newlines-errors.js')
|
|
@@ -76,10 +77,10 @@ const sortModules = createEslintRule.createEslintRule({
|
|
|
76
77
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
77
78
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
78
79
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
80
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
79
81
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
80
82
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
81
83
|
order: commonJsonSchemas.orderJsonSchema,
|
|
82
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
83
84
|
},
|
|
84
85
|
additionalProperties: false,
|
|
85
86
|
type: 'object',
|
|
@@ -260,14 +261,14 @@ let analyzeModule = ({
|
|
|
260
261
|
continue
|
|
261
262
|
}
|
|
262
263
|
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
263
|
-
for (let
|
|
264
|
+
for (let predefinedGroup of generatePredefinedGroups.generatePredefinedGroups(
|
|
264
265
|
{
|
|
265
266
|
cache: cachedGroupsByModifiersAndSelectors,
|
|
266
267
|
selectors: [selector],
|
|
267
268
|
modifiers,
|
|
268
269
|
},
|
|
269
270
|
)) {
|
|
270
|
-
defineGroup(
|
|
271
|
+
defineGroup(predefinedGroup)
|
|
271
272
|
}
|
|
272
273
|
for (let customGroup of options.customGroups) {
|
|
273
274
|
if (
|
|
@@ -295,8 +296,8 @@ let analyzeModule = ({
|
|
|
295
296
|
dependencyName: name,
|
|
296
297
|
group: getGroup(),
|
|
297
298
|
dependencies,
|
|
298
|
-
node,
|
|
299
299
|
name,
|
|
300
|
+
node,
|
|
300
301
|
}
|
|
301
302
|
let lastSortingNode =
|
|
302
303
|
(_a = formattedNodes.at(-1)) == null ? void 0 : _a.at(-1)
|
|
@@ -308,14 +309,13 @@ let analyzeModule = ({
|
|
|
308
309
|
lastSortingNode,
|
|
309
310
|
sortingNode,
|
|
310
311
|
)) ||
|
|
311
|
-
(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
))
|
|
312
|
+
isPartitionComment.hasPartitionComment(
|
|
313
|
+
options.partitionByComment,
|
|
314
|
+
getCommentsBefore.getCommentsBefore({
|
|
315
|
+
sourceCode,
|
|
316
|
+
node,
|
|
317
|
+
}),
|
|
318
|
+
)
|
|
319
319
|
) {
|
|
320
320
|
formattedNodes.push([])
|
|
321
321
|
}
|
|
@@ -344,11 +344,12 @@ let analyzeModule = ({
|
|
|
344
344
|
let sortedNodesExcludingEslintDisabled =
|
|
345
345
|
sortNodesIgnoringEslintDisabledNodes(true)
|
|
346
346
|
let nodes = formattedNodes.flat()
|
|
347
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
347
348
|
pairwise.pairwise(nodes, (left, right) => {
|
|
348
349
|
let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
|
|
349
350
|
let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
|
|
350
|
-
let
|
|
351
|
-
let
|
|
351
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
352
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
352
353
|
let indexOfRightExcludingEslintDisabled =
|
|
353
354
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
354
355
|
let messageIds = []
|
|
@@ -356,8 +357,8 @@ let analyzeModule = ({
|
|
|
356
357
|
sortNodesByDependencies.getFirstUnorderedNodeDependentOn(right, nodes)
|
|
357
358
|
if (
|
|
358
359
|
firstUnorderedNodeDependentOnRight ||
|
|
359
|
-
|
|
360
|
-
|
|
360
|
+
leftIndex > rightIndex ||
|
|
361
|
+
leftIndex >= indexOfRightExcludingEslintDisabled
|
|
361
362
|
) {
|
|
362
363
|
if (firstUnorderedNodeDependentOnRight) {
|
|
363
364
|
messageIds.push('unexpectedModulesDependencyOrder')
|
|
@@ -3,6 +3,7 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
|
3
3
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
4
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
5
5
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
6
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
6
7
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
7
8
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -67,14 +68,13 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
67
68
|
name,
|
|
68
69
|
}
|
|
69
70
|
if (
|
|
70
|
-
(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)) ||
|
|
71
|
+
isPartitionComment.hasPartitionComment(
|
|
72
|
+
options.partitionByComment,
|
|
73
|
+
getCommentsBefore.getCommentsBefore({
|
|
74
|
+
node: specifier,
|
|
75
|
+
sourceCode,
|
|
76
|
+
}),
|
|
77
|
+
) ||
|
|
78
78
|
(options.partitionByNewLine &&
|
|
79
79
|
lastSortingNode &&
|
|
80
80
|
getLinesBetween.getLinesBetween(
|
|
@@ -111,14 +111,15 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
111
111
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
112
112
|
let sortedNodesExcludingEslintDisabled =
|
|
113
113
|
sortNodesExcludingEslintDisabled(true)
|
|
114
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
114
115
|
pairwise.pairwise(nodes, (left, right) => {
|
|
115
|
-
let
|
|
116
|
-
let
|
|
116
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
117
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
117
118
|
let indexOfRightExcludingEslintDisabled =
|
|
118
119
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
119
120
|
if (
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
leftIndex < rightIndex &&
|
|
122
|
+
leftIndex < indexOfRightExcludingEslintDisabled
|
|
122
123
|
) {
|
|
123
124
|
return
|
|
124
125
|
}
|
|
@@ -160,9 +161,9 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
160
161
|
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
161
162
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
162
163
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
164
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
163
165
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
164
166
|
order: commonJsonSchemas.orderJsonSchema,
|
|
165
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
166
167
|
},
|
|
167
168
|
additionalProperties: false,
|
|
168
169
|
type: 'object',
|
|
@@ -3,6 +3,7 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
|
3
3
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
4
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
5
5
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
6
|
+
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
6
7
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
7
8
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -76,14 +77,13 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
76
77
|
name,
|
|
77
78
|
}
|
|
78
79
|
if (
|
|
79
|
-
(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)) ||
|
|
80
|
+
isPartitionComment.hasPartitionComment(
|
|
81
|
+
options.partitionByComment,
|
|
82
|
+
getCommentsBefore.getCommentsBefore({
|
|
83
|
+
node: specifier,
|
|
84
|
+
sourceCode,
|
|
85
|
+
}),
|
|
86
|
+
) ||
|
|
87
87
|
(options.partitionByNewLine &&
|
|
88
88
|
lastSortingNode &&
|
|
89
89
|
getLinesBetween.getLinesBetween(
|
|
@@ -120,14 +120,15 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
120
120
|
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
121
121
|
let sortedNodesExcludingEslintDisabled =
|
|
122
122
|
sortNodesExcludingEslintDisabled(true)
|
|
123
|
+
let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
|
|
123
124
|
pairwise.pairwise(nodes, (left, right) => {
|
|
124
|
-
let
|
|
125
|
-
let
|
|
125
|
+
let leftIndex = nodeIndexMap.get(left)
|
|
126
|
+
let rightIndex = nodeIndexMap.get(right)
|
|
126
127
|
let indexOfRightExcludingEslintDisabled =
|
|
127
128
|
sortedNodesExcludingEslintDisabled.indexOf(right)
|
|
128
129
|
if (
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
leftIndex < rightIndex &&
|
|
131
|
+
leftIndex < indexOfRightExcludingEslintDisabled
|
|
131
132
|
) {
|
|
132
133
|
return
|
|
133
134
|
}
|
|
@@ -173,9 +174,9 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
173
174
|
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
174
175
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
175
176
|
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
177
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
176
178
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
177
179
|
order: commonJsonSchemas.orderJsonSchema,
|
|
178
|
-
type: commonJsonSchemas.typeJsonSchema,
|
|
179
180
|
},
|
|
180
181
|
additionalProperties: false,
|
|
181
182
|
type: 'object',
|