eslint-plugin-perfectionist 4.1.2 → 4.3.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 (44) hide show
  1. package/dist/alphabet.d.ts +176 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +9 -1
  4. package/dist/rules/sort-array-includes.js +6 -1
  5. package/dist/rules/sort-classes-utils.js +0 -23
  6. package/dist/rules/sort-classes.js +19 -43
  7. package/dist/rules/sort-classes.types.js +5 -37
  8. package/dist/rules/sort-decorators.js +9 -1
  9. package/dist/rules/sort-enums.js +11 -1
  10. package/dist/rules/sort-exports.js +8 -1
  11. package/dist/rules/sort-heritage-clauses.js +4 -0
  12. package/dist/rules/sort-imports.js +8 -3
  13. package/dist/rules/sort-interfaces.js +17 -260
  14. package/dist/rules/sort-intersection-types.js +9 -1
  15. package/dist/rules/sort-jsx-props.js +4 -0
  16. package/dist/rules/sort-maps.js +8 -1
  17. package/dist/rules/sort-modules-utils.js +0 -23
  18. package/dist/rules/sort-modules.js +20 -44
  19. package/dist/rules/sort-modules.types.js +5 -41
  20. package/dist/rules/sort-named-exports.js +8 -1
  21. package/dist/rules/sort-named-imports.js +8 -1
  22. package/dist/rules/sort-object-types-utils.js +37 -0
  23. package/dist/rules/sort-object-types.js +345 -223
  24. package/dist/rules/sort-object-types.types.js +20 -0
  25. package/dist/rules/sort-objects.js +36 -10
  26. package/dist/rules/sort-switch-case.js +4 -0
  27. package/dist/rules/sort-union-types.js +9 -1
  28. package/dist/rules/sort-variable-declarations.js +8 -1
  29. package/dist/utils/alphabet.js +385 -0
  30. package/dist/utils/common-json-schemas.js +94 -1
  31. package/dist/utils/compare.js +88 -39
  32. package/dist/utils/convert-boolean-to-sign.js +4 -0
  33. package/dist/utils/get-comments-before.js +4 -4
  34. package/dist/utils/get-custom-groups-compare-options.js +29 -0
  35. package/dist/utils/get-matching-context-options.js +18 -0
  36. package/dist/utils/get-node-range.js +18 -7
  37. package/dist/utils/get-settings.js +1 -0
  38. package/dist/utils/is-node-function-type.js +15 -0
  39. package/dist/utils/make-fixes.js +24 -3
  40. package/dist/utils/make-newlines-fixes.js +7 -4
  41. package/dist/utils/validate-custom-sort-configuration.js +11 -0
  42. package/dist/{rules → utils}/validate-generated-groups-configuration.js +4 -2
  43. package/package.json +9 -5
  44. package/readme.md +4 -3
@@ -2,6 +2,7 @@
2
2
  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
+ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
5
6
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
6
7
  const readClosestTsConfigByPath = require('../utils/read-closest-ts-config-by-path.js')
7
8
  const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
@@ -52,6 +53,7 @@ const sortImports = createEslintRule.createEslintRule({
52
53
  environment: 'node',
53
54
  ignoreCase: true,
54
55
  locales: 'en-US',
56
+ alphabet: '',
55
57
  order: 'asc',
56
58
  }),
57
59
  )
@@ -82,6 +84,7 @@ const sortImports = createEslintRule.createEslintRule({
82
84
  ...Object.keys(options.customGroups.value ?? {}),
83
85
  ],
84
86
  )
87
+ validateCustomSortConfiguration.validateCustomSortConfiguration(options)
85
88
  validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
86
89
  options,
87
90
  )
