eslint-plugin-perfectionist 4.1.1 → 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.
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ let plugin = {
28
28
  'sort-array-includes': sortArrayIncludes.default,
29
29
  'sort-named-imports': sortNamedImports,
30
30
  'sort-named-exports': sortNamedExports,
31
- 'sort-object-types': sortObjectTypes,
31
+ 'sort-object-types': sortObjectTypes.default,
32
32
  'sort-union-types': sortUnionTypes,
33
33
  'sort-switch-case': sortSwitchCase,
34
34
  'sort-decorators': sortDecorators,
@@ -0,0 +1,28 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let getCustomGroupsCompareOptions = (options, groupNumber) => {
4
+ if (!Array.isArray(options.customGroups)) {
5
+ return options
6
+ }
7
+ let group = options.groups[groupNumber]
8
+ let customGroup =
9
+ typeof group === 'string'
10
+ ? options.customGroups.find(
11
+ currentGroup => group === currentGroup.groupName,
12
+ )
13
+ : null
14
+ if ((customGroup == null ? void 0 : customGroup.type) === 'unsorted') {
15
+ return null
16
+ }
17
+ return {
18
+ order:
19
+ customGroup && 'order' in customGroup && customGroup.order
20
+ ? customGroup.order
21
+ : options.order,
22
+ specialCharacters: options.specialCharacters,
23
+ type: (customGroup == null ? void 0 : customGroup.type) ?? options.type,
24
+ ignoreCase: options.ignoreCase,
25
+ locales: options.locales,
26
+ }
27
+ }
28
+ exports.getCustomGroupsCompareOptions = getCustomGroupsCompareOptions
@@ -129,7 +129,10 @@ let sortArray = (context, messageId, elements) => {
129
129
  (options.partitionByComment &&
130
130
  isPartitionComment.hasPartitionComment(
131
131
  options.partitionByComment,
132
- getCommentsBefore.getCommentsBefore(element, sourceCode),
132
+ getCommentsBefore.getCommentsBefore({
133
+ node: element,
134
+ sourceCode,
135
+ }),
133
136
  )) ||
134
137
  (options.partitionByNewLine &&
135
138
  lastSortingNode &&
@@ -89,28 +89,5 @@ let customGroupMatches = props => {
89
89
  }
90
90
  return true
91
91
  }
92
- let getCompareOptions = (options, groupNumber) => {
93
- let group = options.groups[groupNumber]
94
- let customGroup =
95
- typeof group === 'string'
96
- ? options.customGroups.find(
97
- currentGroup => group === currentGroup.groupName,
98
- )
99
- : null
100
- if ((customGroup == null ? void 0 : customGroup.type) === 'unsorted') {
101
- return null
102
- }
103
- return {
104
- order:
105
- customGroup && 'order' in customGroup && customGroup.order
106
- ? customGroup.order
107
- : options.order,
108
- specialCharacters: options.specialCharacters,
109
- type: (customGroup == null ? void 0 : customGroup.type) ?? options.type,
110
- ignoreCase: options.ignoreCase,
111
- locales: options.locales,
112
- }
113
- }
114
92
  exports.customGroupMatches = customGroupMatches
115
- exports.getCompareOptions = getCompareOptions
116
93
  exports.getOverloadSignatureGroups = getOverloadSignatureGroups
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
- const sortClasses_types = require('./sort-classes.types.js')
4
3
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
5
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
- const sortClassesUtils = require('./sort-classes-utils.js')
5
+ const sortClasses_types = require('./sort-classes.types.js')
7
6
  const validateGeneratedGroupsConfiguration = require('./validate-generated-groups-configuration.js')
7
+ const sortClassesUtils = require('./sort-classes-utils.js')
8
+ const getCustomGroupsCompareOptions = require('./get-custom-groups-compare-options.js')
8
9
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
9
10
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
10
11
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
@@ -446,7 +447,6 @@ const sortClasses = createEslintRule.createEslintRule({
446
447
  dependencies,
447
448
  name,
448
449
  }
449
- let comments = getCommentsBefore.getCommentsBefore(member, sourceCode)
450
450
  let lastMember =
451
451
  (_e = accumulator.at(-1)) == null ? void 0 : _e.at(-1)
452
452
  if (
@@ -460,7 +460,10 @@ const sortClasses = createEslintRule.createEslintRule({
460
460
  (options.partitionByComment &&
461
461
  isPartitionComment.hasPartitionComment(
462
462
  options.partitionByComment,
463
- comments,
463
+ getCommentsBefore.getCommentsBefore({
464
+ node: member,
465
+ sourceCode,
466
+ }),
464
467
  ))
465
468
  ) {
466
469
  accumulator.push([])
@@ -478,7 +481,10 @@ const sortClasses = createEslintRule.createEslintRule({
478
481
  getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
479
482
  options.groups.length,
480
483
  getGroupCompareOptions: groupNumber =>
481
- sortClassesUtils.getCompareOptions(options, groupNumber),
484
+ getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
485
+ options,
486
+ groupNumber,
487
+ ),
482
488
  ignoreEslintDisabledNodes,
483
489
  }),
484
490
  ),
@@ -567,44 +573,6 @@ const sortClasses = createEslintRule.createEslintRule({
567
573
  schema: [
568
574
  {
569
575
  properties: {
570
- customGroups: {
571
- items: {
572
- oneOf: [
573
- {
574
- properties: {
575
- ...sortClasses_types.customGroupNameJsonSchema,
576
- ...sortClasses_types.customGroupSortJsonSchema,
577
- anyOf: {
578
- items: {
579
- properties: {
580
- ...sortClasses_types.singleCustomGroupJsonSchema,
581
- },
582
- description: 'Custom group.',
583
- additionalProperties: false,
584
- type: 'object',
585
- },
586
- type: 'array',
587
- },
588
- },
589
- description: 'Custom group block.',
590
- additionalProperties: false,
591
- type: 'object',
592
- },
593
- {
594
- properties: {
595
- ...sortClasses_types.customGroupNameJsonSchema,
596
- ...sortClasses_types.customGroupSortJsonSchema,
597
- ...sortClasses_types.singleCustomGroupJsonSchema,
598
- },
599
- description: 'Custom group.',
600
- additionalProperties: false,
601
- type: 'object',
602
- },
603
- ],
604
- },
605
- description: 'Specifies custom groups.',
606
- type: 'array',
607
- },
608
576
  ignoreCallbackDependenciesPatterns: {
609
577
  description:
610
578
  'Patterns that should be ignored when detecting dependencies in method callbacks.',
@@ -618,6 +586,10 @@ const sortClasses = createEslintRule.createEslintRule({
618
586
  description:
619
587
  'Allows to use comments to separate the class members into logical groups.',
620
588
  },
589
+ customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
590
+ singleCustomGroupJsonSchema:
591
+ sortClasses_types.singleCustomGroupJsonSchema,
592
+ }),
621
593
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
622
594
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
623
595
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
@@ -1,5 +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
4
  let allSelectors = [
4
5
  'accessor-property',
5
6
  'index-signature',
@@ -24,33 +25,7 @@ let allModifiers = [
24
25
  'declare',
25
26
  'optional',
26
27
  ]
27
- let customGroupSortJsonSchema = {
28
- type: {
29
- enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
30
- description: 'Custom group sort type.',
31
- type: 'string',
32
- },
33
- order: {
34
- description: 'Custom group sort order.',
35
- enum: ['desc', 'asc'],
36
- type: 'string',
37
- },
38
- }
39
- let customGroupNameJsonSchema = {
40
- groupName: {
41
- description: 'Custom group name.',
42
- type: 'string',
43
- },
44
- }
45
28
  let singleCustomGroupJsonSchema = {
46
- modifiers: {
47
- items: {
48
- enum: allModifiers,
49
- type: 'string',
50
- },
51
- description: 'Modifier filters.',
52
- type: 'array',
53
- },
54
29
  elementValuePattern: {
55
30
  description: 'Element value pattern filter for properties.',
56
31
  type: 'string',
@@ -59,18 +34,11 @@ let singleCustomGroupJsonSchema = {
59
34
  description: 'Decorator name pattern filter.',
60
35
  type: 'string',
61
36
  },
62
- selector: {
63
- description: 'Selector filter.',
64
- enum: allSelectors,
65
- type: 'string',
66
- },
67
- elementNamePattern: {
68
- description: 'Element name pattern filter.',
69
- type: 'string',
70
- },
37
+ modifiers:
38
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
39
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
40
+ elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
71
41
  }
72
42
  exports.allModifiers = allModifiers
73
43
  exports.allSelectors = allSelectors
74
- exports.customGroupNameJsonSchema = customGroupNameJsonSchema
75
- exports.customGroupSortJsonSchema = customGroupSortJsonSchema
76
44
  exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -176,7 +176,10 @@ let sortDecorators$1 = (context, options, decorators) => {
176
176
  options.partitionByComment &&
177
177
  isPartitionComment.hasPartitionComment(
178
178
  options.partitionByComment,
179
- getCommentsBefore.getCommentsBefore(decorator, sourceCode),
179
+ getCommentsBefore.getCommentsBefore({
180
+ node: decorator,
181
+ sourceCode,
182
+ }),
180
183
  )
181
184
  ) {
182
185
  accumulator.push([])
@@ -226,6 +229,7 @@ let sortDecorators$1 = (context, options, decorators) => {
226
229
  fix: fixer =>
227
230
  makeFixes.makeFixes({
228
231
  sortedNodes: sortedNodesExcludingEslintDisabled,
232
+ ignoreFirstNodeHighestBlockComment: true,
229
233
  sourceCode,
230
234
  options,
231
235
  fixer,
@@ -109,7 +109,10 @@ const sortEnums = createEslintRule.createEslintRule({
109
109
  (options.partitionByComment &&
110
110
  isPartitionComment.hasPartitionComment(
111
111
  options.partitionByComment,
112
- getCommentsBefore.getCommentsBefore(member, sourceCode),
112
+ getCommentsBefore.getCommentsBefore({
113
+ node: member,
114
+ sourceCode,
115
+ }),
113
116
  )) ||
114
117
  (options.partitionByNewLine &&
115
118
  lastSortingNode &&
@@ -295,6 +298,7 @@ let getUnaryExpressionNumberValue = (argumentExpression, operator) => {
295
298
  return -argument
296
299
  case '~':
297
300
  return ~argument
301
+ /* v8 ignore next 2 - Unsure if we can reach it */
298
302
  default:
299
303
  return Number.NaN
300
304
  }
@@ -329,6 +333,7 @@ let getBinaryExpressionNumberValue = (
329
333
  return left & right
330
334
  case '^':
331
335
  return left ^ right
336
+ /* v8 ignore next 2 - Unsure if we can reach it */
332
337
  default:
333
338
  return Number.NaN
334
339
  }
@@ -56,7 +56,10 @@ const sortExports = createEslintRule.createEslintRule({
56
56
  (partitionComment &&
57
57
  isPartitionComment.hasPartitionComment(
58
58
  partitionComment,
59
- getCommentsBefore.getCommentsBefore(node, sourceCode),
59
+ getCommentsBefore.getCommentsBefore({
60
+ sourceCode,
61
+ node,
62
+ }),
60
63
  )) ||
61
64
  (options.partitionByNewLine &&
62
65
  lastNode &&
@@ -340,10 +340,10 @@ const sortImports = createEslintRule.createEslintRule({
340
340
  (options.partitionByComment &&
341
341
  isPartitionComment.hasPartitionComment(
342
342
  options.partitionByComment,
343
- getCommentsBefore.getCommentsBefore(
344
- sortingNode.node,
343
+ getCommentsBefore.getCommentsBefore({
344
+ node: sortingNode.node,
345
345
  sourceCode,
346
- ),
346
+ }),
347
347
  )) ||
348
348
  (options.partitionByNewLine &&
349
349
  lastSortingNode &&
@@ -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,
@@ -37,245 +16,7 @@ let defaultOptions = {
37
16
  groups: [],
38
17
  }
39
18
  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
19
  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
20
  messages: {
280
21
  unexpectedInterfacePropertiesGroupOrder:
281
22
  'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
@@ -291,9 +32,24 @@ const sortInterfaces = createEslintRule.createEslintRule({
291
32
  description: 'Enforce sorted interface properties.',
292
33
  recommended: true,
293
34
  },
35
+ schema: [sortObjectTypes.jsonSchema],
294
36
  type: 'suggestion',
295
37
  fixable: 'code',
296
38
  },
39
+ create: context => ({
40
+ TSInterfaceDeclaration: node =>
41
+ sortObjectTypes.sortObjectTypeElements({
42
+ availableMessageIds: {
43
+ missedSpacingBetweenMembers: 'missedSpacingBetweenInterfaceMembers',
44
+ extraSpacingBetweenMembers: 'extraSpacingBetweenInterfaceMembers',
45
+ unexpectedGroupOrder: 'unexpectedInterfacePropertiesGroupOrder',
46
+ unexpectedOrder: 'unexpectedInterfacePropertiesOrder',
47
+ },
48
+ parentNodeName: node.id.name,
49
+ elements: node.body.body,
50
+ context,
51
+ }),
52
+ }),
297
53
  defaultOptions: [defaultOptions],
298
54
  name: 'sort-interfaces',
299
55
  })
@@ -144,7 +144,11 @@ const sortIntersectionTypes = 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 &&
@@ -94,7 +94,10 @@ const sortMaps = createEslintRule.createEslintRule({
94
94
  (options.partitionByComment &&
95
95
  isPartitionComment.hasPartitionComment(
96
96
  options.partitionByComment,
97
- getCommentsBefore.getCommentsBefore(element, sourceCode),
97
+ getCommentsBefore.getCommentsBefore({
98
+ node: element,
99
+ sourceCode,
100
+ }),
98
101
  )) ||
99
102
  (options.partitionByNewLine &&
100
103
  lastSortingNode &&
@@ -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