eslint-plugin-perfectionist 4.13.0 → 4.15.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 (49) hide show
  1. package/dist/package.json.js +1 -1
  2. package/dist/rules/sort-array-includes.js +5 -2
  3. package/dist/rules/sort-classes.js +8 -5
  4. package/dist/rules/sort-decorators.js +5 -2
  5. package/dist/rules/sort-enums.js +6 -3
  6. package/dist/rules/sort-exports.js +10 -4
  7. package/dist/rules/sort-heritage-clauses.js +2 -1
  8. package/dist/rules/sort-imports/compute-common-selectors.js +15 -5
  9. package/dist/rules/sort-imports/is-side-effect-only-group.js +5 -1
  10. package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +11 -13
  11. package/dist/rules/sort-imports.js +84 -67
  12. package/dist/rules/sort-jsx-props.js +5 -2
  13. package/dist/rules/sort-maps.js +5 -2
  14. package/dist/rules/sort-modules.js +9 -4
  15. package/dist/rules/sort-named-exports.js +5 -2
  16. package/dist/rules/sort-named-imports.js +5 -2
  17. package/dist/rules/sort-object-types/get-custom-groups-compare-options.js +3 -3
  18. package/dist/rules/sort-object-types.js +3 -2
  19. package/dist/rules/sort-objects.js +5 -2
  20. package/dist/rules/sort-switch-case.js +11 -0
  21. package/dist/rules/sort-union-types.js +7 -2
  22. package/dist/rules/sort-variable-declarations.js +7 -2
  23. package/dist/utils/common-json-schemas.js +28 -7
  24. package/dist/utils/compare.js +15 -18
  25. package/dist/utils/get-comment-above-that-should-exist.js +34 -0
  26. package/dist/utils/get-custom-groups-compare-options.js +6 -6
  27. package/dist/utils/get-eslint-disabled-lines.js +12 -10
  28. package/dist/utils/{get-group-number.js → get-group-index.js} +2 -2
  29. package/dist/utils/{get-newlines-errors.js → get-newlines-between-errors.js} +20 -20
  30. package/dist/utils/get-newlines-between-option.js +64 -33
  31. package/dist/utils/is-comment-above-option.js +5 -0
  32. package/dist/utils/make-comment-above-fixes.js +109 -0
  33. package/dist/utils/make-fixes.js +30 -10
  34. package/dist/utils/{make-newlines-fixes.js → make-newlines-between-fixes.js} +51 -25
  35. package/dist/utils/make-single-node-comment-after-fixes.js +16 -2
  36. package/dist/utils/pairwise.js +3 -3
  37. package/dist/utils/report-all-errors.js +38 -14
  38. package/dist/utils/report-errors.js +17 -11
  39. package/dist/utils/should-partition.js +9 -2
  40. package/dist/utils/sort-nodes-by-groups.js +10 -10
  41. package/dist/utils/unreachable-case-error.js +9 -0
  42. package/dist/utils/validate-generated-groups-configuration.js +2 -4
  43. package/dist/utils/validate-no-duplicated-groups.js +5 -1
  44. package/dist/utils/validate-objects-inside-groups.js +18 -0
  45. package/package.json +5 -3
  46. package/dist/utils/get-comment-after.js +0 -18
  47. package/dist/utils/has-partition-comment.js +0 -11
  48. package/dist/utils/to-single-line.js +0 -4
  49. package/dist/utils/validate-newlines-between-inside-groups.js +0 -18
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const name = 'eslint-plugin-perfectionist'
4
- const version = '4.13.0'
4
+ const version = '4.15.0'
5
5
  exports.name = name
6
6
  exports.version = version
@@ -199,7 +199,10 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
199
199
  ) {
200
200
  accumulator.push([])
201
201
  }
202
- accumulator.at(-1).push(sortingNode)
202
+ accumulator.at(-1).push({
203
+ ...sortingNode,
204
+ partitionId: accumulator.length,
205
+ })
203
206
  return accumulator
204
207
  },
205
208
  [[]],
