eslint-plugin-perfectionist 5.0.0 → 5.2.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 (167) hide show
  1. package/dist/alphabet.d.ts +1 -1
  2. package/dist/index.d.ts +15 -244
  3. package/dist/package.json.js +1 -1
  4. package/dist/rules/sort-array-includes/types.d.ts +3 -3
  5. package/dist/rules/sort-array-includes.d.ts +5 -3
  6. package/dist/rules/sort-array-includes.js +1 -1
  7. package/dist/rules/sort-classes/types.d.ts +3 -3
  8. package/dist/rules/sort-classes.d.ts +5 -3
  9. package/dist/rules/sort-classes.js +1 -1
  10. package/dist/rules/sort-decorators/types.d.ts +4 -4
  11. package/dist/rules/sort-decorators.d.ts +5 -3
  12. package/dist/rules/sort-decorators.js +1 -1
  13. package/dist/rules/sort-enums/build-comparator-by-options-computer.d.ts +2 -2
  14. package/dist/rules/sort-enums/types.d.ts +4 -4
  15. package/dist/rules/sort-enums.d.ts +5 -3
  16. package/dist/rules/sort-enums.js +1 -1
  17. package/dist/rules/sort-export-attributes/types.d.ts +4 -4
  18. package/dist/rules/sort-export-attributes.d.ts +5 -3
  19. package/dist/rules/sort-export-attributes.js +1 -1
  20. package/dist/rules/sort-exports/types.d.ts +3 -3
  21. package/dist/rules/sort-exports.d.ts +5 -3
  22. package/dist/rules/sort-exports.js +14 -12
  23. package/dist/rules/sort-heritage-clauses/types.d.ts +3 -3
  24. package/dist/rules/sort-heritage-clauses.d.ts +5 -3
  25. package/dist/rules/sort-heritage-clauses.js +1 -1
  26. package/dist/rules/sort-import-attributes/types.d.ts +4 -4
  27. package/dist/rules/sort-import-attributes.d.ts +5 -3
  28. package/dist/rules/sort-import-attributes.js +1 -1
  29. package/dist/rules/sort-imports/comparator-by-options-computer.d.ts +2 -2
  30. package/dist/rules/sort-imports/comparator-by-options-computer.js +48 -4
  31. package/dist/rules/sort-imports/compute-common-selectors.d.ts +3 -3
  32. package/dist/rules/sort-imports/compute-specifier-name.d.ts +12 -0
  33. package/dist/rules/sort-imports/compute-specifier-name.js +64 -0
  34. package/dist/rules/sort-imports/is-side-effect-only-group.d.ts +1 -1
  35. package/dist/rules/sort-imports/matches-tsconfig-paths.d.ts +1 -1
  36. package/dist/rules/sort-imports/types.d.ts +16 -6
  37. package/dist/rules/sort-imports/types.js +5 -0
  38. package/dist/rules/sort-imports/validate-side-effects-configuration.d.ts +1 -1
  39. package/dist/rules/sort-imports.d.ts +5 -3
  40. package/dist/rules/sort-imports.js +7 -1
  41. package/dist/rules/sort-interfaces.d.ts +5 -3
  42. package/dist/rules/sort-interfaces.js +0 -1
  43. package/dist/rules/sort-intersection-types.d.ts +5 -3
  44. package/dist/rules/sort-intersection-types.js +1 -1
  45. package/dist/rules/sort-jsx-props/types.d.ts +3 -3
  46. package/dist/rules/sort-jsx-props.d.ts +5 -3
  47. package/dist/rules/sort-jsx-props.js +1 -1
  48. package/dist/rules/sort-maps/types.d.ts +3 -3
  49. package/dist/rules/sort-maps.d.ts +5 -3
  50. package/dist/rules/sort-maps.js +1 -1
  51. package/dist/rules/sort-modules/build-comparator-by-options-computer.d.ts +12 -0
  52. package/dist/rules/sort-modules/build-comparator-by-options-computer.js +66 -0
  53. package/dist/rules/sort-modules/compute-dependencies.d.ts +27 -0
  54. package/dist/rules/sort-modules/compute-dependencies.js +195 -0
  55. package/dist/rules/sort-modules/is-arrow-function-node.d.ts +12 -0
  56. package/dist/rules/sort-modules/is-arrow-function-node.js +10 -0
  57. package/dist/rules/sort-modules/is-property-or-accessor-node.d.ts +11 -0
  58. package/dist/rules/sort-modules/is-property-or-accessor-node.js +8 -0
  59. package/dist/rules/sort-modules/types.d.ts +16 -5
  60. package/dist/rules/sort-modules/types.js +7 -1
  61. package/dist/rules/sort-modules.d.ts +5 -3
  62. package/dist/rules/sort-modules.js +34 -142
  63. package/dist/rules/sort-named-exports/compute-node-name.d.ts +12 -0
  64. package/dist/rules/sort-named-exports/compute-node-name.js +15 -0
  65. package/dist/rules/sort-named-exports/types.d.ts +4 -4
  66. package/dist/rules/sort-named-exports.d.ts +5 -3
  67. package/dist/rules/sort-named-exports.js +18 -21
  68. package/dist/rules/sort-named-imports/compute-node-name.d.ts +12 -0
  69. package/dist/rules/sort-named-imports/compute-node-name.js +17 -0
  70. package/dist/rules/sort-named-imports/types.d.ts +4 -4
  71. package/dist/rules/sort-named-imports.d.ts +5 -3
  72. package/dist/rules/sort-named-imports.js +20 -19
  73. package/dist/rules/sort-object-types/comparator-by-options-computer.d.ts +2 -2
  74. package/dist/rules/sort-object-types/compute-matched-context-options.d.ts +1 -1
  75. package/dist/rules/sort-object-types/compute-node-parent-name.d.ts +1 -1
  76. package/dist/rules/sort-object-types/passes-declaration-comment-matches-filter.d.ts +2 -2
  77. package/dist/rules/sort-object-types/passes-declaration-matches-pattern-filter.d.ts +2 -2
  78. package/dist/rules/sort-object-types/types.d.ts +14 -35
  79. package/dist/rules/sort-object-types/types.js +0 -1
  80. package/dist/rules/sort-object-types.d.ts +5 -3
  81. package/dist/rules/sort-object-types.js +24 -26
  82. package/dist/rules/sort-objects/compute-matched-context-options.d.ts +1 -1
  83. package/dist/rules/sort-objects/passes-calling-function-name-pattern-filter.d.ts +2 -2
  84. package/dist/rules/sort-objects/passes-declaration-comment-matches-filter.d.ts +2 -2
  85. package/dist/rules/sort-objects/passes-declaration-matches-pattern-filter.d.ts +2 -2
  86. package/dist/rules/sort-objects/types.d.ts +5 -5
  87. package/dist/rules/sort-objects.d.ts +5 -3
  88. package/dist/rules/sort-objects.js +1 -1
  89. package/dist/rules/sort-sets.d.ts +5 -3
  90. package/dist/rules/sort-sets.js +0 -1
  91. package/dist/rules/sort-switch-case.d.ts +5 -3
  92. package/dist/rules/sort-switch-case.js +0 -1
  93. package/dist/rules/sort-union-types/types.d.ts +3 -3
  94. package/dist/rules/sort-union-types.d.ts +5 -3
  95. package/dist/rules/sort-union-types.js +1 -1
  96. package/dist/rules/sort-variable-declarations/types.d.ts +3 -3
  97. package/dist/rules/sort-variable-declarations.d.ts +5 -3
  98. package/dist/rules/sort-variable-declarations.js +1 -1
  99. package/dist/types/common-groups-options.d.ts +47 -18
  100. package/dist/types/common-options.d.ts +11 -5
  101. package/dist/types/common-partition-options.d.ts +1 -1
  102. package/dist/types/scoped-regex-option.d.ts +1 -1
  103. package/dist/utils/build-default-options-by-group-index-computer.d.ts +3 -3
  104. package/dist/utils/compare/build-line-length-comparator.d.ts +3 -3
  105. package/dist/utils/compare/build-string-formatter.d.ts +1 -1
  106. package/dist/utils/compare/compare-alphabetically.d.ts +1 -1
  107. package/dist/utils/compare/compare-by-custom-sort.d.ts +1 -1
  108. package/dist/utils/compare/compare-naturally.d.ts +1 -1
  109. package/dist/utils/compare/compute-comparators.d.ts +3 -3
  110. package/dist/utils/compare/compute-ordered-value.d.ts +1 -1
  111. package/dist/utils/compare/default-comparator-by-options-computer.d.ts +2 -2
  112. package/dist/utils/compare/unsorted-comparator.d.ts +2 -2
  113. package/dist/utils/complete.d.ts +1 -1
  114. package/dist/utils/complete.js +1 -52
  115. package/dist/utils/compute-group-name.d.ts +1 -1
  116. package/dist/utils/compute-group.d.ts +7 -7
  117. package/dist/utils/compute-group.js +22 -19
  118. package/dist/utils/compute-groups-names.d.ts +1 -1
  119. package/dist/utils/compute-nodes-in-circular-dependencies.d.ts +5 -2
  120. package/dist/utils/compute-overridden-options-by-group-index.d.ts +2 -2
  121. package/dist/utils/compute-overridden-options-by-group-index.js +38 -19
  122. package/dist/utils/compute-parent-nodes-with-types.d.ts +1 -1
  123. package/dist/utils/create-eslint-rule.d.ts +3 -1
  124. package/dist/utils/create-node-index-map.d.ts +1 -1
  125. package/dist/utils/does-custom-group-match.d.ts +2 -2
  126. package/dist/utils/filter-options-by-all-names-match.d.ts +1 -1
  127. package/dist/utils/get-comment-above-that-should-exist.d.ts +2 -2
  128. package/dist/utils/get-group-index.d.ts +2 -2
  129. package/dist/utils/get-lines-between.d.ts +1 -1
  130. package/dist/utils/get-newlines-between-errors.d.ts +2 -2
  131. package/dist/utils/get-newlines-between-option.d.ts +8 -2
  132. package/dist/utils/get-newlines-between-option.js +17 -31
  133. package/dist/utils/get-node-range.d.ts +1 -1
  134. package/dist/utils/get-options-with-clean-groups.d.ts +1 -1
  135. package/dist/utils/get-settings.d.ts +11 -13
  136. package/dist/utils/get-settings.js +2 -0
  137. package/dist/utils/is-group-with-overrides-option.d.ts +10 -3
  138. package/dist/utils/is-newlines-between-option.d.ts +1 -1
  139. package/dist/utils/is-node-dependent-on-other-node.d.ts +9 -3
  140. package/dist/utils/is-partition-comment.d.ts +1 -1
  141. package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +14 -11
  142. package/dist/utils/json-schemas/common-groups-json-schemas.js +81 -54
  143. package/dist/utils/json-schemas/common-json-schemas.d.ts +4 -4
  144. package/dist/utils/json-schemas/common-json-schemas.js +3 -2
  145. package/dist/utils/make-comment-above-fixes.d.ts +2 -2
  146. package/dist/utils/make-comment-after-fixes.d.ts +1 -1
  147. package/dist/utils/make-fixes.d.ts +7 -9
  148. package/dist/utils/make-newlines-between-fixes.d.ts +3 -3
  149. package/dist/utils/make-order-fixes.d.ts +2 -2
  150. package/dist/utils/matches.d.ts +1 -1
  151. package/dist/utils/report-all-errors.d.ts +21 -23
  152. package/dist/utils/report-errors.d.ts +4 -4
  153. package/dist/utils/scoped-regex/matches-scoped-expressions.d.ts +2 -2
  154. package/dist/utils/scoped-regex/partition-patterns-by-scope.d.ts +1 -1
  155. package/dist/utils/should-partition.d.ts +4 -4
  156. package/dist/utils/sort-nodes-by-dependencies.d.ts +5 -2
  157. package/dist/utils/sort-nodes-by-groups.d.ts +4 -4
  158. package/dist/utils/sort-nodes.d.ts +3 -3
  159. package/dist/utils/validate-custom-sort-configuration.d.ts +2 -2
  160. package/dist/utils/validate-groups-configuration.d.ts +1 -1
  161. package/dist/utils/validate-newlines-and-partition-configuration.d.ts +5 -3
  162. package/dist/utils/validate-newlines-and-partition-configuration.js +61 -9
  163. package/dist/utils/validate-no-duplicated-groups.d.ts +1 -1
  164. package/dist/utils/validate-objects-inside-groups.d.ts +1 -1
  165. package/package.json +2 -2
  166. package/dist/rules/sort-object-types/build-options-by-group-index-computer.d.ts +0 -18
  167. package/dist/rules/sort-object-types/build-options-by-group-index-computer.js +0 -33
