eslint-plugin-perfectionist 5.2.0 → 5.3.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/package.json.js +1 -1
- package/dist/rules/sort-array-includes/types.d.ts +15 -18
- package/dist/rules/sort-array-includes/types.js +2 -2
- package/dist/rules/sort-array-includes.js +13 -10
- package/dist/rules/sort-classes/compute-dependencies.d.ts +24 -0
- package/dist/rules/sort-classes/compute-dependencies.js +147 -0
- package/dist/rules/sort-classes/compute-dependency-name.d.ts +9 -0
- package/dist/rules/sort-classes/compute-dependency-name.js +8 -0
- package/dist/rules/sort-classes/compute-identifier-name-details.d.ts +16 -0
- package/dist/rules/sort-classes/compute-identifier-name-details.js +27 -0
- package/dist/rules/sort-classes/get-overload-signature-groups.js +4 -3
- package/dist/rules/sort-classes/node-info/common-modifiers.d.ts +39 -0
- package/dist/rules/sort-classes/node-info/common-modifiers.js +62 -0
- package/dist/rules/sort-classes/node-info/compute-accessor-details.d.ts +26 -0
- package/dist/rules/sort-classes/node-info/compute-accessor-details.js +43 -0
- package/dist/rules/sort-classes/node-info/compute-index-signature-details.d.ts +23 -0
- package/dist/rules/sort-classes/node-info/compute-index-signature-details.js +21 -0
- package/dist/rules/sort-classes/node-info/compute-method-details.d.ts +29 -0
- package/dist/rules/sort-classes/node-info/compute-method-details.js +80 -0
- package/dist/rules/sort-classes/node-info/compute-method-or-property-name-details.d.ts +21 -0
- package/dist/rules/sort-classes/node-info/compute-method-or-property-name-details.js +17 -0
- package/dist/rules/sort-classes/node-info/compute-property-details.d.ts +36 -0
- package/dist/rules/sort-classes/node-info/compute-property-details.js +109 -0
- package/dist/rules/sort-classes/node-info/compute-static-block-details.d.ts +26 -0
- package/dist/rules/sort-classes/node-info/compute-static-block-details.js +18 -0
- package/dist/rules/sort-classes/types.d.ts +15 -18
- package/dist/rules/sort-classes/types.js +6 -2
- package/dist/rules/sort-classes.js +79 -291
- package/dist/rules/sort-decorators/types.d.ts +10 -12
- package/dist/rules/sort-decorators.js +57 -56
- package/dist/rules/sort-enums/build-comparator-by-options-computer.js +6 -0
- package/dist/rules/sort-enums/types.d.ts +16 -19
- package/dist/rules/sort-enums/types.js +2 -2
- package/dist/rules/sort-enums.js +13 -11
- package/dist/rules/sort-export-attributes/types.d.ts +6 -8
- package/dist/rules/sort-export-attributes.js +2 -1
- package/dist/rules/sort-exports/types.d.ts +11 -10
- package/dist/rules/sort-exports/types.js +6 -2
- package/dist/rules/sort-exports.js +7 -6
- package/dist/rules/sort-heritage-clauses/types.d.ts +6 -8
- package/dist/rules/sort-heritage-clauses.js +2 -1
- package/dist/rules/sort-import-attributes/types.d.ts +6 -8
- package/dist/rules/sort-import-attributes.js +2 -1
- package/dist/rules/sort-imports/comparator-by-options-computer.js +5 -0
- package/dist/rules/sort-imports/compute-specifier-modifiers.js +1 -1
- package/dist/rules/sort-imports/is-non-external-reference-ts-import-equals.js +1 -1
- package/dist/rules/sort-imports/is-side-effect-import.js +1 -1
- package/dist/rules/sort-imports/types.d.ts +18 -24
- package/dist/rules/sort-imports/types.js +9 -6
- package/dist/rules/sort-imports.js +25 -17
- package/dist/rules/sort-jsx-props/types.d.ts +18 -18
- package/dist/rules/sort-jsx-props/types.js +6 -2
- package/dist/rules/sort-jsx-props.js +14 -7
- package/dist/rules/sort-maps/types.d.ts +10 -16
- package/dist/rules/sort-maps.js +11 -6
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +2 -0
- package/dist/rules/sort-modules/compute-dependencies.d.ts +2 -5
- package/dist/rules/sort-modules/compute-dependencies.js +3 -0
- package/dist/rules/sort-modules/compute-node-details.d.ts +38 -0
- package/dist/rules/sort-modules/compute-node-details.js +127 -0
- package/dist/rules/sort-modules/is-arrow-function-node.js +1 -1
- package/dist/rules/sort-modules/is-property-or-accessor-node.js +1 -1
- package/dist/rules/sort-modules/types.d.ts +24 -17
- package/dist/rules/sort-modules/types.js +2 -2
- package/dist/rules/sort-modules.js +72 -141
- package/dist/rules/sort-named-exports/compute-node-name.js +1 -1
- package/dist/rules/sort-named-exports/types.d.ts +16 -16
- package/dist/rules/sort-named-exports/types.js +6 -2
- package/dist/rules/sort-named-exports.js +6 -5
- package/dist/rules/sort-named-imports/compute-node-name.js +1 -1
- package/dist/rules/sort-named-imports/types.d.ts +16 -17
- package/dist/rules/sort-named-imports/types.js +6 -2
- package/dist/rules/sort-named-imports.js +7 -6
- package/dist/rules/sort-object-types/comparator-by-options-computer.js +3 -0
- package/dist/rules/sort-object-types/is-member-optional.js +1 -1
- package/dist/rules/sort-object-types/is-node-function-type.js +20 -0
- package/dist/rules/sort-object-types/types.d.ts +21 -34
- package/dist/rules/sort-object-types/types.js +9 -6
- package/dist/rules/sort-object-types.js +7 -6
- package/dist/rules/sort-objects/types.d.ts +17 -21
- package/dist/rules/sort-objects/types.js +3 -3
- package/dist/rules/sort-objects.js +5 -3
- package/dist/rules/sort-sets.js +5 -4
- package/dist/rules/sort-switch-case.js +6 -4
- package/dist/rules/sort-union-types/types.d.ts +12 -12
- package/dist/rules/sort-union-types/types.js +2 -2
- package/dist/rules/sort-union-types.js +37 -35
- package/dist/rules/sort-variable-declarations/types.d.ts +12 -13
- package/dist/rules/sort-variable-declarations/types.js +2 -2
- package/dist/rules/sort-variable-declarations.js +14 -12
- package/dist/types/all-common-options.d.ts +14 -0
- package/dist/types/common-groups-options.d.ts +73 -95
- package/dist/types/common-options.d.ts +60 -55
- package/dist/utils/build-default-options-by-group-index-computer.d.ts +1 -1
- package/dist/utils/compare/build-string-formatter.d.ts +4 -5
- package/dist/utils/compare/build-subgroup-order-comparator.d.ts +10 -0
- package/dist/utils/compare/build-subgroup-order-comparator.js +49 -0
- package/dist/utils/compare/default-comparator-by-options-computer.d.ts +4 -1
- package/dist/utils/compare/default-comparator-by-options-computer.js +9 -0
- package/dist/utils/compute-group.d.ts +9 -9
- package/dist/utils/compute-overridden-options-by-group-index.d.ts +1 -1
- package/dist/utils/does-custom-group-match.d.ts +6 -4
- package/dist/utils/get-comment-above-that-should-exist.d.ts +1 -1
- package/dist/utils/get-newlines-between-errors.d.ts +1 -1
- package/dist/utils/get-newlines-between-option.d.ts +1 -7
- package/dist/utils/get-node-range.d.ts +2 -9
- package/dist/utils/get-settings.d.ts +1 -1
- package/dist/utils/is-group-with-overrides-option.d.ts +3 -6
- package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +6 -6
- package/dist/utils/json-schemas/common-groups-json-schemas.js +12 -10
- package/dist/utils/json-schemas/common-json-schemas.d.ts +5 -5
- package/dist/utils/json-schemas/common-json-schemas.js +13 -12
- package/dist/utils/make-comment-above-fixes.d.ts +1 -1
- package/dist/utils/make-fixes.d.ts +3 -5
- package/dist/utils/make-newlines-between-fixes.d.ts +1 -1
- package/dist/utils/make-order-fixes.d.ts +2 -5
- package/dist/utils/report-all-errors.d.ts +19 -17
- package/dist/utils/report-errors.d.ts +3 -1
- package/dist/utils/should-partition.d.ts +2 -5
- package/dist/utils/validate-custom-sort-configuration.d.ts +1 -1
- package/dist/utils/validate-groups-configuration.d.ts +1 -1
- package/dist/utils/validate-newlines-and-partition-configuration.d.ts +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/types/join.d.ts +0 -19
- package/dist/utils/is-node-function-type.js +0 -13
- /package/dist/{utils → rules/sort-object-types}/is-node-function-type.d.ts +0 -0
|
@@ -6,42 +6,37 @@ import {
|
|
|
6
6
|
MISSED_SPACING_ERROR,
|
|
7
7
|
DEPENDENCY_ORDER_ERROR,
|
|
8
8
|
} from '../utils/report-errors.js'
|
|
9
|
-
import {
|
|
10
|
-
partitionByNewLineJsonSchema,
|
|
11
|
-
partitionByCommentJsonSchema,
|
|
12
|
-
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
13
9
|
import {
|
|
14
10
|
allSelectors,
|
|
15
11
|
allModifiers,
|
|
16
|
-
|
|
12
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
17
13
|
USAGE_TYPE_OPTION,
|
|
18
14
|
} from './sort-modules/types.js'
|
|
15
|
+
import {
|
|
16
|
+
partitionByNewLineJsonSchema,
|
|
17
|
+
partitionByCommentJsonSchema,
|
|
18
|
+
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
19
19
|
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
20
20
|
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
21
21
|
import { buildComparatorByOptionsComputer } from './sort-modules/build-comparator-by-options-computer.js'
|
|
22
22
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
23
23
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
24
|
-
import { isPropertyOrAccessorNode } from './sort-modules/is-property-or-accessor-node.js'
|
|
25
24
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
26
25
|
import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
|
|
27
26
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
28
27
|
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.js'
|
|
29
28
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
30
|
-
import {
|
|
31
|
-
import { computeDependencies } from './sort-modules/compute-dependencies.js'
|
|
29
|
+
import { computeNodeDetails } from './sort-modules/compute-node-details.js'
|
|
32
30
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
33
31
|
import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
34
32
|
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
|
|
35
|
-
import { getNodeDecorators } from '../utils/get-node-decorators.js'
|
|
36
33
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
37
|
-
import { getDecoratorName } from '../utils/get-decorator-name.js'
|
|
38
34
|
import { reportAllErrors } from '../utils/report-all-errors.js'
|
|
39
35
|
import { shouldPartition } from '../utils/should-partition.js'
|
|
40
36
|
import { getGroupIndex } from '../utils/get-group-index.js'
|
|
41
37
|
import { computeGroup } from '../utils/compute-group.js'
|
|
42
38
|
import { rangeToDiff } from '../utils/range-to-diff.js'
|
|
43
39
|
import { getSettings } from '../utils/get-settings.js'
|
|
44
|
-
import { isSortable } from '../utils/is-sortable.js'
|
|
45
40
|
import { complete } from '../utils/complete.js'
|
|
46
41
|
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
47
42
|
const ORDER_ERROR_ID = 'unexpectedModulesOrder'
|
|
@@ -86,8 +81,9 @@ const sortModules = createEslintRule({
|
|
|
86
81
|
allowedAdditionalTypeValues: [USAGE_TYPE_OPTION],
|
|
87
82
|
}),
|
|
88
83
|
...buildCommonGroupsJsonSchemas({
|
|
84
|
+
additionalCustomGroupMatchProperties:
|
|
85
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
89
86
|
allowedAdditionalTypeValues: [USAGE_TYPE_OPTION],
|
|
90
|
-
singleCustomGroupJsonSchema,
|
|
91
87
|
}),
|
|
92
88
|
partitionByComment: partitionByCommentJsonSchema,
|
|
93
89
|
partitionByNewLine: partitionByNewLineJsonSchema,
|
|
@@ -127,17 +123,14 @@ const sortModules = createEslintRule({
|
|
|
127
123
|
sourceCode,
|
|
128
124
|
})
|
|
129
125
|
return {
|
|
130
|
-
Program: program =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
},
|
|
126
|
+
Program: program =>
|
|
127
|
+
analyzeModule({
|
|
128
|
+
eslintDisabledLines,
|
|
129
|
+
module: program,
|
|
130
|
+
sourceCode,
|
|
131
|
+
options,
|
|
132
|
+
context,
|
|
133
|
+
}),
|
|
141
134
|
}
|
|
142
135
|
},
|
|
143
136
|
defaultOptions: [defaultOptions],
|
|
@@ -154,96 +147,49 @@ function analyzeModule({
|
|
|
154
147
|
buildDefaultOptionsByGroupIndexComputer(options)
|
|
155
148
|
let formattedNodes = [[]]
|
|
156
149
|
for (let node of module.body) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
150
|
+
switch (node.type) {
|
|
151
|
+
case AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
152
|
+
case AST_NODE_TYPES.ExportNamedDeclaration:
|
|
153
|
+
case AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
154
|
+
case AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
155
|
+
case AST_NODE_TYPES.FunctionDeclaration:
|
|
156
|
+
case AST_NODE_TYPES.TSModuleDeclaration:
|
|
157
|
+
break
|
|
158
|
+
case AST_NODE_TYPES.VariableDeclaration:
|
|
159
|
+
case AST_NODE_TYPES.ExpressionStatement:
|
|
160
|
+
formattedNodes.push([])
|
|
161
|
+
continue
|
|
162
|
+
case AST_NODE_TYPES.TSDeclareFunction:
|
|
163
|
+
case AST_NODE_TYPES.TSEnumDeclaration:
|
|
164
|
+
case AST_NODE_TYPES.ClassDeclaration:
|
|
165
|
+
break
|
|
166
|
+
default:
|
|
167
|
+
continue
|
|
168
|
+
}
|
|
169
|
+
let details = computeNodeDetails({ sourceCode, node })
|
|
170
|
+
if (!details.nodeDetails) {
|
|
171
|
+
if (details.shouldPartitionAfterNode) {
|
|
172
|
+
formattedNodes.push([])
|
|
160
173
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
modifiers.push('export')
|
|
171
|
-
break
|
|
172
|
-
case AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
173
|
-
selector = 'interface'
|
|
174
|
-
;({ name } = nodeToParse.id)
|
|
175
|
-
break
|
|
176
|
-
case AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
177
|
-
selector = 'type'
|
|
178
|
-
;({ name } = nodeToParse.id)
|
|
179
|
-
addSafetySemicolonWhenInline = true
|
|
180
|
-
break
|
|
181
|
-
case AST_NODE_TYPES.FunctionDeclaration:
|
|
182
|
-
case AST_NODE_TYPES.TSDeclareFunction:
|
|
183
|
-
selector = 'function'
|
|
184
|
-
if (nodeToParse.async) {
|
|
185
|
-
modifiers.push('async')
|
|
186
|
-
}
|
|
187
|
-
if (modifiers.includes('declare')) {
|
|
188
|
-
addSafetySemicolonWhenInline = true
|
|
189
|
-
}
|
|
190
|
-
name = nodeToParse.id?.name
|
|
191
|
-
break
|
|
192
|
-
case AST_NODE_TYPES.TSModuleDeclaration:
|
|
193
|
-
formattedNodes.push([])
|
|
194
|
-
if (nodeToParse.body) {
|
|
195
|
-
analyzeModule({
|
|
196
|
-
module: nodeToParse.body,
|
|
197
|
-
eslintDisabledLines,
|
|
198
|
-
sourceCode,
|
|
199
|
-
options,
|
|
200
|
-
context,
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
break
|
|
204
|
-
case AST_NODE_TYPES.VariableDeclaration:
|
|
205
|
-
case AST_NODE_TYPES.ExpressionStatement:
|
|
206
|
-
formattedNodes.push([])
|
|
207
|
-
break
|
|
208
|
-
case AST_NODE_TYPES.TSEnumDeclaration:
|
|
209
|
-
selector = 'enum'
|
|
210
|
-
;({ name } = nodeToParse.id)
|
|
211
|
-
dependencies = [...dependencies, ...extractDependencies(nodeToParse)]
|
|
212
|
-
break
|
|
213
|
-
case AST_NODE_TYPES.ClassDeclaration:
|
|
214
|
-
selector = 'class'
|
|
215
|
-
name = nodeToParse.id?.name
|
|
216
|
-
let nodeDecorators = getNodeDecorators(nodeToParse)
|
|
217
|
-
if (nodeDecorators.length > 0) {
|
|
218
|
-
modifiers.push('decorated')
|
|
219
|
-
}
|
|
220
|
-
decorators = nodeDecorators.map(decorator =>
|
|
221
|
-
getDecoratorName({
|
|
222
|
-
sourceCode,
|
|
223
|
-
decorator,
|
|
224
|
-
}),
|
|
225
|
-
)
|
|
226
|
-
dependencies = [...dependencies, ...extractDependencies(nodeToParse)]
|
|
227
|
-
break
|
|
174
|
+
if (details.moduleBlock) {
|
|
175
|
+
analyzeModule({
|
|
176
|
+
module: details.moduleBlock,
|
|
177
|
+
eslintDisabledLines,
|
|
178
|
+
sourceCode,
|
|
179
|
+
options,
|
|
180
|
+
context,
|
|
181
|
+
})
|
|
228
182
|
}
|
|
229
|
-
}
|
|
230
|
-
let selector
|
|
231
|
-
let name
|
|
232
|
-
let modifiers = []
|
|
233
|
-
let dependencies = []
|
|
234
|
-
let decorators = []
|
|
235
|
-
let addSafetySemicolonWhenInline = false
|
|
236
|
-
parseNode(node)
|
|
237
|
-
if (!selector || !name) {
|
|
238
|
-
continue
|
|
239
|
-
}
|
|
240
|
-
if (
|
|
241
|
-
selector === 'class' &&
|
|
242
|
-
modifiers.includes('export') &&
|
|
243
|
-
modifiers.includes('decorated')
|
|
244
|
-
) {
|
|
245
183
|
continue
|
|
246
184
|
}
|
|
185
|
+
let {
|
|
186
|
+
addSafetySemicolonWhenInline,
|
|
187
|
+
dependencies,
|
|
188
|
+
decorators,
|
|
189
|
+
modifiers,
|
|
190
|
+
selector,
|
|
191
|
+
name,
|
|
192
|
+
} = details.nodeDetails
|
|
247
193
|
let predefinedGroups = generatePredefinedGroups({
|
|
248
194
|
cache: cachedGroupsByModifiersAndSelectors,
|
|
249
195
|
selectors: [selector],
|
|
@@ -287,53 +233,38 @@ function analyzeModule({
|
|
|
287
233
|
partitionId: formattedNodes.length,
|
|
288
234
|
})
|
|
289
235
|
}
|
|
236
|
+
let sortingNodes = formattedNodes.flat()
|
|
237
|
+
reportAllErrors({
|
|
238
|
+
availableMessageIds: {
|
|
239
|
+
missedSpacingBetweenMembers: MISSED_SPACING_ERROR_ID,
|
|
240
|
+
unexpectedDependencyOrder: DEPENDENCY_ORDER_ERROR_ID,
|
|
241
|
+
extraSpacingBetweenMembers: EXTRA_SPACING_ERROR_ID,
|
|
242
|
+
unexpectedGroupOrder: GROUP_ORDER_ERROR_ID,
|
|
243
|
+
unexpectedOrder: ORDER_ERROR_ID,
|
|
244
|
+
},
|
|
245
|
+
sortNodesExcludingEslintDisabled,
|
|
246
|
+
nodes: sortingNodes,
|
|
247
|
+
options,
|
|
248
|
+
context,
|
|
249
|
+
})
|
|
290
250
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
291
|
-
let nodesSortedByGroups = formattedNodes.flatMap(
|
|
251
|
+
let nodesSortedByGroups = formattedNodes.flatMap(nodes =>
|
|
292
252
|
sortNodesByGroups({
|
|
293
253
|
comparatorByOptionsComputer: buildComparatorByOptionsComputer({
|
|
294
254
|
ignoreEslintDisabledNodes,
|
|
295
|
-
sortingNodes:
|
|
255
|
+
sortingNodes: nodes,
|
|
296
256
|
}),
|
|
297
257
|
isNodeIgnored: sortingNode =>
|
|
298
258
|
getGroupIndex(options.groups, sortingNode) === options.groups.length,
|
|
299
259
|
optionsByGroupIndexComputer,
|
|
300
260
|
ignoreEslintDisabledNodes,
|
|
301
261
|
groups: options.groups,
|
|
302
|
-
nodes
|
|
262
|
+
nodes,
|
|
303
263
|
}),
|
|
304
264
|
)
|
|
305
265
|
return sortNodesByDependencies(nodesSortedByGroups, {
|
|
306
266
|
ignoreEslintDisabledNodes,
|
|
307
267
|
})
|
|
308
268
|
}
|
|
309
|
-
let nodes = formattedNodes.flat()
|
|
310
|
-
reportAllErrors({
|
|
311
|
-
availableMessageIds: {
|
|
312
|
-
missedSpacingBetweenMembers: MISSED_SPACING_ERROR_ID,
|
|
313
|
-
unexpectedDependencyOrder: DEPENDENCY_ORDER_ERROR_ID,
|
|
314
|
-
extraSpacingBetweenMembers: EXTRA_SPACING_ERROR_ID,
|
|
315
|
-
unexpectedGroupOrder: GROUP_ORDER_ERROR_ID,
|
|
316
|
-
unexpectedOrder: ORDER_ERROR_ID,
|
|
317
|
-
},
|
|
318
|
-
sortNodesExcludingEslintDisabled,
|
|
319
|
-
options,
|
|
320
|
-
context,
|
|
321
|
-
nodes,
|
|
322
|
-
})
|
|
323
|
-
}
|
|
324
|
-
function extractDependencies(expression) {
|
|
325
|
-
let searchStaticMethodsAndFunctionProperties =
|
|
326
|
-
expression.type === AST_NODE_TYPES.ClassDeclaration &&
|
|
327
|
-
expression.body.body.some(
|
|
328
|
-
classElement =>
|
|
329
|
-
classElement.type === AST_NODE_TYPES.StaticBlock ||
|
|
330
|
-
(classElement.static &&
|
|
331
|
-
isPropertyOrAccessorNode(classElement) &&
|
|
332
|
-
!isArrowFunctionNode(classElement)),
|
|
333
|
-
)
|
|
334
|
-
return computeDependencies(expression, {
|
|
335
|
-
searchStaticMethodsAndFunctionProperties,
|
|
336
|
-
type: 'hard',
|
|
337
|
-
})
|
|
338
269
|
}
|
|
339
270
|
export { sortModules as default }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
3
3
|
function computeNodeName(node, ignoreAlias) {
|
|
4
4
|
let identifierToCheck = ignoreAlias ? node.local : node.exported
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
3
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
4
|
+
import { TypeOption } from '../../types/common-options.js'
|
|
6
5
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
7
6
|
/**
|
|
8
7
|
* Configuration options for the sort-named-exports rule.
|
|
@@ -18,13 +17,11 @@ export type Options = Partial<
|
|
|
18
17
|
* @default false
|
|
19
18
|
*/
|
|
20
19
|
ignoreAlias: boolean
|
|
21
|
-
} &
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
>
|
|
26
|
-
CommonOptions<TypeOption> &
|
|
27
|
-
CommonPartitionOptions
|
|
20
|
+
} & AllCommonOptions<
|
|
21
|
+
TypeOption,
|
|
22
|
+
AdditionalSortOptions,
|
|
23
|
+
CustomGroupMatchOptions
|
|
24
|
+
>
|
|
28
25
|
>[]
|
|
29
26
|
/** Extended sorting node for named export specifiers. */
|
|
30
27
|
export type SortNamedExportsSortingNode = SortingNode<TSESTree.ExportSpecifier>
|
|
@@ -40,8 +37,8 @@ export type Modifier = (typeof allModifiers)[number]
|
|
|
40
37
|
* Currently only includes the 'export' selector.
|
|
41
38
|
*/
|
|
42
39
|
export type Selector = (typeof allSelectors)[number]
|
|
43
|
-
/**
|
|
44
|
-
interface
|
|
40
|
+
/** Match options for a custom group. */
|
|
41
|
+
interface CustomGroupMatchOptions {
|
|
45
42
|
/**
|
|
46
43
|
* Array of modifiers that exports must have to match this group. Can
|
|
47
44
|
* include 'type' for type exports or 'value' for value exports.
|
|
@@ -53,6 +50,7 @@ interface SingleCustomGroup {
|
|
|
53
50
|
*/
|
|
54
51
|
selector?: Selector
|
|
55
52
|
}
|
|
53
|
+
type AdditionalSortOptions = object
|
|
56
54
|
/**
|
|
57
55
|
* Array of all available selectors for named exports.
|
|
58
56
|
*
|
|
@@ -66,9 +64,11 @@ export declare let allSelectors: readonly ['export']
|
|
|
66
64
|
*/
|
|
67
65
|
export declare let allModifiers: readonly ['value', 'type']
|
|
68
66
|
/**
|
|
69
|
-
* JSON
|
|
70
|
-
*
|
|
71
|
-
* Provides additional schema properties specific to the sort-named-exports.
|
|
67
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
68
|
+
* rule options at configuration time.
|
|
72
69
|
*/
|
|
73
|
-
export declare let
|
|
70
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
71
|
+
string,
|
|
72
|
+
JSONSchema4
|
|
73
|
+
>
|
|
74
74
|
export {}
|
|
@@ -4,8 +4,12 @@ import {
|
|
|
4
4
|
} from '../../utils/json-schemas/common-groups-json-schemas.js'
|
|
5
5
|
let allSelectors = ['export']
|
|
6
6
|
let allModifiers = ['value', 'type']
|
|
7
|
-
let
|
|
7
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
8
8
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
9
9
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
10
10
|
}
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
13
|
+
allModifiers,
|
|
14
|
+
allSelectors,
|
|
15
|
+
}
|
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
EXTRA_SPACING_ERROR,
|
|
9
9
|
MISSED_SPACING_ERROR,
|
|
10
10
|
} from '../utils/report-errors.js'
|
|
11
|
-
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
12
|
-
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
13
|
-
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
14
11
|
import {
|
|
15
|
-
|
|
12
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
16
13
|
allSelectors,
|
|
17
14
|
allModifiers,
|
|
18
15
|
} from './sort-named-exports/types.js'
|
|
16
|
+
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
17
|
+
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
18
|
+
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
19
19
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
20
20
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
21
21
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
@@ -156,7 +156,8 @@ const sortNamedExports = createEslintRule({
|
|
|
156
156
|
properties: {
|
|
157
157
|
...buildCommonJsonSchemas(),
|
|
158
158
|
...buildCommonGroupsJsonSchemas({
|
|
159
|
-
|
|
159
|
+
additionalCustomGroupMatchProperties:
|
|
160
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
160
161
|
}),
|
|
161
162
|
ignoreAlias: {
|
|
162
163
|
description: 'Controls whether to ignore alias names.',
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
3
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
4
|
+
import { TypeOption } from '../../types/common-options.js'
|
|
6
5
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
7
6
|
/**
|
|
8
7
|
* Configuration options for the sort-named-imports rule.
|
|
@@ -18,13 +17,11 @@ export type Options = Partial<
|
|
|
18
17
|
* @default false
|
|
19
18
|
*/
|
|
20
19
|
ignoreAlias: boolean
|
|
21
|
-
} &
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
>
|
|
26
|
-
CommonOptions<TypeOption> &
|
|
27
|
-
CommonPartitionOptions
|
|
20
|
+
} & AllCommonOptions<
|
|
21
|
+
TypeOption,
|
|
22
|
+
AdditionalSortOptions,
|
|
23
|
+
CustomGroupMatchOptions
|
|
24
|
+
>
|
|
28
25
|
>[]
|
|
29
26
|
/** Extended sorting node for named import specifiers. */
|
|
30
27
|
export type SortNamedImportsSortingNode = SortingNode<TSESTree.ImportClause>
|
|
@@ -40,8 +37,8 @@ export type Modifier = (typeof allModifiers)[number]
|
|
|
40
37
|
* Currently only includes the 'import' selector.
|
|
41
38
|
*/
|
|
42
39
|
export type Selector = (typeof allSelectors)[number]
|
|
43
|
-
/**
|
|
44
|
-
interface
|
|
40
|
+
/** Match options for a custom group. */
|
|
41
|
+
interface CustomGroupMatchOptions {
|
|
45
42
|
/**
|
|
46
43
|
* Array of modifiers that imports must have to match this group. Can
|
|
47
44
|
* include 'type' for type imports or 'value' for value imports.
|
|
@@ -53,6 +50,7 @@ interface SingleCustomGroup {
|
|
|
53
50
|
*/
|
|
54
51
|
selector?: Selector
|
|
55
52
|
}
|
|
53
|
+
type AdditionalSortOptions = object
|
|
56
54
|
/**
|
|
57
55
|
* Array of all available selectors for named imports.
|
|
58
56
|
*
|
|
@@ -66,10 +64,11 @@ export declare let allSelectors: readonly ['import']
|
|
|
66
64
|
*/
|
|
67
65
|
export declare let allModifiers: readonly ['value', 'type']
|
|
68
66
|
/**
|
|
69
|
-
* JSON
|
|
70
|
-
*
|
|
71
|
-
* Provides additional schema properties specific to the sort-named-imports
|
|
72
|
-
* rule, extending the base custom group schema with element name patterns.
|
|
67
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
68
|
+
* rule options at configuration time.
|
|
73
69
|
*/
|
|
74
|
-
export declare let
|
|
70
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
71
|
+
string,
|
|
72
|
+
JSONSchema4
|
|
73
|
+
>
|
|
75
74
|
export {}
|
|
@@ -4,8 +4,12 @@ import {
|
|
|
4
4
|
} from '../../utils/json-schemas/common-groups-json-schemas.js'
|
|
5
5
|
let allSelectors = ['import']
|
|
6
6
|
let allModifiers = ['value', 'type']
|
|
7
|
-
let
|
|
7
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
8
8
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
9
9
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
10
10
|
}
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
13
|
+
allModifiers,
|
|
14
|
+
allSelectors,
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import {
|
|
3
3
|
partitionByNewLineJsonSchema,
|
|
4
4
|
partitionByCommentJsonSchema,
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
EXTRA_SPACING_ERROR,
|
|
10
10
|
MISSED_SPACING_ERROR,
|
|
11
11
|
} from '../utils/report-errors.js'
|
|
12
|
-
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
13
|
-
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
14
|
-
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
15
12
|
import {
|
|
16
|
-
|
|
13
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
17
14
|
allSelectors,
|
|
18
15
|
allModifiers,
|
|
19
16
|
} from './sort-named-imports/types.js'
|
|
17
|
+
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
18
|
+
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
19
|
+
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
20
20
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
21
21
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
22
22
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
@@ -160,7 +160,8 @@ const sortNamedImports = createEslintRule({
|
|
|
160
160
|
properties: {
|
|
161
161
|
...buildCommonJsonSchemas(),
|
|
162
162
|
...buildCommonGroupsJsonSchemas({
|
|
163
|
-
|
|
163
|
+
additionalCustomGroupMatchProperties:
|
|
164
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
164
165
|
}),
|
|
165
166
|
ignoreAlias: {
|
|
166
167
|
description: 'Controls whether to ignore alias names.',
|
|
@@ -18,6 +18,9 @@ let comparatorByOptionsComputer = options => {
|
|
|
18
18
|
}
|
|
19
19
|
let byValueComparatorComputer = options => {
|
|
20
20
|
switch (options.type) {
|
|
21
|
+
/* v8 ignore next 2 -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
22
|
+
case 'subgroup-order':
|
|
23
|
+
return defaultComparatorByOptionsComputer(options)
|
|
21
24
|
case 'alphabetical':
|
|
22
25
|
return (a, b) => compareAlphabetically(a.value, b.value, options)
|
|
23
26
|
case 'line-length':
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
function isNodeFunctionType(node) {
|
|
3
|
+
if (
|
|
4
|
+
node.type === AST_NODE_TYPES.TSMethodSignature ||
|
|
5
|
+
node.type === AST_NODE_TYPES.TSFunctionType
|
|
6
|
+
) {
|
|
7
|
+
return true
|
|
8
|
+
}
|
|
9
|
+
if (
|
|
10
|
+
node.type === AST_NODE_TYPES.TSUnionType ||
|
|
11
|
+
node.type === AST_NODE_TYPES.TSIntersectionType
|
|
12
|
+
) {
|
|
13
|
+
return node.types.every(isNodeFunctionType)
|
|
14
|
+
}
|
|
15
|
+
if (node.type === AST_NODE_TYPES.TSPropertySignature && node.typeAnnotation) {
|
|
16
|
+
return isNodeFunctionType(node.typeAnnotation.typeAnnotation)
|
|
17
|
+
}
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
export { isNodeFunctionType }
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import {
|
|
4
|
-
CommonOptions,
|
|
5
|
-
RegexOption,
|
|
6
|
-
TypeOption,
|
|
7
|
-
} from '../../types/common-options.js'
|
|
8
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
9
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
3
|
+
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
10
4
|
import { ScopedRegexOption } from '../../types/scoped-regex-option.js'
|
|
5
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
11
6
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
12
7
|
import { NodeOfType } from '../../types/node-of-type.js'
|
|
13
8
|
/**
|
|
@@ -45,20 +40,11 @@ export type Options = Partial<
|
|
|
45
40
|
*/
|
|
46
41
|
hasNumericKeysOnly?: boolean
|
|
47
42
|
}
|
|
48
|
-
} &
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
TypeOption
|
|
54
|
-
> &
|
|
55
|
-
CommonOptions<
|
|
56
|
-
TypeOption,
|
|
57
|
-
{
|
|
58
|
-
sortBy: SortByOption
|
|
59
|
-
}
|
|
60
|
-
> &
|
|
61
|
-
CommonPartitionOptions
|
|
43
|
+
} & AllCommonOptions<
|
|
44
|
+
TypeOption,
|
|
45
|
+
AdditionalSortOptions,
|
|
46
|
+
CustomGroupMatchOptions
|
|
47
|
+
>
|
|
62
48
|
>[]
|
|
63
49
|
/**
|
|
64
50
|
* Extended sorting node for object type members.
|
|
@@ -74,7 +60,9 @@ export interface SortObjectTypesSortingNode extends SortingNode<TSESTree.TypeEle
|
|
|
74
60
|
*/
|
|
75
61
|
value: string
|
|
76
62
|
}
|
|
77
|
-
|
|
63
|
+
interface AdditionalSortOptions {
|
|
64
|
+
sortBy: SortByOption
|
|
65
|
+
}
|
|
78
66
|
export declare let objectTypeParentTypes: readonly [
|
|
79
67
|
TSESTree.AST_NODE_TYPES.TSTypeAliasDeclaration,
|
|
80
68
|
TSESTree.AST_NODE_TYPES.TSInterfaceDeclaration,
|
|
@@ -98,8 +86,8 @@ export type Selector = (typeof allSelectors)[number]
|
|
|
98
86
|
* whether they are optional, required, or span multiple lines.
|
|
99
87
|
*/
|
|
100
88
|
export type Modifier = (typeof allModifiers)[number]
|
|
101
|
-
/**
|
|
102
|
-
interface
|
|
89
|
+
/** Match options for a custom group. */
|
|
90
|
+
interface CustomGroupMatchOptions {
|
|
103
91
|
/**
|
|
104
92
|
* Regular expression pattern to match against the member's type annotation
|
|
105
93
|
* value. Only applicable to properties.
|
|
@@ -133,21 +121,20 @@ export declare let allSelectors: readonly [
|
|
|
133
121
|
* Used for validation and configuration in the ESLint rule.
|
|
134
122
|
*/
|
|
135
123
|
export declare let allModifiers: readonly ['optional', 'required', 'multiline']
|
|
124
|
+
declare const SORT_BY_OPTION: readonly ['name', 'value']
|
|
125
|
+
type SortByOption = (typeof SORT_BY_OPTION)[number]
|
|
136
126
|
/**
|
|
137
127
|
* JSON Schema definition for the sortBy configuration option.
|
|
138
128
|
*
|
|
139
129
|
* Validates the sortBy parameter in ESLint rule configuration.
|
|
140
130
|
*/
|
|
141
|
-
export declare let
|
|
131
|
+
export declare let additionalSortOptionsJsonSchema: Record<string, JSONSchema4>
|
|
142
132
|
/**
|
|
143
|
-
* JSON
|
|
144
|
-
*
|
|
145
|
-
* Provides additional schema properties specific to the sort-object-types rule,
|
|
146
|
-
* extending the base custom group schema with element patterns and sorting
|
|
147
|
-
* options.
|
|
148
|
-
*
|
|
149
|
-
* Note: Ideally, we should generate as many schemas as there are selectors, and
|
|
150
|
-
* ensure that users do not enter invalid modifiers for a given selector.
|
|
133
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
134
|
+
* rule options at configuration time.
|
|
151
135
|
*/
|
|
152
|
-
export declare let
|
|
136
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
137
|
+
string,
|
|
138
|
+
JSONSchema4
|
|
139
|
+
>
|
|
153
140
|
export {}
|