eslint-plugin-perfectionist 4.1.2 → 4.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.
@@ -1,8 +1,15 @@
1
1
  'use strict'
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: 'Module' },
5
+ })
2
6
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
7
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
4
- const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
8
+ const validateGeneratedGroupsConfiguration = require('./validate-generated-groups-configuration.js')
9
+ const getCustomGroupsCompareOptions = require('./get-custom-groups-compare-options.js')
10
+ const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
5
11
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
+ const sortObjectTypes_types = require('./sort-object-types.types.js')
6
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
7
14
  const isPartitionComment = require('../utils/is-partition-comment.js')
8
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
@@ -11,6 +18,7 @@ const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
11
18
  const getNewlinesErrors = require('../utils/get-newlines-errors.js')
12
19
  const createEslintRule = require('../utils/create-eslint-rule.js')
13
20
  const isMemberOptional = require('../utils/is-member-optional.js')
21
+ const sortObjectTypesUtils = require('./sort-object-types-utils.js')
14
22
  const getLinesBetween = require('../utils/get-lines-between.js')
15
23
  const getGroupNumber = require('../utils/get-group-number.js')
16
24
  const getSourceCode = require('../utils/get-source-code.js')
@@ -22,6 +30,8 @@ const makeFixes = require('../utils/make-fixes.js')
22
30
  const useGroups = require('../utils/use-groups.js')
23
31
  const complete = require('../utils/complete.js')
24
32
  const pairwise = require('../utils/pairwise.js')