@@ -222,7 +225,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
222
225
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
223
226
  filteredGroupKindNodes.flatMap(groupedNodes =>
224
227
  sortNodesByGroups.sortNodesByGroups({
225
- getOptionsByGroupNumber:
228
+ getOptionsByGroupIndex:
226
229
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
227
230
  options,
228
231
  ),
@@ -18,7 +18,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
18
18
  const getDecoratorName = require('../utils/get-decorator-name.js')
19
19
  const reportAllErrors = require('../utils/report-all-errors.js')
20
20
  const shouldPartition = require('../utils/should-partition.js')
21
- const getGroupNumber = require('../utils/get-group-number.js')
21
+ const getGroupIndex = require('../utils/get-group-index.js')
22
22
  const computeGroup = require('../utils/compute-group.js')
23
23
  const rangeToDiff = require('../utils/range-to-diff.js')
24
24
  const getSettings = require('../utils/get-settings.js')
@@ -465,7 +465,10 @@ const sortClasses = createEslintRule.createEslintRule({
465
465
  ) {
466
466
  accumulator.push([])
467
467
  }
468
- accumulator.at(-1).push(sortingNode)
468
+ accumulator.at(-1).push({
469
+ ...sortingNode,
470
+ partitionId: accumulator.length,
471
+ })
469
472
  return accumulator
470
473
  },
471
474
  [[]],
@@ -474,9 +477,9 @@ const sortClasses = createEslintRule.createEslintRule({
474
477
  let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
475
478
  sortNodesByGroups.sortNodesByGroups({
476
479
  isNodeIgnored: sortingNode =>
477
- getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
480
+ getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
478
481
  options.groups.length,
479
- getOptionsByGroupNumber:
482
+ getOptionsByGroupIndex:
480
483
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
481
484
  options,
482
485
  ),
@@ -503,7 +506,7 @@ const sortClasses = createEslintRule.createEslintRule({
503
506
  left.overloadSignaturesGroupId !== null &&
504
507
  left.overloadSignaturesGroupId === right.overloadSignaturesGroupId
505
508
  ) {
506
- return 'never'
509
+ return 0
507
510
  }
508
511
  return computedNewlinesBetween
509
512
  },
@@ -194,7 +194,10 @@ let sortDecorators$1 = (context, options, decorators) => {
194
194
  ) {
195
195
  accumulator.push([])
196
196
  }
197
- accumulator.at(-1).push(sortingNode)
197
+ accumulator.at(-1).push({
198
+ ...sortingNode,
199
+ partitionId: accumulator.length,
200
+ })
198
201
  return accumulator
199
202
  },
200
203
  [[]],
@@ -202,7 +205,7 @@ let sortDecorators$1 = (context, options, decorators) => {
202
205
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
203
206
  formattedMembers.flatMap(nodes2 =>
204
207
  sortNodesByGroups.sortNodesByGroups({
205
- getOptionsByGroupNumber: () => ({ options }),
208
+ getOptionsByGroupIndex: () => ({ options }),
206
209
  ignoreEslintDisabledNodes,
207
210
  groups: options.groups,
208
211
  nodes: nodes2,
@@ -155,7 +155,10 @@ const sortEnums = createEslintRule.createEslintRule({
155
155
  ) {
156
156
  accumulator.push([])
157
157
  }
158
- accumulator.at(-1).push(sortingNode)
158
+ accumulator.at(-1).push({
159
+ ...sortingNode,
160
+ partitionId: accumulator.length,
161
+ })
159
162
  return accumulator
160
163
  },
161
164
  [[]],
@@ -180,11 +183,11 @@ const sortEnums = createEslintRule.createEslintRule({
180
183
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
181
184
  let nodesSortedByGroups = formattedMembers.flatMap(sortingNodes =>
182
185
  sortNodesByGroups.sortNodesByGroups({
183
- getOptionsByGroupNumber: groupNumber => ({
186
+ getOptionsByGroupIndex: groupIndex => ({
184
187
  options:
185
188
  getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions({
186
189
  options: overriddenOptions,
187
- groupNumber,
190
+ groupIndex,
188
191
  }),
189
192
  nodeValueGetter,
190
193
  }),
@@ -95,10 +95,11 @@ const sortExports = createEslintRule.createEslintRule({
95
95
  name,
96
96
  node,
97
97
  }
98
- let lastNode = (_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
98
+ let lastSortingNode =
99
+ (_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
99
100
  if (
100
101
  shouldPartition.shouldPartition({
101
- lastSortingNode: lastNode,
102
+ lastSortingNode,
102
103
  sortingNode,
103
104
  sourceCode,
104
105
  options,
@@ -106,7 +107,10 @@ const sortExports = createEslintRule.createEslintRule({
106
107
  ) {
107
108
  formattedMembers.push([])
108
109
  }
109
- formattedMembers.at(-1).push(sortingNode)
110
+ formattedMembers.at(-1).push({
111
+ ...sortingNode,
112
+ partitionId: formattedMembers.length,
113
+ })
110
114
  }
111
115
  return {
112
116
  'Program:exit': () => {
@@ -128,7 +132,7 @@ const sortExports = createEslintRule.createEslintRule({
128
132
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
129
133
  filteredGroupKindNodes.flatMap(groupedNodes =>
130
134
  sortNodesByGroups.sortNodesByGroups({
131
- getOptionsByGroupNumber:
135
+ getOptionsByGroupIndex:
132
136
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
133
137
  options,
134
138
  ),
@@ -142,6 +146,7 @@ const sortExports = createEslintRule.createEslintRule({
142
146
  missedSpacingBetweenMembers: 'missedSpacingBetweenExports',
143
147
  extraSpacingBetweenMembers: 'extraSpacingBetweenExports',
144
148
  unexpectedGroupOrder: 'unexpectedExportsGroupOrder',
149
+ missedCommentAbove: 'missedCommentAboveExport',
145
150
  unexpectedOrder: 'unexpectedExportsOrder',
146
151
  },
147
152
  sortNodesExcludingEslintDisabled,
@@ -185,6 +190,7 @@ const sortExports = createEslintRule.createEslintRule({
185
190
  type: 'array',
186
191
  },
187
192
  messages: {
193
+ missedCommentAboveExport: reportErrors.MISSED_COMMENT_ABOVE_ERROR,
188
194
  missedSpacingBetweenExports: reportErrors.MISSED_SPACING_ERROR,
189
195
  extraSpacingBetweenExports: reportErrors.EXTRA_SPACING_ERROR,
190
196
  unexpectedExportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
@@ -95,13 +95,14 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
95
95
  ),
96
96
  size: rangeToDiff.rangeToDiff(heritageClause, sourceCode),
97
97
  node: heritageClause,
98
+ partitionId: 0,
98
99
  group,
99
100
  name,
100
101
  }
101
102
  })
102
103
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
103
104
  sortNodesByGroups.sortNodesByGroups({
104
- getOptionsByGroupNumber: () => ({ options }),
105
+ getOptionsByGroupIndex: () => ({ options }),
105
106
  ignoreEslintDisabledNodes,
106
107
  groups: options.groups,
107
108
  nodes,
@@ -65,12 +65,22 @@ let builtinPrefixOnlyModules = /* @__PURE__ */ new Set([
65
65
  'node:sea',
66
66
  ])
67
67
  let isCoreModule = (value, environment) => {
68
- let valueToCheck = value.startsWith('node:') ? value.split('node:')[1] : value
69
- return (
70
- (!!valueToCheck && nodeBuiltinModules.has(valueToCheck)) ||
68
+ let clean = string_ => string_.replace(/^(?:node:){1,2}/u, '')
69
+ let [basePath] = value.split('/')
70
+ let cleanValue = clean(value)
71
+ let cleanBase = clean(basePath)
72
+ if (nodeBuiltinModules.has(cleanValue) || nodeBuiltinModules.has(cleanBase)) {
73
+ return true
74
+ }
75
+ if (
71
76
  builtinPrefixOnlyModules.has(value) ||
72
- (environment === 'bun' ? bunModules.has(value) : false)
73
- )
77
+ builtinPrefixOnlyModules.has(`node:${cleanValue}`) ||
78
+ builtinPrefixOnlyModules.has(basePath) ||
79
+ builtinPrefixOnlyModules.has(`node:${cleanBase}`)
80
+ ) {
81
+ return true
82
+ }
83
+ return environment === 'bun' && bunModules.has(value)
74
84
  }
75
85
  let isParent = value => value.startsWith('..')
76
86
  let isSibling = value => value.startsWith('./')
@@ -1,8 +1,12 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const isNewlinesBetweenOption = require('../../utils/is-newlines-between-option.js')
4
+ const isCommentAboveOption = require('../../utils/is-comment-above-option.js')
4
5
  let isSideEffectOnlyGroup = group => {
5
- if (isNewlinesBetweenOption.isNewlinesBetweenOption(group)) {
6
+ if (
7
+ isNewlinesBetweenOption.isNewlinesBetweenOption(group) ||
8
+ isCommentAboveOption.isCommentAboveOption(group)
9
+ ) {
6
10
  return false
7
11
  }
8
12
  if (typeof group === 'string') {
@@ -29,15 +29,20 @@ const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path)
29
29
  const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs)
30
30
  let directoryCacheByPath = /* @__PURE__ */ new Map()
31
31
  let contentCacheByPath = /* @__PURE__ */ new Map()
32
- let readClosestTsConfigByPath = input => {
32
+ let readClosestTsConfigByPath = ({
33
+ tsconfigFilename,
34
+ tsconfigRootDir,
35
+ contextCwd,
36
+ filePath,
37
+ }) => {
33
38
  let typescriptImport = getTypescriptImport.getTypescriptImport()
34
39
  if (!typescriptImport) {
35
40
  return null
36
41
  }
37
- let directory = path__namespace.dirname(input.filePath)
42
+ let directory = path__namespace.dirname(filePath)
38
43
  let checkedDirectories = [directory]
39
44
  do {
40
- let tsconfigPath = path__namespace.join(directory, 'tsconfig.json')
45
+ let tsconfigPath = path__namespace.join(directory, tsconfigFilename)
41
46
  let cachedDirectory = directoryCacheByPath.get(directory)
42
47
  if (!cachedDirectory && fs__namespace.existsSync(tsconfigPath)) {
43
48
  cachedDirectory = tsconfigPath
@@ -46,20 +51,13 @@ let readClosestTsConfigByPath = input => {
46
51
  for (let checkedDirectory of checkedDirectories) {
47
52
  directoryCacheByPath.set(checkedDirectory, cachedDirectory)
48
53
  }
49
- return getCompilerOptions(
50
- typescriptImport,
51
- input.contextCwd,
52
- cachedDirectory,
53
- )
54
+ return getCompilerOptions(typescriptImport, contextCwd, cachedDirectory)
54
55
  }
55
56
  directory = path__namespace.dirname(directory)
56
57
  checkedDirectories.push(directory)
57
- } while (
58
- directory.length > 1 &&
59
- directory.length >= input.tsconfigRootDir.length
60
- )
58
+ } while (directory.length > 1 && directory.length >= tsconfigRootDir.length)
61
59
  throw new Error(
62
- `Couldn't find any tsconfig.json relative to '${input.filePath}' within '${input.tsconfigRootDir}'.`,
60
+ `Couldn't find any ${tsconfigFilename} relative to '${filePath}' within '${tsconfigRootDir}'.`,
63
61
  )
64
62
  }
65
63
  let getCompilerOptions = (typescriptImport, contextCwd, filePath) => {
@@ -26,38 +26,39 @@ const getSettings = require('../utils/get-settings.js')
26
26
  const isSortable = require('../utils/is-sortable.js')
27
27
  const complete = require('../utils/complete.js')
28
28
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
29
- let defaultGroups = [
30
- 'type-import',
31
- ['value-builtin', 'value-external'],
32
- 'type-internal',
33
- 'value-internal',
34
- ['type-parent', 'type-sibling', 'type-index'],
35
- ['value-parent', 'value-sibling', 'value-index'],
36
- 'ts-equals-import',
37
- 'unknown',
38
- ]
29
+ let defaultOptions = {
30
+ groups: [
31
+ 'type-import',
32
+ ['value-builtin', 'value-external'],
33
+ 'type-internal',
34
+ 'value-internal',
35
+ ['type-parent', 'type-sibling', 'type-index'],
36
+ ['value-parent', 'value-sibling', 'value-index'],
37
+ 'ts-equals-import',
38
+ 'unknown',
39
+ ],
40
+ internalPattern: ['^~/.+', '^@/.+'],
41
+ fallbackSort: { type: 'unsorted' },
42
+ partitionByComment: false,
43
+ partitionByNewLine: false,
44
+ specialCharacters: 'keep',
45
+ sortSideEffects: false,
46
+ type: 'alphabetical',
47
+ environment: 'node',
48
+ newlinesBetween: 1,
49
+ customGroups: [],
50
+ ignoreCase: true,
51
+ locales: 'en-US',
52
+ alphabet: '',
53
+ order: 'asc',
54
+ }
39
55
  const sortImports = createEslintRule.createEslintRule({
40
56
  create: context => {
57
+ var _a, _b
41
58
  let settings = getSettings.getSettings(context.settings)
42
59
  let userOptions = context.options.at(0)
43
60
  let options = getOptionsWithCleanGroups.getOptionsWithCleanGroups(
44
- complete.complete(userOptions, settings, {
45
- internalPattern: ['^~/.+', '^@/.+'],
46
- fallbackSort: { type: 'unsorted' },
47
- partitionByComment: false,
48
- partitionByNewLine: false,
49
- newlinesBetween: 'always',
50
- specialCharacters: 'keep',
51
- sortSideEffects: false,
52
- groups: defaultGroups,
53
- type: 'alphabetical',
54
- environment: 'node',
55
- customGroups: [],
56
- ignoreCase: true,
57
- locales: 'en-US',
58
- alphabet: '',
59
- order: 'asc',
60
- }),
61
+ complete.complete(userOptions, settings, defaultOptions),
61
62
  )
62
63
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
63
64
  options: {
@@ -77,9 +78,15 @@ const sortImports = createEslintRule.createEslintRule({
77
78
  options,
78
79
  )
79
80
  validateSideEffectsConfiguration.validateSideEffectsConfiguration(options)
80
- let tsConfigOutput = options.tsconfigRootDir
81
+ let tsconfigRootDirectory =
82
+ ((_a = options.tsconfig) == null ? void 0 : _a.rootDir) ??
83
+ options.tsconfigRootDir
84
+ let tsConfigOutput = tsconfigRootDirectory
81
85
  ? readClosestTsConfigByPath.readClosestTsConfigByPath({
82
- tsconfigRootDir: options.tsconfigRootDir,
86
+ tsconfigFilename:
87
+ ((_b = options.tsconfig) == null ? void 0 : _b.filename) ??
88
+ 'tsconfig.json',
89
+ tsconfigRootDir: tsconfigRootDirectory,
83
90
  filePath: context.physicalFilename,
84
91
  contextCwd: context.cwd,
85
92
  })
@@ -89,7 +96,7 @@ const sortImports = createEslintRule.createEslintRule({
89
96
  ruleName: id,
90
97
  sourceCode,
91
98
  })
92
- let sortingNodes = []
99
+ let sortingNodesWithoutPartitionId = []
93
100
  let flatGroups = new Set(options.groups.flat())
94
101
  let shouldRegroupSideEffectNodes = flatGroups.has('side-effect')
95
102
  let shouldRegroupSideEffectStyleNodes = flatGroups.has('side-effect-style')
@@ -189,7 +196,16 @@ const sortImports = createEslintRule.createEslintRule({
189
196
  options,
190
197
  name,
191
198
  }) ?? 'unknown')
192
- sortingNodes.push({
199
+ let hasMultipleImportDeclarations = isSortable.isSortable(node.specifiers)
200
+ let size = rangeToDiff.rangeToDiff(node, sourceCode)
201
+ if (
202
+ hasMultipleImportDeclarations &&
203
+ options.maxLineLength &&
204
+ size > options.maxLineLength
205
+ ) {
206
+ size = name.length + 10
207
+ }
208
+ sortingNodesWithoutPartitionId.push({
193
209
  isIgnored:
194
210
  !options.sortSideEffects &&
195
211
  isSideEffect &&
@@ -201,30 +217,28 @@ const sortImports = createEslintRule.createEslintRule({
201
217
  ),
202
218
  dependencyNames: computeDependencyNames({ sourceCode, node }),
203
219
  dependencies: computeDependencies(node),
204
- size: rangeToDiff.rangeToDiff(node, sourceCode),
205
220
  addSafetySemicolonWhenInline: true,
206
221
  group,
222
+ size,
207
223
  name,
208
224
  node,
209
- ...(options.type === 'line-length' &&
210
- options.maxLineLength && {
211
- hasMultipleImportDeclarations: isSortable.isSortable(
212
- node.specifiers,
213
- ),
214
- }),
215
225
  })
216
226
  }
217
227
  return {
218
228
  'Program:exit': () => {
219
229
  let contentSeparatedSortingNodeGroups = [[[]]]
220
- for (let sortingNode of sortingNodes) {
230
+ for (let sortingNodeWithoutPartitionId of sortingNodesWithoutPartitionId) {
221
231
  let lastGroupWithNoContentBetween =
222
232
  contentSeparatedSortingNodeGroups.at(-1)
223
233
  let lastGroup = lastGroupWithNoContentBetween.at(-1)
224
234
  let lastSortingNode = lastGroup.at(-1)
225
235
  if (
226
236
  lastSortingNode &&
227
- hasContentBetweenNodes(sourceCode, lastSortingNode, sortingNode)
237
+ hasContentBetweenNodes(
238
+ sourceCode,
239
+ lastSortingNode,
240
+ sortingNodeWithoutPartitionId,
241
+ )
228
242
  ) {
229
243
  lastGroup = []
230
244
  lastGroupWithNoContentBetween = [lastGroup]
@@ -233,8 +247,8 @@ const sortImports = createEslintRule.createEslintRule({
233
247
  )
234
248
  } else if (
235
249
  shouldPartition.shouldPartition({
250
+ sortingNode: sortingNodeWithoutPartitionId,
236
251
  lastSortingNode,
237
- sortingNode,
238
252
  sourceCode,
239
253
  options,
240
254
  })
@@ -242,13 +256,16 @@ const sortImports = createEslintRule.createEslintRule({
242
256
  lastGroup = []
243
257
  lastGroupWithNoContentBetween.push(lastGroup)
244
258
  }
245
- lastGroup.push(sortingNode)
259
+ lastGroup.push({
260
+ ...sortingNodeWithoutPartitionId,
261
+ partitionId: lastGroupWithNoContentBetween.length,
262
+ })
246
263
  }
247
264
  for (let sortingNodeGroups of contentSeparatedSortingNodeGroups) {
248
265
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
249
266
  let nodesSortedByGroups = sortingNodeGroups.flatMap(nodes2 =>
250
267
  sortNodesByGroups.sortNodesByGroups({
251
- getOptionsByGroupNumber: groupNumber => {
268
+ getOptionsByGroupIndex: groupIndex => {
252
269
  let customGroupOverriddenOptions =
253
270
  getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions(
254
271
  {
@@ -258,7 +275,7 @@ const sortImports = createEslintRule.createEslintRule({
258
275
  ? options.customGroups
259
276
  : [],
260
277
  },
261
- groupNumber,
278
+ groupIndex,
262
279
  },
263
280
  )
264
281
  if (options.sortSideEffects) {
@@ -277,9 +294,9 @@ const sortImports = createEslintRule.createEslintRule({
277
294
  options: {
278
295
  ...overriddenOptions,
279
296
  type:
280
- overriddenOptions.groups[groupNumber] &&
297
+ overriddenOptions.groups[groupIndex] &&
281
298
  isSideEffectOnlyGroup.isSideEffectOnlyGroup(
282
- overriddenOptions.groups[groupNumber],
299
+ overriddenOptions.groups[groupIndex],
283
300
  )
284
301
  ? 'unsorted'
285
302
  : overriddenOptions.type,
@@ -306,6 +323,7 @@ const sortImports = createEslintRule.createEslintRule({
306
323
  missedSpacingBetweenMembers: 'missedSpacingBetweenImports',
307
324
  extraSpacingBetweenMembers: 'extraSpacingBetweenImports',
308
325
  unexpectedGroupOrder: 'unexpectedImportsGroupOrder',
326
+ missedCommentAbove: 'missedCommentAboveImport',
309
327
  unexpectedOrder: 'unexpectedImportsOrder',
310
328
  },
311
329
  options: {
@@ -322,15 +340,15 @@ const sortImports = createEslintRule.createEslintRule({
322
340
  }
323
341
  },
324
342
  VariableDeclaration: node => {
325
- var _a
343
+ var _a2
326
344
  if (
327
345
  node.declarations[0].init &&
328
346
  node.declarations[0].init.type === 'CallExpression' &&
329
347
  node.declarations[0].init.callee.type === 'Identifier' &&
330
348
  node.declarations[0].init.callee.name === 'require' &&
331
- ((_a = node.declarations[0].init.arguments[0]) == null
349
+ ((_a2 = node.declarations[0].init.arguments[0]) == null
332
350
  ? void 0
333
- : _a.type) === 'Literal'
351
+ : _a2.type) === 'Literal'
334
352
  ) {
335
353
  registerNode(node)
336
354
  }
@@ -366,6 +384,21 @@ const sortImports = createEslintRule.createEslintRule({
366
384
  }),
367
385
  ],
368
386
  },
387
+ tsconfig: {
388
+ properties: {
389
+ rootDir: {
390
+ description: 'Specifies the tsConfig root directory.',
391
+ type: 'string',
392
+ },
393
+ filename: {
394
+ description: 'Specifies the tsConfig filename.',
395
+ type: 'string',
396
+ },
397
+ },
398
+ additionalProperties: false,
399
+ required: ['rootDir'],
400
+ type: 'object',
401
+ },
369
402
  maxLineLength: {
370
403
  description: 'Specifies the maximum line length.',
371
404
  exclusiveMinimum: true,
@@ -400,6 +433,7 @@ const sortImports = createEslintRule.createEslintRule({
400
433
  },
401
434
  messages: {
402
435
  unexpectedImportsDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
436
+ missedCommentAboveImport: reportErrors.MISSED_COMMENT_ABOVE_ERROR,
403
437
  missedSpacingBetweenImports: reportErrors.MISSED_SPACING_ERROR,
404
438
  extraSpacingBetweenImports: reportErrors.EXTRA_SPACING_ERROR,
405
439
  unexpectedImportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
@@ -413,24 +447,7 @@ const sortImports = createEslintRule.createEslintRule({
413
447
  type: 'suggestion',
414
448
  fixable: 'code',
415
449
  },
416
- defaultOptions: [
417
- {
418
- customGroups: { value: {}, type: {} },
419
- internalPattern: ['^~/.+', '^@/.+'],
420
- partitionByComment: false,
421
- partitionByNewLine: false,
422
- specialCharacters: 'keep',
423
- newlinesBetween: 'always',
424
- sortSideEffects: false,
425
- groups: defaultGroups,
426
- type: 'alphabetical',
427
- environment: 'node',
428
- ignoreCase: true,
429
- locales: 'en-US',
430
- alphabet: '',
431
- order: 'asc',
432
- },
433
- ],
450
+ defaultOptions: [defaultOptions],
434
451
  name: 'sort-imports',
435
452
  })
436
453
  let hasContentBetweenNodes = (sourceCode, left, right) =>
@@ -166,7 +166,10 @@ const sortJsxProps = createEslintRule.createEslintRule({
166
166
  ) {
167
167
  accumulator.push([])
168
168
  }
169
- accumulator.at(-1).push(sortingNode)
169
+ accumulator.at(-1).push({
170
+ ...sortingNode,
171
+ partitionId: accumulator.length,
172
+ })
170
173
  return accumulator
171
174
  },
172
175
  [[]],
@@ -174,7 +177,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
174
177
  for (let nodes of formattedMembers) {
175
178
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
176
179
  sortNodesByGroups.sortNodesByGroups({
177
- getOptionsByGroupNumber:
180
+ getOptionsByGroupIndex:
178
181
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
179
182
  options,
180
183
  ),
@@ -129,12 +129,15 @@ const sortMaps = createEslintRule.createEslintRule({
129
129
  ) {
130
130
  formattedMembers.push([])
131
131
  }
132
- formattedMembers.at(-1).push(sortingNode)
132
+ formattedMembers.at(-1).push({
133
+ ...sortingNode,
134
+ partitionId: formattedMembers.length,
135
+ })
133
136
  }
134
137
  for (let nodes of formattedMembers) {
135
138
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
136
139
  sortNodesByGroups.sortNodesByGroups({
137
- getOptionsByGroupNumber:
140
+ getOptionsByGroupIndex:
138
141
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
139
142
  options,
140
143
  ),
@@ -18,8 +18,8 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
18
18
  const getDecoratorName = require('../utils/get-decorator-name.js')
19
19
  const reportAllErrors = require('../utils/report-all-errors.js')
20
20
  const shouldPartition = require('../utils/should-partition.js')
21
- const getGroupNumber = require('../utils/get-group-number.js')
22
21
  const getEnumMembers = require('../utils/get-enum-members.js')
22
+ const getGroupIndex = require('../utils/get-group-index.js')
23
23
  const computeGroup = require('../utils/compute-group.js')
24
24
  const rangeToDiff = require('../utils/range-to-diff.js')
25
25
  const getSettings = require('../utils/get-settings.js')
@@ -278,15 +278,20 @@ let analyzeModule = ({
278
278
  ) {
279
279
  formattedNodes.push([])
280
280
  }
281
- ;(_b = formattedNodes.at(-1)) == null ? void 0 : _b.push(sortingNode)
281
+ ;(_b = formattedNodes.at(-1)) == null
282
+ ? void 0
283
+ : _b.push({
284
+ ...sortingNode,
285
+ partitionId: formattedNodes.length,
286
+ })
282
287
  }
283
288
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
284
289
  let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
285
290
  sortNodesByGroups.sortNodesByGroups({
286
291
  isNodeIgnored: sortingNode =>
287
- getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
292
+ getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
288
293
  options.groups.length,
289
- getOptionsByGroupNumber:
294
+ getOptionsByGroupIndex:
290
295
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
291
296
  options,
292
297
  ),
@@ -128,7 +128,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
128
128
  ) {
129
129
  formattedMembers.push([])
130
130
  }
131
- formattedMembers.at(-1).push(sortingNode)
131
+ formattedMembers.at(-1).push({
132
+ ...sortingNode,
133
+ partitionId: formattedMembers.length,
134
+ })
132
135
  }
133
136
  let groupKindOrder
134
137
  if (options.groupKind === 'values-first') {
@@ -148,7 +151,7 @@ const sortNamedExports = createEslintRule.createEslintRule({
148
151
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
149
152
  filteredGroupKindNodes.flatMap(groupedNodes =>
150
153
  sortNodesByGroups.sortNodesByGroups({
151
- getOptionsByGroupNumber:
154
+ getOptionsByGroupIndex:
152
155
  getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
153
156
  options,
154
157
  ),