eslint-plugin-perfectionist 4.3.0 → 4.5.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 (53) hide show
  1. package/dist/alphabet.d.ts +1 -2
  2. package/dist/rules/sort-array-includes/does-custom-group-match.js +30 -0
  3. package/dist/rules/sort-array-includes/types.js +10 -0
  4. package/dist/rules/sort-array-includes.js +149 -56
  5. package/dist/rules/{sort-classes-utils.js → sort-classes/does-custom-group-match.js} +4 -36
  6. package/dist/rules/sort-classes/get-overload-signature-groups.js +34 -0
  7. package/dist/rules/{sort-classes.types.js → sort-classes/types.js} +1 -1
  8. package/dist/rules/sort-classes.js +23 -25
  9. package/dist/rules/sort-decorators.js +13 -12
  10. package/dist/rules/sort-enums.js +36 -33
  11. package/dist/rules/sort-exports.js +12 -10
  12. package/dist/rules/sort-heritage-clauses.js +8 -6
  13. package/dist/{utils → rules/sort-imports}/get-typescript-import.js +4 -1
  14. package/dist/rules/sort-imports.js +46 -28
  15. package/dist/rules/sort-interfaces.js +2 -1
  16. package/dist/rules/sort-intersection-types.js +21 -20
  17. package/dist/rules/sort-jsx-props.js +8 -7
  18. package/dist/rules/sort-maps.js +15 -14
  19. package/dist/rules/{sort-modules-utils.js → sort-modules/does-custom-group-match.js} +4 -4
  20. package/dist/rules/{sort-modules.types.js → sort-modules/types.js} +1 -1
  21. package/dist/rules/sort-modules.js +24 -24
  22. package/dist/rules/sort-named-exports.js +15 -14
  23. package/dist/rules/sort-named-imports.js +15 -14
  24. package/dist/rules/{sort-object-types-utils.js → sort-object-types/does-custom-group-match.js} +4 -4
  25. package/dist/rules/{sort-object-types.types.js → sort-object-types/types.js} +1 -1
  26. package/dist/rules/sort-object-types.js +152 -106
  27. package/dist/{utils/get-node-parent.js → rules/sort-objects/get-first-node-parent-with-type.js} +3 -4
  28. package/dist/rules/sort-objects.js +115 -58
  29. package/dist/rules/sort-sets.js +14 -5
  30. package/dist/rules/sort-switch-case.js +12 -14
  31. package/dist/rules/sort-union-types.js +21 -20
  32. package/dist/rules/sort-variable-declarations.js +15 -14
  33. package/dist/utils/alphabet.js +1 -2
  34. package/dist/utils/common-json-schemas.js +50 -20
  35. package/dist/utils/compare.js +8 -2
  36. package/dist/utils/create-node-index-map.js +10 -0
  37. package/dist/utils/get-eslint-disabled-rules.js +4 -2
  38. package/dist/utils/get-matching-context-options.js +1 -1
  39. package/dist/utils/get-newlines-between-option.js +54 -0
  40. package/dist/utils/get-newlines-errors.js +21 -14
  41. package/dist/utils/get-node-range.js +5 -4
  42. package/dist/utils/get-options-with-clean-groups.js +1 -1
  43. package/dist/utils/get-settings.js +3 -3
  44. package/dist/utils/has-partition-comment.js +11 -0
  45. package/dist/utils/is-partition-comment.js +41 -12
  46. package/dist/utils/make-newlines-fixes.js +19 -29
  47. package/dist/utils/pairwise.js +1 -3
  48. package/dist/utils/sort-nodes-by-groups.js +3 -7
  49. package/dist/utils/validate-groups-configuration.js +11 -5
  50. package/package.json +3 -3
  51. /package/dist/{utils → rules/sort-decorators}/get-decorator-name.js +0 -0
  52. /package/dist/{utils → rules/sort-imports}/read-closest-ts-config-by-path.js +0 -0
  53. /package/dist/{utils → rules/sort-object-types}/is-member-optional.js +0 -0
@@ -4,7 +4,8 @@ const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js'
4
4
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-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 isPartitionComment = require('../utils/is-partition-comment.js')
7
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
8
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
8
9
  const getCommentsBefore = require('../utils/get-comments-before.js')
9
10
  const createEslintRule = require('../utils/create-eslint-rule.js')
10
11
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -54,30 +55,29 @@ const sortEnums = createEslintRule.createEslintRule({
54
55
  })
