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.
@@ -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 ['.less', '.scss', '.sass', '.styl', '.pcss', '.css', '.sss'].some(
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 lastSortingNode =
341
- (_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
347
+ let lastGroup = formattedMembers.at(-1)
348
+ let lastSortingNode = lastGroup == null ? void 0 : lastGroup.at(-1)
342
349
  if (
343
- (options.partitionByComment &&
344
- isPartitionComment.hasPartitionComment(
345
- options.partitionByComment,
346
- getCommentsBefore.getCommentsBefore({
347
- node: sortingNode.node,
348
- sourceCode,
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
- formattedMembers.push([])
367
+ lastGroup = []
368
+ formattedMembers.push(lastGroup)
362
369
  }
363
- formattedMembers.at(-1).push(sortingNode)
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 indexOfLeft = sortedNodes.indexOf(left)
388
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft > indexOfRight ||
394
- indexOfLeft >= indexOfRightExcludingEslintDisabled
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: [sortObjectTypes.jsonSchema],
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 lastSortingNode =
135
- (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
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
- (options.partitionByComment &&
148
- isPartitionComment.hasPartitionComment(
149
- options.partitionByComment,
150
- getCommentsBefore.getCommentsBefore({
151
- tokenValueToIgnoreBefore: '&',
152
- node: type,
153
- sourceCode,
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
- accumulator.push([])
163
+ lastGroup = []
164
+ accumulator.push(lastGroup)
165
165
  }
166
- ;(_b = accumulator.at(-1)) == null ? void 0 : _b.push(sortingNode)
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 indexOfLeft = sortedNodes.indexOf(left)
183
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft > indexOfRight ||
189
- indexOfLeft >= indexOfRightExcludingEslintDisabled
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 indexOfLeft = sortedNodes.indexOf(left)
110
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft < indexOfRight &&
115
- indexOfLeft < indexOfRightExcludingEslintDisabled
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',
@@ -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
- (options.partitionByComment &&
98
- isPartitionComment.hasPartitionComment(
99
- options.partitionByComment,
100
- getCommentsBefore.getCommentsBefore({
101
- node: element,
102
- sourceCode,
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 indexOfLeft = sortedNodes.indexOf(left)
125
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft < indexOfRight &&
130
- indexOfLeft < indexOfRightExcludingEslintDisabled
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 officialGroup of generatePredefinedGroups.generatePredefinedGroups(
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(officialGroup)
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
- (options.partitionByComment &&
312
- isPartitionComment.hasPartitionComment(
313
- options.partitionByComment,
314
- getCommentsBefore.getCommentsBefore({
315
- sourceCode,
316
- node,
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 indexOfLeft = sortedNodes.indexOf(left)
351
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft > indexOfRight ||
360
- indexOfLeft >= indexOfRightExcludingEslintDisabled
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
- (options.partitionByComment &&
71
- isPartitionComment.hasPartitionComment(
72
- options.partitionByComment,
73
- getCommentsBefore.getCommentsBefore({
74
- node: specifier,
75
- sourceCode,
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 indexOfLeft = sortedNodes.indexOf(left)
116
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft < indexOfRight &&
121
- indexOfLeft < indexOfRightExcludingEslintDisabled
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
- (options.partitionByComment &&
80
- isPartitionComment.hasPartitionComment(
81
- options.partitionByComment,
82
- getCommentsBefore.getCommentsBefore({
83
- node: specifier,
84
- sourceCode,
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 indexOfLeft = sortedNodes.indexOf(left)
125
- let indexOfRight = sortedNodes.indexOf(right)
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
- indexOfLeft < indexOfRight &&
130
- indexOfLeft < indexOfRightExcludingEslintDisabled
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',