@@ -10,21 +10,25 @@ import {
10
10
  partitionByNewLineJsonSchema,
11
11
  partitionByCommentJsonSchema,
12
12
  } from '../utils/json-schemas/common-partition-json-schemas.js'
13
- import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
14
- import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
15
- import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
16
13
  import {
17
14
  allSelectors,
18
15
  allModifiers,
19
16
  singleCustomGroupJsonSchema,
17
+ USAGE_TYPE_OPTION,
20
18
  } from './sort-modules/types.js'
19
+ import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
20
+ import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
21
+ import { buildComparatorByOptionsComputer } from './sort-modules/build-comparator-by-options-computer.js'
21
22
  import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
22
23
  import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
24
+ import { isPropertyOrAccessorNode } from './sort-modules/is-property-or-accessor-node.js'
23
25
  import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
24
26
  import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
25
27
  import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
26
28
  import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.js'
27
29
  import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
30
+ import { isArrowFunctionNode } from './sort-modules/is-arrow-function-node.js'
31
+ import { computeDependencies } from './sort-modules/compute-dependencies.js'
28
32
  import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
29
33
  import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
30
34
  import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
@@ -33,7 +37,6 @@ import { createEslintRule } from '../utils/create-eslint-rule.js'
33
37
  import { getDecoratorName } from '../utils/get-decorator-name.js'
