eslint-plugin-perfectionist 4.9.0 → 4.10.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.
@@ -6,10 +6,10 @@ Object.defineProperties(exports, {
6
6
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
7
7
  const reportErrors = require('../utils/report-errors.js')
8
8
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
9
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
9
10
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
10
11
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
11
12
  const types = require('./sort-array-includes/types.js')
12
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
13
13
  const doesCustomGroupMatch = require('./sort-array-includes/does-custom-group-match.js')
14
14
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
15
15
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
@@ -229,13 +229,14 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
229
229
  )
230
230
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
231
231
  filteredGroupKindNodes.flatMap(groupedNodes =>
232
- sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
233
- getGroupCompareOptions: groupNumber =>
234
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
232
+ sortNodesByGroups.sortNodesByGroups({
233
+ getOptionsByGroupNumber:
234
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
235
235
  options,
236
- groupNumber,
237
236
  ),
238
237
  ignoreEslintDisabledNodes,
238
+ groups: options.groups,
239
+ nodes: groupedNodes,
239
240
  }),
240
241
  )
241
242
  reportAllErrors.reportAllErrors({
@@ -2,10 +2,10 @@
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const reportErrors = require('../utils/report-errors.js')
4
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
5
6
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
6
7
  const types = require('./sort-classes/types.js')
7
8
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
8
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
9
9
  const getOverloadSignatureGroups = require('./sort-classes/get-overload-signature-groups.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
11
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
@@ -477,25 +477,28 @@ const sortClasses = createEslintRule.createEslintRule({
477
477
  },
478
478
  [[]],
479
479
  )
480
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
481
- sortNodesByDependencies.sortNodesByDependencies(
482
- formattedNodes.flatMap(nodes2 =>
483
- sortNodesByGroups.sortNodesByGroups(nodes2, options, {
484
- isNodeIgnored: sortingNode =>
485
- getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
486
- options.groups.length,
487
- getGroupCompareOptions: groupNumber =>
488
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
489
- options,
490
- groupNumber,
491
- ),
492
- ignoreEslintDisabledNodes,
493
- }),
494
- ),
480
+ let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
481
+ let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
482
+ sortNodesByGroups.sortNodesByGroups({
483
+ isNodeIgnored: sortingNode =>
484
+ getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
485
+ options.groups.length,
486
+ getOptionsByGroupNumber:
487
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
488
+ options,
489
+ ),
490
+ ignoreEslintDisabledNodes,
491
+ groups: options.groups,
492
+ nodes: nodes2,
493
+ }),
494
+ )
495
+ return sortNodesByDependencies.sortNodesByDependencies(
496
+ nodesSortedByGroups,
495
497
  {
496
498
  ignoreEslintDisabledNodes,
497
499
  },
498
500
  )
501
+ }
499
502
  let nodes = formattedNodes.flat()
