eslint-plugin-perfectionist 5.10.0 → 5.10.1
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-arrays/sort-array.js +8 -6
- package/dist/rules/sort-classes/compute-dependencies-by-sorting-node.js +12 -12
- package/dist/rules/sort-classes/compute-dependencies.js +0 -3
- package/dist/rules/sort-classes/compute-overload-signature-groups.js +4 -3
- package/dist/rules/sort-classes/sort-class.js +33 -35
- package/dist/rules/sort-enums/compute-dependencies.js +0 -3
- package/dist/rules/sort-enums/sort-enum.js +24 -26
- package/dist/rules/sort-exports.js +6 -5
- package/dist/rules/sort-heritage-clauses/sort-heritage-clause.js +6 -9
- package/dist/rules/sort-import-attributes/sort-import-or-export-attributes.js +6 -9
- package/dist/rules/sort-imports/compute-common-selectors.js +1 -1
- package/dist/rules/sort-imports/get-typescript-import.d.ts +14 -1
- package/dist/rules/sort-imports/get-typescript-import.js +19 -2
- package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +5 -10
- package/dist/rules/sort-imports.js +32 -29
- package/dist/rules/sort-jsx-props/sort-jsx-object.js +13 -15
- package/dist/rules/sort-maps/sort-potential-map.js +6 -9
- package/dist/rules/sort-modules/compute-node-details.js +14 -13
- package/dist/rules/sort-modules/compute-overload-signature-groups.js +4 -3
- package/dist/rules/sort-modules.js +27 -26
- package/dist/rules/sort-named-exports/sort-named-export.js +12 -14
- package/dist/rules/sort-named-imports/sort-named-import.js +12 -14
- package/dist/rules/sort-object-types/sort-object-type-elements.js +16 -17
- package/dist/rules/sort-objects/sort-object.js +32 -33
- package/dist/rules/sort-union-or-intersection-types/sort-union-or-intersection-types.js +12 -15
- package/dist/rules/sort-variable-declarations/compute-dependencies.js +0 -1
- package/dist/rules/sort-variable-declarations/sort-variable-declaration.js +24 -26
- package/dist/utils/compare/build-line-length-comparator.js +2 -1
- package/dist/utils/compare/build-subgroup-order-comparator.js +3 -4
- package/dist/utils/compare/compare-alphabetically.js +2 -4
- package/dist/utils/compare/compare-naturally.js +2 -4
- package/dist/utils/get-comments-before.js +1 -1
- package/dist/utils/is-partition-comment.js +3 -3
- package/dist/utils/make-single-node-comment-after-fixes.js +52 -9
- package/dist/utils/should-partition.js +1 -1
- package/dist/utils/sort-nodes-by-groups.js +1 -1
- package/dist/utils/sort-nodes.js +1 -1
- package/package.json +2 -2
package/dist/package.json.js
CHANGED
|
@@ -73,6 +73,11 @@ function sortArray({
|
|
|
73
73
|
sourceCode,
|
|
74
74
|
})
|
|
75
75
|
let selector = 'literal'
|
|
76
|
+
let predefinedGroups = generatePredefinedGroups({
|
|
77
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
78
|
+
selectors: [selector],
|
|
79
|
+
modifiers: [],
|
|
80
|
+
})
|
|
76
81
|
let group = computeGroup({
|
|
77
82
|
customGroupMatcher: customGroup =>
|
|
78
83
|
doesCustomGroupMatch({
|
|
@@ -81,11 +86,7 @@ function sortArray({
|
|
|
81
86
|
modifiers: [],
|
|
82
87
|
customGroup,
|
|
83
88
|
}),
|
|
84
|
-
predefinedGroups
|
|
85
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
86
|
-
selectors: [selector],
|
|
87
|
-
modifiers: [],
|
|
88
|
-
}),
|
|
89
|
+
predefinedGroups,
|
|
89
90
|
options,
|
|
90
91
|
})
|
|
91
92
|
let sortingNode = {
|
|
@@ -125,12 +126,13 @@ function sortArray({
|
|
|
125
126
|
}),
|
|
126
127
|
)
|
|
127
128
|
}
|
|
129
|
+
let nodes = formattedMembers.flat()
|
|
128
130
|
reportAllErrors({
|
|
129
131
|
sortNodesExcludingEslintDisabled,
|
|
130
132
|
availableMessageIds,
|
|
131
133
|
options,
|
|
132
134
|
context,
|
|
133
|
-
nodes
|
|
135
|
+
nodes,
|
|
134
136
|
})
|
|
135
137
|
}
|
|
136
138
|
export { sortArray }
|
|
@@ -10,11 +10,12 @@ function computeDependenciesBySortingNode({
|
|
|
10
10
|
sourceCode,
|
|
11
11
|
classBody,
|
|
12
12
|
}) {
|
|
13
|
+
let staticSortingNodes = sortingNodes.filter(node => node.isStatic)
|
|
13
14
|
let dependenciesBySortingNode = computeDependenciesBySortingNode$1({
|
|
14
15
|
additionalIdentifierDependenciesComputer:
|
|
15
16
|
buildAdditionalIdentifierDependenciesComputer({
|
|
16
17
|
ignoreCallbackDependenciesPatterns,
|
|
17
|
-
staticSortingNodes
|
|
18
|
+
staticSortingNodes,
|
|
18
19
|
classBody,
|
|
19
20
|
}),
|
|
20
21
|
shouldIgnoreSortingNodeComputer: sortingNode =>
|
|
@@ -73,22 +74,21 @@ function computeIdentifierOrThisExpressionDependency({
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
function shouldIgnoreCallbackDependency() {
|
|
76
|
-
|
|
77
|
+
return computeParentNodesWithTypes({
|
|
77
78
|
allowedTypes: [AST_NODE_TYPES.CallExpression],
|
|
78
79
|
maxParent: classElement,
|
|
79
80
|
consecutiveOnly: false,
|
|
80
81
|
node,
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
}).some(shouldIgnoreCallExpression)
|
|
83
|
+
function shouldIgnoreCallExpression(callExpressionParent) {
|
|
84
|
+
return (
|
|
85
|
+
'name' in callExpressionParent.callee &&
|
|
86
|
+
matches(
|
|
87
|
+
callExpressionParent.callee.name,
|
|
88
|
+
ignoreCallbackDependenciesPatterns,
|
|
89
|
+
)
|
|
90
|
+
)
|
|
87
91
|
}
|
|
88
|
-
return matches(
|
|
89
|
-
firstCallExpressionParent.callee.name,
|
|
90
|
-
ignoreCallbackDependenciesPatterns,
|
|
91
|
-
)
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
function computeThisExpressionDependenciesBySortingNode({
|
|
@@ -41,10 +41,11 @@ function computeOverloadSignatureGroups(classElements) {
|
|
|
41
41
|
}
|
|
42
42
|
function buildOverloadSignatureGroup(methods) {
|
|
43
43
|
let implementation = methods.find(isMethodImplementation) ?? methods.at(-1)
|
|
44
|
+
let overloadSignatures = methods.filter(
|
|
45
|
+
method => !isMethodImplementation(method),
|
|
46
|
+
)
|
|
44
47
|
return new OverloadSignatureGroup({
|
|
45
|
-
overloadSignatures
|
|
46
|
-
method => !isMethodImplementation(method),
|
|
47
|
-
),
|
|
48
|
+
overloadSignatures,
|
|
48
49
|
implementation,
|
|
49
50
|
})
|
|
50
51
|
function isMethodImplementation(method) {
|
|
@@ -94,15 +94,12 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
94
94
|
return
|
|
95
95
|
}
|
|
96
96
|
let settings = getSettings(context.settings)
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
settings,
|
|
104
|
-
defaultOptions,
|
|
105
|
-
)
|
|
97
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
98
|
+
matchedAstSelectors,
|
|
99
|
+
classElements,
|
|
100
|
+
context,
|
|
101
|
+
})
|
|
102
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
106
103
|
validateCustomSortConfig(options)
|
|
107
104
|
validateGroupsConfig({
|
|
108
105
|
modifiers: allModifiers,
|
|
@@ -235,6 +232,11 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
235
232
|
default:
|
|
236
233
|
throw new UnreachableCaseError(member)
|
|
237
234
|
}
|
|
235
|
+
let predefinedGroups = generatePredefinedGroups({
|
|
236
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
237
|
+
selectors,
|
|
238
|
+
modifiers,
|
|
239
|
+
})
|
|
238
240
|
let group = computeGroup({
|
|
239
241
|
customGroupMatcher: customGroup =>
|
|
240
242
|
doesCustomGroupMatch({
|
|
@@ -245,11 +247,7 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
245
247
|
modifiers,
|
|
246
248
|
selectors,
|
|
247
249
|
}),
|
|
248
|
-
predefinedGroups
|
|
249
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
250
|
-
selectors,
|
|
251
|
-
modifiers,
|
|
252
|
-
}),
|
|
250
|
+
predefinedGroups,
|
|
253
251
|
options,
|
|
254
252
|
})
|
|
255
253
|
let sortingNode = {
|
|
@@ -288,14 +286,15 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
288
286
|
sortingNodeGroups: sortingNodeGroupsWithoutOverloadSignature,
|
|
289
287
|
})
|
|
290
288
|
if (options.useExperimentalDependencyDetection) {
|
|
289
|
+
let dependenciesBySortingNode = computeDependenciesBySortingNode({
|
|
290
|
+
ignoreCallbackDependenciesPatterns:
|
|
291
|
+
options.ignoreCallbackDependenciesPatterns,
|
|
292
|
+
sortingNodes: sortingNodeGroups.flat(),
|
|
293
|
+
classBody: node,
|
|
294
|
+
sourceCode,
|
|
295
|
+
})
|
|
291
296
|
sortingNodeGroups = populateSortingNodeGroupsWithDependencies({
|
|
292
|
-
dependenciesBySortingNode
|
|
293
|
-
ignoreCallbackDependenciesPatterns:
|
|
294
|
-
options.ignoreCallbackDependenciesPatterns,
|
|
295
|
-
sortingNodes: sortingNodeGroups.flat(),
|
|
296
|
-
classBody: node,
|
|
297
|
-
sourceCode,
|
|
298
|
-
}),
|
|
297
|
+
dependenciesBySortingNode,
|
|
299
298
|
sortingNodeGroups,
|
|
300
299
|
})
|
|
301
300
|
}
|
|
@@ -315,21 +314,20 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
315
314
|
context,
|
|
316
315
|
})
|
|
317
316
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
groups: options.groups,
|
|
329
|
-
}),
|
|
330
|
-
),
|
|
331
|
-
{ ignoreEslintDisabledNodes },
|
|
317
|
+
let nodesSortedByGroups = sortingNodeGroups.flatMap(sortingNodeGroup =>
|
|
318
|
+
sortNodesByGroups({
|
|
319
|
+
isNodeIgnored: sortingNode =>
|
|
320
|
+
getGroupIndex(options.groups, sortingNode) === options.groups.length,
|
|
321
|
+
comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
|
|
322
|
+
optionsByGroupIndexComputer,
|
|
323
|
+
ignoreEslintDisabledNodes,
|
|
324
|
+
nodes: sortingNodeGroup,
|
|
325
|
+
groups: options.groups,
|
|
326
|
+
}),
|
|
332
327
|
)
|
|
328
|
+
return sortNodesByDependencies(nodesSortedByGroups, {
|
|
329
|
+
ignoreEslintDisabledNodes,
|
|
330
|
+
})
|
|
333
331
|
}
|
|
334
332
|
}
|
|
335
333
|
export { defaultOptions, sortClass }
|
|
@@ -54,15 +54,12 @@ function sortEnum({ matchedAstSelectors, context, node }) {
|
|
|
54
54
|
return
|
|
55
55
|
}
|
|
56
56
|
let settings = getSettings(context.settings)
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
settings,
|
|
64
|
-
defaultOptions,
|
|
65
|
-
)
|
|
57
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
58
|
+
enumMembers: members,
|
|
59
|
+
matchedAstSelectors,
|
|
60
|
+
context,
|
|
61
|
+
})
|
|
62
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
66
63
|
validateCustomSortConfig(options)
|
|
67
64
|
validateGroupsConfig({
|
|
68
65
|
selectors: [],
|
|
@@ -131,12 +128,13 @@ function sortEnum({ matchedAstSelectors, context, node }) {
|
|
|
131
128
|
[[]],
|
|
132
129
|
)
|
|
133
130
|
if (options.useExperimentalDependencyDetection) {
|
|
131
|
+
let dependenciesBySortingNode = computeDependenciesBySortingNode({
|
|
132
|
+
sortingNodes: sortingNodeGroups.flat(),
|
|
133
|
+
enumName: node.id.name,
|
|
134
|
+
sourceCode,
|
|
135
|
+
})
|
|
134
136
|
sortingNodeGroups = populateSortingNodeGroupsWithDependencies({
|
|
135
|
-
dependenciesBySortingNode
|
|
136
|
-
sortingNodes: sortingNodeGroups.flat(),
|
|
137
|
-
enumName: node.id.name,
|
|
138
|
-
sourceCode,
|
|
139
|
-
}),
|
|
137
|
+
dependenciesBySortingNode,
|
|
140
138
|
sortingNodeGroups,
|
|
141
139
|
})
|
|
142
140
|
}
|
|
@@ -158,19 +156,19 @@ function sortEnum({ matchedAstSelectors, context, node }) {
|
|
|
158
156
|
context,
|
|
159
157
|
})
|
|
160
158
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}),
|
|
171
|
-
),
|
|
172
|
-
{ ignoreEslintDisabledNodes },
|
|
159
|
+
let nodesSortedByGroups = sortingNodeGroups.flatMap(sortingNodeGroup =>
|
|
160
|
+
sortNodesByGroups({
|
|
161
|
+
comparatorByOptionsComputer:
|
|
162
|
+
buildComparatorByOptionsComputer(isNumericEnum),
|
|
163
|
+
optionsByGroupIndexComputer,
|
|
164
|
+
ignoreEslintDisabledNodes,
|
|
165
|
+
nodes: sortingNodeGroup,
|
|
166
|
+
groups: options.groups,
|
|
167
|
+
}),
|
|
173
168
|
)
|
|
169
|
+
return sortNodesByDependencies(nodesSortedByGroups, {
|
|
170
|
+
ignoreEslintDisabledNodes,
|
|
171
|
+
})
|
|
174
172
|
}
|
|
175
173
|
}
|
|
176
174
|
export { defaultOptions, sortEnum }
|
|
@@ -88,6 +88,11 @@ var sort_exports_default = createEslintRule({
|
|
|
88
88
|
computeLineCountModifier(node),
|
|
89
89
|
]
|
|
90
90
|
let name = node.source.value
|
|
91
|
+
let predefinedGroups = generatePredefinedGroups({
|
|
92
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
93
|
+
selectors: [selector],
|
|
94
|
+
modifiers,
|
|
95
|
+
})
|
|
91
96
|
let group = computeGroup({
|
|
92
97
|
customGroupMatcher: customGroup =>
|
|
93
98
|
doesCustomGroupMatch({
|
|
@@ -96,11 +101,7 @@ var sort_exports_default = createEslintRule({
|
|
|
96
101
|
customGroup,
|
|
97
102
|
modifiers,
|
|
98
103
|
}),
|
|
99
|
-
predefinedGroups
|
|
100
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
101
|
-
selectors: [selector],
|
|
102
|
-
modifiers,
|
|
103
|
-
}),
|
|
104
|
+
predefinedGroups,
|
|
104
105
|
options,
|
|
105
106
|
})
|
|
106
107
|
let sortingNode = {
|
|
@@ -48,15 +48,12 @@ function sortHeritageClause({ matchedAstSelectors, context, node }) {
|
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
50
|
let settings = getSettings(context.settings)
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
settings,
|
|
58
|
-
defaultOptions,
|
|
59
|
-
)
|
|
51
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
52
|
+
matchedAstSelectors,
|
|
53
|
+
heritageClauses,
|
|
54
|
+
context,
|
|
55
|
+
})
|
|
56
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
60
57
|
validateCustomSortConfig(options)
|
|
61
58
|
validateGroupsConfig({
|
|
62
59
|
modifiers: [],
|
|
@@ -29,15 +29,12 @@ function sortImportOrExportAttributes({
|
|
|
29
29
|
}
|
|
30
30
|
let { sourceCode, id } = context
|
|
31
31
|
let settings = getSettings(context.settings)
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
settings,
|
|
39
|
-
defaultOptions,
|
|
40
|
-
)
|
|
32
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
33
|
+
matchedAstSelectors,
|
|
34
|
+
attributes,
|
|
35
|
+
context,
|
|
36
|
+
})
|
|
37
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
41
38
|
validateCustomSortConfig(options)
|
|
42
39
|
validateGroupsConfig({
|
|
43
40
|
selectors: [],
|
|
@@ -135,7 +135,7 @@ function isCoreModule(value, environment) {
|
|
|
135
135
|
function clean(string_) {
|
|
136
136
|
return string_.replace(/^(?:node:){1,2}/u, '')
|
|
137
137
|
}
|
|
138
|
-
let [basePath] = value.split('/')
|
|
138
|
+
let [basePath] = value.split('/', 1)
|
|
139
139
|
let cleanValue = clean(value)
|
|
140
140
|
let cleanBase = clean(basePath)
|
|
141
141
|
if (nodeBuiltinModules.has(cleanValue) || nodeBuiltinModules.has(cleanBase)) {
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { default as ts } from 'typescript'
|
|
2
|
+
declare let requiredTypescriptAttributes: [
|
|
3
|
+
'createModuleResolutionCache',
|
|
4
|
+
'isExternalModuleNameRelative',
|
|
5
|
+
'parseJsonConfigFileContent',
|
|
6
|
+
'readConfigFile',
|
|
7
|
+
'resolveModuleName',
|
|
8
|
+
'sys',
|
|
9
|
+
]
|
|
10
|
+
export type TypescriptImport = Pick<
|
|
11
|
+
typeof ts,
|
|
12
|
+
(typeof requiredTypescriptAttributes)[number]
|
|
13
|
+
>
|
|
2
14
|
/**
|
|
3
15
|
* Dynamically loads the typescript module if it's available and caches it.
|
|
4
16
|
*
|
|
5
17
|
* @returns The TypeScript module or null if it's not available.
|
|
6
18
|
*/
|
|
7
|
-
export declare function getTypescriptImport():
|
|
19
|
+
export declare function getTypescriptImport(): TypescriptImport | null
|
|
20
|
+
export {}
|
|
@@ -8,6 +8,14 @@ var cachedImport
|
|
|
8
8
|
* made.
|
|
9
9
|
*/
|
|
10
10
|
var hasTriedLoadingTypescript = false
|
|
11
|
+
var requiredTypescriptAttributes = [
|
|
12
|
+
'createModuleResolutionCache',
|
|
13
|
+
'isExternalModuleNameRelative',
|
|
14
|
+
'parseJsonConfigFileContent',
|
|
15
|
+
'readConfigFile',
|
|
16
|
+
'resolveModuleName',
|
|
17
|
+
'sys',
|
|
18
|
+
]
|
|
11
19
|
/**
|
|
12
20
|
* Dynamically loads the typescript module if it's available and caches it.
|
|
13
21
|
*
|
|
@@ -22,10 +30,19 @@ function getTypescriptImport() {
|
|
|
22
30
|
}
|
|
23
31
|
hasTriedLoadingTypescript = true
|
|
24
32
|
try {
|
|
25
|
-
|
|
33
|
+
let tsImport = createRequire(import.meta.url)('typescript')
|
|
34
|
+
if (!isSupportedTypescriptVersion(tsImport)) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
cachedImport = tsImport
|
|
38
|
+
return cachedImport
|
|
26
39
|
} catch (_error) {
|
|
27
40
|
return null
|
|
28
41
|
}
|
|
29
|
-
|
|
42
|
+
}
|
|
43
|
+
function isSupportedTypescriptVersion(typescriptImport) {
|
|
44
|
+
return requiredTypescriptAttributes.every(attribute =>
|
|
45
|
+
Object.hasOwn(typescriptImport, attribute),
|
|
46
|
+
)
|
|
30
47
|
}
|
|
31
48
|
export { getTypescriptImport }
|
|
@@ -84,27 +84,22 @@ function getCompilerOptions(typescriptImport, contextCwd, filePath) {
|
|
|
84
84
|
)
|
|
85
85
|
}
|
|
86
86
|
let parsedContent = typescriptImport.parseJsonConfigFileContent(
|
|
87
|
-
configFileRead,
|
|
87
|
+
configFileRead.config,
|
|
88
88
|
typescriptImport.sys,
|
|
89
89
|
path.dirname(filePath),
|
|
90
90
|
)
|
|
91
|
-
|
|
92
|
-
typescriptImport.convertCompilerOptionsFromJson(
|
|
93
|
-
parsedContent.raw.config.compilerOptions,
|
|
94
|
-
path.dirname(filePath),
|
|
95
|
-
)
|
|
96
|
-
if (compilerOptionsConverted.errors.length > 0) {
|
|
91
|
+
if (parsedContent.errors.length > 0) {
|
|
97
92
|
throw new Error(
|
|
98
|
-
`Error getting compiler options: ${JSON.stringify(
|
|
93
|
+
`Error getting compiler options: ${JSON.stringify(parsedContent.errors)}`,
|
|
99
94
|
)
|
|
100
95
|
}
|
|
101
96
|
let cache = typescriptImport.createModuleResolutionCache(
|
|
102
97
|
contextCwd,
|
|
103
98
|
fileName => typescriptImport.sys.resolvePath(fileName),
|
|
104
|
-
|
|
99
|
+
parsedContent.options,
|
|
105
100
|
)
|
|
106
101
|
let output = {
|
|
107
|
-
compilerOptions:
|
|
102
|
+
compilerOptions: parsedContent.options,
|
|
108
103
|
cache,
|
|
109
104
|
}
|
|
110
105
|
contentCacheByPath.set(filePath, output)
|
|
@@ -102,8 +102,9 @@ var defaultOptions = {
|
|
|
102
102
|
var sort_imports_default = createEslintRule({
|
|
103
103
|
create: context => {
|
|
104
104
|
let settings = getSettings(context.settings)
|
|
105
|
+
let userOptions = context.options.at(0)
|
|
105
106
|
let options = getOptionsWithCleanGroups(
|
|
106
|
-
complete(
|
|
107
|
+
complete(userOptions, settings, defaultOptions),
|
|
107
108
|
)
|
|
108
109
|
validateGroupsConfig({
|
|
109
110
|
selectors: allSelectors,
|
|
@@ -364,11 +365,12 @@ function sortImportNodes({ sortingNodesWithoutPartitionId, options, context }) {
|
|
|
364
365
|
for (let contentSeparatedSortingNodeGroup of contentSeparatedSortingNodeGroups) {
|
|
365
366
|
let sortingNodeGroups = [...contentSeparatedSortingNodeGroup]
|
|
366
367
|
if (options.useExperimentalDependencyDetection) {
|
|
368
|
+
let dependenciesBySortingNode = computeDependenciesBySortingNode({
|
|
369
|
+
sortingNodes: sortingNodeGroups.flat(),
|
|
370
|
+
sourceCode,
|
|
371
|
+
})
|
|
367
372
|
sortingNodeGroups = populateSortingNodeGroupsWithDependencies({
|
|
368
|
-
dependenciesBySortingNode
|
|
369
|
-
sortingNodes: sortingNodeGroups.flat(),
|
|
370
|
-
sourceCode,
|
|
371
|
-
}),
|
|
373
|
+
dependenciesBySortingNode,
|
|
372
374
|
sortingNodeGroups,
|
|
373
375
|
})
|
|
374
376
|
}
|
|
@@ -391,25 +393,25 @@ function sortImportNodes({ sortingNodesWithoutPartitionId, options, context }) {
|
|
|
391
393
|
}
|
|
392
394
|
function createSortNodesExcludingEslintDisabled(nodeGroups) {
|
|
393
395
|
return function (ignoreEslintDisabledNodes) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}),
|
|
410
|
-
),
|
|
411
|
-
{ ignoreEslintDisabledNodes },
|
|
396
|
+
let nodesSortedByGroups = nodeGroups.flatMap(nodes =>
|
|
397
|
+
sortNodesByGroups({
|
|
398
|
+
isNodeIgnoredForGroup: ({ groupIndex }) => {
|
|
399
|
+
if (options.sortSideEffects) {
|
|
400
|
+
return false
|
|
401
|
+
}
|
|
402
|
+
return isSideEffectOnlyGroup(options.groups[groupIndex])
|
|
403
|
+
},
|
|
404
|
+
isNodeIgnored: node => node.isIgnored,
|
|
405
|
+
optionsByGroupIndexComputer,
|
|
406
|
+
comparatorByOptionsComputer,
|
|
407
|
+
ignoreEslintDisabledNodes,
|
|
408
|
+
groups: options.groups,
|
|
409
|
+
nodes,
|
|
410
|
+
}),
|
|
412
411
|
)
|
|
412
|
+
return sortNodesByDependencies(nodesSortedByGroups, {
|
|
413
|
+
ignoreEslintDisabledNodes,
|
|
414
|
+
})
|
|
413
415
|
}
|
|
414
416
|
}
|
|
415
417
|
function hasContentBetweenNodes(left, right) {
|
|
@@ -421,6 +423,11 @@ function sortImportNodes({ sortingNodesWithoutPartitionId, options, context }) {
|
|
|
421
423
|
}
|
|
422
424
|
}
|
|
423
425
|
function computeGroupExceptUnknown({ selectors, modifiers, options, name }) {
|
|
426
|
+
let predefinedGroups = generatePredefinedGroups({
|
|
427
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
428
|
+
selectors,
|
|
429
|
+
modifiers,
|
|
430
|
+
})
|
|
424
431
|
let computedCustomGroup = computeGroup({
|
|
425
432
|
customGroupMatcher: customGroup =>
|
|
426
433
|
doesCustomGroupMatch({
|
|
@@ -429,11 +436,7 @@ function computeGroupExceptUnknown({ selectors, modifiers, options, name }) {
|
|
|
429
436
|
modifiers,
|
|
430
437
|
selectors,
|
|
431
438
|
}),
|
|
432
|
-
predefinedGroups
|
|
433
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
434
|
-
selectors,
|
|
435
|
-
modifiers,
|
|
436
|
-
}),
|
|
439
|
+
predefinedGroups,
|
|
437
440
|
options,
|
|
438
441
|
})
|
|
439
442
|
if (computedCustomGroup === 'unknown') {
|
|
@@ -451,7 +454,7 @@ var styleExtensions = [
|
|
|
451
454
|
'.sss',
|
|
452
455
|
]
|
|
453
456
|
function isStyle(value) {
|
|
454
|
-
let [cleanedValue] = value.split('?')
|
|
457
|
+
let [cleanedValue] = value.split('?', 1)
|
|
455
458
|
return styleExtensions.some(extension => cleanedValue?.endsWith(extension))
|
|
456
459
|
}
|
|
457
460
|
export { sort_imports_default as default }
|
|
@@ -52,16 +52,13 @@ function sortJsxObject({ matchedAstSelectors, context, node }) {
|
|
|
52
52
|
}
|
|
53
53
|
let { sourceCode, id } = context
|
|
54
54
|
let settings = getSettings(context.settings)
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
settings,
|
|
63
|
-
defaultOptions,
|
|
64
|
-
)
|
|
55
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
56
|
+
matchedAstSelectors,
|
|
57
|
+
sourceCode,
|
|
58
|
+
context,
|
|
59
|
+
node,
|
|
60
|
+
})
|
|
61
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
65
62
|
validateCustomSortConfig(options)
|
|
66
63
|
validateGroupsConfig({
|
|
67
64
|
selectors: allSelectors,
|
|
@@ -90,6 +87,11 @@ function sortJsxObject({ matchedAstSelectors, context, node }) {
|
|
|
90
87
|
modifiers.push('multiline')
|
|
91
88
|
}
|
|
92
89
|
selectors.push('prop')
|
|
90
|
+
let predefinedGroups = generatePredefinedGroups({
|
|
91
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
92
|
+
selectors,
|
|
93
|
+
modifiers,
|
|
94
|
+
})
|
|
93
95
|
let group = computeGroup({
|
|
94
96
|
customGroupMatcher: customGroup =>
|
|
95
97
|
doesCustomGroupMatch({
|
|
@@ -100,11 +102,7 @@ function sortJsxObject({ matchedAstSelectors, context, node }) {
|
|
|
100
102
|
selectors,
|
|
101
103
|
modifiers,
|
|
102
104
|
}),
|
|
103
|
-
predefinedGroups
|
|
104
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
105
|
-
selectors,
|
|
106
|
-
modifiers,
|
|
107
|
-
}),
|
|
105
|
+
predefinedGroups,
|
|
108
106
|
options,
|
|
109
107
|
})
|
|
110
108
|
let sortingNode = {
|
|
@@ -53,15 +53,12 @@ function sortPotentialMap({ matchedAstSelectors, context, node }) {
|
|
|
53
53
|
}
|
|
54
54
|
let { sourceCode, id } = context
|
|
55
55
|
let settings = getSettings(context.settings)
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
settings,
|
|
63
|
-
defaultOptions,
|
|
64
|
-
)
|
|
56
|
+
let matchedContextOptions = computeMatchedContextOptions({
|
|
57
|
+
matchedAstSelectors,
|
|
58
|
+
elements,
|
|
59
|
+
context,
|
|
60
|
+
})
|
|
61
|
+
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
65
62
|
validateCustomSortConfig(options)
|
|
66
63
|
validateGroupsConfig({
|
|
67
64
|
selectors: [],
|