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
@@ -39,8 +39,7 @@ export declare class Alphabet {
39
39
  * @returns {Alphabet} - The same alphabet instance with the cases prioritized
40
40
  * @example
41
41
  * Alphabet.generateFrom('aAbBcdCD')
42
- * .prioritizeCase('uppercase')
43
- * // Returns 'AaBbCDcd'
42
+ * .prioritizeCase('uppercase') // Returns 'AaBbCDcd'.
44
43
  */
45
44
  prioritizeCase(casePriority: 'lowercase' | 'uppercase'): this
46
45
  /**
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const matches = require('../../utils/matches.js')
4
+ let doesCustomGroupMatch = props => {
5
+ if ('anyOf' in props.customGroup) {
6
+ return props.customGroup.anyOf.some(subgroup =>
7
+ doesCustomGroupMatch({ ...props, customGroup: subgroup }),
8
+ )
9
+ }
10
+ if (
11
+ props.customGroup.selector &&
12
+ !props.selectors.includes(props.customGroup.selector)
13
+ ) {
14
+ return false
15
+ }
16
+ if (
17
+ 'elementNamePattern' in props.customGroup &&
18
+ props.customGroup.elementNamePattern
19
+ ) {
20
+ let matchesElementNamePattern = matches.matches(
21
+ props.elementName,
22
+ props.customGroup.elementNamePattern,
23
+ )
24
+ if (!matchesElementNamePattern) {
25
+ return false
26
+ }
27
+ }
28
+ return true
29
+ }
30
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
+ let allSelectors = ['literal', 'spread']
5
+ let singleCustomGroupJsonSchema = {
6
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
7
+ elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
8
+ }
9
+ exports.allSelectors = allSelectors
10
+ exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -4,58 +4,76 @@ Object.defineProperties(exports, {
4
4
  [Symbol.toStringTag]: { value: 'Module' },
5
5
  })
6
6
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
7
+ const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
8
+ const types = require('./sort-array-includes/types.js')
9
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
10
+ const doesCustomGroupMatch = require('./sort-array-includes/does-custom-group-match.js')
11
+ const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
12
+ const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
7
13
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
8
14
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
9
- const isPartitionComment = require('../utils/is-partition-comment.js')
15
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
16
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
17
+ const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
10
18
  const getCommentsBefore = require('../utils/get-comments-before.js')
11
19
  const createEslintRule = require('../utils/create-eslint-rule.js')
12
20
  const getLinesBetween = require('../utils/get-lines-between.js')
21
+ const getGroupNumber = require('../utils/get-group-number.js')
13
22
  const getSourceCode = require('../utils/get-source-code.js')
14
23
  const toSingleLine = require('../utils/to-single-line.js')
15
24
  const rangeToDiff = require('../utils/range-to-diff.js')
16
25
  const getSettings = require('../utils/get-settings.js')
17
26
  const isSortable = require('../utils/is-sortable.js')
18
- const sortNodes = require('../utils/sort-nodes.js')
19
27
  const makeFixes = require('../utils/make-fixes.js')
28
+ const useGroups = require('../utils/use-groups.js')
20
29
  const complete = require('../utils/complete.js')
21
30
  const pairwise = require('../utils/pairwise.js')
31
+ let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
22
32
  let defaultOptions = {
23
33
  groupKind: 'literals-first',
24
34
  specialCharacters: 'keep',
25
35
  partitionByComment: false,
26
36
  partitionByNewLine: false,
37
+ useConfigurationIf: {},
27
38
  type: 'alphabetical',
28
39
  ignoreCase: true,
29
40
  locales: 'en-US',
41
+ customGroups: [],
30
42
  alphabet: '',
31
43
  order: 'asc',
44
+ groups: [],
32
45
  }
33
46
  let jsonSchema = {
34
- properties: {
35
- partitionByComment: {
36
- ...commonJsonSchemas.partitionByCommentJsonSchema,
37
- description:
38
- 'Allows you to use comments to separate the array members into logical groups.',
47
+ items: {
48
+ properties: {
49
+ partitionByComment: {
50
+ ...commonJsonSchemas.partitionByCommentJsonSchema,
51
+ description:
52
+ 'Allows you to use comments to separate the array members into logical groups.',
53
+ },
54
+ groupKind: {
55
+ enum: ['mixed', 'literals-first', 'spreads-first'],
56
+ description: 'Specifies top-level groups.',
57
+ type: 'string',
58
+ },
59
+ customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
60
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
61
+ }),
62
+ useConfigurationIf: commonJsonSchemas.buildUseConfigurationIfJsonSchema(),
63
+ type: commonJsonSchemas.buildTypeJsonSchema({ withUnsorted: true }),
64
+ partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
65
+ specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
66
+ ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
67
+ alphabet: commonJsonSchemas.alphabetJsonSchema,
68
+ locales: commonJsonSchemas.localesJsonSchema,
69
+ groups: commonJsonSchemas.groupsJsonSchema,
70
+ order: commonJsonSchemas.orderJsonSchema,
39
71
  },
40
- groupKind: {
41
- enum: ['mixed', 'literals-first', 'spreads-first'],
42
- description: 'Specifies top-level groups.',
43
- type: 'string',
44
- },
45
- partitionByNewLine: {
46
- description:
47
- 'Allows to use spaces to separate the nodes into logical groups.',
48
- type: 'boolean',
49
- },
50
- specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
51
- ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
52
- alphabet: commonJsonSchemas.alphabetJsonSchema,
53
- locales: commonJsonSchemas.localesJsonSchema,
54
- order: commonJsonSchemas.orderJsonSchema,
55
- type: commonJsonSchemas.typeJsonSchema,
72
+ additionalProperties: false,
73
+ type: 'object',
56
74
  },
57
- additionalProperties: false,
58
- type: 'object',
75
+ uniqueItems: true,
76
+ type: 'array',
59
77
  }
60
78
  const sortArrayIncludes = createEslintRule.createEslintRule({
61
79
  create: context => ({
@@ -70,38 +88,68 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
70
88
  node.object.type === 'ArrayExpression'
71
89
  ? node.object.elements
72
90
  : node.object.arguments
73
- sortArray(context, 'unexpectedArrayIncludesOrder', elements)
91
+ sortArray({
92
+ availableMessageIds: {
93
+ unexpectedGroupOrder: 'unexpectedArrayIncludesGroupOrder',
94
+ unexpectedOrder: 'unexpectedArrayIncludesOrder',
95
+ },
96
+ elements,
97
+ context,
98
+ })
74
99
  }
75
100
  },
76
101
  }),
77
102
  meta: {
103
+ messages: {
104
+ unexpectedArrayIncludesGroupOrder:
105
+ 'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
106
+ unexpectedArrayIncludesOrder:
107
+ 'Expected "{{right}}" to come before "{{left}}".',
108
+ },
78
109
  docs: {
79
110
  description: 'Enforce sorted arrays before include method.',
80
111
  url: 'https://perfectionist.dev/rules/sort-array-includes',
81
112
  recommended: true,
82
113
  },
83
- messages: {
84
- unexpectedArrayIncludesOrder:
85
- 'Expected "{{right}}" to come before "{{left}}".',
86
- },
87
- schema: [jsonSchema],
114
+ schema: jsonSchema,
88
115
  type: 'suggestion',
89
116
  fixable: 'code',
90
117
  },
91
118
  defaultOptions: [defaultOptions],
92
119
  name: 'sort-array-includes',
93
120
  })
94
- let sortArray = (context, messageId, elements) => {
121
+ let sortArray = ({ availableMessageIds, elements, context }) => {
95
122
  if (!isSortable.isSortable(elements)) {
96
123
  return
97
124
  }
125
+ let sourceCode = getSourceCode.getSourceCode(context)
98
126
  let settings = getSettings.getSettings(context.settings)
99
- let options = complete.complete(
100
- context.options.at(0),
127
+ let matchedContextOptions =
128
+ getMatchingContextOptions.getMatchingContextOptions({
129
+ nodeNames: elements
130
+ .filter(element => element !== null)
131
+ .map(element => getNodeName({ sourceCode, element })),
132
+ contextOptions: context.options,
133
+ })
134
+ let completeOptions = complete.complete(
135
+ matchedContextOptions[0],
101
136
  settings,
102
137
  defaultOptions,
103
138
  )
104
- let sourceCode = getSourceCode.getSourceCode(context)
139
+ let { type } = completeOptions
140
+ if (type === 'unsorted') {
141
+ return
142
+ }
143
+ let options = {
144
+ ...completeOptions,
145
+ type,
146
+ }
147
+ validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
148
+ customGroups: options.customGroups,
149
+ selectors: types.allSelectors,
150
+ groups: options.groups,
151
+ modifiers: [],
152
+ })
105
153
  let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
106
154
  ruleName: context.id,
107
155
  sourceCode,
@@ -112,30 +160,60 @@ let sortArray = (context, messageId, elements) => {
112
160
  if (element === null) {
113
161
  return accumulator
114
162
  }
115
- let lastSortingNode =
116
- (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
163
+ let { defineGroup, getGroup } = useGroups.useGroups(options)
164
+ let groupKind
165
+ let selector
166
+ if (element.type === 'SpreadElement') {
167
+ groupKind = 'spread'
168
+ selector = 'spread'
169
+ } else {
170
+ groupKind = 'literal'
171
+ selector = 'literal'
172
+ }
173
+ let predefinedGroups = generatePredefinedGroups.generatePredefinedGroups({
174
+ cache: cachedGroupsByModifiersAndSelectors,
175
+ selectors: [selector],
176
+ modifiers: [],
177
+ })
178
+ for (let predefinedGroup of predefinedGroups) {
179
+ defineGroup(predefinedGroup)
180
+ }
181
+ let name = getNodeName({ sourceCode, element })
182
+ for (let customGroup of options.customGroups) {
183
+ if (
184
+ doesCustomGroupMatch.doesCustomGroupMatch({
185
+ selectors: [selector],
186
+ elementName: name,
187
+ customGroup,
188
+ })
189
+ ) {
190
+ defineGroup(customGroup.groupName, true)
191
+ if (getGroup() === customGroup.groupName) {
192
+ break
193
+ }
194
+ }
195
+ }
117
196
  let sortingNode = {
118
- name:
119
- element.type === 'Literal'
120
- ? `${element.value}`
121
- : sourceCode.getText(element),
122
197
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
123
198
  element,
124
199
  eslintDisabledLines,
125
200
  ),
126
- groupKind: element.type === 'SpreadElement' ? 'spread' : 'literal',
127
201
  size: rangeToDiff.rangeToDiff(element, sourceCode),
202
+ group: getGroup(),
128
203
  node: element,
204
+ groupKind,
205
+ name,
129
206
  }
207
+ let lastSortingNode =
208
+ (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
130
209
  if (
131
- (options.partitionByComment &&
132
- isPartitionComment.hasPartitionComment(
133
- options.partitionByComment,
134
- getCommentsBefore.getCommentsBefore({
135
- node: element,
136
- sourceCode,
137
- }),
138
- )) ||
210
+ hasPartitionComment.hasPartitionComment({
211
+ comments: getCommentsBefore.getCommentsBefore({
212
+ node: element,
213
+ sourceCode,
214
+ }),
215
+ partitionByComment: options.partitionByComment,
216
+ }) ||
139
217
  (options.partitionByNewLine &&
140
218
  lastSortingNode &&
141
219
  getLinesBetween.getLinesBetween(
@@ -168,21 +246,29 @@ let sortArray = (context, messageId, elements) => {
168
246
  )
169
247
  let sortNodesIgnoringEslintDisabledNodes = ignoreEslintDisabledNodes =>
170
248
  filteredGroupKindNodes.flatMap(groupedNodes =>
171
- sortNodes.sortNodes(groupedNodes, options, {
249
+ sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
250
+ getGroupCompareOptions: groupNumber =>
251
+ getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
252
+ options,
253
+ groupNumber,
254
+ ),
172
255
  ignoreEslintDisabledNodes,
173
256
  }),
174
257
  )
175
258
  let sortedNodes = sortNodesIgnoringEslintDisabledNodes(false)
176
259
  let sortedNodesExcludingEslintDisabled =
177
260
  sortNodesIgnoringEslintDisabledNodes(true)
261
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
178
262
  pairwise.pairwise(nodes, (left, right) => {
179
- let indexOfLeft = sortedNodes.indexOf(left)
180
- let indexOfRight = sortedNodes.indexOf(right)
263
+ let leftIndex = nodeIndexMap.get(left)
264
+ let rightIndex = nodeIndexMap.get(right)
265
+ let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
266
+ let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
181
267
  let indexOfRightExcludingEslintDisabled =
182
268
  sortedNodesExcludingEslintDisabled.indexOf(right)
183
269
  if (
184
- indexOfLeft < indexOfRight &&
185
- indexOfLeft < indexOfRightExcludingEslintDisabled
270
+ leftIndex < rightIndex &&
271
+ leftIndex < indexOfRightExcludingEslintDisabled
186
272
  ) {
187
273
  return
188
274
  }
@@ -198,13 +284,20 @@ let sortArray = (context, messageId, elements) => {
198
284
  data: {
199
285
  right: toSingleLine.toSingleLine(right.name),
200
286
  left: toSingleLine.toSingleLine(left.name),
287
+ rightGroup: right.group,
288
+ leftGroup: left.group,
201
289
  },
290
+ messageId:
291
+ leftNumber === rightNumber
292
+ ? availableMessageIds.unexpectedOrder
293
+ : availableMessageIds.unexpectedGroupOrder,
202
294
  node: right.node,
203
- messageId,
204
295
  })
205
296
  })
206
297
  }
207
298
  }
299
+ let getNodeName = ({ sourceCode, element }) =>
300
+ element.type === 'Literal' ? `${element.value}` : sourceCode.getText(element)
208
301
  exports.default = sortArrayIncludes
209
302
  exports.defaultOptions = defaultOptions
210
303
  exports.jsonSchema = jsonSchema
@@ -1,41 +1,10 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const isSortable = require('../utils/is-sortable.js')
4
- const matches = require('../utils/matches.js')
5
- let getOverloadSignatureGroups = members => {
6
- let methods = members
7
- .filter(
8
- member =>
9
- member.type === 'MethodDefinition' ||
10
- member.type === 'TSAbstractMethodDefinition',
11
- )
12
- .filter(member => member.kind === 'method')
13
- let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
14
- let overloadSignaturesByName = /* @__PURE__ */ new Map()
15
- for (let method of methods) {
16
- if (method.key.type !== 'Identifier') {
17
- continue
18
- }
19
- let { name } = method.key
20
- let mapToUse = method.static
21
- ? staticOverloadSignaturesByName
22
- : overloadSignaturesByName
23
- let signatureOverloadsGroup = mapToUse.get(name)
24
- if (!signatureOverloadsGroup) {
25
- signatureOverloadsGroup = []
26
- mapToUse.set(name, signatureOverloadsGroup)
27
- }
28
- signatureOverloadsGroup.push(method)
29
- }
30
- return [
31
- ...overloadSignaturesByName.values(),
32
- ...staticOverloadSignaturesByName.values(),
33
- ].filter(isSortable.isSortable)
34
- }
35
- let customGroupMatches = props => {
3
+ const matches = require('../../utils/matches.js')
4
+ let doesCustomGroupMatch = props => {
36
5
  if ('anyOf' in props.customGroup) {
37
6
  return props.customGroup.anyOf.some(subgroup =>
38
- customGroupMatches({ ...props, customGroup: subgroup }),
7
+ doesCustomGroupMatch({ ...props, customGroup: subgroup }),
39
8
  )
40
9
  }
41
10
  if (
@@ -89,5 +58,4 @@ let customGroupMatches = props => {
89
58
  }
90
59
  return true
91
60
  }
92
- exports.customGroupMatches = customGroupMatches
93
- exports.getOverloadSignatureGroups = getOverloadSignatureGroups
61
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const isSortable = require('../../utils/is-sortable.js')
4
+ let getOverloadSignatureGroups = members => {
5
+ let methods = members
6
+ .filter(
7
+ member =>
8
+ member.type === 'MethodDefinition' ||
9
+ member.type === 'TSAbstractMethodDefinition',
10
+ )
11
+ .filter(member => member.kind === 'method')
12
+ let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
13
+ let overloadSignaturesByName = /* @__PURE__ */ new Map()
14
+ for (let method of methods) {
15
+ if (method.key.type !== 'Identifier') {
16
+ continue
17
+ }
18
+ let { name } = method.key
19
+ let mapToUse = method.static
20
+ ? staticOverloadSignaturesByName
21
+ : overloadSignaturesByName
22
+ let signatureOverloadsGroup = mapToUse.get(name)
23
+ if (!signatureOverloadsGroup) {
24
+ signatureOverloadsGroup = []
25
+ mapToUse.set(name, signatureOverloadsGroup)
26
+ }
27
+ signatureOverloadsGroup.push(method)
28
+ }
29
+ return [
30
+ ...overloadSignaturesByName.values(),
31
+ ...staticOverloadSignaturesByName.values(),
32
+ ].filter(isSortable.isSortable)
33
+ }
34
+ exports.getOverloadSignatureGroups = getOverloadSignatureGroups
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
4
  let allSelectors = [
5
5
  'accessor-property',
6
6
  'index-signature',
@@ -3,14 +3,15 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
4
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
5
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
6
- const sortClasses_types = require('./sort-classes.types.js')
6
+ const types = require('./sort-classes/types.js')
7
7
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
8
- const sortClassesUtils = require('./sort-classes-utils.js')
9
8
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
9
+ const getOverloadSignatureGroups = require('./sort-classes/get-overload-signature-groups.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
+ const doesCustomGroupMatch = require('./sort-classes/does-custom-group-match.js')
11
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
13
- const isPartitionComment = require('../utils/is-partition-comment.js')
14
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
14
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
15
16
  const getCommentsBefore = require('../utils/get-comments-before.js')
16
17
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -83,8 +84,8 @@ const sortClasses = createEslintRule.createEslintRule({
83
84
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
84
85
  {
85
86
  customGroups: options.customGroups,
86
- modifiers: sortClasses_types.allModifiers,
87
- selectors: sortClasses_types.allSelectors,
87
+ modifiers: types.allModifiers,
88
+ selectors: types.allSelectors,
88
89
  groups: options.groups,
89
90
  },
90
91
  )
@@ -228,9 +229,8 @@ const sortClasses = createEslintRule.createEslintRule({
228
229
  traverseNode(expression)
229
230
  return dependencies
230
231
  }
231
- let overloadSignatureGroups = sortClassesUtils.getOverloadSignatureGroups(
232
- node.body,
233
- )
232
+ let overloadSignatureGroups =
233
+ getOverloadSignatureGroups.getOverloadSignatureGroups(node.body)
234
234
  let formattedNodes = node.body.reduce(
235
235
  (accumulator, member) => {
236
236
  var _a2, _b, _c, _d, _e
@@ -394,18 +394,18 @@ const sortClasses = createEslintRule.createEslintRule({
394
394
  }
395
395
  selectors.push('property')
396
396
  }
397
- for (let officialGroup of generatePredefinedGroups.generatePredefinedGroups(
398
- {
397
+ let predefinedGroups =
398
+ generatePredefinedGroups.generatePredefinedGroups({
399
399
  cache: cachedGroupsByModifiersAndSelectors,
400
400
  selectors,
401
401
  modifiers,
402
- },
403
- )) {
404
- defineGroup(officialGroup)
402
+ })
403
+ for (let predefinedGroup of predefinedGroups) {
404
+ defineGroup(predefinedGroup)
405
405
  }
406
406
  for (let customGroup of options.customGroups) {
407
407
  if (
408
- sortClassesUtils.customGroupMatches({
408
+ doesCustomGroupMatch.doesCustomGroupMatch({
409
409
  elementValue: memberValue,
410
410
  elementName: name,
411
411
  customGroup,
@@ -460,14 +460,13 @@ const sortClasses = createEslintRule.createEslintRule({
460
460
  lastMember,
461
461
  sortingNode,
462
462
  )) ||
463
- (options.partitionByComment &&
464
- isPartitionComment.hasPartitionComment(
465
- options.partitionByComment,
466
- getCommentsBefore.getCommentsBefore({
467
- node: member,
468
- sourceCode,
469
- }),
470
- ))
463
+ hasPartitionComment.hasPartitionComment({
464
+ comments: getCommentsBefore.getCommentsBefore({
465
+ node: member,
466
+ sourceCode,
467
+ }),
468
+ partitionByComment: options.partitionByComment,
469
+ })
471
470
  ) {
472
471
  accumulator.push([])
473
472
  }
@@ -590,18 +589,17 @@ const sortClasses = createEslintRule.createEslintRule({
590
589
  'Allows to use comments to separate the class members into logical groups.',
591
590
  },
592
591
  customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
593
- singleCustomGroupJsonSchema:
594
- sortClasses_types.singleCustomGroupJsonSchema,
592
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
595
593
  }),
596
594
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
597
595
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
598
596
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
599
597
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
600
598
  alphabet: commonJsonSchemas.alphabetJsonSchema,
599
+ type: commonJsonSchemas.buildTypeJsonSchema(),
601
600
  locales: commonJsonSchemas.localesJsonSchema,
602
601
  groups: commonJsonSchemas.groupsJsonSchema,
603
602
  order: commonJsonSchemas.orderJsonSchema,
604
- type: commonJsonSchemas.typeJsonSchema,
605
603
  },
606
604
  additionalProperties: false,
607
605
  type: 'object',
@@ -4,12 +4,13 @@ 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 isPartitionComment = require('../utils/is-partition-comment.js')
7
+ const getDecoratorName = require('./sort-decorators/get-decorator-name.js')
8
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
9
+ const createNodeIndexMap = require('../utils/create-node-index-map.js')
8
10
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
9
11
  const getCommentsBefore = require('../utils/get-comments-before.js')
10
12
  const getNodeDecorators = require('../utils/get-node-decorators.js')
11
13
  const createEslintRule = require('../utils/create-eslint-rule.js')
12
- const getDecoratorName = require('../utils/get-decorator-name.js')
13
14
  const getGroupNumber = require('../utils/get-group-number.js')
14
15
  const getSourceCode = require('../utils/get-source-code.js')
15
16
  const toSingleLine = require('../utils/to-single-line.js')
@@ -75,10 +76,10 @@ const sortDecorators = createEslintRule.createEslintRule({
75
76
  customGroups: commonJsonSchemas.customGroupsJsonSchema,
76
77
  ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
77
78
  alphabet: commonJsonSchemas.alphabetJsonSchema,
79
+ type: commonJsonSchemas.buildTypeJsonSchema(),
78
80
  locales: commonJsonSchemas.localesJsonSchema,
79
81
  groups: commonJsonSchemas.groupsJsonSchema,
80
82
  order: commonJsonSchemas.orderJsonSchema,
81
- type: commonJsonSchemas.typeJsonSchema,
82
83
  },
83
84
  additionalProperties: false,
84
85
  type: 'object',
@@ -177,14 +178,13 @@ let sortDecorators$1 = (context, options, decorators) => {
177
178
  let formattedMembers = decorators.reduce(
178
179
  (accumulator, decorator) => {
179
180
  if (
180
- options.partitionByComment &&
181
- isPartitionComment.hasPartitionComment(
182
- options.partitionByComment,
183
- getCommentsBefore.getCommentsBefore({
181
+ hasPartitionComment.hasPartitionComment({
182
+ comments: getCommentsBefore.getCommentsBefore({
184
183
  node: decorator,
185
184
  sourceCode,
186
185
  }),
187
- )
186
+ partitionByComment: options.partitionByComment,
187
+ })
188
188
  ) {
189
189
  accumulator.push([])
190
190
  }
@@ -216,14 +216,15 @@ let sortDecorators$1 = (context, options, decorators) => {
216
216
  let sortedNodesExcludingEslintDisabled =
217
217
  sortNodesExcludingEslintDisabled(true)
218
218
  let nodes = formattedMembers.flat()
219
+ let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
219
220
  pairwise.pairwise(nodes, (left, right) => {
220
- let indexOfLeft = sortedNodes.indexOf(left)
221
- let indexOfRight = sortedNodes.indexOf(right)
221
+ let leftIndex = nodeIndexMap.get(left)
222
+ let rightIndex = nodeIndexMap.get(right)
222
223
  let indexOfRightExcludingEslintDisabled =
223
224
  sortedNodesExcludingEslintDisabled.indexOf(right)
224
225
  if (
225
- indexOfLeft < indexOfRight &&
226
- indexOfLeft < indexOfRightExcludingEslintDisabled
226
+ leftIndex < rightIndex &&
227
+ leftIndex < indexOfRightExcludingEslintDisabled
227
228
  ) {
228
229
  return
229
230
  }