33
+ const matches = require('../utils/matches.js')
34
+ let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
25
35
  let defaultOptions = {
26
36
  partitionByComment: false,
27
37
  partitionByNewLine: false,
@@ -29,235 +39,56 @@ let defaultOptions = {
29
39
  specialCharacters: 'keep',
30
40
  type: 'alphabetical',
31
41
  groupKind: 'mixed',
42
+ ignorePattern: [],
32
43
  ignoreCase: true,
33
44
  customGroups: {},
34
45
  locales: 'en-US',
35
46
  order: 'asc',
36
47
  groups: [],
37
48
  }
38
- const sortObjectTypes = createEslintRule.createEslintRule({
39
- create: context => ({
40
- TSTypeLiteral: node => {
41
- if (!isSortable.isSortable(node.members)) {
42
- return
43
- }
44
- let settings = getSettings.getSettings(context.settings)
45
- let options = complete.complete(
46
- context.options.at(0),
47
- settings,
48
- defaultOptions,
49
- )
50
- validateGroupsConfiguration.validateGroupsConfiguration(
51
- options.groups,
52
- ['multiline', 'method', 'unknown'],
53
- Object.keys(options.customGroups),
54
- )
55
- validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
56
- options,
57
- )
58
- let sourceCode = getSourceCode.getSourceCode(context)
59
- let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
60
- ruleName: context.id,
61
- sourceCode,
62
- })
63
- let formattedMembers = node.members.reduce(
64
- (accumulator, member) => {
65
- var _a, _b, _c, _d, _e
66
- let name
67
- let lastSortingNode =
68
- (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
69
- let { setCustomGroups, defineGroup, getGroup } =
70
- useGroups.useGroups(options)
71
- let formatName = value => value.replace(/[,;]$/u, '')
72
- if (member.type === 'TSPropertySignature') {
73
- if (member.key.type === 'Identifier') {
74
- ;({ name } = member.key)
75
- } else if (member.key.type === 'Literal') {
76
- name = `${member.key.value}`
77
- } else {
78
- name = sourceCode.text.slice(
79
- member.range.at(0),
80
- ((_b = member.typeAnnotation) == null
81
- ? void 0
82
- : _b.range.at(0)) ?? member.range.at(1),
83
- )
84
- }
85
- } else if (member.type === 'TSIndexSignature') {
86
- let endIndex =
87
- ((_c = member.typeAnnotation) == null
88
- ? void 0
89
- : _c.range.at(0)) ?? member.range.at(1)
90
- name = formatName(
91
- sourceCode.text.slice(member.range.at(0), endIndex),
92
- )
93
- } else {
94
- name = formatName(
95
- sourceCode.text.slice(member.range.at(0), member.range.at(1)),
96
- )
97
- }
98
- setCustomGroups(options.customGroups, name)
99
- if (
100
- member.type === 'TSMethodSignature' ||
101
- (member.type === 'TSPropertySignature' &&
102
- ((_d = member.typeAnnotation) == null
103
- ? void 0
104
- : _d.typeAnnotation.type) === 'TSFunctionType')
105
- ) {
106
- defineGroup('method')
107
- }
108
- if (member.loc.start.line !== member.loc.end.line) {
109
- defineGroup('multiline')
110
- }
111
- let sortingNode = {
112
- isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
113
- member,
114
- eslintDisabledLines,
115
- ),
116
- groupKind: isMemberOptional.isMemberOptional(member)
117
- ? 'optional'
118
- : 'required',
119
- size: rangeToDiff.rangeToDiff(member, sourceCode),
120
- addSafetySemicolonWhenInline: true,
121
- group: getGroup(),
122
- node: member,
123
- name,
124
- }
125
- if (
126
- (options.partitionByComment &&
127
- isPartitionComment.hasPartitionComment(
128
- options.partitionByComment,
129
- getCommentsBefore.getCommentsBefore(member, sourceCode),
130
- )) ||
131
- (options.partitionByNewLine &&
132
- lastSortingNode &&
133
- getLinesBetween.getLinesBetween(
134
- sourceCode,
135
- lastSortingNode,
136
- sortingNode,
137
- ))
138
- ) {
139
- accumulator.push([])
140
- }
141
- ;(_e = accumulator.at(-1)) == null ? void 0 : _e.push(sortingNode)
142
- return accumulator
143
- },
144
- [[]],
145
- )
146
- let groupKindOrder
147
- if (options.groupKind === 'required-first') {
148
- groupKindOrder = ['required', 'optional']
149
- } else if (options.groupKind === 'optional-first') {
150
- groupKindOrder = ['optional', 'required']
151
- } else {
152
- groupKindOrder = ['any']
153
- }
154
- for (let nodes of formattedMembers) {
155
- let filteredGroupKindNodes = groupKindOrder.map(groupKind =>
156
- nodes.filter(
157
- currentNode =>
158
- groupKind === 'any' || currentNode.groupKind === groupKind,
159
- ),
160
- )
161
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
162
- filteredGroupKindNodes.flatMap(groupedNodes =>
163
- sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
164
- ignoreEslintDisabledNodes,
165
- }),
166
- )
167
- let sortedNodes = sortNodesExcludingEslintDisabled(false)
168
- let sortedNodesExcludingEslintDisabled =
169
- sortNodesExcludingEslintDisabled(true)
170
- pairwise.pairwise(nodes, (left, right) => {
171
- let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
172
- let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
173
- let indexOfLeft = sortedNodes.indexOf(left)
174
- let indexOfRight = sortedNodes.indexOf(right)
175
- let indexOfRightExcludingEslintDisabled =
176
- sortedNodesExcludingEslintDisabled.indexOf(right)
177
- let messageIds = []
178
- if (
179
- indexOfLeft > indexOfRight ||
180
- indexOfLeft >= indexOfRightExcludingEslintDisabled
181
- ) {
182
- messageIds.push(
183
- leftNumber === rightNumber
184
- ? 'unexpectedObjectTypesOrder'
185
- : 'unexpectedObjectTypesGroupOrder',
186
- )
187
- }
188
- messageIds = [
189
- ...messageIds,
190
- ...getNewlinesErrors.getNewlinesErrors({
191
- missedSpacingError: 'missedSpacingBetweenObjectTypeMembers',
192
- extraSpacingError: 'extraSpacingBetweenObjectTypeMembers',
193
- rightNum: rightNumber,
194
- leftNum: leftNumber,
195
- sourceCode,
196
- options,
197
- right,
198
- left,
199
- }),
200
- ]
201
- for (let messageId of messageIds) {
202
- context.report({
203
- fix: fixer => [
204
- ...makeFixes.makeFixes({
205
- sortedNodes: sortedNodesExcludingEslintDisabled,
206
- sourceCode,
207
- options,
208
- fixer,
209
- nodes,
210
- }),
211
- ...makeNewlinesFixes.makeNewlinesFixes({
212
- sortedNodes: sortedNodesExcludingEslintDisabled,
213
- sourceCode,
214
- options,
215
- fixer,
216
- nodes,
217
- }),
218
- ],
219
- data: {
220
- right: toSingleLine.toSingleLine(right.name),
221
- left: toSingleLine.toSingleLine(left.name),
222
- rightGroup: right.group,
223
- leftGroup: left.group,
224
- },
225
- node: right.node,
226
- messageId,
227
- })
228
- }
229
- })
230
- }
49
+ let jsonSchema = {
50
+ properties: {
51
+ ignorePattern: {
52
+ description:
53
+ 'Specifies names or patterns for nodes that should be ignored by rule.',
54
+ items: {
55
+ type: 'string',
56
+ },
57
+ type: 'array',
231
58
  },
232
- }),
59
+ partitionByComment: {
60
+ ...commonJsonSchemas.partitionByCommentJsonSchema,
61
+ description:
62
+ 'Allows you to use comments to separate members into logical groups.',
63
+ },
64
+ customGroups: {
65
+ oneOf: [
66
+ commonJsonSchemas.customGroupsJsonSchema,
67
+ commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
68
+ singleCustomGroupJsonSchema:
69
+ sortObjectTypes_types.singleCustomGroupJsonSchema,
70
+ }),
71
+ ],
72
+ },
73
+ groupKind: {
74
+ enum: ['mixed', 'required-first', 'optional-first'],
75
+ description: 'Specifies top-level groups.',
76
+ type: 'string',
77
+ },
78
+ partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
79
+ specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
80
+ newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
81
+ ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
82
+ locales: commonJsonSchemas.localesJsonSchema,
83
+ groups: commonJsonSchemas.groupsJsonSchema,
84
+ order: commonJsonSchemas.orderJsonSchema,
85
+ type: commonJsonSchemas.typeJsonSchema,
86
+ },
87
+ additionalProperties: false,
88
+ type: 'object',
89
+ }
90
+ const sortObjectTypes = createEslintRule.createEslintRule({
233
91
  meta: {
234
- schema: [
235
- {
236
- properties: {
237
- partitionByComment: {
238
- ...commonJsonSchemas.partitionByCommentJsonSchema,
239
- description:
240
- 'Allows you to use comments to separate the type members into logical groups.',
241
- },
242
- groupKind: {
243
- enum: ['mixed', 'required-first', 'optional-first'],
244
- description: 'Specifies top-level groups.',
245
- type: 'string',
246
- },
247
- partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
248
- specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
249
- newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
250
- customGroups: commonJsonSchemas.customGroupsJsonSchema,
251
- ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
252
- locales: commonJsonSchemas.localesJsonSchema,
253
- groups: commonJsonSchemas.groupsJsonSchema,
254
- order: commonJsonSchemas.orderJsonSchema,
255
- type: commonJsonSchemas.typeJsonSchema,
256
- },
257
- additionalProperties: false,
258
- type: 'object',
259
- },
260
- ],
261
92
  messages: {
262
93
  unexpectedObjectTypesGroupOrder:
263
94
  'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
@@ -273,10 +104,302 @@ const sortObjectTypes = createEslintRule.createEslintRule({
273
104
  description: 'Enforce sorted object types.',
274
105
  recommended: true,
275
106
  },
107
+ schema: [jsonSchema],
276
108
  type: 'suggestion',
277
109
  fixable: 'code',
278
110
  },
111
+ create: context => ({
112
+ TSTypeLiteral: node =>
113
+ sortObjectTypeElements({
114
+ availableMessageIds: {
115
+ missedSpacingBetweenMembers: 'missedSpacingBetweenObjectTypeMembers',
116
+ extraSpacingBetweenMembers: 'extraSpacingBetweenObjectTypeMembers',
117
+ unexpectedGroupOrder: 'unexpectedObjectTypesGroupOrder',
118
+ unexpectedOrder: 'unexpectedObjectTypesOrder',
119
+ },
120
+ parentNodeName:
121
+ node.parent.type === 'TSTypeAliasDeclaration'
122
+ ? node.parent.id.name
123
+ : null,
124
+ elements: node.members,
125
+ context,
126
+ }),
127
+ }),
279
128
  defaultOptions: [defaultOptions],
280
129
  name: 'sort-object-types',
281
130
  })
282
- module.exports = sortObjectTypes
131
+ let sortObjectTypeElements = ({
132
+ availableMessageIds,
133
+ parentNodeName,
134
+ elements,
135
+ context,
136
+ }) => {
137
+ if (!isSortable.isSortable(elements)) {
138
+ return
139
+ }
140
+ let settings = getSettings.getSettings(context.settings)
141
+ let options = complete.complete(
142
+ context.options.at(0),
143
+ settings,
144
+ defaultOptions,
145
+ )
146
+ validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
147
+ customGroups: options.customGroups,
148
+ selectors: sortObjectTypes_types.allSelectors,
149
+ modifiers: sortObjectTypes_types.allModifiers,
150
+ groups: options.groups,
151
+ })
152
+ validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
153
+ options,
154
+ )
155
+ if (
156
+ options.ignorePattern.some(
157
+ pattern => parentNodeName && matches.matches(parentNodeName, pattern),
158
+ )
159
+ ) {
160
+ return
161
+ }
162
+ let sourceCode = getSourceCode.getSourceCode(context)
163
+ let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
164
+ ruleName: context.id,
165
+ sourceCode,
166
+ })
167
+ let formattedMembers = elements.reduce(
168
+ (accumulator, typeElement) => {
169
+ var _a, _b, _c, _d, _e
170
+ if (typeElement.type === 'TSCallSignatureDeclaration') {
171
+ accumulator.push([])
172
+ return accumulator
173
+ }
174
+ let name
175
+ let lastSortingNode =
176
+ (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
177
+ let { setCustomGroups, defineGroup, getGroup } =
178
+ useGroups.useGroups(options)
179
+ let formatName = value => value.replace(/[,;]$/u, '')
180
+ if (typeElement.type === 'TSPropertySignature') {
181
+ if (typeElement.key.type === 'Identifier') {
182
+ ;({ name } = typeElement.key)
183
+ } else if (typeElement.key.type === 'Literal') {
184
+ name = `${typeElement.key.value}`
185
+ } else {
186
+ let end =
187
+ ((_b = typeElement.typeAnnotation) == null
188
+ ? void 0
189
+ : _b.range.at(0)) ??
190
+ typeElement.range.at(1) - (typeElement.optional ? '?'.length : 0)
191
+ name = sourceCode.text.slice(typeElement.range.at(0), end)
192
+ }
193
+ } else if (typeElement.type === 'TSIndexSignature') {
194
+ let endIndex =
195
+ ((_c = typeElement.typeAnnotation) == null
196
+ ? void 0
197
+ : _c.range.at(0)) ?? typeElement.range.at(1)
198
+ name = formatName(
199
+ sourceCode.text.slice(typeElement.range.at(0), endIndex),
200
+ )
201
+ } else if (
202
+ typeElement.type === 'TSMethodSignature' &&
203
+ 'name' in typeElement.key
204
+ ) {
205
+ ;({ name } = typeElement.key)
206
+ } else {
207
+ name = formatName(
208
+ sourceCode.text.slice(
209
+ typeElement.range.at(0),
210
+ typeElement.range.at(1),
211
+ ),
212
+ )
213
+ }
214
+ let selectors = []
215
+ let modifiers = []
216
+ if (typeElement.type === 'TSIndexSignature') {
217
+ selectors.push('index-signature')
218
+ }
219
+ if (
220
+ typeElement.type === 'TSMethodSignature' ||
221
+ (typeElement.type === 'TSPropertySignature' &&
222
+ ((_d = typeElement.typeAnnotation) == null
223
+ ? void 0
224
+ : _d.typeAnnotation.type) === 'TSFunctionType')
225
+ ) {
226
+ selectors.push('method')
227
+ }
228
+ if (typeElement.loc.start.line !== typeElement.loc.end.line) {
229
+ modifiers.push('multiline')
230
+ selectors.push('multiline')
231
+ }
232
+ if (
233
+ !selectors.includes('index-signature') &&
234
+ !selectors.includes('method')
235
+ ) {
236
+ selectors.push('property')
237
+ }
238
+ selectors.push('member')
239
+ if (isMemberOptional.isMemberOptional(typeElement)) {
240
+ modifiers.push('optional')
241
+ } else {
242
+ modifiers.push('required')
243
+ }
244
+ for (let predefinedGroup of generatePredefinedGroups.generatePredefinedGroups(
245
+ {
246
+ cache: cachedGroupsByModifiersAndSelectors,
247
+ selectors,
248
+ modifiers,
249
+ },
250
+ )) {
251
+ defineGroup(predefinedGroup)
252
+ }
253
+ if (Array.isArray(options.customGroups)) {
254
+ for (let customGroup of options.customGroups) {
255
+ if (
256
+ sortObjectTypesUtils.customGroupMatches({
257
+ elementName: name,
258
+ customGroup,
259
+ selectors,
260
+ modifiers,
261
+ })
262
+ ) {
263
+ defineGroup(customGroup.groupName, true)
264
+ if (getGroup() === customGroup.groupName) {
265
+ break
266
+ }
267
+ }
268
+ }
269
+ } else {
270
+ setCustomGroups(options.customGroups, name, {
271
+ override: true,
272
+ })
273
+ }
274
+ let sortingNode = {
275
+ isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
276
+ typeElement,
277
+ eslintDisabledLines,
278
+ ),
279
+ groupKind: isMemberOptional.isMemberOptional(typeElement)
280
+ ? 'optional'
281
+ : 'required',
282
+ size: rangeToDiff.rangeToDiff(typeElement, sourceCode),
283
+ addSafetySemicolonWhenInline: true,
284
+ group: getGroup(),
285
+ node: typeElement,
286
+ name,
287
+ }
288
+ if (
289
+ (options.partitionByComment &&
290
+ isPartitionComment.hasPartitionComment(
291
+ options.partitionByComment,
292
+ getCommentsBefore.getCommentsBefore({
293
+ node: typeElement,
294
+ sourceCode,
295
+ }),
296
+ )) ||
297
+ (options.partitionByNewLine &&
298
+ lastSortingNode &&
299
+ getLinesBetween.getLinesBetween(
300
+ sourceCode,
301
+ lastSortingNode,
302
+ sortingNode,
303
+ ))
304
+ ) {
305
+ accumulator.push([])
306
+ }
307
+ ;(_e = accumulator.at(-1)) == null ? void 0 : _e.push(sortingNode)
308
+ return accumulator
309
+ },
310
+ [[]],
311
+ )
312
+ let groupKindOrder
313
+ if (options.groupKind === 'required-first') {
314
+ groupKindOrder = ['required', 'optional']
315
+ } else if (options.groupKind === 'optional-first') {
316
+ groupKindOrder = ['optional', 'required']
317
+ } else {
318
+ groupKindOrder = ['any']
319
+ }
320
+ for (let nodes of formattedMembers) {
321
+ let filteredGroupKindNodes = groupKindOrder.map(groupKind =>
322
+ nodes.filter(
323
+ currentNode =>
324
+ groupKind === 'any' || currentNode.groupKind === groupKind,
325
+ ),
326
+ )
327
+ let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
328
+ filteredGroupKindNodes.flatMap(groupedNodes =>
329
+ sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
330
+ getGroupCompareOptions: groupNumber =>
331
+ getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
332
+ options,
333
+ groupNumber,
334
+ ),
335
+ ignoreEslintDisabledNodes,
336
+ }),
337
+ )
338
+ let sortedNodes = sortNodesExcludingEslintDisabled(false)
339
+ let sortedNodesExcludingEslintDisabled =
340
+ sortNodesExcludingEslintDisabled(true)
341
+ pairwise.pairwise(nodes, (left, right) => {
342
+ let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
343
+ let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
344
+ let indexOfLeft = sortedNodes.indexOf(left)
345
+ let indexOfRight = sortedNodes.indexOf(right)
346
+ let indexOfRightExcludingEslintDisabled =
347
+ sortedNodesExcludingEslintDisabled.indexOf(right)
348
+ let messageIds = []
349
+ if (
350
+ indexOfLeft > indexOfRight ||
351
+ indexOfLeft >= indexOfRightExcludingEslintDisabled
352
+ ) {
353
+ messageIds.push(
354
+ leftNumber === rightNumber
355
+ ? availableMessageIds.unexpectedOrder
356
+ : availableMessageIds.unexpectedGroupOrder,
357
+ )
358
+ }
359
+ messageIds = [
360
+ ...messageIds,
361
+ ...getNewlinesErrors.getNewlinesErrors({
362
+ missedSpacingError: availableMessageIds.missedSpacingBetweenMembers,
363
+ extraSpacingError: availableMessageIds.extraSpacingBetweenMembers,
364
+ rightNum: rightNumber,
365
+ leftNum: leftNumber,
366
+ sourceCode,
367
+ options,
368
+ right,
369
+ left,
370
+ }),
371
+ ]
372
+ for (let messageId of messageIds) {
373
+ context.report({
374
+ fix: fixer => [
375
+ ...makeFixes.makeFixes({
376
+ sortedNodes: sortedNodesExcludingEslintDisabled,
377
+ sourceCode,
378
+ options,
379
+ fixer,
380
+ nodes,
381
+ }),
382
+ ...makeNewlinesFixes.makeNewlinesFixes({
383
+ sortedNodes: sortedNodesExcludingEslintDisabled,
384
+ sourceCode,
385
+ options,
386
+ fixer,
387
+ nodes,
388
+ }),
389
+ ],
390
+ data: {
391
+ right: toSingleLine.toSingleLine(right.name),
392
+ left: toSingleLine.toSingleLine(left.name),
393
+ rightGroup: right.group,
394
+ leftGroup: left.group,
395
+ },
396
+ node: right.node,
397
+ messageId,
398
+ })
399
+ }
400
+ })
401
+ }
402
+ }
403
+ exports.default = sortObjectTypes
404
+ exports.jsonSchema = jsonSchema
405
+ exports.sortObjectTypeElements = sortObjectTypeElements
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
+ let allSelectors = [
5
+ 'index-signature',
6
+ 'member',
7
+ 'method',
8
+ 'multiline',
9
+ 'property',
10
+ ]
11
+ let allModifiers = ['optional', 'required', 'multiline']
12
+ let singleCustomGroupJsonSchema = {
13
+ modifiers:
14
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
15
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
16
+ elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
17
+ }
18
+ exports.allModifiers = allModifiers
19
+ exports.allSelectors = allSelectors
20
+ exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -218,10 +218,6 @@ const sortObjects = createEslintRule.createEslintRule({
218
218
  accumulator.push([])
219
219
  return accumulator
220
220
  }
221
- let comments = getCommentsBefore.getCommentsBefore(
222
- property,
223
- sourceCode,
224
- )
225
221
  let lastProperty =
226
222
  (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
227
223
  let name
@@ -270,7 +266,10 @@ const sortObjects = createEslintRule.createEslintRule({
270
266
  (options.partitionByComment &&
271
267
  isPartitionComment.hasPartitionComment(
272
268
  options.partitionByComment,
273
- comments,
269
+ getCommentsBefore.getCommentsBefore({
270
+ node: property,
271
+ sourceCode,
272
+ }),
274
273
  ))
275
274
  ) {
276
275
  accumulator.push([])
@@ -144,7 +144,11 @@ const sortUnionTypes = createEslintRule.createEslintRule({
144
144
  (options.partitionByComment &&
145
145
  isPartitionComment.hasPartitionComment(
146
146
  options.partitionByComment,
147
- getCommentsBefore.getCommentsBefore(type, sourceCode, '|'),
147
+ getCommentsBefore.getCommentsBefore({
148
+ tokenValueToIgnoreBefore: '|',
149
+ node: type,
150
+ sourceCode,
151
+ }),
148
152
  )) ||
149
153
  (options.partitionByNewLine &&
150
154
  lastSortingNode &&
@@ -146,7 +146,10 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
146
146
  (options.partitionByComment &&
147
147
  isPartitionComment.hasPartitionComment(
148
148
  options.partitionByComment,
149
- getCommentsBefore.getCommentsBefore(declaration, sourceCode),
149
+ getCommentsBefore.getCommentsBefore({
150
+ node: declaration,
151
+ sourceCode,
152
+ }),
150
153
  )) ||
151
154
  (options.partitionByNewLine &&
152
155
  lastSortingNode &&
@@ -8,7 +8,9 @@ let validateGeneratedGroupsConfiguration = ({
8
8
  groups,
9
9
  }) => {
10
10
  let availableCustomGroupNames = new Set(
11
- customGroups.map(customGroup => customGroup.groupName),
11
+ Array.isArray(customGroups)
12
+ ? customGroups.map(customGroup => customGroup.groupName)
13
+ : Object.keys(customGroups),
12
14
  )
13
15
  let invalidGroups = groups
14
16
  .flat()