34
38
  import { reportAllErrors } from '../utils/report-all-errors.js'
35
39
  import { shouldPartition } from '../utils/should-partition.js'
36
- import { getEnumMembers } from '../utils/get-enum-members.js'
37
40
  import { getGroupIndex } from '../utils/get-group-index.js'
38
41
  import { computeGroup } from '../utils/compute-group.js'
39
42
  import { rangeToDiff } from '../utils/range-to-diff.js'
@@ -62,6 +65,7 @@ let defaultOptions = {
62
65
  'function',
63
66
  ],
64
67
  fallbackSort: { type: 'unsorted' },
68
+ newlinesInside: 'newlinesBetween',
65
69
  partitionByComment: false,
66
70
  partitionByNewLine: false,
67
71
  newlinesBetween: 'ignore',
@@ -78,8 +82,11 @@ const sortModules = createEslintRule({
78
82
  schema: [
79
83
  {
80
84
  properties: {
81
- ...buildCommonJsonSchemas(),
85
+ ...buildCommonJsonSchemas({
86
+ allowedAdditionalTypeValues: [USAGE_TYPE_OPTION],
87
+ }),
82
88
  ...buildCommonGroupsJsonSchemas({
89
+ allowedAdditionalTypeValues: [USAGE_TYPE_OPTION],
83
90
  singleCustomGroupJsonSchema,
84
91
  }),
85
92
  partitionByComment: partitionByCommentJsonSchema,
@@ -101,7 +108,6 @@ const sortModules = createEslintRule({
101
108
  description: 'Enforce sorted modules.',
102
109
  recommended: true,
103
110
  },
104
- defaultOptions: [defaultOptions],
105
111
  type: 'suggestion',
106
112
  fixable: 'code',
107
113
  },
@@ -125,9 +131,9 @@ const sortModules = createEslintRule({
125
131
  if (isSortable(program.body)) {
126
132
  return analyzeModule({
127
133
  eslintDisabledLines,
134
+ module: program,
128
135
  sourceCode,
129
136
  options,
130
- program,
131
137
  context,
132
138
  })
133
139
  }
@@ -141,11 +147,13 @@ function analyzeModule({
141
147
  eslintDisabledLines,
142
148
  sourceCode,
143
149
  options,
144
- program,
145
150
  context,
151
+ module,
146
152
  }) {
153
+ let optionsByGroupIndexComputer =
154
+ buildDefaultOptionsByGroupIndexComputer(options)
147
155
  let formattedNodes = [[]]
148
- for (let node of program.body) {
156
+ for (let node of module.body) {
149
157
  let parseNode = function (nodeToParse) {
150
158
  if ('declare' in nodeToParse && nodeToParse.declare) {
151
159
  modifiers.push('declare')
@@ -185,7 +193,7 @@ function analyzeModule({
185
193
  formattedNodes.push([])
186
194
  if (nodeToParse.body) {
187
195
  analyzeModule({
188
- program: nodeToParse.body,
196
+ module: nodeToParse.body,
189
197
  eslintDisabledLines,
190
198
  sourceCode,
191
199
  options,
@@ -200,10 +208,7 @@ function analyzeModule({
200
208
  case AST_NODE_TYPES.TSEnumDeclaration:
201
209
  selector = 'enum'
202
210
  ;({ name } = nodeToParse.id)
203
- dependencies = [
204
- ...dependencies,
205
- ...getEnumMembers(nodeToParse).flatMap(extractDependencies),
206
- ]
211
+ dependencies = [...dependencies, ...extractDependencies(nodeToParse)]
207
212
  break
208
213
  case AST_NODE_TYPES.ClassDeclaration:
209
214
  selector = 'class'
@@ -218,13 +223,7 @@ function analyzeModule({
218
223
  decorator,
219
224
  }),
220
225
  )
221
- dependencies = [
222
- ...dependencies,
223
- ...(nodeToParse.superClass && 'name' in nodeToParse.superClass
224
- ? [nodeToParse.superClass.name]
225
- : []),
226
- ...extractDependencies(nodeToParse.body),
227
- ]
226
+ dependencies = [...dependencies, ...extractDependencies(nodeToParse)]
228
227
  break
229
228
  }
230
229
  }
@@ -291,11 +290,13 @@ function analyzeModule({
291
290
  function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
292
291
  let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
293
292
  sortNodesByGroups({
293
+ comparatorByOptionsComputer: buildComparatorByOptionsComputer({
294
+ ignoreEslintDisabledNodes,
295
+ sortingNodes: nodes2,
296
+ }),
294
297
  isNodeIgnored: sortingNode =>
295
298
  getGroupIndex(options.groups, sortingNode) === options.groups.length,
296
- optionsByGroupIndexComputer:
297
- buildDefaultOptionsByGroupIndexComputer(options),
298
- comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
299
+ optionsByGroupIndexComputer,
299
300
  ignoreEslintDisabledNodes,
300
301
  groups: options.groups,
301
302
  nodes: nodes2,
@@ -321,127 +322,18 @@ function analyzeModule({
321
322
  })
322
323
  }
323
324
  function extractDependencies(expression) {
324
- let dependencies = []
325
325
  let searchStaticMethodsAndFunctionProperties =
326
- expression.type === 'ClassBody' &&
327
- expression.body.some(
326
+ expression.type === AST_NODE_TYPES.ClassDeclaration &&
327
+ expression.body.body.some(
328
328
  classElement =>
329
- classElement.type === 'StaticBlock' ||
329
+ classElement.type === AST_NODE_TYPES.StaticBlock ||
330
330
  (classElement.static &&
331
- isPropertyOrAccessor(classElement) &&
332
- !isArrowFunction(classElement)),
331
+ isPropertyOrAccessorNode(classElement) &&
332
+ !isArrowFunctionNode(classElement)),
333
333
  )
334
- function checkNode(nodeValue) {
335
- if (
336
- (nodeValue.type === 'MethodDefinition' || isArrowFunction(nodeValue)) &&
337
- (!nodeValue.static || !searchStaticMethodsAndFunctionProperties)
338
- ) {
339
- return
340
- }
341
- if ('decorators' in nodeValue) {
342
- traverseNode(nodeValue.decorators)
343
- }
344
- if (
345
- nodeValue.type === 'NewExpression' &&
346
- nodeValue.callee.type === 'Identifier'
347
- ) {
348
- dependencies.push(nodeValue.callee.name)
349
- }
350
- if (nodeValue.type === 'Identifier') {
351
- dependencies.push(nodeValue.name)
352
- }
353
- if (nodeValue.type === 'ConditionalExpression') {
354
- checkNode(nodeValue.test)
355
- checkNode(nodeValue.consequent)
356
- checkNode(nodeValue.alternate)
357
- }
358
- if (
359
- 'expression' in nodeValue &&
360
- typeof nodeValue.expression !== 'boolean'
361
- ) {
362
- checkNode(nodeValue.expression)
363
- }
364
- if ('object' in nodeValue) {
365
- checkNode(nodeValue.object)
366
- }
367
- if ('callee' in nodeValue) {
368
- checkNode(nodeValue.callee)
369
- }
370
- if ('init' in nodeValue && nodeValue.init) {
371
- checkNode(nodeValue.init)
372
- }
373
- if ('body' in nodeValue && nodeValue.body) {
374
- traverseNode(nodeValue.body)
375
- }
376
- if ('left' in nodeValue) {
377
- checkNode(nodeValue.left)
378
- }
379
- if ('right' in nodeValue) {
380
- checkNode(nodeValue.right)
381
- }
382
- if ('initializer' in nodeValue && nodeValue.initializer) {
383
- checkNode(nodeValue.initializer)
384
- }
385
- if ('elements' in nodeValue) {
386
- let elements = nodeValue.elements.filter(
387
- currentNode => currentNode !== null,
388
- )
389
- for (let element of elements) {
390
- traverseNode(element)
391
- }
392
- }
393
- if ('argument' in nodeValue && nodeValue.argument) {
394
- checkNode(nodeValue.argument)
395
- }
396
- if ('arguments' in nodeValue) {
397
- for (let argument of nodeValue.arguments) {
398
- checkNode(argument)
399
- }
400
- }
401
- if ('declarations' in nodeValue) {
402
- for (let declaration of nodeValue.declarations) {
403
- checkNode(declaration)
404
- }
405
- }
406
- if ('properties' in nodeValue) {
407
- for (let property of nodeValue.properties) {
408
- checkNode(property)
409
- }
410
- }
411
- if (
412
- 'value' in nodeValue &&
413
- nodeValue.value &&
414
- typeof nodeValue.value === 'object' &&
415
- 'type' in nodeValue.value
416
- ) {
417
- checkNode(nodeValue.value)
418
- }
419
- if ('expressions' in nodeValue) {
420
- for (let nodeExpression of nodeValue.expressions) {
421
- checkNode(nodeExpression)
422
- }
423
- }
424
- }
425
- function traverseNode(nodeValue) {
426
- if (Array.isArray(nodeValue)) {
427
- for (let nodeItem of nodeValue) {
428
- traverseNode(nodeItem)
429
- }
430
- } else {
431
- checkNode(nodeValue)
432
- }
433
- }
434
- checkNode(expression)
435
- return dependencies
436
- }
437
- function isArrowFunction(node) {
438
- return (
439
- isPropertyOrAccessor(node) &&
440
- node.value !== null &&
441
- node.value.type === 'ArrowFunctionExpression'
442
- )
443
- }
444
- function isPropertyOrAccessor(node) {
445
- return node.type === 'PropertyDefinition' || node.type === 'AccessorProperty'
334
+ return computeDependencies(expression, {
335
+ searchStaticMethodsAndFunctionProperties,
336
+ type: 'hard',
337
+ })
446
338
  }
447
339
  export { sortModules as default }
@@ -0,0 +1,12 @@
1
+ import { TSESTree } from '@typescript-eslint/types'
2
+ /**
3
+ * Computes the name of an export specifier node.
4
+ *
5
+ * @param node - The export specifier node.
6
+ * @param ignoreAlias - Whether to ignore the alias and use the local name.
7
+ * @returns The computed name of the export specifier.
8
+ */
9
+ export declare function computeNodeName(
10
+ node: TSESTree.ExportSpecifier,
11
+ ignoreAlias: boolean,
12
+ ): string
@@ -0,0 +1,15 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
2
+ import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
3
+ function computeNodeName(node, ignoreAlias) {
4
+ let identifierToCheck = ignoreAlias ? node.local : node.exported
5
+ switch (identifierToCheck.type) {
6
+ case AST_NODE_TYPES.Identifier:
7
+ return identifierToCheck.name
8
+ case AST_NODE_TYPES.Literal:
9
+ return identifierToCheck.value
10
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
11
+ default:
12
+ throw new UnreachableCaseError(identifierToCheck)
13
+ }
14
+ }
15
+ export { computeNodeName }
@@ -1,9 +1,9 @@
1
1
  import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
2
2
  import { TSESTree } from '@typescript-eslint/types'
3
- import { CommonPartitionOptions } from '../../types/common-partition-options'
4
- import { CommonGroupsOptions } from '../../types/common-groups-options'
5
- import { CommonOptions, TypeOption } from '../../types/common-options'
6
- import { SortingNode } from '../../types/sorting-node'
3
+ import { CommonPartitionOptions } from '../../types/common-partition-options.js'
4
+ import { CommonGroupsOptions } from '../../types/common-groups-options.js'
5
+ import { CommonOptions, TypeOption } from '../../types/common-options.js'
6
+ import { SortingNode } from '../../types/sorting-node.js'
7
7
  /**
8
8
  * Configuration options for the sort-named-exports rule.
9
9
  *
@@ -1,4 +1,4 @@
1
- import { Options } from './sort-named-exports/types'
1
+ import { Options } from './sort-named-exports/types.js'
2
2
  declare const ORDER_ERROR_ID = 'unexpectedNamedExportsOrder'
3
3
  declare const GROUP_ORDER_ERROR_ID = 'unexpectedNamedExportsGroupOrder'
4
4
  declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenNamedExports'
@@ -11,7 +11,9 @@ type MessageId =
11
11
  declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
12
12
  MessageId,
13
13
  Options,
14
- import('../utils/create-eslint-rule').ESLintPluginDocumentation,
14
+ import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
15
15
  import('@typescript-eslint/utils/ts-eslint').RuleListener
16
- >
16
+ > & {
17
+ name: string
18
+ }
17
19
  export default _default
@@ -22,8 +22,10 @@ import { validateGroupsConfiguration } from '../utils/validate-groups-configurat
22
22
  import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
23
23
  import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
24
24
  import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
25
+ import { computeNodeName } from './sort-named-exports/compute-node-name.js'
25
26
  import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
26
27
  import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
28
+ import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
27
29
  import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
28
30
  import { createEslintRule } from '../utils/create-eslint-rule.js'
29
31
  import { reportAllErrors } from '../utils/report-all-errors.js'
@@ -40,6 +42,7 @@ const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenNamedExports'
40
42
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
41
43
  let defaultOptions = {
42
44
  fallbackSort: { type: 'unsorted' },
45
+ newlinesInside: 'newlinesBetween',
43
46
  specialCharacters: 'keep',
44
47
  partitionByNewLine: false,
45
48
  partitionByComment: false,
@@ -75,27 +78,9 @@ const sortNamedExports = createEslintRule({
75
78
  })
76
79
  let formattedMembers = [[]]
77
80
  for (let specifier of node.specifiers) {
78
- let name
79
- if (options.ignoreAlias) {
80
- if (specifier.local.type === 'Identifier') {
81
- ;({ name } = specifier.local)
82
- } else {
83
- name = specifier.local.value
84
- }
85
- } else {
86
- if (specifier.exported.type === 'Identifier') {
87
- ;({ name } = specifier.exported)
88
- } else {
89
- name = specifier.exported.value
90
- }
91
- }
81
+ let name = computeNodeName(specifier, options.ignoreAlias)
92
82
  let selector = 'export'
93
- let modifiers = []
94
- if (specifier.exportKind === 'value') {
95
- modifiers.push('value')
96
- } else {
97
- modifiers.push('type')
98
- }
83
+ let modifiers = [computeExportKindModifier(specifier)]
99
84
  let predefinedGroups = generatePredefinedGroups({
100
85
  cache: cachedGroupsByModifiersAndSelectors,
101
86
  selectors: [selector],
@@ -197,11 +182,23 @@ const sortNamedExports = createEslintRule({
197
182
  description: 'Enforce sorted named exports.',
198
183
  recommended: true,
199
184
  },
200
- defaultOptions: [defaultOptions],
201
185
  type: 'suggestion',
202
186
  fixable: 'code',
203
187
  },
204
188
  defaultOptions: [defaultOptions],
205
189
  name: 'sort-named-exports',
206
190
  })
191
+ function computeExportKindModifier(node) {
192
+ let exportKind = 'exportKind' in node ? node.exportKind : void 0
193
+ switch (exportKind) {
194
+ case void 0:
195
+ case 'value':
196
+ return 'value'
197
+ case 'type':
198
+ return 'type'
199
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
200
+ default:
201
+ throw new UnreachableCaseError(exportKind)
202
+ }
203
+ }
207
204
  export { sortNamedExports as default }
@@ -0,0 +1,12 @@
1
+ import { TSESTree } from '@typescript-eslint/types'
2
+ /**
3
+ * Computes the name of an import specifier node.
4
+ *
5
+ * @param node - The import specifier node.
6
+ * @param ignoreAlias - Whether to ignore the alias and use the local name.
7
+ * @returns The computed name of the import specifier.
8
+ */
9
+ export declare function computeNodeName(
10
+ node: TSESTree.ImportSpecifier,
11
+ ignoreAlias: boolean,
12
+ ): string
@@ -0,0 +1,17 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
2
+ import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
3
+ function computeNodeName(node, ignoreAlias) {
4
+ if (!ignoreAlias) {
5
+ return node.local.name
6
+ }
7
+ switch (node.imported.type) {
8
+ case AST_NODE_TYPES.Identifier:
9
+ return node.imported.name
10
+ case AST_NODE_TYPES.Literal:
11
+ return node.imported.value
12
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
13
+ default:
14
+ throw new UnreachableCaseError(node.imported)
15
+ }
16
+ }
17
+ export { computeNodeName }
@@ -1,9 +1,9 @@
1
1
  import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
2
2
  import { TSESTree } from '@typescript-eslint/types'
3
- import { CommonPartitionOptions } from '../../types/common-partition-options'
4
- import { CommonGroupsOptions } from '../../types/common-groups-options'
5
- import { CommonOptions, TypeOption } from '../../types/common-options'
6
- import { SortingNode } from '../../types/sorting-node'
3
+ import { CommonPartitionOptions } from '../../types/common-partition-options.js'
4
+ import { CommonGroupsOptions } from '../../types/common-groups-options.js'
5
+ import { CommonOptions, TypeOption } from '../../types/common-options.js'
6
+ import { SortingNode } from '../../types/sorting-node.js'
7
7
  /**
8
8
  * Configuration options for the sort-named-imports rule.
9
9
  *
@@ -1,4 +1,4 @@
1
- import { Options } from './sort-named-imports/types'
1
+ import { Options } from './sort-named-imports/types.js'
2
2
  declare const ORDER_ERROR_ID = 'unexpectedNamedImportsOrder'
3
3
  declare const GROUP_ORDER_ERROR_ID = 'unexpectedNamedImportsGroupOrder'
4
4
  declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenNamedImports'
@@ -11,7 +11,9 @@ type MessageId =
11
11
  declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
12
12
  MessageId,
13
13
  Options,
14
- import('../utils/create-eslint-rule').ESLintPluginDocumentation,
14
+ import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
15
15
  import('@typescript-eslint/utils/ts-eslint').RuleListener
16
- >
16
+ > & {
17
+ name: string
18
+ }
17
19
  export default _default
@@ -1,3 +1,4 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
1
2
  import {
2
3
  partitionByNewLineJsonSchema,
3
4
  partitionByCommentJsonSchema,
@@ -22,8 +23,10 @@ import { validateGroupsConfiguration } from '../utils/validate-groups-configurat
22
23
  import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
23
24
  import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
24
25
  import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
26
+ import { computeNodeName } from './sort-named-imports/compute-node-name.js'
25
27
  import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
26
28
  import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
29
+ import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
27
30
  import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
28
31
  import { createEslintRule } from '../utils/create-eslint-rule.js'
29
32
  import { reportAllErrors } from '../utils/report-all-errors.js'
@@ -40,6 +43,7 @@ const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenNamedImports'
40
43
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
41
44
  let defaultOptions = {
42
45
  fallbackSort: { type: 'unsorted' },
46
+ newlinesInside: 'newlinesBetween',
43
47
  specialCharacters: 'keep',
44
48
  partitionByNewLine: false,
45
49
  partitionByComment: false,
@@ -57,7 +61,7 @@ const sortNamedImports = createEslintRule({
57
61
  create: context => ({
58
62
  ImportDeclaration: node => {
59
63
  let specifiers = node.specifiers.filter(
60
- ({ type }) => type === 'ImportSpecifier',
64
+ importClause => importClause.type === AST_NODE_TYPES.ImportSpecifier,
61
65
  )
62
66
  if (!isSortable(specifiers)) {
63
67
  return
@@ -78,24 +82,9 @@ const sortNamedImports = createEslintRule({
78
82
  })
79
83
  let formattedMembers = [[]]
80
84
  for (let specifier of specifiers) {
81
- let { name } = specifier.local
82
- if (specifier.type === 'ImportSpecifier' && options.ignoreAlias) {
83
- if (specifier.imported.type === 'Identifier') {
84
- ;({ name } = specifier.imported)
85
- } else {
86
- name = specifier.imported.value
87
- }
88
- }
85
+ let name = computeNodeName(specifier, options.ignoreAlias)
89
86
  let selector = 'import'
90
- let modifiers = []
91
- if (
92
- specifier.type === 'ImportSpecifier' &&
93
- specifier.importKind === 'type'
94
- ) {
95
- modifiers.push('type')
96
- } else {
97
- modifiers.push('value')
98
- }
87
+ let modifiers = [computeImportKindModifier(specifier)]
99
88
  let predefinedGroups = generatePredefinedGroups({
100
89
  cache: cachedGroupsByModifiersAndSelectors,
101
90
  selectors: [selector],
@@ -197,11 +186,23 @@ const sortNamedImports = createEslintRule({
197
186
  description: 'Enforce sorted named imports.',
198
187
  recommended: true,
199
188
  },
200
- defaultOptions: [defaultOptions],
201
189
  type: 'suggestion',
202
190
  fixable: 'code',
203
191
  },
204
192
  defaultOptions: [defaultOptions],
205
193
  name: 'sort-named-imports',
206
194
  })
195
+ function computeImportKindModifier(node) {
196
+ let importKind = 'importKind' in node ? node.importKind : void 0
197
+ switch (importKind) {
198
+ case void 0:
199
+ case 'value':
200
+ return 'value'
201
+ case 'type':
202
+ return 'type'
203
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
204
+ default:
205
+ throw new UnreachableCaseError(importKind)
206
+ }
207
+ }
207
208
  export { sortNamedImports as default }
@@ -1,5 +1,5 @@
1
- import { ComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer'
2
- import { SortObjectTypesSortingNode, Options } from './types'
1
+ import { ComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
2
+ import { SortObjectTypesSortingNode, Options } from './types.js'
3
3
  export declare let comparatorByOptionsComputer: ComparatorByOptionsComputer<
4
4
  Required<Options[number]>,
5
5
  SortObjectTypesSortingNode
@@ -1,6 +1,6 @@
1
1
  import { TSESTree } from '@typescript-eslint/types'
2
2
  import { TSESLint } from '@typescript-eslint/utils'
3
- import { ObjectTypeParent, Options } from './types'
3
+ import { ObjectTypeParent, Options } from './types.js'
4
4
  /**
5
5
  * Computes the matched context options for the given nodes.
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import { TSESLint } from '@typescript-eslint/utils'
2
- import { ObjectTypeParent } from './types'
2
+ import { ObjectTypeParent } from './types.js'
3
3
  /**
4
4
  * Computes the name of an object-type-like parent node.
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { TSESLint } from '@typescript-eslint/utils'
2
- import { ScopedRegexOption } from '../../types/scoped-regex-option'
3
- import { ObjectTypeParent } from './types'
2
+ import { ScopedRegexOption } from '../../types/scoped-regex-option.js'
3
+ import { ObjectTypeParent } from './types.js'
4
4
  /**
5
5
  * Checks if the object passes the declaration comment matches filter.
6
6
  *
@@ -1,6 +1,6 @@
1
1
  import { TSESLint } from '@typescript-eslint/utils'
2
- import { ScopedRegexOption } from '../../types/scoped-regex-option'
3
- import { ObjectTypeParent } from './types'
2
+ import { ScopedRegexOption } from '../../types/scoped-regex-option.js'
3
+ import { ObjectTypeParent } from './types.js'
4
4
  /**
5
5
  * Checks whether the parent node's name matches the given pattern.
6
6
  *