eslint-plugin-perfectionist 4.7.0 → 4.8.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.js +6 -9
- package/dist/rules/sort-classes.js +30 -14
- package/dist/rules/sort-decorators.js +52 -53
- package/dist/rules/sort-enums/does-custom-group-match.js +36 -0
- package/dist/rules/sort-enums/types.js +8 -0
- package/dist/rules/sort-enums.js +67 -14
- package/dist/rules/sort-exports.js +2 -1
- package/dist/rules/sort-heritage-clauses.js +5 -6
- package/dist/rules/sort-imports.js +7 -8
- package/dist/rules/sort-interfaces.js +17 -20
- package/dist/rules/sort-intersection-types.js +5 -8
- package/dist/rules/sort-jsx-props.js +5 -8
- package/dist/rules/sort-maps.js +10 -14
- package/dist/rules/sort-modules.js +9 -13
- package/dist/rules/sort-named-exports.js +19 -7
- package/dist/rules/sort-named-imports.js +2 -2
- package/dist/rules/sort-object-types.js +18 -22
- package/dist/rules/sort-objects.js +7 -11
- package/dist/rules/sort-sets.js +5 -7
- package/dist/rules/sort-switch-case.js +6 -7
- package/dist/rules/sort-union-types.js +17 -20
- package/dist/rules/sort-variable-declarations.js +6 -6
- package/dist/utils/get-custom-groups-compare-options.js +1 -4
- package/dist/utils/get-newlines-between-option.js +20 -4
- package/dist/utils/get-newlines-errors.js +9 -0
- package/dist/utils/is-newlines-between-option.js +5 -0
- package/dist/utils/make-fixes.js +2 -0
- package/dist/utils/make-newlines-fixes.js +9 -0
- package/dist/utils/report-all-errors.js +6 -3
- package/dist/utils/report-errors.js +29 -10
- package/dist/utils/sort-nodes-by-dependencies.js +1 -3
- package/dist/utils/validate-generated-groups-configuration.js +6 -7
- package/dist/utils/validate-groups-configuration.js +3 -2
- package/dist/utils/validate-newlines-and-partition-configuration.js +3 -2
- package/package.json +3 -3
|
@@ -4,6 +4,7 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
[Symbol.toStringTag]: { value: 'Module' },
|
|
5
5
|
})
|
|
6
6
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
7
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
7
8
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
8
9
|
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
9
10
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
@@ -95,14 +96,11 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
|
|
|
95
96
|
}),
|
|
96
97
|
meta: {
|
|
97
98
|
messages: {
|
|
98
|
-
unexpectedArrayIncludesGroupOrder:
|
|
99
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
100
99
|
missedSpacingBetweenArrayIncludesMembers:
|
|
101
|
-
|
|
102
|
-
extraSpacingBetweenArrayIncludesMembers:
|
|
103
|
-
|
|
104
|
-
unexpectedArrayIncludesOrder:
|
|
105
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
100
|
+
reportErrors.MISSED_SPACING_ERROR,
|
|
101
|
+
extraSpacingBetweenArrayIncludesMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
102
|
+
unexpectedArrayIncludesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
103
|
+
unexpectedArrayIncludesOrder: reportErrors.ORDER_ERROR,
|
|
106
104
|
},
|
|
107
105
|
docs: {
|
|
108
106
|
description: 'Enforce sorted arrays before include method.',
|
|
@@ -144,10 +142,9 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
144
142
|
}
|
|
145
143
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
146
144
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
147
|
-
customGroups: options.customGroups,
|
|
148
145
|
selectors: types.allSelectors,
|
|
149
|
-
groups: options.groups,
|
|
150
146
|
modifiers: [],
|
|
147
|
+
options,
|
|
151
148
|
})
|
|
152
149
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
153
150
|
options,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
3
4
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
4
5
|
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
5
6
|
const types = require('./sort-classes/types.js')
|
|
@@ -77,10 +78,9 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
77
78
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
78
79
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
|
|
79
80
|
{
|
|
80
|
-
customGroups: options.customGroups,
|
|
81
81
|
modifiers: types.allModifiers,
|
|
82
82
|
selectors: types.allSelectors,
|
|
83
|
-
|
|
83
|
+
options,
|
|
84
84
|
},
|
|
85
85
|
)
|
|
86
86
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
@@ -432,10 +432,13 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
|
-
let
|
|
436
|
-
|
|
435
|
+
let overloadSignatureGroupMemberIndex =
|
|
436
|
+
overloadSignatureGroups.findIndex(overloadSignatures =>
|
|
437
437
|
overloadSignatures.includes(member),
|
|
438
|
-
)
|
|
438
|
+
)
|
|
439
|
+
let overloadSignatureGroupMember =
|
|
440
|
+
(_b = overloadSignatureGroups[overloadSignatureGroupMemberIndex]) ==
|
|
441
|
+
null
|
|
439
442
|
? void 0
|
|
440
443
|
: _b.at(-1)
|
|
441
444
|
let sortingNode = {
|
|
@@ -446,6 +449,10 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
446
449
|
isStatic: modifiers.includes('static'),
|
|
447
450
|
isPrivateHash,
|
|
448
451
|
}),
|
|
452
|
+
overloadSignaturesGroupId:
|
|
453
|
+
overloadSignatureGroupMemberIndex === -1
|
|
454
|
+
? null
|
|
455
|
+
: overloadSignatureGroupMemberIndex,
|
|
449
456
|
size: overloadSignatureGroupMember
|
|
450
457
|
? rangeToDiff.rangeToDiff(
|
|
451
458
|
overloadSignatureGroupMember,
|
|
@@ -500,6 +507,19 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
500
507
|
)
|
|
501
508
|
let nodes = formattedNodes.flat()
|
|
502
509
|
reportAllErrors.reportAllErrors({
|
|
510
|
+
newlinesBetweenValueGetter: ({
|
|
511
|
+
computedNewlinesBetween,
|
|
512
|
+
right,
|
|
513
|
+
left,
|
|
514
|
+
}) => {
|
|
515
|
+
if (
|
|
516
|
+
left.overloadSignaturesGroupId !== null &&
|
|
517
|
+
left.overloadSignaturesGroupId === right.overloadSignaturesGroupId
|
|
518
|
+
) {
|
|
519
|
+
return 'never'
|
|
520
|
+
}
|
|
521
|
+
return computedNewlinesBetween
|
|
522
|
+
},
|
|
503
523
|
availableMessageIds: {
|
|
504
524
|
missedSpacingBetweenMembers: 'missedSpacingBetweenClassMembers',
|
|
505
525
|
extraSpacingBetweenMembers: 'extraSpacingBetweenClassMembers',
|
|
@@ -542,15 +562,11 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
542
562
|
},
|
|
543
563
|
],
|
|
544
564
|
messages: {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
'Missed spacing between "{{left}}" and "{{right}}" objects.',
|
|
551
|
-
extraSpacingBetweenClassMembers:
|
|
552
|
-
'Extra spacing between "{{left}}" and "{{right}}" objects.',
|
|
553
|
-
unexpectedClassesOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
565
|
+
unexpectedClassesDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
566
|
+
missedSpacingBetweenClassMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
567
|
+
extraSpacingBetweenClassMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
568
|
+
unexpectedClassesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
569
|
+
unexpectedClassesOrder: reportErrors.ORDER_ERROR,
|
|
554
570
|
},
|
|
555
571
|
docs: {
|
|
556
572
|
url: 'https://perfectionist.dev/rules/sort-classes',
|
|
@@ -5,6 +5,7 @@ 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 reportErrors = require('../utils/report-errors.js')
|
|
8
9
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
9
10
|
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
10
11
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -33,59 +34,6 @@ let defaultOptions = {
|
|
|
33
34
|
groups: [],
|
|
34
35
|
}
|
|
35
36
|
const sortDecorators = createEslintRule.createEslintRule({
|
|
36
|
-
meta: {
|
|
37
|
-
schema: [
|
|
38
|
-
{
|
|
39
|
-
properties: {
|
|
40
|
-
...commonJsonSchemas.commonJsonSchemas,
|
|
41
|
-
sortOnParameters: {
|
|
42
|
-
description:
|
|
43
|
-
'Controls whether sorting should be enabled for method parameter decorators.',
|
|
44
|
-
type: 'boolean',
|
|
45
|
-
},
|
|
46
|
-
sortOnProperties: {
|
|
47
|
-
description:
|
|
48
|
-
'Controls whether sorting should be enabled for class property decorators.',
|
|
49
|
-
type: 'boolean',
|
|
50
|
-
},
|
|
51
|
-
sortOnAccessors: {
|
|
52
|
-
description:
|
|
53
|
-
'Controls whether sorting should be enabled for class accessor decorators.',
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
},
|
|
56
|
-
sortOnMethods: {
|
|
57
|
-
description:
|
|
58
|
-
'Controls whether sorting should be enabled for class method decorators.',
|
|
59
|
-
type: 'boolean',
|
|
60
|
-
},
|
|
61
|
-
sortOnClasses: {
|
|
62
|
-
description:
|
|
63
|
-
'Controls whether sorting should be enabled for class decorators.',
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
},
|
|
66
|
-
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
67
|
-
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
68
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
69
|
-
groups: commonJsonSchemas.groupsJsonSchema,
|
|
70
|
-
},
|
|
71
|
-
additionalProperties: false,
|
|
72
|
-
type: 'object',
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
messages: {
|
|
76
|
-
unexpectedDecoratorsGroupOrder:
|
|
77
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
78
|
-
unexpectedDecoratorsOrder:
|
|
79
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
80
|
-
},
|
|
81
|
-
docs: {
|
|
82
|
-
url: 'https://perfectionist.dev/rules/sort-decorators',
|
|
83
|
-
description: 'Enforce sorted decorators.',
|
|
84
|
-
recommended: true,
|
|
85
|
-
},
|
|
86
|
-
type: 'suggestion',
|
|
87
|
-
fixable: 'code',
|
|
88
|
-
},
|
|
89
37
|
create: context => {
|
|
90
38
|
let settings = getSettings.getSettings(context.settings)
|
|
91
39
|
let options = complete.complete(
|
|
@@ -150,6 +98,57 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
150
98
|
: null,
|
|
151
99
|
}
|
|
152
100
|
},
|
|
101
|
+
meta: {
|
|
102
|
+
schema: [
|
|
103
|
+
{
|
|
104
|
+
properties: {
|
|
105
|
+
...commonJsonSchemas.commonJsonSchemas,
|
|
106
|
+
sortOnParameters: {
|
|
107
|
+
description:
|
|
108
|
+
'Controls whether sorting should be enabled for method parameter decorators.',
|
|
109
|
+
type: 'boolean',
|
|
110
|
+
},
|
|
111
|
+
sortOnProperties: {
|
|
112
|
+
description:
|
|
113
|
+
'Controls whether sorting should be enabled for class property decorators.',
|
|
114
|
+
type: 'boolean',
|
|
115
|
+
},
|
|
116
|
+
sortOnAccessors: {
|
|
117
|
+
description:
|
|
118
|
+
'Controls whether sorting should be enabled for class accessor decorators.',
|
|
119
|
+
type: 'boolean',
|
|
120
|
+
},
|
|
121
|
+
sortOnMethods: {
|
|
122
|
+
description:
|
|
123
|
+
'Controls whether sorting should be enabled for class method decorators.',
|
|
124
|
+
type: 'boolean',
|
|
125
|
+
},
|
|
126
|
+
sortOnClasses: {
|
|
127
|
+
description:
|
|
128
|
+
'Controls whether sorting should be enabled for class decorators.',
|
|
129
|
+
type: 'boolean',
|
|
130
|
+
},
|
|
131
|
+
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
132
|
+
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
133
|
+
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
134
|
+
groups: commonJsonSchemas.groupsJsonSchema,
|
|
135
|
+
},
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
type: 'object',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
docs: {
|
|
141
|
+
url: 'https://perfectionist.dev/rules/sort-decorators',
|
|
142
|
+
description: 'Enforce sorted decorators.',
|
|
143
|
+
recommended: true,
|
|
144
|
+
},
|
|
145
|
+
messages: {
|
|
146
|
+
unexpectedDecoratorsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
147
|
+
unexpectedDecoratorsOrder: reportErrors.ORDER_ERROR,
|
|
148
|
+
},
|
|
149
|
+
type: 'suggestion',
|
|
150
|
+
fixable: 'code',
|
|
151
|
+
},
|
|
153
152
|
defaultOptions: [defaultOptions],
|
|
154
153
|
name: 'sort-decorators',
|
|
155
154
|
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const matches = require('../../utils/matches.js')
|
|
4
|
+
let doesCustomGroupMatch = props => {
|
|
5
|
+
if ('anyOf' in props.customGroup) {
|
|
6
|
+
return props.customGroup.anyOf.some(subgroup =>
|
|
7
|
+
doesCustomGroupMatch({ ...props, customGroup: subgroup }),
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
if (
|
|
11
|
+
'elementNamePattern' in props.customGroup &&
|
|
12
|
+
props.customGroup.elementNamePattern
|
|
13
|
+
) {
|
|
14
|
+
let matchesElementNamePattern = matches.matches(
|
|
15
|
+
props.elementName,
|
|
16
|
+
props.customGroup.elementNamePattern,
|
|
17
|
+
)
|
|
18
|
+
if (!matchesElementNamePattern) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (
|
|
23
|
+
'elementValuePattern' in props.customGroup &&
|
|
24
|
+
props.customGroup.elementValuePattern
|
|
25
|
+
) {
|
|
26
|
+
let matchesElementValuePattern = matches.matches(
|
|
27
|
+
props.elementValue,
|
|
28
|
+
props.customGroup.elementValuePattern,
|
|
29
|
+
)
|
|
30
|
+
if (!matchesElementValuePattern) {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
exports.doesCustomGroupMatch = doesCustomGroupMatch
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
4
|
+
let singleCustomGroupJsonSchema = {
|
|
5
|
+
elementValuePattern: commonJsonSchemas.elementValuePatternJsonSchema,
|
|
6
|
+
elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
|
|
7
|
+
}
|
|
8
|
+
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
4
|
+
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
5
|
+
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
3
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
7
|
+
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
4
8
|
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
5
9
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
10
|
+
const doesCustomGroupMatch = require('./sort-enums/does-custom-group-match.js')
|
|
6
11
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
12
|
+
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
13
|
+
const types = require('./sort-enums/types.js')
|
|
7
14
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
8
15
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
9
16
|
const shouldPartition = require('../utils/should-partition.js')
|
|
@@ -12,19 +19,22 @@ const getSourceCode = require('../utils/get-source-code.js')
|
|
|
12
19
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
13
20
|
const getSettings = require('../utils/get-settings.js')
|
|
14
21
|
const isSortable = require('../utils/is-sortable.js')
|
|
15
|
-
const
|
|
22
|
+
const useGroups = require('../utils/use-groups.js')
|
|
16
23
|
const complete = require('../utils/complete.js')
|
|
17
24
|
let defaultOptions = {
|
|
18
25
|
partitionByComment: false,
|
|
19
26
|
partitionByNewLine: false,
|
|
20
27
|
specialCharacters: 'keep',
|
|
28
|
+
newlinesBetween: 'ignore',
|
|
21
29
|
forceNumericSort: false,
|
|
22
30
|
type: 'alphabetical',
|
|
23
31
|
sortByValue: false,
|
|
24
32
|
ignoreCase: true,
|
|
25
33
|
locales: 'en-US',
|
|
34
|
+
customGroups: [],
|
|
26
35
|
alphabet: '',
|
|
27
36
|
order: 'asc',
|
|
37
|
+
groups: [],
|
|
28
38
|
}
|
|
29
39
|
const sortEnums = createEslintRule.createEslintRule({
|
|
30
40
|
create: context => ({
|
|
@@ -43,6 +53,16 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
43
53
|
defaultOptions,
|
|
44
54
|
)
|
|
45
55
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
56
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
|
|
57
|
+
{
|
|
58
|
+
selectors: [],
|
|
59
|
+
modifiers: [],
|
|
60
|
+
options,
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
64
|
+
options,
|
|
65
|
+
)
|
|
46
66
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
47
67
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
48
68
|
ruleName: context.id,
|
|
@@ -85,23 +105,40 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
85
105
|
enumDeclaration.id.name,
|
|
86
106
|
)
|
|
87
107
|
}
|
|
108
|
+
let name =
|
|
109
|
+
member.id.type === 'Literal'
|
|
110
|
+
? `${member.id.value}`
|
|
111
|
+
: sourceCode.getText(member.id)
|
|
112
|
+
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
113
|
+
for (let customGroup of options.customGroups) {
|
|
114
|
+
if (
|
|
115
|
+
doesCustomGroupMatch.doesCustomGroupMatch({
|
|
116
|
+
elementValue: sourceCode.getText(member.initializer),
|
|
117
|
+
elementName: name,
|
|
118
|
+
customGroup,
|
|
119
|
+
})
|
|
120
|
+
) {
|
|
121
|
+
defineGroup(customGroup.groupName, true)
|
|
122
|
+
if (getGroup() === customGroup.groupName) {
|
|
123
|
+
break
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
88
127
|
let lastSortingNode =
|
|
89
128
|
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
90
129
|
let sortingNode = {
|
|
91
130
|
numericValue: member.initializer
|
|
92
131
|
? getExpressionNumberValue(member.initializer)
|
|
93
132
|
: null,
|
|
94
|
-
name:
|
|
95
|
-
member.id.type === 'Literal'
|
|
96
|
-
? `${member.id.value}`
|
|
97
|
-
: sourceCode.getText(member.id),
|
|
98
133
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
99
134
|
member,
|
|
100
135
|
eslintDisabledLines,
|
|
101
136
|
),
|
|
102
137
|
size: rangeToDiff.rangeToDiff(member, sourceCode),
|
|
138
|
+
group: getGroup(),
|
|
103
139
|
node: member,
|
|
104
140
|
dependencies,
|
|
141
|
+
name,
|
|
105
142
|
}
|
|
106
143
|
if (
|
|
107
144
|
shouldPartition.shouldPartition({
|
|
@@ -125,6 +162,7 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
125
162
|
!Number.isNaN(sortingNode.numericValue),
|
|
126
163
|
)
|
|
127
164
|
let compareOptions = {
|
|
165
|
+
...options,
|
|
128
166
|
// Get the enum value rather than the name if needed.
|
|
129
167
|
nodeValueGetter:
|
|
130
168
|
options.sortByValue || (isNumericEnum && options.forceNumericSort)
|
|
@@ -155,16 +193,16 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
155
193
|
isNumericEnum && (options.forceNumericSort || options.sortByValue)
|
|
156
194
|
? 'natural'
|
|
157
195
|
: options.type,
|
|
158
|
-
specialCharacters: options.specialCharacters,
|
|
159
|
-
ignoreCase: options.ignoreCase,
|
|
160
|
-
alphabet: options.alphabet,
|
|
161
|
-
locales: options.locales,
|
|
162
|
-
order: options.order,
|
|
163
196
|
}
|
|
164
197
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
165
198
|
sortNodesByDependencies.sortNodesByDependencies(
|
|
166
199
|
formattedMembers.flatMap(sortingNodes =>
|
|
167
|
-
|
|
200
|
+
sortNodesByGroups.sortNodesByGroups(sortingNodes, compareOptions, {
|
|
201
|
+
getGroupCompareOptions: groupNumber =>
|
|
202
|
+
getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
|
|
203
|
+
compareOptions,
|
|
204
|
+
groupNumber,
|
|
205
|
+
),
|
|
168
206
|
ignoreEslintDisabledNodes,
|
|
169
207
|
}),
|
|
170
208
|
),
|
|
@@ -174,7 +212,10 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
174
212
|
)
|
|
175
213
|
reportAllErrors.reportAllErrors({
|
|
176
214
|
availableMessageIds: {
|
|
215
|
+
missedSpacingBetweenMembers: 'missedSpacingBetweenEnumsMembers',
|
|
216
|
+
extraSpacingBetweenMembers: 'extraSpacingBetweenEnumsMembers',
|
|
177
217
|
unexpectedDependencyOrder: 'unexpectedEnumsDependencyOrder',
|
|
218
|
+
unexpectedGroupOrder: 'unexpectedEnumsGroupOrder',
|
|
178
219
|
unexpectedOrder: 'unexpectedEnumsOrder',
|
|
179
220
|
},
|
|
180
221
|
sortNodesExcludingEslintDisabled,
|
|
@@ -195,22 +236,34 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
195
236
|
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
196
237
|
type: 'boolean',
|
|
197
238
|
},
|
|
239
|
+
customGroups: {
|
|
240
|
+
oneOf: [
|
|
241
|
+
commonJsonSchemas.customGroupsJsonSchema,
|
|
242
|
+
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
243
|
+
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
244
|
+
}),
|
|
245
|
+
],
|
|
246
|
+
},
|
|
198
247
|
sortByValue: {
|
|
199
248
|
description: 'Compare enum values instead of names.',
|
|
200
249
|
type: 'boolean',
|
|
201
250
|
},
|
|
202
251
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
203
252
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
253
|
+
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
204
254
|
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
255
|
+
groups: commonJsonSchemas.groupsJsonSchema,
|
|
205
256
|
},
|
|
206
257
|
additionalProperties: false,
|
|
207
258
|
type: 'object',
|
|
208
259
|
},
|
|
209
260
|
],
|
|
210
261
|
messages: {
|
|
211
|
-
unexpectedEnumsDependencyOrder:
|
|
212
|
-
|
|
213
|
-
|
|
262
|
+
unexpectedEnumsDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
263
|
+
missedSpacingBetweenEnumsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
264
|
+
extraSpacingBetweenEnumsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
265
|
+
unexpectedEnumsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
266
|
+
unexpectedEnumsOrder: reportErrors.ORDER_ERROR,
|
|
214
267
|
},
|
|
215
268
|
docs: {
|
|
216
269
|
url: 'https://perfectionist.dev/rules/sort-enums',
|
|
@@ -8,6 +8,7 @@ const reportAllErrors = require('../utils/report-all-errors.js')
|
|
|
8
8
|
const shouldPartition = require('../utils/should-partition.js')
|
|
9
9
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
10
10
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
11
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
11
12
|
const getSettings = require('../utils/get-settings.js')
|
|
12
13
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
13
14
|
const complete = require('../utils/complete.js')
|
|
@@ -130,7 +131,7 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
130
131
|
recommended: true,
|
|
131
132
|
},
|
|
132
133
|
messages: {
|
|
133
|
-
unexpectedExportsOrder:
|
|
134
|
+
unexpectedExportsOrder: reportErrors.ORDER_ERROR,
|
|
134
135
|
},
|
|
135
136
|
type: 'suggestion',
|
|
136
137
|
fixable: 'code',
|
|
@@ -4,6 +4,7 @@ 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 reportErrors = require('../utils/report-errors.js')
|
|
7
8
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
9
10
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
@@ -37,17 +38,15 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
37
38
|
type: 'object',
|
|
38
39
|
},
|
|
39
40
|
],
|
|
40
|
-
messages: {
|
|
41
|
-
unexpectedHeritageClausesGroupOrder:
|
|
42
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
43
|
-
unexpectedHeritageClausesOrder:
|
|
44
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
45
|
-
},
|
|
46
41
|
docs: {
|
|
47
42
|
url: 'https://perfectionist.dev/rules/sort-heritage-clauses',
|
|
48
43
|
description: 'Enforce sorted heritage clauses.',
|
|
49
44
|
recommended: true,
|
|
50
45
|
},
|
|
46
|
+
messages: {
|
|
47
|
+
unexpectedHeritageClausesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
48
|
+
unexpectedHeritageClausesOrder: reportErrors.ORDER_ERROR,
|
|
49
|
+
},
|
|
51
50
|
type: 'suggestion',
|
|
52
51
|
fixable: 'code',
|
|
53
52
|
},
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const node_module = require('node:module')
|
|
3
3
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
4
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
4
5
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
5
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
6
7
|
const readClosestTsConfigByPath = require('./sort-imports/read-closest-ts-config-by-path.js')
|
|
7
8
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
8
9
|
const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
|
|
10
|
+
const isNewlinesBetweenOption = require('../utils/is-newlines-between-option.js')
|
|
9
11
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
10
12
|
const getTypescriptImport = require('./sort-imports/get-typescript-import.js')
|
|
11
13
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
@@ -90,7 +92,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
90
92
|
})
|
|
91
93
|
: null
|
|
92
94
|
let isSideEffectOnlyGroup = group => {
|
|
93
|
-
if (!group || (
|
|
95
|
+
if (!group || isNewlinesBetweenOption.isNewlinesBetweenOption(group)) {
|
|
94
96
|
return false
|
|
95
97
|
}
|
|
96
98
|
if (typeof group === 'string') {
|
|
@@ -496,13 +498,10 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
496
498
|
},
|
|
497
499
|
],
|
|
498
500
|
messages: {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
extraSpacingBetweenImports:
|
|
504
|
-
'Extra spacing between "{{left}}" and "{{right}}" imports.',
|
|
505
|
-
unexpectedImportsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
501
|
+
missedSpacingBetweenImports: reportErrors.MISSED_SPACING_ERROR,
|
|
502
|
+
extraSpacingBetweenImports: reportErrors.EXTRA_SPACING_ERROR,
|
|
503
|
+
unexpectedImportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
504
|
+
unexpectedImportsOrder: reportErrors.ORDER_ERROR,
|
|
506
505
|
},
|
|
507
506
|
docs: {
|
|
508
507
|
url: 'https://perfectionist.dev/rules/sort-imports',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
2
3
|
const sortObjectTypes = require('./sort-object-types.js')
|
|
3
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
4
5
|
let defaultOptions = {
|
|
@@ -18,26 +19,6 @@ let defaultOptions = {
|
|
|
18
19
|
groups: [],
|
|
19
20
|
}
|
|
20
21
|
const sortInterfaces = createEslintRule.createEslintRule({
|
|
21
|
-
meta: {
|
|
22
|
-
messages: {
|
|
23
|
-
unexpectedInterfacePropertiesGroupOrder:
|
|
24
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
25
|
-
missedSpacingBetweenInterfaceMembers:
|
|
26
|
-
'Missed spacing between "{{left}}" and "{{right}}" properties.',
|
|
27
|
-
extraSpacingBetweenInterfaceMembers:
|
|
28
|
-
'Extra spacing between "{{left}}" and "{{right}}" properties.',
|
|
29
|
-
unexpectedInterfacePropertiesOrder:
|
|
30
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
31
|
-
},
|
|
32
|
-
docs: {
|
|
33
|
-
url: 'https://perfectionist.dev/rules/sort-interfaces',
|
|
34
|
-
description: 'Enforce sorted interface properties.',
|
|
35
|
-
recommended: true,
|
|
36
|
-
},
|
|
37
|
-
schema: sortObjectTypes.jsonSchema,
|
|
38
|
-
type: 'suggestion',
|
|
39
|
-
fixable: 'code',
|
|
40
|
-
},
|
|
41
22
|
create: context => ({
|
|
42
23
|
TSInterfaceDeclaration: node =>
|
|
43
24
|
sortObjectTypes.sortObjectTypeElements({
|
|
@@ -52,6 +33,22 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
52
33
|
context,
|
|
53
34
|
}),
|
|
54
35
|
}),
|
|
36
|
+
meta: {
|
|
37
|
+
messages: {
|
|
38
|
+
unexpectedInterfacePropertiesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
39
|
+
missedSpacingBetweenInterfaceMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
40
|
+
extraSpacingBetweenInterfaceMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
41
|
+
unexpectedInterfacePropertiesOrder: reportErrors.ORDER_ERROR,
|
|
42
|
+
},
|
|
43
|
+
docs: {
|
|
44
|
+
url: 'https://perfectionist.dev/rules/sort-interfaces',
|
|
45
|
+
description: 'Enforce sorted interface properties.',
|
|
46
|
+
recommended: true,
|
|
47
|
+
},
|
|
48
|
+
schema: sortObjectTypes.jsonSchema,
|
|
49
|
+
type: 'suggestion',
|
|
50
|
+
fixable: 'code',
|
|
51
|
+
},
|
|
55
52
|
defaultOptions: [defaultOptions],
|
|
56
53
|
name: 'sort-interfaces',
|
|
57
54
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
2
3
|
const sortUnionTypes = require('./sort-union-types.js')
|
|
3
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
4
5
|
let defaultOptions = {
|
|
@@ -16,14 +17,10 @@ let defaultOptions = {
|
|
|
16
17
|
const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
17
18
|
meta: {
|
|
18
19
|
messages: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
extraSpacingBetweenIntersectionTypes:
|
|
24
|
-
'Extra spacing between "{{left}}" and "{{right}}" types.',
|
|
25
|
-
unexpectedIntersectionTypesOrder:
|
|
26
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
20
|
+
missedSpacingBetweenIntersectionTypes: reportErrors.MISSED_SPACING_ERROR,
|
|
21
|
+
extraSpacingBetweenIntersectionTypes: reportErrors.EXTRA_SPACING_ERROR,
|
|
22
|
+
unexpectedIntersectionTypesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
23
|
+
unexpectedIntersectionTypesOrder: reportErrors.ORDER_ERROR,
|
|
27
24
|
},
|
|
28
25
|
docs: {
|
|
29
26
|
url: 'https://perfectionist.dev/rules/sort-intersection-types',
|