55
56
  let extractDependencies = (expression, enumName) => {
56
57
  let dependencies = []
57
- let checkNode = nodeValue => {
58
+ let stack = [expression]
59
+ while (stack.length) {
60
+ let node = stack.pop()
58
61
  if (
59
- nodeValue.type === 'MemberExpression' &&
60
- nodeValue.object.type === 'Identifier' &&
61
- nodeValue.object.name === enumName &&
62
- nodeValue.property.type === 'Identifier'
62
+ node.type === 'MemberExpression' &&
63
+ node.object.type === 'Identifier' &&
64
+ node.object.name === enumName &&
65
+ node.property.type === 'Identifier'
63
66
  ) {
64
- dependencies.push(nodeValue.property.name)
65
- } else if (nodeValue.type === 'Identifier') {
66
- dependencies.push(nodeValue.name)
67
+ dependencies.push(node.property.name)
68
+ } else if (node.type === 'Identifier') {
69
+ dependencies.push(node.name)
67
70
  }
68
- if ('left' in nodeValue) {
69
- checkNode(nodeValue.left)
71
+ if ('left' in node) {
72
+ stack.push(node.left)
70
73
  }
71
- if ('right' in nodeValue) {
72
- checkNode(nodeValue.right)
74
+ if ('right' in node) {
75
+ stack.push(node.right)
73
76
  }
74
- if ('expressions' in nodeValue) {
75
- for (let currentExpression of nodeValue.expressions) {
76
- checkNode(currentExpression)
77
- }
77
+ if ('expressions' in node) {
78
+ stack.push(...node.expressions)
78
79
  }
79
80
  }
80
- checkNode(expression)
81
81
  return dependencies
82
82
  }
83
83
  let formattedMembers = members.reduce(
@@ -109,14 +109,13 @@ const sortEnums = createEslintRule.createEslintRule({
109
109
  dependencies,
110
110
  }
111
111
  if (
112
- (options.partitionByComment &&
113
- isPartitionComment.hasPartitionComment(
114
- options.partitionByComment,
115
- getCommentsBefore.getCommentsBefore({
116
- node: member,
117
- sourceCode,
118
- }),
119
- )) ||
112
+ hasPartitionComment.hasPartitionComment({
113
+ comments: getCommentsBefore.getCommentsBefore({
114
+ node: member,
115
+ sourceCode,
116
+ }),
117
+ partitionByComment: options.partitionByComment,
118
+ }) ||
120
119
  (options.partitionByNewLine &&
121
120
  lastSortingNode &&
122
121
  getLinesBetween.getLinesBetween(
@@ -139,7 +138,7 @@ const sortEnums = createEslintRule.createEslintRule({
139
138
  !Number.isNaN(sortingNode.numericValue),
140
139
  )
141
140
  let compareOptions = {
142
- // Get the enum value rather than the name if needed
141
+ // Get the enum value rather than the name if needed.
143
142
  nodeValueGetter:
144
143
  options.sortByValue || (isNumericEnum && options.forceNumericSort)
145
144
  ? sortingNode => {
@@ -161,7 +160,10 @@ const sortEnums = createEslintRule.createEslintRule({
161
160
  return ''
162
161
  }
163
162
  : null,
164
- // If the enum is numeric, and we sort by value, always use the `natural` sort type, which will correctly sort them.
163
+ /**
164
+ * If the enum is numeric, and we sort by value, always use the
165
+ * `natural` sort type, which will correctly sort them.
166
+ */
165
167
  type:
166
168
  isNumericEnum && (options.forceNumericSort || options.sortByValue)
167
169
  ? 'natural'
@@ -186,14 +188,15 @@ const sortEnums = createEslintRule.createEslintRule({
186
188
  let sortedNodes = sortNodesIgnoringEslintDisabledNodes(false)
187
189
  let sortedNodesExcludingEslintDisabled =
188
190
  sortNodesIgnoringEslintDisabledNodes(true)
191
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
189
192
  pairwise.pairwise(sortingNodes, (left, right) => {
190
- let indexOfLeft = sortedNodes.indexOf(left)
191
- let indexOfRight = sortedNodes.indexOf(right)
193
+ let leftIndex = nodeIndexMap.get(left)
194
+ let rightIndex = nodeIndexMap.get(right)
192
195
  let indexOfRightExcludingEslintDisabled =
193
196
  sortedNodesExcludingEslintDisabled.indexOf(right)
194
197
  if (
195
- indexOfLeft < indexOfRight &&
196
- indexOfLeft < indexOfRightExcludingEslintDisabled
198
+ leftIndex < rightIndex &&
199
+ leftIndex < indexOfRightExcludingEslintDisabled
197
200
  ) {
198
201
  return
199
202
  }
@@ -249,9 +252,9 @@ const sortEnums = createEslintRule.createEslintRule({
249
252
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
250
253
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
251
254
  alphabet: commonJsonSchemas.alphabetJsonSchema,
255
+ type: commonJsonSchemas.buildTypeJsonSchema(),
252
256
  locales: commonJsonSchemas.localesJsonSchema,
253
257
  order: commonJsonSchemas.orderJsonSchema,
254
- type: commonJsonSchemas.typeJsonSchema,
255
258
  },
256
259
  additionalProperties: false,
257
260
  type: 'object',
@@ -3,7 +3,8 @@ 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 isPartitionComment = require('../utils/is-partition-comment.js')
6
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
7
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
7
8
  const getCommentsBefore = require('../utils/get-comments-before.js')
8
9
  const createEslintRule = require('../utils/create-eslint-rule.js')
9
10
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -57,13 +58,13 @@ const sortExports = createEslintRule.createEslintRule({
57
58
  let lastNode = (_a = parts.at(-1)) == null ? void 0 : _a.at(-1)
58
59
  if (
59
60
  (partitionComment &&
60
- isPartitionComment.hasPartitionComment(
61
- partitionComment,
62
- getCommentsBefore.getCommentsBefore({
61
+ hasPartitionComment.hasPartitionComment({
62
+ comments: getCommentsBefore.getCommentsBefore({
63
63
  sourceCode,
64
64
  node,
65
65
  }),
66
- )) ||
66
+ partitionByComment: options.partitionByComment,
67
+ })) ||
67
68
  (options.partitionByNewLine &&
68
69
  lastNode &&
69
70
  getLinesBetween.getLinesBetween(sourceCode, lastNode, sortingNode))
@@ -98,14 +99,15 @@ const sortExports = createEslintRule.createEslintRule({
98
99
  let sortedNodes = sortNodesExcludingEslintDisabled(false)
99
100
  let sortedNodesExcludingEslintDisabled =
100
101
  sortNodesExcludingEslintDisabled(true)
102
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
101
103
  pairwise.pairwise(nodes, (left, right) => {
102
- let indexOfLeft = sortedNodes.indexOf(left)
103
- let indexOfRight = sortedNodes.indexOf(right)
104
+ let leftIndex = nodeIndexMap.get(left)
105
+ let rightIndex = nodeIndexMap.get(right)
104
106
  let indexOfRightExcludingEslintDisabled =
105
107
  sortedNodesExcludingEslintDisabled.indexOf(right)
106
108
  if (
107
- indexOfLeft < indexOfRight &&
108
- indexOfLeft < indexOfRightExcludingEslintDisabled
109
+ leftIndex < rightIndex &&
110
+ leftIndex < indexOfRightExcludingEslintDisabled
109
111
  ) {
110
112
  return
111
113
  }
@@ -154,9 +156,9 @@ const sortExports = createEslintRule.createEslintRule({
154
156
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
155
157
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
156
158
  alphabet: commonJsonSchemas.alphabetJsonSchema,
159
+ type: commonJsonSchemas.buildTypeJsonSchema(),
157
160
  locales: commonJsonSchemas.localesJsonSchema,
158
161
  order: commonJsonSchemas.orderJsonSchema,
159
- type: commonJsonSchemas.typeJsonSchema,
160
162
  },
161
163
  additionalProperties: false,
162
164
  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')
@@ -35,10 +36,10 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
35
36
  customGroups: commonJsonSchemas.customGroupsJsonSchema,
36
37
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
37
38
  alphabet: commonJsonSchemas.alphabetJsonSchema,
39
+ type: commonJsonSchemas.buildTypeJsonSchema(),
38
40
  locales: commonJsonSchemas.localesJsonSchema,
39
41
  groups: commonJsonSchemas.groupsJsonSchema,
40
42
  order: commonJsonSchemas.orderJsonSchema,
41
- type: commonJsonSchemas.typeJsonSchema,
42
43
  },
43
44
  additionalProperties: false,
44
45
  type: 'object',
@@ -82,7 +83,7 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
82
83
  name: 'sort-heritage-clauses',
83
84
  })
84
85
  let sortHeritageClauses$1 = (context, options, heritageClauses) => {
85
- if (!heritageClauses || !isSortable.isSortable(heritageClauses)) {
86
+ if (!isSortable.isSortable(heritageClauses)) {
86
87
  return
87
88
  }
88
89
  let sourceCode = getSourceCode.getSourceCode(context)
@@ -112,14 +113,15 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
112
113
  let sortedNodes = sortNodesExcludingEslintDisabled(false)
113
114
  let sortedNodesExcludingEslintDisabled =
114
115
  sortNodesExcludingEslintDisabled(true)
116
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
115
117
  pairwise.pairwise(nodes, (left, right) => {
116
- let indexOfLeft = sortedNodes.indexOf(left)
117
- let indexOfRight = sortedNodes.indexOf(right)
118
+ let leftIndex = nodeIndexMap.get(left)
119
+ let rightIndex = nodeIndexMap.get(right)
118
120
  let indexOfRightExcludingEslintDisabled =
119
121
  sortedNodesExcludingEslintDisabled.indexOf(right)
120
122
  if (
121
- indexOfLeft < indexOfRight &&
122
- indexOfLeft < indexOfRightExcludingEslintDisabled
123
+ leftIndex < rightIndex &&
124
+ leftIndex < indexOfRightExcludingEslintDisabled
123
125
  ) {
124
126
  return
125
127
  }
@@ -20,7 +20,10 @@ let getTypescriptImport = () => {
20
20
  : (_documentCurrentScript &&
21
21
  _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' &&
22
22
  _documentCurrentScript.src) ||
23
- new URL('utils/get-typescript-import.js', document.baseURI).href,
23
+ new URL(
24
+ 'rules/sort-imports/get-typescript-import.js',
25
+ document.baseURI,
26
+ ).href,
24
27
  )('typescript')
25
28
  } catch (_error) {
26
29
  return null
@@ -3,13 +3,14 @@ const node_module = require('node:module')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
5
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
6
+ const readClosestTsConfigByPath = require('./sort-imports/read-closest-ts-config-by-path.js')
6
7
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
7
- const readClosestTsConfigByPath = require('../utils/read-closest-ts-config-by-path.js')
8
8
  const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
9
9
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
10
+ const getTypescriptImport = require('./sort-imports/get-typescript-import.js')
10
11
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
11
- const getTypescriptImport = require('../utils/get-typescript-import.js')
12
- const isPartitionComment = require('../utils/is-partition-comment.js')
12
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
13
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
13
14
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
14
15
  const getCommentsBefore = require('../utils/get-comments-before.js')
15
16
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -132,10 +133,19 @@ 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),
147
+ return styleExtensions.some(extension =>
148
+ cleanedValue == null ? void 0 : cleanedValue.endsWith(extension),
139
149
  )
140
150
  }
141
151
  let flatGroups = new Set(options.groups.flat())
@@ -186,10 +196,12 @@ const sortImports = createEslintRule.createEslintRule({
186
196
  'ws',
187
197
  ]
188
198
  let builtinPrefixOnlyModules = ['sea', 'sqlite', 'test']
199
+ let valueToCheck = value.startsWith('node:')
200
+ ? value.split('node:')[1]
201
+ : value
189
202
  return (
190
- node_module.builtinModules.includes(
191
- value.startsWith('node:') ? value.split('node:')[1] : value,
192
- ) ||
203
+ (!!valueToCheck &&
204
+ node_module.builtinModules.includes(valueToCheck)) ||
193
205
  builtinPrefixOnlyModules.some(
194
206
  module2 => `node:${module2}` === value,
195
207
  ) ||
@@ -330,24 +342,22 @@ const sortImports = createEslintRule.createEslintRule({
330
342
  }
331
343
  return {
332
344
  'Program:exit': () => {
333
- var _a
334
345
  let hasContentBetweenNodes = (left, right) =>
335
346
  !!sourceCode.getTokensBetween(left.node, right.node, {
336
347
  includeComments: false,
337
348
  }).length
338
349
  let formattedMembers = [[]]
339
350
  for (let sortingNode of nodes) {
340
- let lastSortingNode =
341
- (_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
351
+ let lastGroup = formattedMembers.at(-1)
352
+ let lastSortingNode = lastGroup == null ? void 0 : lastGroup.at(-1)
342
353
  if (
343
- (options.partitionByComment &&
344
- isPartitionComment.hasPartitionComment(
345
- options.partitionByComment,
346
- getCommentsBefore.getCommentsBefore({
347
- node: sortingNode.node,
348
- sourceCode,
349
- }),
350
- )) ||
354
+ hasPartitionComment.hasPartitionComment({
355
+ comments: getCommentsBefore.getCommentsBefore({
356
+ node: sortingNode.node,
357
+ sourceCode,
358
+ }),
359
+ partitionByComment: options.partitionByComment,
360
+ }) ||
351
361
  (options.partitionByNewLine &&
352
362
  lastSortingNode &&
353
363
  getLinesBetween.getLinesBetween(
@@ -358,9 +368,10 @@ const sortImports = createEslintRule.createEslintRule({
358
368
  (lastSortingNode &&
359
369
  hasContentBetweenNodes(lastSortingNode, sortingNode))
360
370
  ) {
361
- formattedMembers.push([])
371
+ lastGroup = []
372
+ formattedMembers.push(lastGroup)
362
373
  }
363
- formattedMembers.at(-1).push(sortingNode)
374
+ lastGroup.push(sortingNode)
364
375
  }
365
376
  for (let nodeList of formattedMembers) {
366
377
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
@@ -378,20 +389,21 @@ const sortImports = createEslintRule.createEslintRule({
378
389
  let sortedNodes = sortNodesExcludingEslintDisabled(false)
379
390
  let sortedNodesExcludingEslintDisabled =
380
391
  sortNodesExcludingEslintDisabled(true)
392
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
381
393
  pairwise.pairwise(nodeList, (left, right) => {
382
394
  let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
383
395
  let rightNumber = getGroupNumber.getGroupNumber(
384
396
  options.groups,
385
397
  right,
386
398
  )
387
- let indexOfLeft = sortedNodes.indexOf(left)
388
- let indexOfRight = sortedNodes.indexOf(right)
399
+ let leftIndex = nodeIndexMap.get(left)
400
+ let rightIndex = nodeIndexMap.get(right)
389
401
  let indexOfRightExcludingEslintDisabled =
390
402
  sortedNodesExcludingEslintDisabled.indexOf(right)
391
403
  let messageIds = []
392
404
  if (
393
- indexOfLeft > indexOfRight ||
394
- indexOfLeft >= indexOfRightExcludingEslintDisabled
405
+ leftIndex > rightIndex ||
406
+ leftIndex >= indexOfRightExcludingEslintDisabled
395
407
  ) {
396
408
  messageIds.push(
397
409
  leftNumber === rightNumber
@@ -402,12 +414,15 @@ const sortImports = createEslintRule.createEslintRule({
402
414
  messageIds = [
403
415
  ...messageIds,
404
416
  ...getNewlinesErrors.getNewlinesErrors({
417
+ options: {
418
+ ...options,
419
+ customGroups: [],
420
+ },
405
421
  missedSpacingError: 'missedSpacingBetweenImports',
406
422
  extraSpacingError: 'extraSpacingBetweenImports',
407
423
  rightNum: rightNumber,
408
424
  leftNum: leftNumber,
409
425
  sourceCode,
410
- options,
411
426
  right,
412
427
  left,
413
428
  }),
@@ -423,10 +438,13 @@ const sortImports = createEslintRule.createEslintRule({
423
438
  fixer,
424
439
  }),
425
440
  ...makeNewlinesFixes.makeNewlinesFixes({
441
+ options: {
442
+ ...options,
443
+ customGroups: [],
444
+ },
426
445
  sortedNodes: sortedNodesExcludingEslintDisabled,
427
446
  nodes: nodeList,
428
447
  sourceCode,
429
- options,
430
448
  fixer,
431
449
  }),
432
450
  ],
@@ -517,10 +535,10 @@ const sortImports = createEslintRule.createEslintRule({
517
535
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
518
536
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
519
537
  alphabet: commonJsonSchemas.alphabetJsonSchema,
538
+ type: commonJsonSchemas.buildTypeJsonSchema(),
520
539
  locales: commonJsonSchemas.localesJsonSchema,
521
540
  groups: commonJsonSchemas.groupsJsonSchema,
522
541
  order: commonJsonSchemas.orderJsonSchema,
523
- type: commonJsonSchemas.typeJsonSchema,
524
542
  },
525
543
  definitions: {
526
544
  '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,7 +5,8 @@ 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 isPartitionComment = require('../utils/is-partition-comment.js')
8
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
9
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
9
10
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
10
11
  const getCommentsBefore = require('../utils/get-comments-before.js')
11
12
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.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
+ hasPartitionComment.hasPartitionComment({
148
+ comments: getCommentsBefore.getCommentsBefore({
149
+ tokenValueToIgnoreBefore: '&',
150
+ node: type,
151
+ sourceCode,
152
+ }),
153
+ partitionByComment: options.partitionByComment,
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,7 +3,8 @@ 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 isPartitionComment = require('../utils/is-partition-comment.js')
6
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
7
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
7
8
  const getCommentsBefore = require('../utils/get-comments-before.js')
8
9
  const createEslintRule = require('../utils/create-eslint-rule.js')
9
10
  const getLinesBetween = require('../utils/get-lines-between.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
+ hasPartitionComment.hasPartitionComment({
99
+ comments: getCommentsBefore.getCommentsBefore({
100
+ node: element,
101
+ sourceCode,
102
+ }),
103
+ partitionByComment: options.partitionByComment,
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',