eslint-plugin-perfectionist 4.8.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.
- package/dist/rules/sort-array-includes/types.js +1 -1
- package/dist/rules/sort-array-includes.js +8 -15
- package/dist/rules/sort-classes/types.js +3 -6
- package/dist/rules/sort-classes.js +93 -107
- package/dist/rules/sort-decorators.js +15 -9
- package/dist/rules/sort-enums/types.js +2 -2
- package/dist/rules/sort-enums.js +53 -43
- package/dist/rules/sort-exports.js +4 -2
- package/dist/rules/sort-heritage-clauses.js +10 -7
- package/dist/rules/sort-imports.js +22 -18
- package/dist/rules/sort-interfaces.js +2 -0
- package/dist/rules/sort-intersection-types.js +1 -0
- package/dist/rules/sort-jsx-props.js +64 -32
- package/dist/rules/sort-maps/types.js +1 -1
- package/dist/rules/sort-maps.js +8 -10
- package/dist/rules/sort-modules/types.js +2 -5
- package/dist/rules/sort-modules.js +27 -27
- package/dist/rules/sort-named-exports.js +4 -2
- package/dist/rules/sort-named-imports.js +4 -2
- package/dist/rules/sort-object-types/build-node-value-getter.js +5 -0
- package/dist/rules/sort-object-types/does-custom-group-match.js +12 -0
- package/dist/rules/sort-object-types/get-custom-groups-compare-options.js +44 -0
- package/dist/rules/sort-object-types/types.js +8 -1
- package/dist/rules/sort-object-types.js +52 -33
- package/dist/rules/sort-objects/types.js +2 -2
- package/dist/rules/sort-objects.js +38 -44
- package/dist/rules/sort-switch-case.js +11 -6
- package/dist/rules/sort-union-types.js +10 -7
- package/dist/rules/sort-variable-declarations.js +4 -2
- package/dist/utils/common-json-schemas.js +76 -61
- package/dist/utils/compare.js +35 -4
- package/dist/utils/get-comment-after.js +1 -1
- package/dist/utils/get-custom-groups-compare-options.js +39 -18
- package/dist/utils/get-decorator-name.js +10 -0
- package/dist/utils/get-settings.js +1 -0
- package/dist/utils/is-partition-comment.js +14 -10
- package/dist/utils/matches.js +9 -1
- package/dist/utils/sort-nodes-by-groups.js +30 -20
- package/dist/utils/sort-nodes.js +17 -4
- package/dist/utils/validate-generated-groups-configuration.js +6 -2
- package/dist/utils/validate-groups-configuration.js +18 -38
- package/dist/utils/validate-newlines-between-inside-groups.js +18 -0
- package/dist/utils/validate-no-duplicated-groups.js +22 -0
- package/package.json +4 -4
- package/readme.md +4 -4
- package/dist/rules/sort-decorators/get-decorator-name.js +0 -23
|
@@ -4,7 +4,7 @@ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
|
4
4
|
let allSelectors = ['literal', 'spread']
|
|
5
5
|
let singleCustomGroupJsonSchema = {
|
|
6
6
|
selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
7
|
-
elementNamePattern: commonJsonSchemas.
|
|
7
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
8
8
|
}
|
|
9
9
|
exports.allSelectors = allSelectors
|
|
10
10
|
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
|
@@ -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')
|
|
@@ -27,6 +27,7 @@ const useGroups = require('../utils/use-groups.js')
|
|
|
27
27
|
const complete = require('../utils/complete.js')
|
|
28
28
|
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
29
29
|
let defaultOptions = {
|
|
30
|
+
fallbackSort: { type: 'unsorted' },
|
|
30
31
|
groupKind: 'literals-first',
|
|
31
32
|
specialCharacters: 'keep',
|
|
32
33
|
partitionByComment: false,
|
|
@@ -54,7 +55,6 @@ let jsonSchema = {
|
|
|
54
55
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
55
56
|
}),
|
|
56
57
|
useConfigurationIf: commonJsonSchemas.buildUseConfigurationIfJsonSchema(),
|
|
57
|
-
type: commonJsonSchemas.buildTypeJsonSchema({ withUnsorted: true }),
|
|
58
58
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
59
59
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
60
60
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
@@ -127,19 +127,11 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
127
127
|
.map(element => getNodeName({ sourceCode, element })),
|
|
128
128
|
contextOptions: context.options,
|
|
129
129
|
})
|
|
130
|
-
let
|
|
130
|
+
let options = complete.complete(
|
|
131
131
|
matchedContextOptions[0],
|
|
132
132
|
settings,
|
|
133
133
|
defaultOptions,
|
|
134
134
|
)
|
|
135
|
-
let { type } = completeOptions
|
|
136
|
-
if (type === 'unsorted') {
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
let options = {
|
|
140
|
-
...completeOptions,
|
|
141
|
-
type,
|
|
142
|
-
}
|
|
143
135
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
144
136
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
145
137
|
selectors: types.allSelectors,
|
|
@@ -237,13 +229,14 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
237
229
|
)
|
|
238
230
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
239
231
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
240
|
-
sortNodesByGroups.sortNodesByGroups(
|
|
241
|
-
|
|
242
|
-
getCustomGroupsCompareOptions.
|
|
232
|
+
sortNodesByGroups.sortNodesByGroups({
|
|
233
|
+
getOptionsByGroupNumber:
|
|
234
|
+
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
243
235
|
options,
|
|
244
|
-
groupNumber,
|
|
245
236
|
),
|
|
246
237
|
ignoreEslintDisabledNodes,
|
|
238
|
+
groups: options.groups,
|
|
239
|
+
nodes: groupedNodes,
|
|
247
240
|
}),
|
|
248
241
|
)
|
|
249
242
|
reportAllErrors.reportAllErrors({
|
|
@@ -26,15 +26,12 @@ let allModifiers = [
|
|
|
26
26
|
'optional',
|
|
27
27
|
]
|
|
28
28
|
let singleCustomGroupJsonSchema = {
|
|
29
|
-
decoratorNamePattern: {
|
|
30
|
-
description: 'Decorator name pattern filter.',
|
|
31
|
-
type: 'string',
|
|
32
|
-
},
|
|
33
29
|
modifiers:
|
|
34
30
|
commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
35
31
|
selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
decoratorNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
33
|
+
elementValuePattern: commonJsonSchemas.regexJsonSchema,
|
|
34
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
38
35
|
}
|
|
39
36
|
exports.allModifiers = allModifiers
|
|
40
37
|
exports.allSelectors = allSelectors
|
|
@@ -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')
|
|
@@ -13,7 +13,9 @@ const doesCustomGroupMatch = require('./sort-classes/does-custom-group-match.js'
|
|
|
13
13
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
14
14
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
15
15
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
16
|
+
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
16
17
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
18
|
+
const getDecoratorName = require('../utils/get-decorator-name.js')
|
|
17
19
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
18
20
|
const shouldPartition = require('../utils/should-partition.js')
|
|
19
21
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
@@ -51,6 +53,7 @@ let defaultOptions = {
|
|
|
51
53
|
'unknown',
|
|
52
54
|
],
|
|
53
55
|
ignoreCallbackDependenciesPatterns: [],
|
|
56
|
+
fallbackSort: { type: 'unsorted' },
|
|
54
57
|
partitionByComment: false,
|
|
55
58
|
partitionByNewLine: false,
|
|
56
59
|
newlinesBetween: 'ignore',
|
|
@@ -185,8 +188,9 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
185
188
|
'name' in nodeValue.callee ? nodeValue.callee.name : null
|
|
186
189
|
shouldIgnore =
|
|
187
190
|
functionName !== null &&
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
matches.matches(
|
|
192
|
+
functionName,
|
|
193
|
+
options.ignoreCallbackDependenciesPatterns,
|
|
190
194
|
)
|
|
191
195
|
}
|
|
192
196
|
if (!shouldIgnore) {
|
|
@@ -227,7 +231,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
227
231
|
getOverloadSignatureGroups.getOverloadSignatureGroups(node.body)
|
|
228
232
|
let formattedNodes = node.body.reduce(
|
|
229
233
|
(accumulator, member) => {
|
|
230
|
-
var _a2, _b, _c
|
|
234
|
+
var _a2, _b, _c, _d, _e
|
|
231
235
|
let name
|
|
232
236
|
let dependencies = []
|
|
233
237
|
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
@@ -250,25 +254,73 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
250
254
|
let decorated = false
|
|
251
255
|
let decorators = []
|
|
252
256
|
if ('decorators' in member) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
decorator.expression.callee.type === 'Identifier'
|
|
260
|
-
) {
|
|
261
|
-
decorators.push(decorator.expression.callee.name)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
257
|
+
decorators = getNodeDecorators
|
|
258
|
+
.getNodeDecorators(member)
|
|
259
|
+
.map(decorator =>
|
|
260
|
+
getDecoratorName.getDecoratorName({ sourceCode, decorator }),
|
|
261
|
+
)
|
|
262
|
+
decorated = decorators.length > 0
|
|
264
263
|
}
|
|
265
264
|
let memberValue
|
|
266
265
|
let modifiers = []
|
|
267
266
|
let selectors = []
|
|
268
267
|
let addSafetySemicolonWhenInline = true
|
|
269
268
|
switch (member.type) {
|
|
269
|
+
case 'TSAbstractPropertyDefinition':
|
|
270
|
+
case 'PropertyDefinition':
|
|
271
|
+
if ('static' in member && member.static) {
|
|
272
|
+
modifiers.push('static')
|
|
273
|
+
}
|
|
274
|
+
if ('declare' in member && member.declare) {
|
|
275
|
+
modifiers.push('declare')
|
|
276
|
+
}
|
|
277
|
+
if (member.type === 'TSAbstractPropertyDefinition') {
|
|
278
|
+
modifiers.push('abstract')
|
|
279
|
+
}
|
|
280
|
+
if (decorated) {
|
|
281
|
+
modifiers.push('decorated')
|
|
282
|
+
}
|
|
283
|
+
if ('override' in member && member.override) {
|
|
284
|
+
modifiers.push('override')
|
|
285
|
+
}
|
|
286
|
+
if ('readonly' in member && member.readonly) {
|
|
287
|
+
modifiers.push('readonly')
|
|
288
|
+
}
|
|
289
|
+
if (
|
|
290
|
+
'accessibility' in member &&
|
|
291
|
+
member.accessibility === 'protected'
|
|
292
|
+
) {
|
|
293
|
+
modifiers.push('protected')
|
|
294
|
+
} else if (
|
|
295
|
+
('accessibility' in member &&
|
|
296
|
+
member.accessibility === 'private') ||
|
|
297
|
+
isPrivateHash
|
|
298
|
+
) {
|
|
299
|
+
modifiers.push('private')
|
|
300
|
+
} else {
|
|
301
|
+
modifiers.push('public')
|
|
302
|
+
}
|
|
303
|
+
if ('optional' in member && member.optional) {
|
|
304
|
+
modifiers.push('optional')
|
|
305
|
+
}
|
|
306
|
+
if (
|
|
307
|
+
((_b = member.value) == null ? void 0 : _b.type) ===
|
|
308
|
+
'ArrowFunctionExpression' ||
|
|
309
|
+
((_c = member.value) == null ? void 0 : _c.type) ===
|
|
310
|
+
'FunctionExpression'
|
|
311
|
+
) {
|
|
312
|
+
if (member.value.async) {
|
|
313
|
+
modifiers.push('async')
|
|
314
|
+
}
|
|
315
|
+
selectors.push('function-property')
|
|
316
|
+
} else if (member.value) {
|
|
317
|
+
memberValue = sourceCode.getText(member.value)
|
|
318
|
+
dependencies = extractDependencies(member.value, member.static)
|
|
319
|
+
}
|
|
320
|
+
selectors.push('property')
|
|
321
|
+
break
|
|
270
322
|
case 'TSAbstractMethodDefinition':
|
|
271
|
-
case 'MethodDefinition':
|
|
323
|
+
case 'MethodDefinition':
|
|
272
324
|
if (member.static) {
|
|
273
325
|
modifiers.push('static')
|
|
274
326
|
}
|
|
@@ -307,9 +359,8 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
307
359
|
}
|
|
308
360
|
selectors.push('method')
|
|
309
361
|
break
|
|
310
|
-
}
|
|
311
362
|
case 'TSAbstractAccessorProperty':
|
|
312
|
-
case 'AccessorProperty':
|
|
363
|
+
case 'AccessorProperty':
|
|
313
364
|
if (member.static) {
|
|
314
365
|
modifiers.push('static')
|
|
315
366
|
}
|
|
@@ -331,8 +382,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
331
382
|
}
|
|
332
383
|
selectors.push('accessor-property')
|
|
333
384
|
break
|
|
334
|
-
|
|
335
|
-
case 'TSIndexSignature': {
|
|
385
|
+
case 'TSIndexSignature':
|
|
336
386
|
if (member.static) {
|
|
337
387
|
modifiers.push('static')
|
|
338
388
|
}
|
|
@@ -341,70 +391,11 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
341
391
|
}
|
|
342
392
|
selectors.push('index-signature')
|
|
343
393
|
break
|
|
344
|
-
|
|
345
|
-
case 'StaticBlock': {
|
|
394
|
+
case 'StaticBlock':
|
|
346
395
|
addSafetySemicolonWhenInline = false
|
|
347
396
|
selectors.push('static-block')
|
|
348
397
|
dependencies = extractDependencies(member, true)
|
|
349
398
|
break
|
|
350
|
-
}
|
|
351
|
-
default: {
|
|
352
|
-
if ('static' in member && member.static) {
|
|
353
|
-
modifiers.push('static')
|
|
354
|
-
}
|
|
355
|
-
if ('declare' in member && member.declare) {
|
|
356
|
-
modifiers.push('declare')
|
|
357
|
-
}
|
|
358
|
-
if (member.type === 'TSAbstractPropertyDefinition') {
|
|
359
|
-
modifiers.push('abstract')
|
|
360
|
-
}
|
|
361
|
-
if (decorated) {
|
|
362
|
-
modifiers.push('decorated')
|
|
363
|
-
}
|
|
364
|
-
if ('override' in member && member.override) {
|
|
365
|
-
modifiers.push('override')
|
|
366
|
-
}
|
|
367
|
-
if ('readonly' in member && member.readonly) {
|
|
368
|
-
modifiers.push('readonly')
|
|
369
|
-
}
|
|
370
|
-
if (
|
|
371
|
-
'accessibility' in member &&
|
|
372
|
-
member.accessibility === 'protected'
|
|
373
|
-
) {
|
|
374
|
-
modifiers.push('protected')
|
|
375
|
-
} else if (
|
|
376
|
-
('accessibility' in member &&
|
|
377
|
-
member.accessibility === 'private') ||
|
|
378
|
-
isPrivateHash
|
|
379
|
-
) {
|
|
380
|
-
modifiers.push('private')
|
|
381
|
-
} else {
|
|
382
|
-
modifiers.push('public')
|
|
383
|
-
}
|
|
384
|
-
if ('optional' in member && member.optional) {
|
|
385
|
-
modifiers.push('optional')
|
|
386
|
-
}
|
|
387
|
-
if ('value' in member && member.value) {
|
|
388
|
-
if (
|
|
389
|
-
member.value.type === 'ArrowFunctionExpression' ||
|
|
390
|
-
member.value.type === 'FunctionExpression'
|
|
391
|
-
) {
|
|
392
|
-
if (member.value.async) {
|
|
393
|
-
modifiers.push('async')
|
|
394
|
-
}
|
|
395
|
-
selectors.push('function-property')
|
|
396
|
-
} else {
|
|
397
|
-
memberValue = sourceCode.getText(member.value)
|
|
398
|
-
}
|
|
399
|
-
if (member.value.type !== 'TSEmptyBodyFunctionExpression') {
|
|
400
|
-
dependencies = extractDependencies(
|
|
401
|
-
member.value,
|
|
402
|
-
member.static,
|
|
403
|
-
)
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
selectors.push('property')
|
|
407
|
-
}
|
|
408
399
|
}
|
|
409
400
|
let predefinedGroups =
|
|
410
401
|
generatePredefinedGroups.generatePredefinedGroups({
|
|
@@ -437,10 +428,10 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
437
428
|
overloadSignatures.includes(member),
|
|
438
429
|
)
|
|
439
430
|
let overloadSignatureGroupMember =
|
|
440
|
-
(
|
|
431
|
+
(_d = overloadSignatureGroups[overloadSignatureGroupMemberIndex]) ==
|
|
441
432
|
null
|
|
442
433
|
? void 0
|
|
443
|
-
:
|
|
434
|
+
: _d.at(-1)
|
|
444
435
|
let sortingNode = {
|
|
445
436
|
dependencyName: getDependencyName({
|
|
446
437
|
nodeNameWithoutStartingHash: name.startsWith('#')
|
|
@@ -470,7 +461,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
470
461
|
name,
|
|
471
462
|
}
|
|
472
463
|
let lastSortingNode =
|
|
473
|
-
(
|
|
464
|
+
(_e = accumulator.at(-1)) == null ? void 0 : _e.at(-1)
|
|
474
465
|
if (
|
|
475
466
|
shouldPartition.shouldPartition({
|
|
476
467
|
lastSortingNode,
|
|
@@ -486,25 +477,28 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
486
477
|
},
|
|
487
478
|
[[]],
|
|
488
479
|
)
|
|
489
|
-
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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,
|
|
504
497
|
{
|
|
505
498
|
ignoreEslintDisabledNodes,
|
|
506
499
|
},
|
|
507
500
|
)
|
|
501
|
+
}
|
|
508
502
|
let nodes = formattedNodes.flat()
|
|
509
503
|
reportAllErrors.reportAllErrors({
|
|
510
504
|
newlinesBetweenValueGetter: ({
|
|
@@ -540,21 +534,13 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
540
534
|
{
|
|
541
535
|
properties: {
|
|
542
536
|
...commonJsonSchemas.commonJsonSchemas,
|
|
543
|
-
ignoreCallbackDependenciesPatterns: {
|
|
544
|
-
description:
|
|
545
|
-
'Patterns that should be ignored when detecting dependencies in method callbacks.',
|
|
546
|
-
items: {
|
|
547
|
-
type: 'string',
|
|
548
|
-
},
|
|
549
|
-
type: 'array',
|
|
550
|
-
},
|
|
551
537
|
customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
552
538
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
553
539
|
}),
|
|
540
|
+
ignoreCallbackDependenciesPatterns: commonJsonSchemas.regexJsonSchema,
|
|
554
541
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
555
542
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
556
543
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
557
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
558
544
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
559
545
|
},
|
|
560
546
|
additionalProperties: false,
|
|
@@ -4,10 +4,10 @@ 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 getDecoratorName = require('./sort-decorators/get-decorator-name.js')
|
|
8
7
|
const reportErrors = require('../utils/report-errors.js')
|
|
9
8
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
10
9
|
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
10
|
+
const getDecoratorName = require('../utils/get-decorator-name.js')
|
|
11
11
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
12
12
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
13
13
|
const shouldPartition = require('../utils/should-partition.js')
|
|
@@ -18,6 +18,7 @@ const isSortable = require('../utils/is-sortable.js')
|
|
|
18
18
|
const useGroups = require('../utils/use-groups.js')
|
|
19
19
|
const complete = require('../utils/complete.js')
|
|
20
20
|
let defaultOptions = {
|
|
21
|
+
fallbackSort: { type: 'unsorted' },
|
|
21
22
|
specialCharacters: 'keep',
|
|
22
23
|
partitionByComment: false,
|
|
23
24
|
sortOnProperties: true,
|
|
@@ -42,11 +43,11 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
42
43
|
defaultOptions,
|
|
43
44
|
)
|
|
44
45
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
45
|
-
validateGroupsConfiguration.validateGroupsConfiguration(
|
|
46
|
-
options.
|
|
47
|
-
['unknown'],
|
|
48
|
-
|
|
49
|
-
)
|
|
46
|
+
validateGroupsConfiguration.validateGroupsConfiguration({
|
|
47
|
+
allowedCustomGroups: Object.keys(options.customGroups),
|
|
48
|
+
allowedPredefinedGroups: ['unknown'],
|
|
49
|
+
options,
|
|
50
|
+
})
|
|
50
51
|
return {
|
|
51
52
|
Decorator: decorator => {
|
|
52
53
|
if (!options.sortOnParameters) {
|
|
@@ -130,7 +131,6 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
130
131
|
},
|
|
131
132
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
132
133
|
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
133
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
134
134
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
135
135
|
},
|
|
136
136
|
additionalProperties: false,
|
|
@@ -165,7 +165,10 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
165
165
|
(accumulator, decorator) => {
|
|
166
166
|
var _a
|
|
167
167
|
let { setCustomGroups, getGroup } = useGroups.useGroups(options)
|
|
168
|
-
let name = getDecoratorName.getDecoratorName(
|
|
168
|
+
let name = getDecoratorName.getDecoratorName({
|
|
169
|
+
sourceCode,
|
|
170
|
+
decorator,
|
|
171
|
+
})
|
|
169
172
|
setCustomGroups(options.customGroups, name)
|
|
170
173
|
let sortingNode = {
|
|
171
174
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
@@ -196,8 +199,11 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
196
199
|
)
|
|
197
200
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
198
201
|
formattedMembers.flatMap(nodes2 =>
|
|
199
|
-
sortNodesByGroups.sortNodesByGroups(
|
|
202
|
+
sortNodesByGroups.sortNodesByGroups({
|
|
203
|
+
getOptionsByGroupNumber: () => ({ options }),
|
|
200
204
|
ignoreEslintDisabledNodes,
|
|
205
|
+
groups: options.groups,
|
|
206
|
+
nodes: nodes2,
|
|
201
207
|
}),
|
|
202
208
|
)
|
|
203
209
|
let nodes = formattedMembers.flat()
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
4
4
|
let singleCustomGroupJsonSchema = {
|
|
5
|
-
elementValuePattern: commonJsonSchemas.
|
|
6
|
-
elementNamePattern: commonJsonSchemas.
|
|
5
|
+
elementValuePattern: commonJsonSchemas.regexJsonSchema,
|
|
6
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
7
7
|
}
|
|
8
8
|
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -22,6 +22,7 @@ const isSortable = require('../utils/is-sortable.js')
|
|
|
22
22
|
const useGroups = require('../utils/use-groups.js')
|
|
23
23
|
const complete = require('../utils/complete.js')
|
|
24
24
|
let defaultOptions = {
|
|
25
|
+
fallbackSort: { type: 'unsorted' },
|
|
25
26
|
partitionByComment: false,
|
|
26
27
|
partitionByNewLine: false,
|
|
27
28
|
specialCharacters: 'keep',
|
|
@@ -97,7 +98,7 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
97
98
|
}
|
|
98
99
|
let formattedMembers = members.reduce(
|
|
99
100
|
(accumulator, member) => {
|
|
100
|
-
var _a
|
|
101
|
+
var _a, _b, _c
|
|
101
102
|
let dependencies = []
|
|
102
103
|
if (member.initializer) {
|
|
103
104
|
dependencies = extractDependencies(
|
|
@@ -130,6 +131,13 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
130
131
|
numericValue: member.initializer
|
|
131
132
|
? getExpressionNumberValue(member.initializer)
|
|
132
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,
|
|
133
141
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
134
142
|
member,
|
|
135
143
|
eslintDisabledLines,
|
|
@@ -161,55 +169,40 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
161
169
|
sortingNode.numericValue !== null &&
|
|
162
170
|
!Number.isNaN(sortingNode.numericValue),
|
|
163
171
|
)
|
|
164
|
-
let
|
|
172
|
+
let nodeValueGetter = computeNodeValueGetter({
|
|
173
|
+
isNumericEnum,
|
|
174
|
+
options,
|
|
175
|
+
})
|
|
176
|
+
let overriddenOptions = {
|
|
165
177
|
...options,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
options
|
|
169
|
-
|
|
170
|
-
var _a, _b
|
|
171
|
-
if (isNumericEnum) {
|
|
172
|
-
return sortingNode.numericValue.toString()
|
|
173
|
-
}
|
|
174
|
-
if (
|
|
175
|
-
((_a = sortingNode.node.initializer) == null
|
|
176
|
-
? void 0
|
|
177
|
-
: _a.type) === 'Literal'
|
|
178
|
-
) {
|
|
179
|
-
return (
|
|
180
|
-
((_b = sortingNode.node.initializer.value) == null
|
|
181
|
-
? void 0
|
|
182
|
-
: _b.toString()) ?? ''
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
return ''
|
|
186
|
-
}
|
|
187
|
-
: null,
|
|
188
|
-
/**
|
|
189
|
-
* If the enum is numeric, and we sort by value, always use the
|
|
190
|
-
* `natural` sort type, which will correctly sort them.
|
|
191
|
-
*/
|
|
192
|
-
type:
|
|
193
|
-
isNumericEnum && (options.forceNumericSort || options.sortByValue)
|
|
194
|
-
? 'natural'
|
|
195
|
-
: options.type,
|
|
178
|
+
type: computeOptionType({
|
|
179
|
+
isNumericEnum,
|
|
180
|
+
options,
|
|
181
|
+
}),
|
|
196
182
|
}
|
|
197
|
-
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
getCustomGroupsCompareOptions.
|
|
203
|
-
|
|
183
|
+
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
184
|
+
let nodesSortedByGroups = formattedMembers.flatMap(sortingNodes =>
|
|
185
|
+
sortNodesByGroups.sortNodesByGroups({
|
|
186
|
+
getOptionsByGroupNumber: groupNumber => ({
|
|
187
|
+
options:
|
|
188
|
+
getCustomGroupsCompareOptions.getCustomGroupOverriddenOptions({
|
|
189
|
+
options: overriddenOptions,
|
|
204
190
|
groupNumber,
|
|
205
|
-
),
|
|
206
|
-
|
|
191
|
+
}),
|
|
192
|
+
nodeValueGetter,
|
|
207
193
|
}),
|
|
208
|
-
|
|
194
|
+
ignoreEslintDisabledNodes,
|
|
195
|
+
groups: options.groups,
|
|
196
|
+
nodes: sortingNodes,
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
return sortNodesByDependencies.sortNodesByDependencies(
|
|
200
|
+
nodesSortedByGroups,
|
|
209
201
|
{
|
|
210
202
|
ignoreEslintDisabledNodes,
|
|
211
203
|
},
|
|
212
204
|
)
|
|
205
|
+
}
|
|
213
206
|
reportAllErrors.reportAllErrors({
|
|
214
207
|
availableMessageIds: {
|
|
215
208
|
missedSpacingBetweenMembers: 'missedSpacingBetweenEnumsMembers',
|
|
@@ -251,7 +244,6 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
251
244
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
252
245
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
253
246
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
254
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
255
247
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
256
248
|
},
|
|
257
249
|
additionalProperties: false,
|
|
@@ -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
|
|
@@ -13,6 +13,7 @@ const getSettings = require('../utils/get-settings.js')
|
|
|
13
13
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
14
14
|
const complete = require('../utils/complete.js')
|
|
15
15
|
let defaultOptions = {
|
|
16
|
+
fallbackSort: { type: 'unsorted' },
|
|
16
17
|
specialCharacters: 'keep',
|
|
17
18
|
partitionByComment: false,
|
|
18
19
|
partitionByNewLine: false,
|
|
@@ -83,8 +84,10 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
83
84
|
)
|
|
84
85
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
85
86
|
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
86
|
-
sortNodes.sortNodes(
|
|
87
|
+
sortNodes.sortNodes({
|
|
87
88
|
ignoreEslintDisabledNodes,
|
|
89
|
+
nodes: groupedNodes,
|
|
90
|
+
options,
|
|
88
91
|
}),
|
|
89
92
|
)
|
|
90
93
|
reportAllErrors.reportAllErrors({
|
|
@@ -119,7 +122,6 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
119
122
|
},
|
|
120
123
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
121
124
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
122
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
123
125
|
},
|
|
124
126
|
additionalProperties: false,
|
|
125
127
|
type: 'object',
|