500
503
  reportAllErrors.reportAllErrors({
501
504
  newlinesBetweenValueGetter: ({
@@ -199,8 +199,11 @@ let sortDecorators$1 = (context, options, decorators) => {
199
199
  )
200
200
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
201
201
  formattedMembers.flatMap(nodes2 =>
202
- sortNodesByGroups.sortNodesByGroups(nodes2, options, {
202
+ sortNodesByGroups.sortNodesByGroups({
203
+ getOptionsByGroupNumber: () => ({ options }),
203
204
  ignoreEslintDisabledNodes,
205
+ groups: options.groups,
206
+ nodes: nodes2,
204
207
  }),
205
208
  )
206
209
  let nodes = formattedMembers.flat()
@@ -98,7 +98,7 @@ const sortEnums = createEslintRule.createEslintRule({
98
98
  }
99
99
  let formattedMembers = members.reduce(
100
100
  (accumulator, member) => {
101
- var _a
101
+ var _a, _b, _c
102
102
  let dependencies = []
103
103
  if (member.initializer) {
104
104
  dependencies = extractDependencies(
@@ -131,6 +131,13 @@ const sortEnums = createEslintRule.createEslintRule({
131
131
  numericValue: member.initializer
132
132
  ? getExpressionNumberValue(member.initializer)
133
133
  : null,
134
+ value:
135
+ ((_b = member.initializer) == null ? void 0 : _b.type) ===
136
+ 'Literal'
137
+ ? (((_c = member.initializer.value) == null
138
+ ? void 0
139
+ : _c.toString()) ?? null)
140
+ : null,
134
141
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
135
142
  member,
136
143
  eslintDisabledLines,
@@ -162,55 +169,40 @@ const sortEnums = createEslintRule.createEslintRule({
162
169
  sortingNode.numericValue !== null &&
163
170
  !Number.isNaN(sortingNode.numericValue),
164
171
  )
165
- let compareOptions = {
172
+ let nodeValueGetter = computeNodeValueGetter({
173
+ isNumericEnum,
174
+ options,
175
+ })
176
+ let overriddenOptions = {
166
177
  ...options,
167
- // Get the enum value rather than the name if needed.
168
- nodeValueGetter:
169
- options.sortByValue || (isNumericEnum && options.forceNumericSort)
170
- ? sortingNode => {
171
- var _a, _b
172
- if (isNumericEnum) {
173
- return sortingNode.numericValue.toString()
174
- }
175
- if (
176
- ((_a = sortingNode.node.initializer) == null
177
- ? void 0
178
- : _a.type) === 'Literal'
179
- ) {
180
- return (
181
- ((_b = sortingNode.node.initializer.value) == null
182
- ? void 0
183
- : _b.toString()) ?? ''
184
- )
185
- }
186
- return ''
187
- }
188
- : null,
189
- /**
190
- * If the enum is numeric, and we sort by value, always use the
191
- * `natural` sort type, which will correctly sort them.
192
- */
193
- type:
194
- isNumericEnum && (options.forceNumericSort || options.sortByValue)
195
- ? 'natural'
196
- : options.type,
178
+ type: computeOptionType({
179
+ isNumericEnum,
180
+ options,
181
+ }),
197
182
  }
198
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
199
- sortNodesByDependencies.sortNodesByDependencies(
200
- formattedMembers.flatMap(sortingNodes =>
201
- sortNodesByGroups.sortNodesByGroups(sortingNodes, compareOptions, {
202
- getGroupCompareOptions: groupNumber =>
203
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
204
- compareOptions,
183
+ let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
184
+ let nodesSortedByGroups = formattedMembers.flatMap(sortingNodes =>
185
+ sortNodesByGroups.sortNodesByGroups({
186
+ getOptionsByGroupNumber: groupNumber => ({
187
+ options:
188
+ getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions({
189
+ options: overriddenOptions,
205
190
  groupNumber,
206
- ),
207
- ignoreEslintDisabledNodes,
191
+ }),
192
+ nodeValueGetter,
208
193
  }),
209
- ),
194
+ ignoreEslintDisabledNodes,
195
+ groups: options.groups,
196
+ nodes: sortingNodes,
197
+ }),
198
+ )
199
+ return sortNodesByDependencies.sortNodesByDependencies(
200
+ nodesSortedByGroups,
210
201
  {
211
202
  ignoreEslintDisabledNodes,
212
203
  },
213
204
  )
205
+ }
214
206
  reportAllErrors.reportAllErrors({
215
207
  availableMessageIds: {
216
208
  missedSpacingBetweenMembers: 'missedSpacingBetweenEnumsMembers',
@@ -346,4 +338,22 @@ let getBinaryExpressionNumberValue = (
346
338
  return Number.NaN
347
339
  }
348
340
  }
341
+ let computeNodeValueGetter = ({ isNumericEnum, options }) =>
342
+ // Get the enum value rather than the name if needed.
343
+ options.sortByValue || (isNumericEnum && options.forceNumericSort)
344
+ ? sortingNode => {
345
+ if (isNumericEnum) {
346
+ return sortingNode.numericValue.toString()
347
+ }
348
+ return sortingNode.value ?? ''
349
+ }
350
+ : null
351
+ let computeOptionType = ({ isNumericEnum, options }) =>
352
+ /**
353
+ * If the enum is numeric, and we sort by value, always use the
354
+ * `natural` sort type, which will correctly sort them.
355
+ */
356
+ isNumericEnum && (options.forceNumericSort || options.sortByValue)
357
+ ? 'natural'
358
+ : options.type
349
359
  module.exports = sortEnums
@@ -84,8 +84,10 @@ const sortExports = createEslintRule.createEslintRule({
84
84
  )
85
85
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
86
86
  filteredGroupKindNodes.flatMap(groupedNodes =>
87
- sortNodes.sortNodes(groupedNodes, options, {
87
+ sortNodes.sortNodes({
88
88
  ignoreEslintDisabledNodes,
89
+ nodes: groupedNodes,
90
+ options,
89
91
  }),
90
92
  )
91
93
  reportAllErrors.reportAllErrors({
@@ -98,8 +98,11 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
98
98
  }
99
99
  })
100
100
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
101
- sortNodesByGroups.sortNodesByGroups(nodes, options, {
101
+ sortNodesByGroups.sortNodesByGroups({
102
+ getOptionsByGroupNumber: () => ({ options }),
102
103
  ignoreEslintDisabledNodes,
104
+ groups: options.groups,
105
+ nodes,
103
106
  })
104
107
  reportAllErrors.reportAllErrors({
105
108
  availableMessageIds: {
@@ -362,16 +362,26 @@ const sortImports = createEslintRule.createEslintRule({
362
362
  }
363
363
  for (let nodes of formattedMembers) {
364
364
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
365
- sortNodesByGroups.sortNodesByGroups(nodes, options, {
366
- getGroupCompareOptions: groupNumber => {
365
+ sortNodesByGroups.sortNodesByGroups({
366
+ getOptionsByGroupNumber: groupNumber => {
367
367
  if (options.sortSideEffects) {
368
- return options
368
+ return {
369
+ options,
370
+ }
371
+ }
372
+ return {
373
+ options: {
374
+ ...options,
375
+ type: isSideEffectOnlyGroup(options.groups[groupNumber])
376
+ ? 'unsorted'
377
+ : options.type,
378
+ },
369
379
  }
370
- let group = options.groups[groupNumber]
371
- return isSideEffectOnlyGroup(group) ? null : options
372
380
  },
373
381
  isNodeIgnored: node => node.isIgnored,
374
382
  ignoreEslintDisabledNodes,
383
+ groups: options.groups,
384
+ nodes,
375
385
  })
376
386
  reportAllErrors.reportAllErrors({
377
387
  availableMessageIds: {
@@ -15,6 +15,7 @@ let defaultOptions = {
15
15
  ignoreCase: true,
16
16
  customGroups: {},
17
17
  locales: 'en-US',
18
+ sortBy: 'name',
18
19
  alphabet: '',
19
20
  order: 'asc',
20
21
  groups: [],
@@ -142,8 +142,11 @@ const sortJsxProps = createEslintRule.createEslintRule({
142
142
  )
143
143
  for (let nodes of formattedMembers) {
144
144
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
145
- sortNodesByGroups.sortNodesByGroups(nodes, options, {
145
+ sortNodesByGroups.sortNodesByGroups({
146
+ getOptionsByGroupNumber: () => ({ options }),
146
147
  ignoreEslintDisabledNodes,
148
+ groups: options.groups,
149
+ nodes,
147
150
  })
148
151
  reportAllErrors.reportAllErrors({
149
152
  availableMessageIds: {
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const reportErrors = require('../utils/report-errors.js')
4
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
4
5
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
5
6
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
6
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
7
7
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
8
8
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
9
9
  const doesCustomGroupMatch = require('./sort-maps/does-custom-group-match.js')
@@ -137,13 +137,14 @@ const sortMaps = createEslintRule.createEslintRule({
137
137
  }
138
138
  for (let nodes of formattedMembers) {
139
139
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
140
- sortNodesByGroups.sortNodesByGroups(nodes, options, {
141
- getGroupCompareOptions: groupNumber =>
142
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
140
+ sortNodesByGroups.sortNodesByGroups({
141
+ getOptionsByGroupNumber:
142
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
143
143
  options,
144
- groupNumber,
145
144
  ),
146
145
  ignoreEslintDisabledNodes,
146
+ groups: options.groups,
147
+ nodes,
147
148
  })
148
149
  reportAllErrors.reportAllErrors({
149
150
  availableMessageIds: {
@@ -3,10 +3,10 @@ const utils = require('@typescript-eslint/utils')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const reportErrors = require('../utils/report-errors.js')
5
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
6
7
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
7
8
  const types = require('./sort-modules/types.js')
8
9
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
9
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
11
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
12
12
  const doesCustomGroupMatch = require('./sort-modules/does-custom-group-match.js')
@@ -290,25 +290,28 @@ let analyzeModule = ({
290
290
  }
291
291
  ;(_b = formattedNodes.at(-1)) == null ? void 0 : _b.push(sortingNode)
292
292
  }
293
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
294
- sortNodesByDependencies.sortNodesByDependencies(
295
- formattedNodes.flatMap(nodes2 =>
296
- sortNodesByGroups.sortNodesByGroups(nodes2, options, {
297
- isNodeIgnored: sortingNode =>
298
- getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
299
- options.groups.length,
300
- getGroupCompareOptions: groupNumber =>
301
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
302
- options,
303
- groupNumber,
304
- ),
305
- ignoreEslintDisabledNodes,
306
- }),
307
- ),
293
+ let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
294
+ let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
295
+ sortNodesByGroups.sortNodesByGroups({
296
+ isNodeIgnored: sortingNode =>
297
+ getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
298
+ options.groups.length,
299
+ getOptionsByGroupNumber:
300
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
301
+ options,
302
+ ),
303
+ ignoreEslintDisabledNodes,
304
+ groups: options.groups,
305
+ nodes: nodes2,
306
+ }),
307
+ )
308
+ return sortNodesByDependencies.sortNodesByDependencies(
309
+ nodesSortedByGroups,
308
310
  {
309
311
  ignoreEslintDisabledNodes,
310
312
  },
311
313
  )
314
+ }
312
315
  let nodes = formattedNodes.flat()
313
316
  reportAllErrors.reportAllErrors({
314
317
  availableMessageIds: {
@@ -102,8 +102,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
102
102
  )
103
103
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
104
104
  filteredGroupKindNodes.flatMap(groupedNodes =>
105
- sortNodes.sortNodes(groupedNodes, options, {
105
+ sortNodes.sortNodes({
106
106
  ignoreEslintDisabledNodes,
107
+ nodes: groupedNodes,
108
+ options,
107
109
  }),
108
110
  )
109
111
  reportAllErrors.reportAllErrors({
@@ -103,8 +103,10 @@ const sortNamedImports = createEslintRule.createEslintRule({
103
103
  )
104
104
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
105
105
  filteredGroupKindNodes.flatMap(groupedNodes =>
106
- sortNodes.sortNodes(groupedNodes, options, {
106
+ sortNodes.sortNodes({
107
107
  ignoreEslintDisabledNodes,
108
+ nodes: groupedNodes,
109
+ options,
108
110
  }),
109
111
  )
110
112
  reportAllErrors.reportAllErrors({
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let buildNodeValueGetter = sortBy =>
4
+ sortBy === 'value' ? node => node.value ?? '' : null
5
+ exports.buildNodeValueGetter = buildNodeValueGetter
@@ -32,6 +32,18 @@ let doesCustomGroupMatch = props => {
32
32
  return false
33
33
  }
34
34
  }
35
+ if (
36
+ 'elementValuePattern' in props.customGroup &&
37
+ props.customGroup.elementValuePattern
38
+ ) {
39
+ let matchesElementValuePattern = matches.matches(
40
+ props.elementValue ?? '',
41
+ props.customGroup.elementValuePattern,
42
+ )
43
+ if (!matchesElementValuePattern) {
44
+ return false
45
+ }
46
+ }
35
47
  return true
36
48
  }
37
49
  exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -0,0 +1,44 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const getCustomGroupsCompareOptions$1 = require('../../utils/get-custom-groups-compare-options.js')
4
+ const buildNodeValueGetter = require('./build-node-value-getter.js')
5
+ let getCustomGroupsCompareOptions = (options, groupNumber) => {
6
+ var _a
7
+ let baseCompareOptions =
8
+ getCustomGroupsCompareOptions$1.getCustomGroupsCompareOptions(
9
+ options,
10
+ groupNumber,
11
+ )
12
+ let { fallbackSort, customGroups, sortBy, groups } = options
13
+ let fallbackSortBy = fallbackSort.sortBy
14
+ if (Array.isArray(customGroups)) {
15
+ let group = groups[groupNumber]
16
+ let customGroup =
17
+ typeof group === 'string'
18
+ ? customGroups.find(currentGroup => group === currentGroup.groupName)
19
+ : null
20
+ if (customGroup) {
21
+ fallbackSortBy =
22
+ ((_a = customGroup.fallbackSort) == null ? void 0 : _a.sortBy) ??
23
+ fallbackSortBy
24
+ if ('sortBy' in customGroup && customGroup.sortBy) {
25
+ ;({ sortBy } = customGroup)
26
+ }
27
+ }
28
+ }
29
+ return {
30
+ options: {
31
+ ...baseCompareOptions,
32
+ fallbackSort: {
33
+ ...baseCompareOptions.fallbackSort,
34
+ sortBy: fallbackSortBy,
35
+ },
36
+ sortBy,
37
+ },
38
+ fallbackSortNodeValueGetter: fallbackSortBy
39
+ ? buildNodeValueGetter.buildNodeValueGetter(fallbackSortBy)
40
+ : null,
41
+ nodeValueGetter: buildNodeValueGetter.buildNodeValueGetter(sortBy),
42
+ }
43
+ }
44
+ exports.getCustomGroupsCompareOptions = getCustomGroupsCompareOptions
@@ -9,12 +9,19 @@ let allSelectors = [
9
9
  'property',
10
10
  ]
11
11
  let allModifiers = ['optional', 'required', 'multiline']
12
+ let sortByJsonSchema = {
13
+ enum: ['name', 'value'],
14
+ type: 'string',
15
+ }
12
16
  let singleCustomGroupJsonSchema = {
13
17
  modifiers:
14
18
  commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
15
19
  selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
20
+ elementValuePattern: commonJsonSchemas.regexJsonSchema,
16
21
  elementNamePattern: commonJsonSchemas.regexJsonSchema,
22
+ sortBy: sortByJsonSchema,
17
23
  }
18
24
  exports.allModifiers = allModifiers
19
25
  exports.allSelectors = allSelectors
20
26
  exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
27
+ exports.sortByJsonSchema = sortByJsonSchema
@@ -8,8 +8,8 @@ const reportErrors = require('../utils/report-errors.js')
8
8
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
9
9
  const types = require('./sort-object-types/types.js')
10
10
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
11
+ const getCustomGroupsCompareOptions = require('./sort-object-types/get-custom-groups-compare-options.js')
11
12
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
12
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
13
13
  const doesCustomGroupMatch = require('./sort-object-types/does-custom-group-match.js')
14
14
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
15
15
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
@@ -30,7 +30,7 @@ const complete = require('../utils/complete.js')
30
30
  const matches = require('../utils/matches.js')
31
31
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
32
32
  let defaultOptions = {
33
- fallbackSort: { type: 'unsorted' },
33
+ fallbackSort: { type: 'unsorted', sortBy: 'name' },
34
34
  partitionByComment: false,
35
35
  partitionByNewLine: false,
36
36
  newlinesBetween: 'ignore',
@@ -42,6 +42,7 @@ let defaultOptions = {
42
42
  ignoreCase: true,
43
43
  customGroups: {},
44
44
  locales: 'en-US',
45
+ sortBy: 'name',
45
46
  alphabet: '',
46
47
  order: 'asc',
47
48
  groups: [],
@@ -49,11 +50,16 @@ let defaultOptions = {
49
50
  let jsonSchema = {
50
51
  items: {
51
52
  properties: {
52
- ...commonJsonSchemas.commonJsonSchemas,
53
+ ...commonJsonSchemas.buildCommonJsonSchemas({
54
+ additionalFallbackSortProperties: {},
55
+ }),
53
56
  customGroups: {
54
57
  oneOf: [
55
58
  commonJsonSchemas.customGroupsJsonSchema,
56
59
  commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
60
+ additionalFallbackSortProperties: {
61
+ sortBy: types.sortByJsonSchema,
62
+ },
57
63
  singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
58
64
  }),
59
65
  ],
@@ -72,6 +78,7 @@ let jsonSchema = {
72
78
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
73
79
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
74
80
  ignorePattern: commonJsonSchemas.regexJsonSchema,
81
+ sortBy: types.sortByJsonSchema,
75
82
  groups: commonJsonSchemas.groupsJsonSchema,
76
83
  },
77
84
  additionalProperties: false,
@@ -223,10 +230,18 @@ let sortObjectTypeElements = ({
223
230
  defineGroup(predefinedGroup)
224
231
  }
225
232
  let name = getNodeName({ typeElement, sourceCode })
233
+ let value = null
234
+ if (
235
+ typeElement.type === 'TSPropertySignature' &&
236
+ typeElement.typeAnnotation
237
+ ) {
238
+ value = sourceCode.getText(typeElement.typeAnnotation.typeAnnotation)
239
+ }
226
240
  if (Array.isArray(options.customGroups)) {
227
241
  for (let customGroup of options.customGroups) {
228
242
  if (
229
243
  doesCustomGroupMatch.doesCustomGroupMatch({
244
+ elementValue: value,
230
245
  elementName: name,
231
246
  customGroup,
232
247
  selectors,
@@ -256,6 +271,7 @@ let sortObjectTypeElements = ({
256
271
  addSafetySemicolonWhenInline: true,
257
272
  group: getGroup(),
258
273
  node: typeElement,
274
+ value,
259
275
  name,
260
276
  }
261
277
  if (
@@ -291,13 +307,34 @@ let sortObjectTypeElements = ({
291
307
  )
292
308
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
293
309
  filteredGroupKindNodes.flatMap(groupedNodes =>
294
- sortNodesByGroups.sortNodesByGroups(groupedNodes, options, {
295
- getGroupCompareOptions: groupNumber =>
296
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
310
+ sortNodesByGroups.sortNodesByGroups({
311
+ getOptionsByGroupNumber: groupNumber => {
312
+ let {
313
+ fallbackSortNodeValueGetter,
314
+ options: overriddenOptions,
315
+ nodeValueGetter,
316
+ } = getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
297
317
  options,
298
318
  groupNumber,
299
- ),
319
+ )
320
+ return {
321
+ options: {
322
+ ...options,
323
+ ...overriddenOptions,
324
+ },
325
+ fallbackSortNodeValueGetter,
326
+ nodeValueGetter,
327
+ }
328
+ },
329
+ isNodeIgnoredForGroup: (node, groupOptions) => {
330
+ if (groupOptions.sortBy === 'value') {
331
+ return !node.value
332
+ }
333
+ return false
334
+ },
300
335
  ignoreEslintDisabledNodes,
336
+ groups: options.groups,
337
+ nodes: groupedNodes,
301
338
  }),
302
339
  )
303
340
  reportAllErrors.reportAllErrors({
@@ -3,17 +3,17 @@ const types$1 = require('@typescript-eslint/types')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const reportErrors = require('../utils/report-errors.js')
5
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
6
7
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
8
+ const types = require('./sort-objects/types.js')
7
9
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
8
10
  const getFirstNodeParentWithType = require('./sort-objects/get-first-node-parent-with-type.js')
9
- const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
10
11
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
11
12
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
12
13
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
13
14
  const doesCustomGroupMatch = require('./sort-objects/does-custom-group-match.js')
14
15
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
15
16
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
16
- const types = require('./sort-objects/types.js')
17
17
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
18
18
  const createEslintRule = require('../utils/create-eslint-rule.js')
19
19
  const reportAllErrors = require('../utils/report-all-errors.js')
@@ -325,28 +325,38 @@ const sortObjects = createEslintRule.createEslintRule({
325
325
  [[]],
326
326
  )
327
327
  let formattedMembers = formatProperties(nodeObject.properties)
328
+ let sortingOptions = options
328
329
  let nodesSortingFunction =
329
330
  isDestructuredObject &&
330
331
  typeof options.destructuredObjects === 'object' &&
331
332
  !options.destructuredObjects.groups
332
- ? sortNodes.sortNodes
333
- : sortNodesByGroups.sortNodesByGroups
334
- let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
335
- sortNodesByDependencies.sortNodesByDependencies(
336
- formattedMembers.flatMap(nodes2 =>
337
- nodesSortingFunction(nodes2, options, {
338
- getGroupCompareOptions: groupNumber =>
339
- getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
340
- options,
341
- groupNumber,
342
- ),
343
- ignoreEslintDisabledNodes,
344
- }),
345
- ),
333
+ ? 'sortNodes'
334
+ : 'sortNodesByGroups'
335
+ let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
336
+ let nodesSortedByGroups = formattedMembers.flatMap(nodes2 =>
337
+ nodesSortingFunction === 'sortNodes'
338
+ ? sortNodes.sortNodes({
339
+ ignoreEslintDisabledNodes,
340
+ options: sortingOptions,
341
+ nodes: nodes2,
342
+ })
343
+ : sortNodesByGroups.sortNodesByGroups({
344
+ getOptionsByGroupNumber:
345
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
346
+ options,
347
+ ),
348
+ ignoreEslintDisabledNodes,
349
+ groups: options.groups,
350
+ nodes: nodes2,
351
+ }),
352
+ )
353
+ return sortNodesByDependencies.sortNodesByDependencies(
354
+ nodesSortedByGroups,
346
355
  {
347
356
  ignoreEslintDisabledNodes,
348
357
  },
349
358
  )
359
+ }
350
360
  let nodes = formattedMembers.flat()
351
361
  reportAllErrors.reportAllErrors({
352
362
  availableMessageIds: {
@@ -65,10 +65,11 @@ const sortSwitchCase = createEslintRule.createEslintRule({
65
65
  )
66
66
  let hasUnsortedNodes = false
67
67
  for (let caseNodesSortingNodeGroup of caseNameSortingNodeGroups) {
68
- let sortedCaseNameSortingNodes = sortNodes.sortNodes(
69
- caseNodesSortingNodeGroup,
68
+ let sortedCaseNameSortingNodes = sortNodes.sortNodes({
69
+ nodes: caseNodesSortingNodeGroup,
70
+ ignoreEslintDisabledNodes: false,
70
71
  options,
71
- )
72
+ })
72
73
  hasUnsortedNodes ||
73
74
  (hasUnsortedNodes = sortedCaseNameSortingNodes.some(
74
75
  (node, index) => node !== caseNodesSortingNodeGroup[index],
@@ -188,7 +189,11 @@ const sortSwitchCase = createEslintRule.createEslintRule({
188
189
  if (b.some(node => node.isDefaultClause)) {
189
190
  return -1
190
191
  }
191
- return compare.compare(a.at(0), b.at(0), options)
192
+ return compare.compare({
193
+ a: a.at(0),
194
+ b: b.at(0),
195
+ options,
196
+ })
192
197
  })
193
198
  .flat()
194
199
  let sortingNodeGroupsForBlockSortFlat =
@@ -209,8 +209,11 @@ let sortUnionOrIntersectionTypes = ({
209
209
  )
210
210
  for (let nodes of formattedMembers) {
211
211
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
212
- sortNodesByGroups.sortNodesByGroups(nodes, options, {
212
+ sortNodesByGroups.sortNodesByGroups({
213
+ getOptionsByGroupNumber: () => ({ options }),
213
214
  ignoreEslintDisabledNodes,
215
+ groups: options.groups,
216
+ nodes,
214
217
  })
215
218
  reportAllErrors.reportAllErrors({
216
219
  sortNodesExcludingEslintDisabled,
@@ -161,8 +161,10 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
161
161
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
162
162
  sortNodesByDependencies.sortNodesByDependencies(
163
163
  formattedMembers.flatMap(nodes2 =>
164
- sortNodes.sortNodes(nodes2, options, {
164
+ sortNodes.sortNodes({
165
165
  ignoreEslintDisabledNodes,
166
+ options,
167
+ nodes: nodes2,
166
168
  }),
167
169
  ),
168
170
  {
@@ -39,23 +39,25 @@ let specialCharactersJsonSchema = {
39
39
  enum: ['remove', 'trim', 'keep'],
40
40
  type: 'string',
41
41
  }
42
- let fallbackSortJsonSchema = {
42
+ let buildFallbackSortJsonSchema = ({ additionalProperties } = {}) => ({
43
43
  properties: {
44
44
  order: orderJsonSchema,
45
45
  type: typeJsonSchema,
46
+ ...additionalProperties,
46
47
  },
47
48
  description: 'Fallback sort order.',
48
49
  type: 'object',
49
- }
50
- let commonJsonSchemas = {
50
+ })
51
+ let buildCommonJsonSchemas = ({ additionalFallbackSortProperties } = {}) => ({
52
+ fallbackSort: buildFallbackSortJsonSchema(additionalFallbackSortProperties),
51
53
  specialCharacters: specialCharactersJsonSchema,
52
- fallbackSort: fallbackSortJsonSchema,
53
54
  ignoreCase: ignoreCaseJsonSchema,
54
55
  alphabet: alphabetJsonSchema,
55
56
  locales: localesJsonSchema,
56
57
  order: orderJsonSchema,
57
58
  type: typeJsonSchema,
58
- }
59
+ })
60
+ let commonJsonSchemas = buildCommonJsonSchemas()
59
61
  let newlinesBetweenJsonSchema = {
60
62
  description: 'Specifies how new lines should be handled between groups.',
61
63
  enum: ['ignore', 'always', 'never'],
@@ -170,40 +172,36 @@ let buildUseConfigurationIfJsonSchema = ({ additionalProperties } = {}) => ({
170
172
  additionalProperties: false,
171
173
  type: 'object',
172
174
  })
173
- let customGroupSortJsonSchema = {
174
- type: {
175
- enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
176
- description: 'Custom group sort type.',
177
- type: 'string',
178
- },
179
- order: {
180
- description: 'Custom group sort order.',
181
- enum: ['desc', 'asc'],
182
- type: 'string',
183
- },
184
- }
185
- let customGroupNameJsonSchema = {
186
- groupName: {
187
- description: 'Custom group name.',
188
- type: 'string',
189
- },
190
- }
191
- let customGroupNewlinesInsideJsonSchema = {
175
+ let buildCommonCustomGroupJsonSchemas = ({
176
+ additionalFallbackSortProperties,
177
+ } = {}) => ({
192
178
  newlinesInside: {
193
179
  description:
194
180
  'Specifies how new lines should be handled between members of the custom group.',
195
181
  enum: ['always', 'never'],
196
182
  type: 'string',
197
183
  },
198
- }
199
- let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
184
+ fallbackSort: buildFallbackSortJsonSchema({
185
+ additionalProperties: additionalFallbackSortProperties,
186
+ }),
187
+ groupName: {
188
+ description: 'Custom group name.',
189
+ type: 'string',
190
+ },
191
+ order: orderJsonSchema,
192
+ type: typeJsonSchema,
193
+ })
194
+ let buildCustomGroupsArrayJsonSchema = ({
195
+ additionalFallbackSortProperties,
196
+ singleCustomGroupJsonSchema,
197
+ }) => ({
200
198
  items: {
201
199
  oneOf: [
202
200
  {
203
201
  properties: {
204
- ...customGroupNameJsonSchema,
205
- ...customGroupSortJsonSchema,
206
- ...customGroupNewlinesInsideJsonSchema,
202
+ ...buildCommonCustomGroupJsonSchemas({
203
+ additionalFallbackSortProperties,
204
+ }),
207
205
  anyOf: {
208
206
  items: {
209
207
  properties: {
@@ -222,9 +220,9 @@ let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
222
220
  },
223
221
  {
224
222
  properties: {
225
- ...customGroupNameJsonSchema,
226
- ...customGroupSortJsonSchema,
227
- ...customGroupNewlinesInsideJsonSchema,
223
+ ...buildCommonCustomGroupJsonSchemas({
224
+ additionalFallbackSortProperties,
225
+ }),
228
226
  ...singleCustomGroupJsonSchema,
229
227
  },
230
228
  description: 'Custom group.',
@@ -249,6 +247,7 @@ let buildCustomGroupSelectorJsonSchema = selectors => ({
249
247
  enum: selectors,
250
248
  type: 'string',
251
249
  })
250
+ exports.buildCommonJsonSchemas = buildCommonJsonSchemas
252
251
  exports.buildCustomGroupModifiersJsonSchema =
253
252
  buildCustomGroupModifiersJsonSchema
254
253
  exports.buildCustomGroupSelectorJsonSchema = buildCustomGroupSelectorJsonSchema
@@ -3,9 +3,37 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const naturalOrderby = require('natural-orderby')
4
4
  const convertBooleanToSign = require('./convert-boolean-to-sign.js')
5
5
  let alphabetCache = /* @__PURE__ */ new Map()
6
- let compare = (a, b, options) => {
6
+ let compare = ({
7
+ fallbackSortNodeValueGetter,
8
+ nodeValueGetter,
9
+ options,
10
+ a,
11
+ b,
12
+ }) => {
13
+ let finalNodeValueGetter = nodeValueGetter ?? (node => node.name)
14
+ let compareValue = computeCompareValue({
15
+ nodeValueGetter: finalNodeValueGetter,
16
+ options,
17
+ a,
18
+ b,
19
+ })
20
+ if (compareValue) {
21
+ return compareValue
22
+ }
23
+ let { fallbackSort, order } = options
24
+ return computeCompareValue({
25
+ options: {
26
+ ...options,
27
+ order: fallbackSort.order ?? order,
28
+ type: fallbackSort.type,
29
+ },
30
+ nodeValueGetter: fallbackSortNodeValueGetter ?? finalNodeValueGetter,
31
+ a,
32
+ b,
33
+ })
34
+ }
35
+ let computeCompareValue = ({ nodeValueGetter, options, a, b }) => {
7
36
  let sortingFunction
8
- let nodeValueGetter = options.nodeValueGetter ?? (node => node.name)
9
37
  switch (options.type) {
10
38
  case 'alphabetical':
11
39
  sortingFunction = getAlphabeticalSortingFunction(options, nodeValueGetter)
@@ -22,19 +50,10 @@ let compare = (a, b, options) => {
22
50
  sortingFunction = getCustomSortingFunction(options, nodeValueGetter)
23
51
  break
24
52
  }
25
- let compareValue =
53
+ return (
26
54
  convertBooleanToSign.convertBooleanToSign(options.order === 'asc') *
27
55
  sortingFunction(a, b)
28
- if (compareValue) {
29
- return compareValue
30
- }
31
- let { fallbackSort, order } = options
32
- return compare(a, b, {
33
- ...options,
34
- order: fallbackSort.order ?? order,
35
- type: fallbackSort.type,
36
- fallbackSort,
37
- })
56
+ )
38
57
  }
39
58
  let getAlphabeticalSortingFunction = (
40
59
  { specialCharacters, ignoreCase, locales },
@@ -1,20 +1,47 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  let getCustomGroupsCompareOptions = (options, groupNumber) => {
4
- if (!Array.isArray(options.customGroups)) {
5
- return options
4
+ var _a, _b
5
+ let { customGroups, fallbackSort, groups, order, type } = options
6
+ if (Array.isArray(customGroups)) {
7
+ let group = groups[groupNumber]
8
+ let customGroup =
9
+ typeof group === 'string'
10
+ ? customGroups.find(currentGroup => group === currentGroup.groupName)
11
+ : null
12
+ if (customGroup) {
13
+ fallbackSort = {
14
+ type:
15
+ ((_a = customGroup.fallbackSort) == null ? void 0 : _a.type) ??
16
+ fallbackSort.type,
17
+ }
18
+ let fallbackOrder =
19
+ ((_b = customGroup.fallbackSort) == null ? void 0 : _b.order) ??
20
+ fallbackSort.order
21
+ if (fallbackOrder) {
22
+ fallbackSort.order = fallbackOrder
23
+ }
24
+ order = customGroup.order ?? order
25
+ type = customGroup.type ?? type
26
+ }
6
27
  }
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
28
  return {
15
- ...options,
16
- order: (customGroup == null ? void 0 : customGroup.order) ?? options.order,
17
- type: (customGroup == null ? void 0 : customGroup.type) ?? options.type,
29
+ fallbackSort,
30
+ order,
31
+ type,
18
32
  }
19
33
  }
34
+ let buildGetCustomGroupOverriddenOptionsFunction = options => groupNumber => ({
35
+ options: getCustomGroupOverriddenOptions({
36
+ groupNumber,
37
+ options,
38
+ }),
39
+ })
40
+ let getCustomGroupOverriddenOptions = ({ groupNumber, options }) => ({
41
+ ...options,
42
+ ...getCustomGroupsCompareOptions(options, groupNumber),
43
+ })
44
+ exports.buildGetCustomGroupOverriddenOptionsFunction =
45
+ buildGetCustomGroupOverriddenOptionsFunction
46
+ exports.getCustomGroupOverriddenOptions = getCustomGroupOverriddenOptions
20
47
  exports.getCustomGroupsCompareOptions = getCustomGroupsCompareOptions
@@ -10,6 +10,7 @@ let getSettings = (settings = {}) => {
10
10
  'partitionByNewLine',
11
11
  'specialCharacters',
12
12
  'ignorePattern',
13
+ 'fallbackSort',
13
14
  'ignoreCase',
14
15
  'alphabet',
15
16
  'locales',
@@ -2,24 +2,25 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const getGroupNumber = require('./get-group-number.js')
4
4
  const sortNodes = require('./sort-nodes.js')
5
- let sortNodesByGroups = (nodes, options, extraOptions) => {
6
- var _a
5
+ let sortNodesByGroups = ({
6
+ ignoreEslintDisabledNodes,
7
+ getOptionsByGroupNumber,
8
+ isNodeIgnoredForGroup,
9
+ isNodeIgnored,
10
+ groups,
11
+ nodes,
12
+ }) => {
7
13
  let nodesByNonIgnoredGroupNumber = {}
8
14
  let ignoredNodeIndices = []
9
15
  for (let [index, sortingNode] of nodes.entries()) {
10
16
  if (
11
- (sortingNode.isEslintDisabled &&
12
- (extraOptions == null
13
- ? void 0
14
- : extraOptions.ignoreEslintDisabledNodes)) ||
15
- ((_a = extraOptions == null ? void 0 : extraOptions.isNodeIgnored) == null
16
- ? void 0
17
- : _a.call(extraOptions, sortingNode))
17
+ (sortingNode.isEslintDisabled && ignoreEslintDisabledNodes) ||
18
+ (isNodeIgnored == null ? void 0 : isNodeIgnored(sortingNode))
18
19
  ) {
19
20
  ignoredNodeIndices.push(index)
20
21
  continue
21
22
  }
22
- let groupNumber = getGroupNumber.getGroupNumber(options.groups, sortingNode)
23
+ let groupNumber = getGroupNumber.getGroupNumber(groups, sortingNode)
23
24
  nodesByNonIgnoredGroupNumber[groupNumber] ??
24
25
  (nodesByNonIgnoredGroupNumber[groupNumber] = [])
25
26
  nodesByNonIgnoredGroupNumber[groupNumber].push(sortingNode)
@@ -28,17 +29,26 @@ let sortNodesByGroups = (nodes, options, extraOptions) => {
28
29
  for (let groupNumber of Object.keys(nodesByNonIgnoredGroupNumber).sort(
29
30
  (a, b) => Number(a) - Number(b),
30
31
  )) {
31
- let compareOptions = (
32
- extraOptions == null ? void 0 : extraOptions.getGroupCompareOptions
33
- )
34
- ? extraOptions.getGroupCompareOptions(Number(groupNumber))
35
- : options
32
+ let { fallbackSortNodeValueGetter, nodeValueGetter, options } =
33
+ getOptionsByGroupNumber(Number(groupNumber))
36
34
  let nodesToPush = nodesByNonIgnoredGroupNumber[Number(groupNumber)]
37
- if (!compareOptions) {
38
- sortedNodes.push(...nodesToPush)
39
- continue
40
- }
41
- sortedNodes.push(...sortNodes.sortNodes(nodesToPush, compareOptions))
35
+ let groupIgnoredNodes = new Set(
36
+ nodesToPush.filter(node =>
37
+ isNodeIgnoredForGroup == null
38
+ ? void 0
39
+ : isNodeIgnoredForGroup(node, options),
40
+ ),
41
+ )
42
+ sortedNodes.push(
43
+ ...sortNodes.sortNodes({
44
+ isNodeIgnored: node => groupIgnoredNodes.has(node),
45
+ ignoreEslintDisabledNodes: false,
46
+ fallbackSortNodeValueGetter,
47
+ nodes: nodesToPush,
48
+ nodeValueGetter,
49
+ options,
50
+ }),
51
+ )
42
52
  }
43
53
  for (let ignoredIndex of ignoredNodeIndices) {
44
54
  sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
@@ -1,13 +1,20 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const compare = require('./compare.js')
4
- let sortNodes = (nodes, options, extraOptions) => {
4
+ let sortNodes = ({
5
+ fallbackSortNodeValueGetter,
6
+ ignoreEslintDisabledNodes,
7
+ nodeValueGetter,
8
+ isNodeIgnored,
9
+ options,
10
+ nodes,
11
+ }) => {
5
12
  let nonIgnoredNodes = []
6
13
  let ignoredNodeIndices = []
7
14
  for (let [index, sortingNode] of nodes.entries()) {
8
15
  if (
9
- sortingNode.isEslintDisabled &&
10
- (extraOptions == null ? void 0 : extraOptions.ignoreEslintDisabledNodes)
16
+ (sortingNode.isEslintDisabled && ignoreEslintDisabledNodes) ||
17
+ (isNodeIgnored == null ? void 0 : isNodeIgnored(sortingNode))
11
18
  ) {
12
19
  ignoredNodeIndices.push(index)
13
20
  } else {
@@ -15,7 +22,13 @@ let sortNodes = (nodes, options, extraOptions) => {
15
22
  }
16
23
  }
17
24
  let sortedNodes = [...nonIgnoredNodes].sort((a, b) =>
18
- compare.compare(a, b, options),
25
+ compare.compare({
26
+ fallbackSortNodeValueGetter,
27
+ nodeValueGetter,
28
+ options,
29
+ a,
30
+ b,
31
+ }),
19
32
  )
20
33
  for (let ignoredIndex of ignoredNodeIndices) {
21
34
  sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-perfectionist",
3
- "version": "4.9.0",
3
+ "version": "4.10.0",
4
4
  "description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -27,12 +27,12 @@
27
27
  "./dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@typescript-eslint/types": "^8.24.0",
31
- "@typescript-eslint/utils": "^8.24.0",
30
+ "@typescript-eslint/types": "^8.26.0",
31
+ "@typescript-eslint/utils": "^8.26.0",
32
32
  "natural-orderby": "^5.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "eslint": ">=8.0.0"
35
+ "eslint": ">=8.45.0"
36
36
  },
37
37
  "engines": {
38
38
  "node": "^18.0.0 || >=20.0.0"
package/readme.md CHANGED
@@ -73,7 +73,7 @@ See [docs](https://perfectionist.dev).
73
73
 
74
74
  ## Installation
75
75
 
76
- You'll first need to install [ESLint](https://eslint.org):
76
+ You'll first need to install [ESLint](https://eslint.org) v8.45.0 or greater:
77
77
 
78
78
  ```sh
79
79
  npm install --save-dev eslint