eslint-plugin-perfectionist 4.6.0 → 4.7.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 +1 -1
- package/dist/rules/sort-array-includes.js +34 -71
- package/dist/rules/sort-classes/types.js +1 -4
- package/dist/rules/sort-classes.js +162 -226
- package/dist/rules/sort-decorators.js +28 -67
- package/dist/rules/sort-enums.js +27 -80
- package/dist/rules/sort-exports.js +19 -59
- package/dist/rules/sort-heritage-clauses.js +12 -47
- package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +2 -2
- package/dist/rules/sort-imports.js +31 -112
- package/dist/rules/sort-interfaces.js +2 -2
- package/dist/rules/sort-intersection-types.js +17 -249
- package/dist/rules/sort-jsx-props.js +45 -51
- package/dist/rules/sort-maps/does-custom-group-match.js +24 -0
- package/dist/rules/sort-maps/types.js +7 -0
- package/dist/rules/sort-maps.js +117 -85
- package/dist/rules/sort-modules.js +35 -119
- package/dist/rules/sort-named-exports.js +19 -61
- package/dist/rules/sort-named-imports.js +19 -61
- package/dist/rules/sort-object-types.js +19 -100
- package/dist/rules/sort-objects/does-custom-group-match.js +49 -0
- package/dist/rules/sort-objects/types.js +15 -0
- package/dist/rules/sort-objects.js +114 -139
- package/dist/rules/sort-sets.js +7 -1
- package/dist/rules/sort-switch-case.js +30 -35
- package/dist/rules/sort-union-types.js +181 -238
- package/dist/rules/sort-variable-declarations.js +23 -72
- package/dist/utils/common-json-schemas.js +15 -5
- package/dist/utils/get-comments-before.js +1 -1
- package/dist/utils/get-lines-between.js +1 -1
- package/dist/utils/get-settings.js +1 -1
- package/dist/utils/get-source-code.js +1 -1
- package/dist/utils/make-comment-after-fixes.js +20 -20
- package/dist/utils/make-fixes.js +34 -65
- package/dist/utils/make-order-fixes.js +69 -0
- package/dist/utils/make-single-node-comment-after-fixes.js +31 -0
- package/dist/utils/report-all-errors.js +93 -0
- package/dist/utils/report-errors.js +43 -0
- package/dist/utils/should-partition.js +32 -0
- package/dist/utils/validate-custom-sort-configuration.js +1 -1
- package/dist/utils/validate-generated-groups-configuration.js +1 -1
- package/dist/utils/validate-groups-configuration.js +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
-
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
4
3
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
5
4
|
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
6
5
|
const types = require('./sort-classes/types.js')
|
|
@@ -8,26 +7,21 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
|
|
|
8
7
|
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
9
8
|
const getOverloadSignatureGroups = require('./sort-classes/get-overload-signature-groups.js')
|
|
10
9
|
const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
|
|
10
|
+
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
11
11
|
const doesCustomGroupMatch = require('./sort-classes/does-custom-group-match.js')
|
|
12
12
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
13
13
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
14
|
-
const hasPartitionComment = require('../utils/has-partition-comment.js')
|
|
15
14
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
16
|
-
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
17
|
-
const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
|
|
18
|
-
const getNewlinesErrors = require('../utils/get-newlines-errors.js')
|
|
19
15
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
20
|
-
const
|
|
16
|
+
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
17
|
+
const shouldPartition = require('../utils/should-partition.js')
|
|
21
18
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
22
19
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
23
|
-
const toSingleLine = require('../utils/to-single-line.js')
|
|
24
20
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
25
21
|
const getSettings = require('../utils/get-settings.js')
|
|
26
22
|
const isSortable = require('../utils/is-sortable.js')
|
|
27
23
|
const useGroups = require('../utils/use-groups.js')
|
|
28
|
-
const makeFixes = require('../utils/make-fixes.js')
|
|
29
24
|
const complete = require('../utils/complete.js')
|
|
30
|
-
const pairwise = require('../utils/pairwise.js')
|
|
31
25
|
const matches = require('../utils/matches.js')
|
|
32
26
|
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
33
27
|
let defaultOptions = {
|
|
@@ -233,7 +227,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
233
227
|
getOverloadSignatureGroups.getOverloadSignatureGroups(node.body)
|
|
234
228
|
let formattedNodes = node.body.reduce(
|
|
235
229
|
(accumulator, member) => {
|
|
236
|
-
var _a2, _b, _c
|
|
230
|
+
var _a2, _b, _c
|
|
237
231
|
let name
|
|
238
232
|
let dependencies = []
|
|
239
233
|
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
@@ -272,127 +266,145 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
272
266
|
let modifiers = []
|
|
273
267
|
let selectors = []
|
|
274
268
|
let addSafetySemicolonWhenInline = true
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
} else if (member.type === 'TSIndexSignature') {
|
|
317
|
-
if (member.static) {
|
|
318
|
-
modifiers.push('static')
|
|
319
|
-
}
|
|
320
|
-
if (member.readonly) {
|
|
321
|
-
modifiers.push('readonly')
|
|
322
|
-
}
|
|
323
|
-
selectors.push('index-signature')
|
|
324
|
-
} else if (member.type === 'StaticBlock') {
|
|
325
|
-
addSafetySemicolonWhenInline = false
|
|
326
|
-
selectors.push('static-block')
|
|
327
|
-
dependencies = extractDependencies(member, true)
|
|
328
|
-
} else if (
|
|
329
|
-
member.type === 'AccessorProperty' ||
|
|
330
|
-
member.type === 'TSAbstractAccessorProperty'
|
|
331
|
-
) {
|
|
332
|
-
if (member.static) {
|
|
333
|
-
modifiers.push('static')
|
|
334
|
-
}
|
|
335
|
-
if (member.type === 'TSAbstractAccessorProperty') {
|
|
336
|
-
modifiers.push('abstract')
|
|
337
|
-
}
|
|
338
|
-
if (decorated) {
|
|
339
|
-
modifiers.push('decorated')
|
|
340
|
-
}
|
|
341
|
-
if (member.override) {
|
|
342
|
-
modifiers.push('override')
|
|
343
|
-
}
|
|
344
|
-
if (member.accessibility === 'protected') {
|
|
345
|
-
modifiers.push('protected')
|
|
346
|
-
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
347
|
-
modifiers.push('private')
|
|
348
|
-
} else {
|
|
349
|
-
modifiers.push('public')
|
|
350
|
-
}
|
|
351
|
-
selectors.push('accessor-property')
|
|
352
|
-
} else {
|
|
353
|
-
if (member.static) {
|
|
354
|
-
modifiers.push('static')
|
|
355
|
-
}
|
|
356
|
-
if (member.declare) {
|
|
357
|
-
modifiers.push('declare')
|
|
358
|
-
}
|
|
359
|
-
if (member.type === 'TSAbstractPropertyDefinition') {
|
|
360
|
-
modifiers.push('abstract')
|
|
361
|
-
}
|
|
362
|
-
if (decorated) {
|
|
363
|
-
modifiers.push('decorated')
|
|
364
|
-
}
|
|
365
|
-
if (member.override) {
|
|
366
|
-
modifiers.push('override')
|
|
269
|
+
switch (member.type) {
|
|
270
|
+
case 'TSAbstractMethodDefinition':
|
|
271
|
+
case 'MethodDefinition': {
|
|
272
|
+
if (member.static) {
|
|
273
|
+
modifiers.push('static')
|
|
274
|
+
}
|
|
275
|
+
if (member.type === 'TSAbstractMethodDefinition') {
|
|
276
|
+
modifiers.push('abstract')
|
|
277
|
+
} else if (!node.parent.declare) {
|
|
278
|
+
addSafetySemicolonWhenInline = false
|
|
279
|
+
}
|
|
280
|
+
if (decorated) {
|
|
281
|
+
modifiers.push('decorated')
|
|
282
|
+
}
|
|
283
|
+
if (member.override) {
|
|
284
|
+
modifiers.push('override')
|
|
285
|
+
}
|
|
286
|
+
if (member.accessibility === 'protected') {
|
|
287
|
+
modifiers.push('protected')
|
|
288
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
289
|
+
modifiers.push('private')
|
|
290
|
+
} else {
|
|
291
|
+
modifiers.push('public')
|
|
292
|
+
}
|
|
293
|
+
if (member.optional) {
|
|
294
|
+
modifiers.push('optional')
|
|
295
|
+
}
|
|
296
|
+
if (member.value.async) {
|
|
297
|
+
modifiers.push('async')
|
|
298
|
+
}
|
|
299
|
+
if (member.kind === 'constructor') {
|
|
300
|
+
selectors.push('constructor')
|
|
301
|
+
}
|
|
302
|
+
if (member.kind === 'get') {
|
|
303
|
+
selectors.push('get-method')
|
|
304
|
+
}
|
|
305
|
+
if (member.kind === 'set') {
|
|
306
|
+
selectors.push('set-method')
|
|
307
|
+
}
|
|
308
|
+
selectors.push('method')
|
|
309
|
+
break
|
|
367
310
|
}
|
|
368
|
-
|
|
369
|
-
|
|
311
|
+
case 'TSAbstractAccessorProperty':
|
|
312
|
+
case 'AccessorProperty': {
|
|
313
|
+
if (member.static) {
|
|
314
|
+
modifiers.push('static')
|
|
315
|
+
}
|
|
316
|
+
if (member.type === 'TSAbstractAccessorProperty') {
|
|
317
|
+
modifiers.push('abstract')
|
|
318
|
+
}
|
|
319
|
+
if (decorated) {
|
|
320
|
+
modifiers.push('decorated')
|
|
321
|
+
}
|
|
322
|
+
if (member.override) {
|
|
323
|
+
modifiers.push('override')
|
|
324
|
+
}
|
|
325
|
+
if (member.accessibility === 'protected') {
|
|
326
|
+
modifiers.push('protected')
|
|
327
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
328
|
+
modifiers.push('private')
|
|
329
|
+
} else {
|
|
330
|
+
modifiers.push('public')
|
|
331
|
+
}
|
|
332
|
+
selectors.push('accessor-property')
|
|
333
|
+
break
|
|
370
334
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
335
|
+
case 'TSIndexSignature': {
|
|
336
|
+
if (member.static) {
|
|
337
|
+
modifiers.push('static')
|
|
338
|
+
}
|
|
339
|
+
if (member.readonly) {
|
|
340
|
+
modifiers.push('readonly')
|
|
341
|
+
}
|
|
342
|
+
selectors.push('index-signature')
|
|
343
|
+
break
|
|
377
344
|
}
|
|
378
|
-
|
|
379
|
-
|
|
345
|
+
case 'StaticBlock': {
|
|
346
|
+
addSafetySemicolonWhenInline = false
|
|
347
|
+
selectors.push('static-block')
|
|
348
|
+
dependencies = extractDependencies(member, true)
|
|
349
|
+
break
|
|
380
350
|
}
|
|
381
|
-
|
|
382
|
-
(
|
|
383
|
-
'
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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')
|
|
389
369
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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')
|
|
394
407
|
}
|
|
395
|
-
selectors.push('property')
|
|
396
408
|
}
|
|
397
409
|
let predefinedGroups =
|
|
398
410
|
generatePredefinedGroups.generatePredefinedGroups({
|
|
@@ -421,11 +433,11 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
421
433
|
}
|
|
422
434
|
}
|
|
423
435
|
let overloadSignatureGroupMember =
|
|
424
|
-
(
|
|
436
|
+
(_b = overloadSignatureGroups.find(overloadSignatures =>
|
|
425
437
|
overloadSignatures.includes(member),
|
|
426
438
|
)) == null
|
|
427
439
|
? void 0
|
|
428
|
-
:
|
|
440
|
+
: _b.at(-1)
|
|
429
441
|
let sortingNode = {
|
|
430
442
|
dependencyName: getDependencyName({
|
|
431
443
|
nodeNameWithoutStartingHash: name.startsWith('#')
|
|
@@ -450,22 +462,14 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
450
462
|
dependencies,
|
|
451
463
|
name,
|
|
452
464
|
}
|
|
453
|
-
let
|
|
454
|
-
(
|
|
465
|
+
let lastSortingNode =
|
|
466
|
+
(_c = accumulator.at(-1)) == null ? void 0 : _c.at(-1)
|
|
455
467
|
if (
|
|
456
|
-
(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
sortingNode,
|
|
462
|
-
)) ||
|
|
463
|
-
hasPartitionComment.hasPartitionComment({
|
|
464
|
-
comments: getCommentsBefore.getCommentsBefore({
|
|
465
|
-
node: member,
|
|
466
|
-
sourceCode,
|
|
467
|
-
}),
|
|
468
|
-
partitionByComment: options.partitionByComment,
|
|
468
|
+
shouldPartition.shouldPartition({
|
|
469
|
+
lastSortingNode,
|
|
470
|
+
sortingNode,
|
|
471
|
+
sourceCode,
|
|
472
|
+
options,
|
|
469
473
|
})
|
|
470
474
|
) {
|
|
471
475
|
accumulator.push([])
|
|
@@ -475,7 +479,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
475
479
|
},
|
|
476
480
|
[[]],
|
|
477
481
|
)
|
|
478
|
-
let
|
|
482
|
+
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
479
483
|
sortNodesByDependencies.sortNodesByDependencies(
|
|
480
484
|
formattedNodes.flatMap(nodes2 =>
|
|
481
485
|
sortNodesByGroups.sortNodesByGroups(nodes2, options, {
|
|
@@ -494,80 +498,20 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
494
498
|
ignoreEslintDisabledNodes,
|
|
495
499
|
},
|
|
496
500
|
)
|
|
497
|
-
let sortedNodes = sortNodesIgnoringEslintDisabledNodes(false)
|
|
498
|
-
let sortedNodesExcludingEslintDisabled =
|
|
499
|
-
sortNodesIgnoringEslintDisabledNodes(true)
|
|
500
501
|
let nodes = formattedNodes.flat()
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
indexOfLeft >= indexOfRightExcludingEslintDisabled
|
|
515
|
-
) {
|
|
516
|
-
if (firstUnorderedNodeDependentOnRight) {
|
|
517
|
-
messageIds.push('unexpectedClassesDependencyOrder')
|
|
518
|
-
} else {
|
|
519
|
-
messageIds.push(
|
|
520
|
-
leftNumber === rightNumber
|
|
521
|
-
? 'unexpectedClassesOrder'
|
|
522
|
-
: 'unexpectedClassesGroupOrder',
|
|
523
|
-
)
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
messageIds = [
|
|
527
|
-
...messageIds,
|
|
528
|
-
...getNewlinesErrors.getNewlinesErrors({
|
|
529
|
-
missedSpacingError: 'missedSpacingBetweenClassMembers',
|
|
530
|
-
extraSpacingError: 'extraSpacingBetweenClassMembers',
|
|
531
|
-
rightNum: rightNumber,
|
|
532
|
-
leftNum: leftNumber,
|
|
533
|
-
sourceCode,
|
|
534
|
-
options,
|
|
535
|
-
right,
|
|
536
|
-
left,
|
|
537
|
-
}),
|
|
538
|
-
]
|
|
539
|
-
for (let messageId of messageIds) {
|
|
540
|
-
context.report({
|
|
541
|
-
fix: fixer => [
|
|
542
|
-
...makeFixes.makeFixes({
|
|
543
|
-
sortedNodes: sortedNodesExcludingEslintDisabled,
|
|
544
|
-
sourceCode,
|
|
545
|
-
options,
|
|
546
|
-
fixer,
|
|
547
|
-
nodes,
|
|
548
|
-
}),
|
|
549
|
-
...makeNewlinesFixes.makeNewlinesFixes({
|
|
550
|
-
sortedNodes: sortedNodesExcludingEslintDisabled,
|
|
551
|
-
sourceCode,
|
|
552
|
-
options,
|
|
553
|
-
fixer,
|
|
554
|
-
nodes,
|
|
555
|
-
}),
|
|
556
|
-
],
|
|
557
|
-
data: {
|
|
558
|
-
nodeDependentOnRight:
|
|
559
|
-
firstUnorderedNodeDependentOnRight == null
|
|
560
|
-
? void 0
|
|
561
|
-
: firstUnorderedNodeDependentOnRight.name,
|
|
562
|
-
right: toSingleLine.toSingleLine(right.name),
|
|
563
|
-
left: toSingleLine.toSingleLine(left.name),
|
|
564
|
-
rightGroup: right.group,
|
|
565
|
-
leftGroup: left.group,
|
|
566
|
-
},
|
|
567
|
-
node: right.node,
|
|
568
|
-
messageId,
|
|
569
|
-
})
|
|
570
|
-
}
|
|
502
|
+
reportAllErrors.reportAllErrors({
|
|
503
|
+
availableMessageIds: {
|
|
504
|
+
missedSpacingBetweenMembers: 'missedSpacingBetweenClassMembers',
|
|
505
|
+
extraSpacingBetweenMembers: 'extraSpacingBetweenClassMembers',
|
|
506
|
+
unexpectedDependencyOrder: 'unexpectedClassesDependencyOrder',
|
|
507
|
+
unexpectedGroupOrder: 'unexpectedClassesGroupOrder',
|
|
508
|
+
unexpectedOrder: 'unexpectedClassesOrder',
|
|
509
|
+
},
|
|
510
|
+
sortNodesExcludingEslintDisabled,
|
|
511
|
+
sourceCode,
|
|
512
|
+
options,
|
|
513
|
+
context,
|
|
514
|
+
nodes,
|
|
571
515
|
})
|
|
572
516
|
},
|
|
573
517
|
}),
|
|
@@ -575,6 +519,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
575
519
|
schema: [
|
|
576
520
|
{
|
|
577
521
|
properties: {
|
|
522
|
+
...commonJsonSchemas.commonJsonSchemas,
|
|
578
523
|
ignoreCallbackDependenciesPatterns: {
|
|
579
524
|
description:
|
|
580
525
|
'Patterns that should be ignored when detecting dependencies in method callbacks.',
|
|
@@ -583,23 +528,14 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
583
528
|
},
|
|
584
529
|
type: 'array',
|
|
585
530
|
},
|
|
586
|
-
partitionByComment: {
|
|
587
|
-
...commonJsonSchemas.partitionByCommentJsonSchema,
|
|
588
|
-
description:
|
|
589
|
-
'Allows to use comments to separate the class members into logical groups.',
|
|
590
|
-
},
|
|
591
531
|
customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
592
532
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
593
533
|
}),
|
|
534
|
+
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
594
535
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
595
|
-
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
596
536
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
597
|
-
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
598
|
-
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
599
537
|
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
600
|
-
locales: commonJsonSchemas.localesJsonSchema,
|
|
601
538
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
602
|
-
order: commonJsonSchemas.orderJsonSchema,
|
|
603
539
|
},
|
|
604
540
|
additionalProperties: false,
|
|
605
541
|
type: 'object',
|
|
@@ -5,22 +5,17 @@ const validateGroupsConfiguration = require('../utils/validate-groups-configurat
|
|
|
5
5
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
6
6
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
7
7
|
const getDecoratorName = require('./sort-decorators/get-decorator-name.js')
|
|
8
|
-
const hasPartitionComment = require('../utils/has-partition-comment.js')
|
|
9
|
-
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
10
8
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
11
|
-
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
12
9
|
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
13
10
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
14
|
-
const
|
|
11
|
+
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
12
|
+
const shouldPartition = require('../utils/should-partition.js')
|
|
15
13
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
16
|
-
const toSingleLine = require('../utils/to-single-line.js')
|
|
17
14
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
18
15
|
const getSettings = require('../utils/get-settings.js')
|
|
19
16
|
const isSortable = require('../utils/is-sortable.js')
|
|
20
17
|
const useGroups = require('../utils/use-groups.js')
|
|
21
|
-
const makeFixes = require('../utils/make-fixes.js')
|
|
22
18
|
const complete = require('../utils/complete.js')
|
|
23
|
-
const pairwise = require('../utils/pairwise.js')
|
|
24
19
|
let defaultOptions = {
|
|
25
20
|
specialCharacters: 'keep',
|
|
26
21
|
partitionByComment: false,
|
|
@@ -42,11 +37,7 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
42
37
|
schema: [
|
|
43
38
|
{
|
|
44
39
|
properties: {
|
|
45
|
-
|
|
46
|
-
...commonJsonSchemas.partitionByCommentJsonSchema,
|
|
47
|
-
description:
|
|
48
|
-
'Allows you to use comments to separate the decorators into logical groups.',
|
|
49
|
-
},
|
|
40
|
+
...commonJsonSchemas.commonJsonSchemas,
|
|
50
41
|
sortOnParameters: {
|
|
51
42
|
description:
|
|
52
43
|
'Controls whether sorting should be enabled for method parameter decorators.',
|
|
@@ -72,14 +63,10 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
72
63
|
'Controls whether sorting should be enabled for class decorators.',
|
|
73
64
|
type: 'boolean',
|
|
74
65
|
},
|
|
75
|
-
|
|
66
|
+
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
76
67
|
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
77
|
-
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
78
|
-
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
79
68
|
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
80
|
-
locales: commonJsonSchemas.localesJsonSchema,
|
|
81
69
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
82
|
-
order: commonJsonSchemas.orderJsonSchema,
|
|
83
70
|
},
|
|
84
71
|
additionalProperties: false,
|
|
85
72
|
type: 'object',
|
|
@@ -177,17 +164,7 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
177
164
|
})
|
|
178
165
|
let formattedMembers = decorators.reduce(
|
|
179
166
|
(accumulator, decorator) => {
|
|
180
|
-
|
|
181
|
-
hasPartitionComment.hasPartitionComment({
|
|
182
|
-
comments: getCommentsBefore.getCommentsBefore({
|
|
183
|
-
node: decorator,
|
|
184
|
-
sourceCode,
|
|
185
|
-
}),
|
|
186
|
-
partitionByComment: options.partitionByComment,
|
|
187
|
-
})
|
|
188
|
-
) {
|
|
189
|
-
accumulator.push([])
|
|
190
|
-
}
|
|
167
|
+
var _a
|
|
191
168
|
let { setCustomGroups, getGroup } = useGroups.useGroups(options)
|
|
192
169
|
let name = getDecoratorName.getDecoratorName(decorator)
|
|
193
170
|
setCustomGroups(options.customGroups, name)
|
|
@@ -201,6 +178,18 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
201
178
|
node: decorator,
|
|
202
179
|
name,
|
|
203
180
|
}
|
|
181
|
+
let lastSortingNode =
|
|
182
|
+
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
183
|
+
if (
|
|
184
|
+
shouldPartition.shouldPartition({
|
|
185
|
+
lastSortingNode,
|
|
186
|
+
sortingNode,
|
|
187
|
+
sourceCode,
|
|
188
|
+
options,
|
|
189
|
+
})
|
|
190
|
+
) {
|
|
191
|
+
accumulator.push([])
|
|
192
|
+
}
|
|
204
193
|
accumulator.at(-1).push(sortingNode)
|
|
205
194
|
return accumulator
|
|
206
195
|
},
|
|
@@ -212,46 +201,18 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
212
201
|
ignoreEslintDisabledNodes,
|
|
213
202
|
}),
|
|
214
203
|
)
|
|
215
|
-
let sortedNodes = sortNodesExcludingEslintDisabled(false)
|
|
216
|
-
let sortedNodesExcludingEslintDisabled =
|
|
217
|
-
sortNodesExcludingEslintDisabled(true)
|
|
218
204
|
let nodes = formattedMembers.flat()
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
|
|
232
|
-
let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
|
|
233
|
-
context.report({
|
|
234
|
-
fix: fixer =>
|
|
235
|
-
makeFixes.makeFixes({
|
|
236
|
-
sortedNodes: sortedNodesExcludingEslintDisabled,
|
|
237
|
-
ignoreFirstNodeHighestBlockComment: true,
|
|
238
|
-
sourceCode,
|
|
239
|
-
options,
|
|
240
|
-
fixer,
|
|
241
|
-
nodes,
|
|
242
|
-
}),
|
|
243
|
-
data: {
|
|
244
|
-
right: toSingleLine.toSingleLine(right.name),
|
|
245
|
-
left: toSingleLine.toSingleLine(left.name),
|
|
246
|
-
rightGroup: right.group,
|
|
247
|
-
leftGroup: left.group,
|
|
248
|
-
},
|
|
249
|
-
messageId:
|
|
250
|
-
leftNumber === rightNumber
|
|
251
|
-
? 'unexpectedDecoratorsOrder'
|
|
252
|
-
: 'unexpectedDecoratorsGroupOrder',
|
|
253
|
-
node: right.node,
|
|
254
|
-
})
|
|
205
|
+
reportAllErrors.reportAllErrors({
|
|
206
|
+
availableMessageIds: {
|
|
207
|
+
unexpectedGroupOrder: 'unexpectedDecoratorsGroupOrder',
|
|
208
|
+
unexpectedOrder: 'unexpectedDecoratorsOrder',
|
|
209
|
+
},
|
|
210
|
+
ignoreFirstNodeHighestBlockComment: true,
|
|
211
|
+
sortNodesExcludingEslintDisabled,
|
|
212
|
+
sourceCode,
|
|
213
|
+
options,
|
|
214
|
+
context,
|
|
215
|
+
nodes,
|
|
255
216
|
})
|
|
256
217
|
}
|
|
257
218
|
module.exports = sortDecorators
|