@@ -340,10 +343,10 @@ const sortImports = createEslintRule.createEslintRule({
340
343
  (options.partitionByComment &&
341
344
  isPartitionComment.hasPartitionComment(
342
345
  options.partitionByComment,
343
- getCommentsBefore.getCommentsBefore(
344
- sortingNode.node,
346
+ getCommentsBefore.getCommentsBefore({
347
+ node: sortingNode.node,
345
348
  sourceCode,
346
- ),
349
+ }),
347
350
  )) ||
348
351
  (options.partitionByNewLine &&
349
352
  lastSortingNode &&
@@ -513,6 +516,7 @@ const sortImports = createEslintRule.createEslintRule({
513
516
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
514
517
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
515
518
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
519
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
516
520
  locales: commonJsonSchemas.localesJsonSchema,
517
521
  groups: commonJsonSchemas.groupsJsonSchema,
518
522
  order: commonJsonSchemas.orderJsonSchema,
@@ -594,6 +598,7 @@ const sortImports = createEslintRule.createEslintRule({
594
598
  environment: 'node',
595
599
  ignoreCase: true,
596
600
  locales: 'en-US',
601
+ alphabet: '',
597
602
  order: 'asc',
598
603
  },
599
604
  ],
@@ -1,27 +1,6 @@
1
1
  'use strict'
2
- const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
- const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
4
- const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
5
- const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
6
- const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
7
- const isPartitionComment = require('../utils/is-partition-comment.js')
8
- const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
9
- const getCommentsBefore = require('../utils/get-comments-before.js')
10
- const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
11
- const getNewlinesErrors = require('../utils/get-newlines-errors.js')
2
+ const sortObjectTypes = require('./sort-object-types.js')
12
3
  const createEslintRule = require('../utils/create-eslint-rule.js')
13
- const isMemberOptional = require('../utils/is-member-optional.js')
14
- const getLinesBetween = require('../utils/get-lines-between.js')
15
- const getGroupNumber = require('../utils/get-group-number.js')
16
- const getSourceCode = require('../utils/get-source-code.js')
17
- const rangeToDiff = require('../utils/range-to-diff.js')
18
- const getSettings = require('../utils/get-settings.js')
19
- const isSortable = require('../utils/is-sortable.js')
20
- const useGroups = require('../utils/use-groups.js')
21
- const makeFixes = require('../utils/make-fixes.js')
22
- const complete = require('../utils/complete.js')
23
- const pairwise = require('../utils/pairwise.js')
24
- const matches = require('../utils/matches.js')
25
4
  let defaultOptions = {
26
5
  partitionByComment: false,
27
6
  partitionByNewLine: false,
@@ -33,249 +12,12 @@ let defaultOptions = {
33
12
  ignoreCase: true,
34
13
  customGroups: {},
35
14
  locales: 'en-US',
15
+ alphabet: '',
36
16
  order: 'asc',
37
17
  groups: [],
38
18
  }
39
19
  const sortInterfaces = createEslintRule.createEslintRule({
40
- create: context => ({
41
- TSInterfaceDeclaration: node => {
42
- if (!isSortable.isSortable(node.body.body)) {
43
- return
44
- }
45
- let settings = getSettings.getSettings(context.settings)
46
- let options = complete.complete(
47
- context.options.at(0),
48
- settings,
49
- defaultOptions,
50
- )
51
- validateGroupsConfiguration.validateGroupsConfiguration(
52
- options.groups,
53
- ['multiline', 'method', 'unknown'],
54
- Object.keys(options.customGroups),
55
- )
56
- validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
57
- options,
58
- )
59
- if (
60
- options.ignorePattern.some(pattern =>
61
- matches.matches(node.id.name, pattern),
62
- )
63
- ) {
64
- return
65
- }
66
- let sourceCode = getSourceCode.getSourceCode(context)
67
- let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
68
- ruleName: context.id,
69
- sourceCode,
70
- })
71
- let formattedMembers = node.body.body.reduce(
72
- (accumulator, element) => {
73
- var _a, _b, _c, _d, _e
74
- if (element.type === 'TSCallSignatureDeclaration') {
75
- accumulator.push([])
76
- return accumulator
77
- }
78
- let lastElement =
79
- (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
80
- let name
81
- let { setCustomGroups, defineGroup, getGroup } =
82
- useGroups.useGroups(options)
83
- if (element.type === 'TSPropertySignature') {
84
- if (element.key.type === 'Identifier') {
85
- ;({ name } = element.key)
86
- } else if (element.key.type === 'Literal') {
87
- name = `${element.key.value}`
88
- } else {
89
- let end =
90
- ((_b = element.typeAnnotation) == null
91
- ? void 0
92
- : _b.range.at(0)) ??
93
- element.range.at(1) - (element.optional ? '?'.length : 0)
94
- name = sourceCode.text.slice(element.range.at(0), end)
95
- }
96
- } else if (element.type === 'TSIndexSignature') {
97
- let endIndex =
98
- ((_c = element.typeAnnotation) == null
99
- ? void 0
100
- : _c.range.at(0)) ?? element.range.at(1)
101
- name = sourceCode.text.slice(element.range.at(0), endIndex)
102
- } else {
103
- let endIndex =
104
- ((_d = element.returnType) == null ? void 0 : _d.range.at(0)) ??
105
- element.range.at(1)
106
- name = sourceCode.text.slice(element.range.at(0), endIndex)
107
- }
108
- setCustomGroups(options.customGroups, name)
109
- if (
110
- element.type === 'TSMethodSignature' ||
111
- (element.type === 'TSPropertySignature' &&
112
- ((_e = element.typeAnnotation) == null
113
- ? void 0
114
- : _e.typeAnnotation.type) === 'TSFunctionType')
115
- ) {
116
- defineGroup('method')
117
- }
118
- if (element.loc.start.line !== element.loc.end.line) {
119
- defineGroup('multiline')
120
- }
121
- let elementSortingNode = {
122
- isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
123
- element,
124
- eslintDisabledLines,
125
- ),
126
- groupKind: isMemberOptional.isMemberOptional(element)
127
- ? 'optional'
128
- : 'required',
129
- size: rangeToDiff.rangeToDiff(element, sourceCode),
130
- addSafetySemicolonWhenInline: true,
131
- group: getGroup(),
132
- node: element,
133
- name,
134
- }
135
- if (
136
- (options.partitionByComment &&
137
- isPartitionComment.hasPartitionComment(
138
- options.partitionByComment,
139
- getCommentsBefore.getCommentsBefore(element, sourceCode),
140
- )) ||
141
- (options.partitionByNewLine &&
142
- lastElement &&
143
- getLinesBetween.getLinesBetween(
144
- sourceCode,
145
- lastElement,
146
- elementSortingNode,
147
- ))
148
- ) {
149
- accumulator.push([])
150
- }
151
- accumulator.at(-1).push(elementSortingNode)
152
- return accumulator
153
- },
154
- [[]],
155
- )
156
- let groupKindOrder
157
- if (options.groupKind === 'required-first') {
158
- groupKindOrder = ['required', 'optional']
159
- } else if (options.groupKind === 'optional-first') {
160
- groupKindOrder = ['optional', 'required']
161
- } else {
162
- groupKindOrder = ['any']
163
- }
164
- for (let nodes of formattedMembers) {
165
- let filteredGroupKindNodes = groupKindOrder.map(groupKind =>
166
- nodes.filter(
167
- currentNode =>
168
- groupKind === 'any' || currentNode.groupKind === groupKind,
169
- ),
170
- )
171
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
172
- filteredGroupKindNodes.flatMap(groupedNodes =>
173
- sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
174
- ignoreEslintDisabledNodes,
175
- }),
176
- )
177
- let sortedNodes = sortNodesExcludingEslintDisabled(false)
178
- let sortedNodesExcludingEslintDisabled =
179
- sortNodesExcludingEslintDisabled(true)
180
- pairwise.pairwise(nodes, (left, right) => {
181
- let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
182
- let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
183
- let indexOfLeft = sortedNodes.indexOf(left)
184
- let indexOfRight = sortedNodes.indexOf(right)
185
- let indexOfRightExcludingEslintDisabled =
186
- sortedNodesExcludingEslintDisabled.indexOf(right)
187
- let messageIds = []
188
- if (
189
- indexOfLeft > indexOfRight ||
190
- indexOfLeft >= indexOfRightExcludingEslintDisabled
191
- ) {
192
- messageIds.push(
193
- leftNumber === rightNumber
194
- ? 'unexpectedInterfacePropertiesOrder'
195
- : 'unexpectedInterfacePropertiesGroupOrder',
196
- )
197
- }
198
- messageIds = [
199
- ...messageIds,
200
- ...getNewlinesErrors.getNewlinesErrors({
201
- missedSpacingError: 'missedSpacingBetweenInterfaceMembers',
202
- extraSpacingError: 'extraSpacingBetweenInterfaceMembers',
203
- rightNum: rightNumber,
204
- leftNum: leftNumber,
205
- sourceCode,
206
- options,
207
- right,
208
- left,
209
- }),
210
- ]
211
- for (let messageId of messageIds) {
212
- context.report({
213
- fix: fixer => [
214
- ...makeFixes.makeFixes({
215
- sortedNodes: sortedNodesExcludingEslintDisabled,
216
- sourceCode,
217
- options,
218
- fixer,
219
- nodes,
220
- }),
221
- ...makeNewlinesFixes.makeNewlinesFixes({
222
- sortedNodes: sortedNodesExcludingEslintDisabled,
223
- sourceCode,
224
- options,
225
- fixer,
226
- nodes,
227
- }),
228
- ],
229
- data: {
230
- rightGroup: right.group,
231
- leftGroup: left.group,
232
- right: right.name,
233
- left: left.name,
234
- },
235
- node: right.node,
236
- messageId,
237
- })
238
- }
239
- })
240
- }
241
- },
242
- }),
243
20
  meta: {
244
- schema: [
245
- {
246
- properties: {
247
- ignorePattern: {
248
- description:
249
- 'Specifies names or patterns for nodes that should be ignored by rule.',
250
- items: {
251
- type: 'string',
252
- },
253
- type: 'array',
254
- },
255
- partitionByComment: {
256
- ...commonJsonSchemas.partitionByCommentJsonSchema,
257
- description:
258
- 'Allows you to use comments to separate the interface properties into logical groups.',
259
- },
260
- groupKind: {
261
- description: 'Specifies the order of optional and required nodes.',
262
- enum: ['mixed', 'optional-first', 'required-first'],
263
- type: 'string',
264
- },
265
- partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
266
- specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
267
- newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
268
- customGroups: commonJsonSchemas.customGroupsJsonSchema,
269
- ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
270
- locales: commonJsonSchemas.localesJsonSchema,
271
- groups: commonJsonSchemas.groupsJsonSchema,
272
- order: commonJsonSchemas.orderJsonSchema,
273
- type: commonJsonSchemas.typeJsonSchema,
274
- },
275
- additionalProperties: false,
276
- type: 'object',
277
- },
278
- ],
279
21
  messages: {
280
22
  unexpectedInterfacePropertiesGroupOrder:
281
23
  'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
@@ -291,9 +33,24 @@ const sortInterfaces = createEslintRule.createEslintRule({
291
33
  description: 'Enforce sorted interface properties.',
292
34
  recommended: true,
293
35
  },
36
+ schema: [sortObjectTypes.jsonSchema],
294
37
  type: 'suggestion',
295
38
  fixable: 'code',
296
39
  },
40
+ create: context => ({
41
+ TSInterfaceDeclaration: node =>
42
+ sortObjectTypes.sortObjectTypeElements({
43
+ availableMessageIds: {
44
+ missedSpacingBetweenMembers: 'missedSpacingBetweenInterfaceMembers',
45
+ extraSpacingBetweenMembers: 'extraSpacingBetweenInterfaceMembers',
46
+ unexpectedGroupOrder: 'unexpectedInterfacePropertiesGroupOrder',
47
+ unexpectedOrder: 'unexpectedInterfacePropertiesOrder',
48
+ },
49
+ parentNodeName: node.id.name,
50
+ elements: node.body.body,
51
+ context,
52
+ }),
53
+ }),
297
54
  defaultOptions: [defaultOptions],
298
55
  name: 'sort-interfaces',
299
56
  })
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
4
+ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
4
5
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
5
6
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
6
7
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
@@ -28,6 +29,7 @@ let defaultOptions = {
28
29
  type: 'alphabetical',
29
30
  ignoreCase: true,
30
31
  locales: 'en-US',
32
+ alphabet: '',
31
33
  order: 'asc',
32
34
  groups: [],
33
35
  }
@@ -40,6 +42,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
40
42
  settings,
41
43
  defaultOptions,
42
44
  )
45
+ validateCustomSortConfiguration.validateCustomSortConfiguration(options)
43
46
  validateGroupsConfiguration.validateGroupsConfiguration(
44
47
  options.groups,
45
48
  [
@@ -144,7 +147,11 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
144
147
  (options.partitionByComment &&
145
148
  isPartitionComment.hasPartitionComment(
146
149
  options.partitionByComment,
147
- getCommentsBefore.getCommentsBefore(type, sourceCode, '&'),
150
+ getCommentsBefore.getCommentsBefore({
151
+ tokenValueToIgnoreBefore: '&',
152
+ node: type,
153
+ sourceCode,
154
+ }),
148
155
  )) ||
149
156
  (options.partitionByNewLine &&
150
157
  lastSortingNode &&
@@ -245,6 +252,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
245
252
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
246
253
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
247
254
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
255
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
248
256
  locales: commonJsonSchemas.localesJsonSchema,
249
257
  groups: commonJsonSchemas.groupsJsonSchema,
250
258
  order: commonJsonSchemas.orderJsonSchema,
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
3
4
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
4
5
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
5
6
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
@@ -22,6 +23,7 @@ let defaultOptions = {
22
23
  ignoreCase: true,
23
24
  customGroups: {},
24
25
  locales: 'en-US',
26
+ alphabet: '',
25
27
  order: 'asc',
26
28
  groups: [],
27
29
  }
@@ -37,6 +39,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
37
39
  settings,
38
40
  defaultOptions,
39
41
  )
42
+ validateCustomSortConfiguration.validateCustomSortConfiguration(options)
40
43
  validateGroupsConfiguration.validateGroupsConfiguration(
41
44
  options.groups,
42
45
  ['multiline', 'shorthand', 'unknown'],
@@ -154,6 +157,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
154
157
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
155
158
  customGroups: commonJsonSchemas.customGroupsJsonSchema,
156
159
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
160
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
157
161
  locales: commonJsonSchemas.localesJsonSchema,
158
162
  groups: commonJsonSchemas.groupsJsonSchema,
159
163
  order: commonJsonSchemas.orderJsonSchema,
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
3
4
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
4
5
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
5
6
  const isPartitionComment = require('../utils/is-partition-comment.js')
@@ -22,6 +23,7 @@ let defaultOptions = {
22
23
  type: 'alphabetical',
23
24
  ignoreCase: true,
24
25
  locales: 'en-US',
26
+ alphabet: '',
25
27
  order: 'asc',
26
28
  }
27
29
  const sortMaps = createEslintRule.createEslintRule({
@@ -47,6 +49,7 @@ const sortMaps = createEslintRule.createEslintRule({
47
49
  settings,
48
50
  defaultOptions,
49
51
  )
52
+ validateCustomSortConfiguration.validateCustomSortConfiguration(options)
50
53
  let sourceCode = getSourceCode.getSourceCode(context)
51
54
  let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
52
55
  ruleName: context.id,
@@ -94,7 +97,10 @@ const sortMaps = createEslintRule.createEslintRule({
94
97
  (options.partitionByComment &&
95
98
  isPartitionComment.hasPartitionComment(
96
99
  options.partitionByComment,
97
- getCommentsBefore.getCommentsBefore(element, sourceCode),
100
+ getCommentsBefore.getCommentsBefore({
101
+ node: element,
102
+ sourceCode,
103
+ }),
98
104
  )) ||
99
105
  (options.partitionByNewLine &&
100
106
  lastSortingNode &&
@@ -158,6 +164,7 @@ const sortMaps = createEslintRule.createEslintRule({
158
164
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
159
165
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
160
166
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
167
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
161
168
  locales: commonJsonSchemas.localesJsonSchema,
162
169
  order: commonJsonSchemas.orderJsonSchema,
163
170
  type: commonJsonSchemas.typeJsonSchema,
@@ -46,27 +46,4 @@ let customGroupMatches = props => {
46
46
  }
47
47
  return true
48
48
  }
49
- let getCompareOptions = (options, groupNumber) => {
50
- let group = options.groups[groupNumber]
51
- let customGroup =
52
- typeof group === 'string'
53
- ? options.customGroups.find(
54
- currentGroup => group === currentGroup.groupName,
55
- )
56
- : null
57
- if ((customGroup == null ? void 0 : customGroup.type) === 'unsorted') {
58
- return null
59
- }
60
- return {
61
- order:
62
- customGroup && 'order' in customGroup && customGroup.order
63
- ? customGroup.order
64
- : options.order,
65
- specialCharacters: options.specialCharacters,
66
- type: (customGroup == null ? void 0 : customGroup.type) ?? options.type,
67
- ignoreCase: options.ignoreCase,
68
- locales: options.locales,
69
- }
70
- }
71
49
  exports.customGroupMatches = customGroupMatches
72
- exports.getCompareOptions = getCompareOptions
@@ -1,12 +1,13 @@
1
1
  'use strict'
2
2
  const utils = require('@typescript-eslint/utils')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
- const sortModules_types = require('./sort-modules.types.js')
5
4
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
6
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
7
- const validateGeneratedGroupsConfiguration = require('./validate-generated-groups-configuration.js')
6
+ const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
7
+ const sortModules_types = require('./sort-modules.types.js')
8
+ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
9
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
8
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
9
- const sortModulesUtils = require('./sort-modules-utils.js')
10
11
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
11
12
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
12
13
  const isPartitionComment = require('../utils/is-partition-comment.js')
@@ -19,6 +20,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
19
20
  const getLinesBetween = require('../utils/get-lines-between.js')
20
21
  const getGroupNumber = require('../utils/get-group-number.js')
21
22
  const getEnumMembers = require('../utils/get-enum-members.js')
23
+ const sortModulesUtils = require('./sort-modules-utils.js')
22
24
  const getSourceCode = require('../utils/get-source-code.js')
23
25
  const toSingleLine = require('../utils/to-single-line.js')
24
26
  const rangeToDiff = require('../utils/range-to-diff.js')
@@ -52,6 +54,7 @@ let defaultOptions = {
52
54
  ignoreCase: true,
53
55
  customGroups: [],
54
56
  locales: 'en-US',
57
+ alphabet: '',
55
58
  order: 'asc',
56
59
  }
57
60
  const sortModules = createEslintRule.createEslintRule({
@@ -59,53 +62,20 @@ const sortModules = createEslintRule.createEslintRule({
59
62
  schema: [
60
63
  {
61
64
  properties: {
62
- customGroups: {
63
- items: {
64
- oneOf: [
65
- {
66
- properties: {
67
- ...sortModules_types.customGroupNameJsonSchema,
68
- ...sortModules_types.customGroupSortJsonSchema,
69
- anyOf: {
70
- items: {
71
- properties: {
72
- ...sortModules_types.singleCustomGroupJsonSchema,
73
- },
74
- description: 'Custom group.',
75
- additionalProperties: false,
76
- type: 'object',
77
- },
78
- type: 'array',
79
- },
80
- },
81
- description: 'Custom group block.',
82
- additionalProperties: false,
83
- type: 'object',
84
- },
85
- {
86
- properties: {
87
- ...sortModules_types.customGroupNameJsonSchema,
88
- ...sortModules_types.customGroupSortJsonSchema,
89
- ...sortModules_types.singleCustomGroupJsonSchema,
90
- },
91
- description: 'Custom group.',
92
- additionalProperties: false,
93
- type: 'object',
94
- },
95
- ],
96
- },
97
- description: 'Specifies custom groups.',
98
- type: 'array',
99
- },
100
65
  partitionByComment: {
101
66
  ...commonJsonSchemas.partitionByCommentJsonSchema,
102
67
  description:
103
68
  'Allows to use comments to separate the modules members into logical groups.',
104
69
  },
70
+ customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
71
+ singleCustomGroupJsonSchema:
72
+ sortModules_types.singleCustomGroupJsonSchema,
73
+ }),
105
74
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
106
75
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
107
76
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
108
77
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
78
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
109
79
  locales: commonJsonSchemas.localesJsonSchema,
110
80
  groups: commonJsonSchemas.groupsJsonSchema,
111
81
  order: commonJsonSchemas.orderJsonSchema,
@@ -141,6 +111,7 @@ const sortModules = createEslintRule.createEslintRule({
141
111
  settings,
142
112
  defaultOptions,
143
113
  )
114
+ validateCustomSortConfiguration.validateCustomSortConfiguration(options)
144
115
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
145
116
  customGroups: options.customGroups,
146
117
  modifiers: sortModules_types.allModifiers,
@@ -327,7 +298,6 @@ let analyzeModule = ({
327
298
  node,
328
299
  name,
329
300
  }
330
- let comments = getCommentsBefore.getCommentsBefore(node, sourceCode)
331
301
  let lastSortingNode =
332
302
  (_a = formattedNodes.at(-1)) == null ? void 0 : _a.at(-1)
333
303
  if (
@@ -341,7 +311,10 @@ let analyzeModule = ({
341
311
  (options.partitionByComment &&
342
312
  isPartitionComment.hasPartitionComment(
343
313
  options.partitionByComment,
344
- comments,
314
+ getCommentsBefore.getCommentsBefore({
315
+ sourceCode,
316
+ node,
317
+ }),
345
318
  ))
346
319
  ) {
347
320
  formattedNodes.push([])
@@ -356,7 +329,10 @@ let analyzeModule = ({
356
329
  getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
357
330
  options.groups.length,
358
331
  getGroupCompareOptions: groupNumber =>
359
- sortModulesUtils.getCompareOptions(options, groupNumber),
332
+ getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
333
+ options,
334
+ groupNumber,
335
+ ),
360
336
  ignoreEslintDisabledNodes,
361
337
  }),
362
338
  ),