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
|
@@ -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 validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
5
6
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
@@ -159,14 +160,10 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
159
160
|
},
|
|
160
161
|
],
|
|
161
162
|
messages: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
extraSpacingBetweenJSXPropsMembers:
|
|
167
|
-
'Extra spacing between "{{left}}" and "{{right}}" props.',
|
|
168
|
-
unexpectedJSXPropsOrder:
|
|
169
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
163
|
+
missedSpacingBetweenJSXPropsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
164
|
+
extraSpacingBetweenJSXPropsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
165
|
+
unexpectedJSXPropsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
166
|
+
unexpectedJSXPropsOrder: reportErrors.ORDER_ERROR,
|
|
170
167
|
},
|
|
171
168
|
docs: {
|
|
172
169
|
url: 'https://perfectionist.dev/rules/sort-jsx-props',
|
package/dist/rules/sort-maps.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
const types = require('@typescript-eslint/types')
|
|
2
|
+
const types$1 = require('@typescript-eslint/types')
|
|
3
3
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
4
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
4
5
|
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
5
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
6
7
|
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
@@ -9,7 +10,7 @@ const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
|
9
10
|
const doesCustomGroupMatch = require('./sort-maps/does-custom-group-match.js')
|
|
10
11
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
11
12
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
12
|
-
const types
|
|
13
|
+
const types = require('./sort-maps/types.js')
|
|
13
14
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
14
15
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
15
16
|
const shouldPartition = require('../utils/should-partition.js')
|
|
@@ -58,7 +59,7 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
58
59
|
.filter(
|
|
59
60
|
element =>
|
|
60
61
|
element !== null &&
|
|
61
|
-
element.type !== types.TSESTree.AST_NODE_TYPES.SpreadElement,
|
|
62
|
+
element.type !== types$1.TSESTree.AST_NODE_TYPES.SpreadElement,
|
|
62
63
|
)
|
|
63
64
|
.map(element => getNodeName({ sourceCode, element })),
|
|
64
65
|
contextOptions: context.options,
|
|
@@ -71,10 +72,9 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
71
72
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
72
73
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
|
|
73
74
|
{
|
|
74
|
-
customGroups: options.customGroups,
|
|
75
|
-
groups: options.groups,
|
|
76
75
|
selectors: [],
|
|
77
76
|
modifiers: [],
|
|
77
|
+
options,
|
|
78
78
|
},
|
|
79
79
|
)
|
|
80
80
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
@@ -172,7 +172,7 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
172
172
|
properties: {
|
|
173
173
|
...commonJsonSchemas.commonJsonSchemas,
|
|
174
174
|
customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
175
|
-
singleCustomGroupJsonSchema: types
|
|
175
|
+
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
176
176
|
}),
|
|
177
177
|
useConfigurationIf:
|
|
178
178
|
commonJsonSchemas.buildUseConfigurationIfJsonSchema(),
|
|
@@ -189,14 +189,10 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
189
189
|
type: 'array',
|
|
190
190
|
},
|
|
191
191
|
messages: {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
extraSpacingBetweenMapElementsMembers:
|
|
197
|
-
'Extra spacing between "{{left}}" and "{{right}}" members.',
|
|
198
|
-
unexpectedMapElementsOrder:
|
|
199
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
192
|
+
missedSpacingBetweenMapElementsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
193
|
+
extraSpacingBetweenMapElementsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
194
|
+
unexpectedMapElementsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
195
|
+
unexpectedMapElementsOrder: reportErrors.ORDER_ERROR,
|
|
200
196
|
},
|
|
201
197
|
docs: {
|
|
202
198
|
url: 'https://perfectionist.dev/rules/sort-maps',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const utils = require('@typescript-eslint/utils')
|
|
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 validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
6
7
|
const types = require('./sort-modules/types.js')
|
|
@@ -53,17 +54,6 @@ let defaultOptions = {
|
|
|
53
54
|
}
|
|
54
55
|
const sortModules = createEslintRule.createEslintRule({
|
|
55
56
|
meta: {
|
|
56
|
-
messages: {
|
|
57
|
-
unexpectedModulesGroupOrder:
|
|
58
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
59
|
-
unexpectedModulesDependencyOrder:
|
|
60
|
-
'Expected dependency "{{right}}" to come before "{{nodeDependentOnRight}}".',
|
|
61
|
-
missedSpacingBetweenModulesMembers:
|
|
62
|
-
'Missed spacing between "{{left}}" and "{{right}}" objects.',
|
|
63
|
-
extraSpacingBetweenModulesMembers:
|
|
64
|
-
'Extra spacing between "{{left}}" and "{{right}}" objects.',
|
|
65
|
-
unexpectedModulesOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
66
|
-
},
|
|
67
57
|
schema: [
|
|
68
58
|
{
|
|
69
59
|
properties: {
|
|
@@ -81,6 +71,13 @@ const sortModules = createEslintRule.createEslintRule({
|
|
|
81
71
|
type: 'object',
|
|
82
72
|
},
|
|
83
73
|
],
|
|
74
|
+
messages: {
|
|
75
|
+
unexpectedModulesDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
76
|
+
missedSpacingBetweenModulesMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
77
|
+
extraSpacingBetweenModulesMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
78
|
+
unexpectedModulesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
79
|
+
unexpectedModulesOrder: reportErrors.ORDER_ERROR,
|
|
80
|
+
},
|
|
84
81
|
docs: {
|
|
85
82
|
url: 'https://perfectionist.dev/rules/sort-modules',
|
|
86
83
|
description: 'Enforce sorted modules.',
|
|
@@ -98,10 +95,9 @@ const sortModules = createEslintRule.createEslintRule({
|
|
|
98
95
|
)
|
|
99
96
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
100
97
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
101
|
-
customGroups: options.customGroups,
|
|
102
98
|
modifiers: types.allModifiers,
|
|
103
99
|
selectors: types.allSelectors,
|
|
104
|
-
|
|
100
|
+
options,
|
|
105
101
|
})
|
|
106
102
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
107
103
|
options,
|
|
@@ -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 isSortable = require('../utils/is-sortable.js')
|
|
13
14
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -17,6 +18,7 @@ let defaultOptions = {
|
|
|
17
18
|
partitionByNewLine: false,
|
|
18
19
|
partitionByComment: false,
|
|
19
20
|
type: 'alphabetical',
|
|
21
|
+
ignoreAlias: false,
|
|
20
22
|
groupKind: 'mixed',
|
|
21
23
|
ignoreCase: true,
|
|
22
24
|
locales: 'en-US',
|
|
@@ -44,12 +46,19 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
44
46
|
})
|
|
45
47
|
let formattedMembers = [[]]
|
|
46
48
|
for (let specifier of node.specifiers) {
|
|
47
|
-
let groupKind = specifier.exportKind === 'type' ? 'type' : 'value'
|
|
48
49
|
let name
|
|
49
|
-
if (
|
|
50
|
-
|
|
50
|
+
if (options.ignoreAlias) {
|
|
51
|
+
if (specifier.local.type === 'Identifier') {
|
|
52
|
+
;({ name } = specifier.local)
|
|
53
|
+
} else {
|
|
54
|
+
name = specifier.local.value
|
|
55
|
+
}
|
|
51
56
|
} else {
|
|
52
|
-
|
|
57
|
+
if (specifier.exported.type === 'Identifier') {
|
|
58
|
+
;({ name } = specifier.exported)
|
|
59
|
+
} else {
|
|
60
|
+
name = specifier.exported.value
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
let lastSortingNode =
|
|
55
64
|
(_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
|
|
@@ -58,9 +67,9 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
58
67
|
specifier,
|
|
59
68
|
eslintDisabledLines,
|
|
60
69
|
),
|
|
70
|
+
groupKind: specifier.exportKind === 'type' ? 'type' : 'value',
|
|
61
71
|
size: rangeToDiff.rangeToDiff(specifier, sourceCode),
|
|
62
72
|
node: specifier,
|
|
63
|
-
groupKind,
|
|
64
73
|
name,
|
|
65
74
|
}
|
|
66
75
|
if (
|
|
@@ -119,6 +128,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
119
128
|
description: 'Specifies top-level groups.',
|
|
120
129
|
type: 'string',
|
|
121
130
|
},
|
|
131
|
+
ignoreAlias: {
|
|
132
|
+
description: 'Controls whether to ignore alias names.',
|
|
133
|
+
type: 'boolean',
|
|
134
|
+
},
|
|
122
135
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
123
136
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
124
137
|
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
@@ -133,8 +146,7 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
133
146
|
recommended: true,
|
|
134
147
|
},
|
|
135
148
|
messages: {
|
|
136
|
-
unexpectedNamedExportsOrder:
|
|
137
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
149
|
+
unexpectedNamedExportsOrder: reportErrors.ORDER_ERROR,
|
|
138
150
|
},
|
|
139
151
|
type: 'suggestion',
|
|
140
152
|
fixable: 'code',
|
|
@@ -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 isSortable = require('../utils/is-sortable.js')
|
|
13
14
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -146,8 +147,7 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
146
147
|
recommended: true,
|
|
147
148
|
},
|
|
148
149
|
messages: {
|
|
149
|
-
unexpectedNamedImportsOrder:
|
|
150
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
150
|
+
unexpectedNamedImportsOrder: reportErrors.ORDER_ERROR,
|
|
151
151
|
},
|
|
152
152
|
type: 'suggestion',
|
|
153
153
|
fixable: 'code',
|
|
@@ -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 types = require('./sort-object-types/types.js')
|
|
9
10
|
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
@@ -89,26 +90,6 @@ let jsonSchema = {
|
|
|
89
90
|
type: 'array',
|
|
90
91
|
}
|
|
91
92
|
const sortObjectTypes = createEslintRule.createEslintRule({
|
|
92
|
-
meta: {
|
|
93
|
-
messages: {
|
|
94
|
-
unexpectedObjectTypesGroupOrder:
|
|
95
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
96
|
-
missedSpacingBetweenObjectTypeMembers:
|
|
97
|
-
'Missed spacing between "{{left}}" and "{{right}}" properties.',
|
|
98
|
-
extraSpacingBetweenObjectTypeMembers:
|
|
99
|
-
'Extra spacing between "{{left}}" and "{{right}}" properties.',
|
|
100
|
-
unexpectedObjectTypesOrder:
|
|
101
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
102
|
-
},
|
|
103
|
-
docs: {
|
|
104
|
-
url: 'https://perfectionist.dev/rules/sort-object-types',
|
|
105
|
-
description: 'Enforce sorted object types.',
|
|
106
|
-
recommended: true,
|
|
107
|
-
},
|
|
108
|
-
schema: jsonSchema,
|
|
109
|
-
type: 'suggestion',
|
|
110
|
-
fixable: 'code',
|
|
111
|
-
},
|
|
112
93
|
create: context => ({
|
|
113
94
|
TSTypeLiteral: node =>
|
|
114
95
|
sortObjectTypeElements({
|
|
@@ -126,6 +107,22 @@ const sortObjectTypes = createEslintRule.createEslintRule({
|
|
|
126
107
|
context,
|
|
127
108
|
}),
|
|
128
109
|
}),
|
|
110
|
+
meta: {
|
|
111
|
+
messages: {
|
|
112
|
+
missedSpacingBetweenObjectTypeMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
113
|
+
extraSpacingBetweenObjectTypeMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
114
|
+
unexpectedObjectTypesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
115
|
+
unexpectedObjectTypesOrder: reportErrors.ORDER_ERROR,
|
|
116
|
+
},
|
|
117
|
+
docs: {
|
|
118
|
+
url: 'https://perfectionist.dev/rules/sort-object-types',
|
|
119
|
+
description: 'Enforce sorted object types.',
|
|
120
|
+
recommended: true,
|
|
121
|
+
},
|
|
122
|
+
schema: jsonSchema,
|
|
123
|
+
type: 'suggestion',
|
|
124
|
+
fixable: 'code',
|
|
125
|
+
},
|
|
129
126
|
defaultOptions: [defaultOptions],
|
|
130
127
|
name: 'sort-object-types',
|
|
131
128
|
})
|
|
@@ -179,10 +176,9 @@ let sortObjectTypeElements = ({
|
|
|
179
176
|
}
|
|
180
177
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
181
178
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
182
|
-
customGroups: options.customGroups,
|
|
183
179
|
selectors: types.allSelectors,
|
|
184
180
|
modifiers: types.allModifiers,
|
|
185
|
-
|
|
181
|
+
options,
|
|
186
182
|
})
|
|
187
183
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
188
184
|
options,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const types$1 = require('@typescript-eslint/types')
|
|
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 validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
6
7
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
@@ -105,10 +106,9 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
105
106
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
106
107
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
|
|
107
108
|
{
|
|
108
|
-
customGroups: options.customGroups,
|
|
109
109
|
selectors: types.allSelectors,
|
|
110
110
|
modifiers: types.allModifiers,
|
|
111
|
-
|
|
111
|
+
options,
|
|
112
112
|
},
|
|
113
113
|
)
|
|
114
114
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
@@ -447,15 +447,11 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
447
447
|
type: 'array',
|
|
448
448
|
},
|
|
449
449
|
messages: {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
'Missed spacing between "{{left}}" and "{{right}}" objects.',
|
|
456
|
-
extraSpacingBetweenObjectMembers:
|
|
457
|
-
'Extra spacing between "{{left}}" and "{{right}}" objects.',
|
|
458
|
-
unexpectedObjectsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
450
|
+
unexpectedObjectsDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
451
|
+
missedSpacingBetweenObjectMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
452
|
+
extraSpacingBetweenObjectMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
453
|
+
unexpectedObjectsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
454
|
+
unexpectedObjectsOrder: reportErrors.ORDER_ERROR,
|
|
459
455
|
},
|
|
460
456
|
docs: {
|
|
461
457
|
url: 'https://perfectionist.dev/rules/sort-objects',
|
package/dist/rules/sort-sets.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
2
3
|
const sortArrayIncludes = require('./sort-array-includes.js')
|
|
3
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
4
5
|
const sortSets = createEslintRule.createEslintRule({
|
|
@@ -35,13 +36,10 @@ const sortSets = createEslintRule.createEslintRule({
|
|
|
35
36
|
}),
|
|
36
37
|
meta: {
|
|
37
38
|
messages: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
extraSpacingBetweenSetsMembers:
|
|
43
|
-
'Extra spacing between "{{left}}" and "{{right}}" members.',
|
|
44
|
-
unexpectedSetsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
39
|
+
missedSpacingBetweenSetsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
40
|
+
extraSpacingBetweenSetsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
41
|
+
unexpectedSetsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
42
|
+
unexpectedSetsOrder: reportErrors.ORDER_ERROR,
|
|
45
43
|
},
|
|
46
44
|
docs: {
|
|
47
45
|
url: 'https://perfectionist.dev/rules/sort-sets',
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
const makeSingleNodeCommentAfterFixes = require('../utils/make-single-node-comment-after-fixes.js')
|
|
3
3
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
4
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
5
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
5
6
|
const createNodeIndexMap = require('../utils/create-node-index-map.js')
|
|
6
7
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
7
8
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
8
|
-
const reportErrors = require('../utils/report-errors.js')
|
|
9
9
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
10
10
|
const getSettings = require('../utils/get-settings.js')
|
|
11
11
|
const isSortable = require('../utils/is-sortable.js')
|
|
@@ -154,8 +154,8 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
154
154
|
]
|
|
155
155
|
},
|
|
156
156
|
data: {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
[reportErrors.LEFT]: defaultCase.name,
|
|
158
|
+
[reportErrors.RIGHT]: lastCase.name,
|
|
159
159
|
},
|
|
160
160
|
messageId: 'unexpectedSwitchCaseOrder',
|
|
161
161
|
node: defaultCase.node,
|
|
@@ -209,8 +209,8 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
209
209
|
fixer,
|
|
210
210
|
}),
|
|
211
211
|
data: {
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
[reportErrors.RIGHT]: right.name,
|
|
213
|
+
[reportErrors.LEFT]: left.name,
|
|
214
214
|
},
|
|
215
215
|
messageId: 'unexpectedSwitchCaseOrder',
|
|
216
216
|
node: right.node,
|
|
@@ -235,8 +235,7 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
235
235
|
recommended: true,
|
|
236
236
|
},
|
|
237
237
|
messages: {
|
|
238
|
-
unexpectedSwitchCaseOrder:
|
|
239
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
238
|
+
unexpectedSwitchCaseOrder: reportErrors.ORDER_ERROR,
|
|
240
239
|
},
|
|
241
240
|
type: 'suggestion',
|
|
242
241
|
fixable: 'code',
|
|
@@ -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 validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
9
10
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
@@ -43,26 +44,6 @@ let jsonSchema = {
|
|
|
43
44
|
type: 'object',
|
|
44
45
|
}
|
|
45
46
|
const sortUnionTypes = createEslintRule.createEslintRule({
|
|
46
|
-
meta: {
|
|
47
|
-
messages: {
|
|
48
|
-
unexpectedUnionTypesGroupOrder:
|
|
49
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
50
|
-
missedSpacingBetweenUnionTypes:
|
|
51
|
-
'Missed spacing between "{{left}}" and "{{right}}" types.',
|
|
52
|
-
extraSpacingBetweenUnionTypes:
|
|
53
|
-
'Extra spacing between "{{left}}" and "{{right}}" types.',
|
|
54
|
-
unexpectedUnionTypesOrder:
|
|
55
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
56
|
-
},
|
|
57
|
-
docs: {
|
|
58
|
-
url: 'https://perfectionist.dev/rules/sort-union-types',
|
|
59
|
-
description: 'Enforce sorted union types.',
|
|
60
|
-
recommended: true,
|
|
61
|
-
},
|
|
62
|
-
schema: [jsonSchema],
|
|
63
|
-
type: 'suggestion',
|
|
64
|
-
fixable: 'code',
|
|
65
|
-
},
|
|
66
47
|
create: context => ({
|
|
67
48
|
TSUnionType: node => {
|
|
68
49
|
sortUnionOrIntersectionTypes({
|
|
@@ -78,6 +59,22 @@ const sortUnionTypes = createEslintRule.createEslintRule({
|
|
|
78
59
|
})
|
|
79
60
|
},
|
|
80
61
|
}),
|
|
62
|
+
meta: {
|
|
63
|
+
messages: {
|
|
64
|
+
missedSpacingBetweenUnionTypes: reportErrors.MISSED_SPACING_ERROR,
|
|
65
|
+
extraSpacingBetweenUnionTypes: reportErrors.EXTRA_SPACING_ERROR,
|
|
66
|
+
unexpectedUnionTypesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
67
|
+
unexpectedUnionTypesOrder: reportErrors.ORDER_ERROR,
|
|
68
|
+
},
|
|
69
|
+
docs: {
|
|
70
|
+
url: 'https://perfectionist.dev/rules/sort-union-types',
|
|
71
|
+
description: 'Enforce sorted union types.',
|
|
72
|
+
recommended: true,
|
|
73
|
+
},
|
|
74
|
+
schema: [jsonSchema],
|
|
75
|
+
type: 'suggestion',
|
|
76
|
+
fixable: 'code',
|
|
77
|
+
},
|
|
81
78
|
defaultOptions: [defaultOptions],
|
|
82
79
|
name: 'sort-union-types',
|
|
83
80
|
})
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
3
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
4
|
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
5
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
5
6
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
6
7
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
7
8
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -195,17 +196,16 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
195
196
|
type: 'object',
|
|
196
197
|
},
|
|
197
198
|
],
|
|
198
|
-
messages: {
|
|
199
|
-
unexpectedVariableDeclarationsDependencyOrder:
|
|
200
|
-
'Expected dependency "{{right}}" to come before "{{nodeDependentOnRight}}".',
|
|
201
|
-
unexpectedVariableDeclarationsOrder:
|
|
202
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
203
|
-
},
|
|
204
199
|
docs: {
|
|
205
200
|
url: 'https://perfectionist.dev/rules/sort-variable-declarations',
|
|
206
201
|
description: 'Enforce sorted variable declarations.',
|
|
207
202
|
recommended: true,
|
|
208
203
|
},
|
|
204
|
+
messages: {
|
|
205
|
+
unexpectedVariableDeclarationsDependencyOrder:
|
|
206
|
+
reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
207
|
+
unexpectedVariableDeclarationsOrder: reportErrors.ORDER_ERROR,
|
|
208
|
+
},
|
|
209
209
|
type: 'suggestion',
|
|
210
210
|
fixable: 'code',
|
|
211
211
|
},
|
|
@@ -15,15 +15,12 @@ let getCustomGroupsCompareOptions = (options, groupNumber) => {
|
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
18
|
+
...options,
|
|
18
19
|
order:
|
|
19
20
|
customGroup && 'order' in customGroup && customGroup.order
|
|
20
21
|
? customGroup.order
|
|
21
22
|
: options.order,
|
|
22
|
-
specialCharacters: options.specialCharacters,
|
|
23
23
|
type: (customGroup == null ? void 0 : customGroup.type) ?? options.type,
|
|
24
|
-
ignoreCase: options.ignoreCase,
|
|
25
|
-
alphabet: options.alphabet,
|
|
26
|
-
locales: options.locales,
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
exports.getCustomGroupsCompareOptions = getCustomGroupsCompareOptions
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const isNewlinesBetweenOption = require('./is-newlines-between-option.js')
|
|
3
4
|
const getGroupNumber = require('./get-group-number.js')
|
|
4
5
|
let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
|
|
5
6
|
let nodeGroupNumber = getGroupNumber.getGroupNumber(
|
|
@@ -37,10 +38,25 @@ let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
|
|
|
37
38
|
return nodeCustomGroup.newlinesInside ?? globalNewlinesBetweenOption
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
if (nextNodeGroupNumber
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (nextNodeGroupNumber >= nodeGroupNumber + 2) {
|
|
42
|
+
if (nextNodeGroupNumber === nodeGroupNumber + 2) {
|
|
43
|
+
let groupBetween = options.groups[nodeGroupNumber + 1]
|
|
44
|
+
if (isNewlinesBetweenOption.isNewlinesBetweenOption(groupBetween)) {
|
|
45
|
+
return groupBetween.newlinesBetween
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (globalNewlinesBetweenOption === 'always') {
|
|
49
|
+
return 'always'
|
|
50
|
+
}
|
|
51
|
+
for (let i = nodeGroupNumber + 2; i < nextNodeGroupNumber; i++) {
|
|
52
|
+
let groupBetween = options.groups[i]
|
|
53
|
+
if (
|
|
54
|
+
isNewlinesBetweenOption.isNewlinesBetweenOption(groupBetween) &&
|
|
55
|
+
groupBetween.newlinesBetween !== 'never'
|
|
56
|
+
) {
|
|
57
|
+
return groupBetween.newlinesBetween
|
|
58
|
+
}
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
return globalNewlinesBetweenOption
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
|
3
3
|
const getNewlinesBetweenOption = require('./get-newlines-between-option.js')
|
|
4
4
|
const getLinesBetween = require('./get-lines-between.js')
|
|
5
5
|
let getNewlinesErrors = ({
|
|
6
|
+
newlinesBetweenValueGetter,
|
|
6
7
|
missedSpacingError,
|
|
7
8
|
extraSpacingError,
|
|
8
9
|
sourceCode,
|
|
@@ -17,6 +18,14 @@ let getNewlinesErrors = ({
|
|
|
17
18
|
sortingNode: left,
|
|
18
19
|
options,
|
|
19
20
|
})
|
|
21
|
+
newlinesBetween =
|
|
22
|
+
(newlinesBetweenValueGetter == null
|
|
23
|
+
? void 0
|
|
24
|
+
: newlinesBetweenValueGetter({
|
|
25
|
+
computedNewlinesBetween: newlinesBetween,
|
|
26
|
+
right,
|
|
27
|
+
left,
|
|
28
|
+
})) ?? newlinesBetween
|
|
20
29
|
if (leftNum > rightNum) {
|
|
21
30
|
return []
|
|
22
31
|
}
|
package/dist/utils/make-fixes.js
CHANGED
|
@@ -5,6 +5,7 @@ const makeNewlinesFixes = require('./make-newlines-fixes.js')
|
|
|
5
5
|
const makeOrderFixes = require('./make-order-fixes.js')
|
|
6
6
|
let makeFixes = ({
|
|
7
7
|
ignoreFirstNodeHighestBlockComment,
|
|
8
|
+
newlinesBetweenValueGetter,
|
|
8
9
|
sortedNodes,
|
|
9
10
|
sourceCode,
|
|
10
11
|
options,
|
|
@@ -38,6 +39,7 @@ let makeFixes = ({
|
|
|
38
39
|
newlinesBetween: options.newlinesBetween,
|
|
39
40
|
groups: options.groups,
|
|
40
41
|
},
|
|
42
|
+
newlinesBetweenValueGetter,
|
|
41
43
|
sortedNodes,
|
|
42
44
|
sourceCode,
|
|
43
45
|
fixer,
|
|
@@ -4,6 +4,7 @@ const getNewlinesBetweenOption = require('./get-newlines-between-option.js')
|
|
|
4
4
|
const getLinesBetween = require('./get-lines-between.js')
|
|
5
5
|
const getNodeRange = require('./get-node-range.js')
|
|
6
6
|
let makeNewlinesFixes = ({
|
|
7
|
+
newlinesBetweenValueGetter,
|
|
7
8
|
sortedNodes,
|
|
8
9
|
sourceCode,
|
|
9
10
|
options,
|
|
@@ -21,6 +22,14 @@ let makeNewlinesFixes = ({
|
|
|
21
22
|
sortingNode: sortedSortingNode,
|
|
22
23
|
options,
|
|
23
24
|
})
|
|
25
|
+
newlinesBetween =
|
|
26
|
+
(newlinesBetweenValueGetter == null
|
|
27
|
+
? void 0
|
|
28
|
+
: newlinesBetweenValueGetter({
|
|
29
|
+
computedNewlinesBetween: newlinesBetween,
|
|
30
|
+
right: nextSortedSortingNode,
|
|
31
|
+
left: sortedSortingNode,
|
|
32
|
+
})) ?? newlinesBetween
|
|
24
33
|
if (newlinesBetween === 'ignore') {
|
|
25
34
|
continue
|
|
26
35
|
}
|