eslint-plugin-perfectionist 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes.js +3 -3
- package/dist/rules/sort-classes/compute-dependencies.js +2 -3
- package/dist/rules/sort-classes/compute-overload-signature-groups.d.ts +13 -0
- package/dist/rules/sort-classes/compute-overload-signature-groups.js +58 -0
- package/dist/rules/sort-classes/types.d.ts +9 -1
- package/dist/rules/sort-classes.d.ts +2 -2
- package/dist/rules/sort-classes.js +32 -48
- package/dist/rules/sort-decorators.js +3 -3
- package/dist/rules/sort-enums/compute-dependencies-by-sorting-node.d.ts +13 -0
- package/dist/rules/sort-enums/compute-dependencies-by-sorting-node.js +51 -0
- package/dist/rules/sort-enums/compute-dependencies.d.ts +14 -0
- package/dist/rules/sort-enums/compute-dependencies.js +73 -0
- package/dist/rules/sort-enums/types.d.ts +2 -0
- package/dist/rules/sort-enums.js +49 -54
- package/dist/rules/sort-export-attributes.js +4 -3
- package/dist/rules/sort-exports.js +2 -3
- package/dist/rules/sort-heritage-clauses.js +3 -3
- package/dist/rules/sort-import-attributes.js +4 -3
- package/dist/rules/sort-imports/comparator-by-options-computer.js +0 -1
- package/dist/rules/sort-imports/compute-dependencies.d.ts +4 -7
- package/dist/rules/sort-imports/compute-dependency-names.d.ts +2 -5
- package/dist/rules/sort-imports/compute-node-name.d.ts +2 -5
- package/dist/rules/sort-imports/compute-specifier-modifiers.d.ts +2 -5
- package/dist/rules/sort-imports/compute-specifier-name.d.ts +2 -5
- package/dist/rules/sort-imports/is-non-external-reference-ts-import-equals.d.ts +2 -4
- package/dist/rules/sort-imports/is-side-effect-import.d.ts +2 -5
- package/dist/rules/sort-imports/types.d.ts +7 -5
- package/dist/rules/sort-imports.js +29 -11
- package/dist/rules/sort-jsx-props.js +4 -3
- package/dist/rules/sort-maps.js +4 -3
- package/dist/rules/sort-modules/build-comparator-by-options-computer.d.ts +7 -2
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +5 -37
- package/dist/rules/sort-modules/build-usage-comparator.d.ts +29 -0
- package/dist/rules/sort-modules/build-usage-comparator.js +115 -0
- package/dist/rules/sort-modules/compute-dependencies-by-sorting-node.d.ts +16 -0
- package/dist/rules/sort-modules/compute-dependencies-by-sorting-node.js +127 -0
- package/dist/rules/sort-modules/compute-dependencies.d.ts +2 -0
- package/dist/rules/sort-modules/compute-dependencies.js +9 -2
- package/dist/rules/sort-modules/compute-node-details.d.ts +11 -1
- package/dist/rules/sort-modules/compute-node-details.js +25 -4
- package/dist/rules/sort-modules/compute-overload-signature-groups.d.ts +11 -0
- package/dist/rules/sort-modules/compute-overload-signature-groups.js +67 -0
- package/dist/rules/sort-modules/types.d.ts +10 -4
- package/dist/rules/sort-modules.d.ts +2 -2
- package/dist/rules/sort-modules.js +59 -16
- package/dist/rules/sort-named-exports.js +4 -3
- package/dist/rules/sort-named-imports.js +4 -3
- package/dist/rules/sort-object-types/types.d.ts +1 -5
- package/dist/rules/sort-object-types.js +5 -3
- package/dist/rules/sort-objects/comparator-by-options-computer.d.ts +6 -0
- package/dist/rules/sort-objects/comparator-by-options-computer.js +39 -0
- package/dist/rules/sort-objects/compute-dependencies.d.ts +2 -0
- package/dist/rules/sort-objects/compute-dependencies.js +75 -0
- package/dist/rules/sort-objects/compute-matched-context-options.js +2 -0
- package/dist/rules/sort-objects/is-style-component.d.ts +10 -0
- package/dist/rules/sort-objects/{is-style-node.js → is-style-component.js} +24 -1
- package/dist/rules/sort-objects/types.d.ts +22 -5
- package/dist/rules/sort-objects/types.js +8 -0
- package/dist/rules/sort-objects.js +136 -204
- package/dist/rules/sort-union-types.js +3 -3
- package/dist/rules/sort-variable-declarations/compute-dependencies.d.ts +12 -0
- package/dist/rules/sort-variable-declarations/compute-dependencies.js +74 -0
- package/dist/rules/sort-variable-declarations/compute-node-name.d.ts +17 -0
- package/dist/rules/sort-variable-declarations/compute-node-name.js +15 -0
- package/dist/rules/sort-variable-declarations/types.d.ts +14 -1
- package/dist/rules/sort-variable-declarations.js +50 -108
- package/dist/types/common-groups-options.d.ts +4 -4
- package/dist/utils/{build-default-options-by-group-index-computer.d.ts → build-options-by-group-index-computer.d.ts} +4 -5
- package/dist/utils/{build-default-options-by-group-index-computer.js → build-options-by-group-index-computer.js} +2 -2
- package/dist/utils/build-sorting-node-by-node-map.d.ts +10 -0
- package/dist/utils/build-sorting-node-by-node-map.js +8 -0
- package/dist/utils/compute-consecutive-parent-nodes-by-type.d.ts +6 -0
- package/dist/utils/compute-deep-scope-references.d.ts +13 -0
- package/dist/utils/compute-deep-scope-references.js +10 -0
- package/dist/utils/compute-dependencies-by-sorting-node.d.ts +42 -0
- package/dist/utils/compute-dependencies-by-sorting-node.js +88 -0
- package/dist/utils/compute-dependencies-outside-functions-by-sorting-node.d.ts +13 -0
- package/dist/utils/compute-dependencies-outside-functions-by-sorting-node.js +28 -0
- package/dist/utils/compute-parent-nodes-with-types.d.ts +8 -0
- package/dist/utils/compute-parent-nodes-with-types.js +11 -1
- package/dist/utils/does-sorting-node-have-one-of-dependency-names.d.ts +14 -0
- package/dist/utils/does-sorting-node-have-one-of-dependency-names.js +7 -0
- package/dist/utils/generate-predefined-groups.js +3 -7
- package/dist/utils/get-enum-members.d.ts +4 -4
- package/dist/utils/get-eslint-disabled-lines.js +1 -1
- package/dist/utils/get-group-index.d.ts +4 -4
- package/dist/utils/get-newlines-between-errors.d.ts +6 -3
- package/dist/utils/get-newlines-between-errors.js +1 -1
- package/dist/utils/get-options-with-clean-groups.d.ts +1 -1
- package/dist/utils/json-schemas/common-json-schemas.d.ts +1 -0
- package/dist/utils/json-schemas/common-json-schemas.js +6 -0
- package/dist/utils/make-comment-after-fixes.js +2 -3
- package/dist/utils/overload-signature/build-overload-signature-newlines-between-value-getter.d.ts +13 -0
- package/dist/utils/overload-signature/build-overload-signature-newlines-between-value-getter.js +13 -0
- package/dist/utils/overload-signature/overload-signature-group.d.ts +21 -0
- package/dist/utils/overload-signature/overload-signature-group.js +12 -0
- package/dist/utils/overload-signature/populate-sorting-node-groups-with-overload-signature.d.ts +25 -0
- package/dist/utils/overload-signature/populate-sorting-node-groups-with-overload-signature.js +75 -0
- package/dist/utils/populate-sorting-node-groups-with-dependencies.d.ts +25 -0
- package/dist/utils/populate-sorting-node-groups-with-dependencies.js +37 -0
- package/dist/utils/range-contains-range.d.ts +12 -0
- package/dist/utils/range-contains-range.js +4 -0
- package/dist/utils/report-all-errors.js +3 -4
- package/dist/utils/report-errors.d.ts +1 -1
- package/dist/utils/report-errors.js +1 -1
- package/package.json +2 -2
- package/dist/rules/sort-classes/get-overload-signature-groups.d.ts +0 -10
- package/dist/rules/sort-classes/get-overload-signature-groups.js +0 -33
- package/dist/rules/sort-objects/is-style-node.d.ts +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ESLint, Linter } from 'eslint'
|
|
2
|
-
interface PluginConfigs
|
|
2
|
+
interface PluginConfigs extends Record<
|
|
3
|
+
string,
|
|
4
|
+
Linter.LegacyConfig | Linter.Config[] | Linter.Config
|
|
5
|
+
> {
|
|
3
6
|
'recommended-alphabetical-legacy': Linter.LegacyConfig
|
|
4
7
|
'recommended-line-length-legacy': Linter.LegacyConfig
|
|
5
8
|
'recommended-natural-legacy': Linter.LegacyConfig
|
package/dist/package.json.js
CHANGED
|
@@ -14,12 +14,12 @@ import {
|
|
|
14
14
|
buildCommonJsonSchemas,
|
|
15
15
|
} from '../utils/json-schemas/common-json-schemas.js'
|
|
16
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
17
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
19
18
|
import {
|
|
20
19
|
additionalCustomGroupMatchOptionsJsonSchema,
|
|
21
20
|
allSelectors,
|
|
22
21
|
} from './sort-array-includes/types.js'
|
|
22
|
+
import { buildOptionsByGroupIndexComputer } from '../utils/build-options-by-group-index-computer.js'
|
|
23
23
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
24
24
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
25
25
|
import { filterOptionsByAllNamesMatch } from '../utils/filter-options-by-all-names-match.js'
|
|
@@ -145,6 +145,7 @@ function sortArray({ availableMessageIds, elements, context }) {
|
|
|
145
145
|
ruleName: id,
|
|
146
146
|
sourceCode,
|
|
147
147
|
})
|
|
148
|
+
let optionsByGroupIndexComputer = buildOptionsByGroupIndexComputer(options)
|
|
148
149
|
let formattedMembers = elements.reduce(
|
|
149
150
|
(accumulator, element) => {
|
|
150
151
|
if (element === null) {
|
|
@@ -198,9 +199,8 @@ function sortArray({ availableMessageIds, elements, context }) {
|
|
|
198
199
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
199
200
|
return formattedMembers.flatMap(nodes2 =>
|
|
200
201
|
sortNodesByGroups({
|
|
201
|
-
optionsByGroupIndexComputer:
|
|
202
|
-
buildDefaultOptionsByGroupIndexComputer(options),
|
|
203
202
|
comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
|
|
203
|
+
optionsByGroupIndexComputer,
|
|
204
204
|
ignoreEslintDisabledNodes,
|
|
205
205
|
groups: options.groups,
|
|
206
206
|
nodes: nodes2,
|
|
@@ -17,14 +17,13 @@ function computeDependencies({
|
|
|
17
17
|
traverseNode(nodeValue.alternate)
|
|
18
18
|
break
|
|
19
19
|
case AST_NODE_TYPES.MemberExpression:
|
|
20
|
-
dependencies
|
|
21
|
-
...dependencies,
|
|
20
|
+
dependencies.push(
|
|
22
21
|
...computeMemberExpressionDependencies({
|
|
23
22
|
memberExpression: nodeValue,
|
|
24
23
|
isMemberStatic,
|
|
25
24
|
className,
|
|
26
25
|
}),
|
|
27
|
-
|
|
26
|
+
)
|
|
28
27
|
break
|
|
29
28
|
case AST_NODE_TYPES.CallExpression:
|
|
30
29
|
if (!('name' in nodeValue.callee)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils'
|
|
2
|
+
import { OverloadSignatureGroup } from '../../utils/overload-signature/overload-signature-group.js'
|
|
3
|
+
type Method = TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition
|
|
4
|
+
/**
|
|
5
|
+
* Returns a list of groups of overload signatures.
|
|
6
|
+
*
|
|
7
|
+
* @param classElements - The class elements to process.
|
|
8
|
+
* @returns A list of overload signature groups.
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeOverloadSignatureGroups(
|
|
11
|
+
classElements: TSESTree.ClassElement[],
|
|
12
|
+
): OverloadSignatureGroup<Method>[]
|
|
13
|
+
export {}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import { OverloadSignatureGroup } from '../../utils/overload-signature/overload-signature-group.js'
|
|
3
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
4
|
+
import { isSortable } from '../../utils/is-sortable.js'
|
|
5
|
+
function computeOverloadSignatureGroups(classElements) {
|
|
6
|
+
let methods = classElements
|
|
7
|
+
.filter(
|
|
8
|
+
classElement =>
|
|
9
|
+
classElement.type === AST_NODE_TYPES.MethodDefinition ||
|
|
10
|
+
classElement.type === AST_NODE_TYPES.TSAbstractMethodDefinition,
|
|
11
|
+
)
|
|
12
|
+
.filter(classElement => classElement.kind === 'method')
|
|
13
|
+
let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
14
|
+
let overloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
15
|
+
for (let method of methods) {
|
|
16
|
+
if (method.key.type !== AST_NODE_TYPES.Identifier) {
|
|
17
|
+
continue
|
|
18
|
+
}
|
|
19
|
+
let { name } = method.key
|
|
20
|
+
let mapToUse = method.static
|
|
21
|
+
? staticOverloadSignaturesByName
|
|
22
|
+
: overloadSignaturesByName
|
|
23
|
+
let overloadSignaturesArray = mapToUse.get(name)
|
|
24
|
+
if (!overloadSignaturesArray) {
|
|
25
|
+
overloadSignaturesArray = []
|
|
26
|
+
mapToUse.set(name, overloadSignaturesArray)
|
|
27
|
+
}
|
|
28
|
+
overloadSignaturesArray.push(method)
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
...overloadSignaturesByName.values(),
|
|
32
|
+
...staticOverloadSignaturesByName.values(),
|
|
33
|
+
]
|
|
34
|
+
.filter(isSortable)
|
|
35
|
+
.map(buildOverloadSignatureGroup)
|
|
36
|
+
}
|
|
37
|
+
function buildOverloadSignatureGroup(methods) {
|
|
38
|
+
let implementation = methods.find(isMethodImplementation) ?? methods.at(-1)
|
|
39
|
+
let overloadSignatures = methods.filter(
|
|
40
|
+
method => !isMethodImplementation(method),
|
|
41
|
+
)
|
|
42
|
+
return new OverloadSignatureGroup({
|
|
43
|
+
overloadSignatures,
|
|
44
|
+
implementation,
|
|
45
|
+
})
|
|
46
|
+
function isMethodImplementation(method) {
|
|
47
|
+
switch (method.value.type) {
|
|
48
|
+
case AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
|
|
49
|
+
return false
|
|
50
|
+
case AST_NODE_TYPES.FunctionExpression:
|
|
51
|
+
return true
|
|
52
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
53
|
+
default:
|
|
54
|
+
throw new UnreachableCaseError(method.value)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export { computeOverloadSignatureGroups }
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
+
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
2
4
|
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
3
5
|
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
4
6
|
/**
|
|
@@ -7,7 +9,7 @@ import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
|
7
9
|
* This rule enforces consistent ordering of class members (properties, methods,
|
|
8
10
|
* constructors, etc.) to improve code readability and maintainability.
|
|
9
11
|
*/
|
|
10
|
-
export type
|
|
12
|
+
export type Options = [
|
|
11
13
|
Partial<
|
|
12
14
|
{
|
|
13
15
|
/**
|
|
@@ -23,6 +25,12 @@ export type SortClassesOptions = [
|
|
|
23
25
|
>
|
|
24
26
|
>,
|
|
25
27
|
]
|
|
28
|
+
export interface SortClassesSortingNode extends SortingNodeWithDependencies<TSESTree.ClassElement> {
|
|
29
|
+
overloadSignatureImplementation:
|
|
30
|
+
| TSESTree.TSAbstractMethodDefinition
|
|
31
|
+
| TSESTree.MethodDefinition
|
|
32
|
+
| null
|
|
33
|
+
}
|
|
26
34
|
/**
|
|
27
35
|
* Union type of all available class member selectors. Used to identify and
|
|
28
36
|
* categorize different types of class members.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Options } from './sort-classes/types.js'
|
|
2
2
|
declare const ORDER_ERROR_ID = 'unexpectedClassesOrder'
|
|
3
3
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedClassesGroupOrder'
|
|
4
4
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenClassMembers'
|
|
@@ -12,7 +12,7 @@ type MessageId =
|
|
|
12
12
|
| typeof ORDER_ERROR_ID
|
|
13
13
|
declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
|
|
14
14
|
MessageId,
|
|
15
|
-
|
|
15
|
+
Options,
|
|
16
16
|
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
17
17
|
import('@typescript-eslint/utils/ts-eslint').RuleListener
|
|
18
18
|
> & {
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
MISSED_SPACING_ERROR,
|
|
7
7
|
DEPENDENCY_ORDER_ERROR,
|
|
8
8
|
} from '../utils/report-errors.js'
|
|
9
|
+
import { buildOverloadSignatureNewlinesBetweenValueGetter } from '../utils/overload-signature/build-overload-signature-newlines-between-value-getter.js'
|
|
10
|
+
import { populateSortingNodeGroupsWithOverloadSignature } from '../utils/overload-signature/populate-sorting-node-groups-with-overload-signature.js'
|
|
9
11
|
import {
|
|
10
12
|
partitionByNewLineJsonSchema,
|
|
11
13
|
partitionByCommentJsonSchema,
|
|
@@ -16,19 +18,19 @@ import {
|
|
|
16
18
|
allModifiers,
|
|
17
19
|
} from './sort-classes/types.js'
|
|
18
20
|
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
19
|
-
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
20
21
|
import {
|
|
21
22
|
buildRegexJsonSchema,
|
|
22
23
|
buildCommonJsonSchemas,
|
|
23
24
|
} from '../utils/json-schemas/common-json-schemas.js'
|
|
24
25
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
25
26
|
import { computeIndexSignatureDetails } from './sort-classes/node-info/compute-index-signature-details.js'
|
|
27
|
+
import { buildOptionsByGroupIndexComputer } from '../utils/build-options-by-group-index-computer.js'
|
|
26
28
|
import { computeStaticBlockDetails } from './sort-classes/node-info/compute-static-block-details.js'
|
|
29
|
+
import { computeOverloadSignatureGroups } from './sort-classes/compute-overload-signature-groups.js'
|
|
27
30
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
28
31
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
29
32
|
import { computePropertyDetails } from './sort-classes/node-info/compute-property-details.js'
|
|
30
33
|
import { computeAccessorDetails } from './sort-classes/node-info/compute-accessor-details.js'
|
|
31
|
-
import { getOverloadSignatureGroups } from './sort-classes/get-overload-signature-groups.js'
|
|
32
34
|
import { computeMethodDetails } from './sort-classes/node-info/compute-method-details.js'
|
|
33
35
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
34
36
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
@@ -114,9 +116,12 @@ const sortClasses = createEslintRule({
|
|
|
114
116
|
ruleName: id,
|
|
115
117
|
sourceCode,
|
|
116
118
|
})
|
|
119
|
+
let optionsByGroupIndexComputer =
|
|
120
|
+
buildOptionsByGroupIndexComputer(options)
|
|
121
|
+
let overloadSignatureNewlinesBetweenValueGetter =
|
|
122
|
+
buildOverloadSignatureNewlinesBetweenValueGetter()
|
|
117
123
|
let className = node.parent.id?.name
|
|
118
|
-
let
|
|
119
|
-
let formattedNodes = node.body.reduce(
|
|
124
|
+
let sortingNodeGroupsWithoutOverloadSignature = node.body.reduce(
|
|
120
125
|
(accumulator, member) => {
|
|
121
126
|
let dependencies = []
|
|
122
127
|
let isDecorated = false
|
|
@@ -216,21 +221,9 @@ const sortClasses = createEslintRule({
|
|
|
216
221
|
predefinedGroups,
|
|
217
222
|
options,
|
|
218
223
|
})
|
|
219
|
-
let overloadSignatureGroupMemberIndex =
|
|
220
|
-
overloadSignatureGroups.findIndex(overloadSignatures =>
|
|
221
|
-
overloadSignatures.includes(member),
|
|
222
|
-
)
|
|
223
|
-
let overloadSignatureGroupMember =
|
|
224
|
-
overloadSignatureGroups[overloadSignatureGroupMemberIndex]?.at(-1)
|
|
225
224
|
let sortingNode = {
|
|
226
|
-
overloadSignaturesGroupId:
|
|
227
|
-
overloadSignatureGroupMemberIndex === -1
|
|
228
|
-
? null
|
|
229
|
-
: overloadSignatureGroupMemberIndex,
|
|
230
|
-
size: overloadSignatureGroupMember
|
|
231
|
-
? rangeToDiff(overloadSignatureGroupMember, sourceCode)
|
|
232
|
-
: rangeToDiff(member, sourceCode),
|
|
233
225
|
isEslintDisabled: isNodeEslintDisabled(member, eslintDisabledLines),
|
|
226
|
+
size: rangeToDiff(member, sourceCode),
|
|
234
227
|
addSafetySemicolonWhenInline,
|
|
235
228
|
dependencyNames,
|
|
236
229
|
node: member,
|
|
@@ -257,51 +250,42 @@ const sortClasses = createEslintRule({
|
|
|
257
250
|
},
|
|
258
251
|
[[]],
|
|
259
252
|
)
|
|
253
|
+
let sortingNodeGroups = populateSortingNodeGroupsWithOverloadSignature({
|
|
254
|
+
overloadSignatureGroups: computeOverloadSignatureGroups(node.body),
|
|
255
|
+
sortingNodeGroups: sortingNodeGroupsWithoutOverloadSignature,
|
|
256
|
+
})
|
|
257
|
+
let sortingNodes = sortingNodeGroups.flat()
|
|
258
|
+
reportAllErrors({
|
|
259
|
+
availableMessageIds: {
|
|
260
|
+
missedSpacingBetweenMembers: MISSED_SPACING_ERROR_ID,
|
|
261
|
+
unexpectedDependencyOrder: DEPENDENCY_ORDER_ERROR_ID,
|
|
262
|
+
extraSpacingBetweenMembers: EXTRA_SPACING_ERROR_ID,
|
|
263
|
+
unexpectedGroupOrder: GROUP_ORDER_ERROR_ID,
|
|
264
|
+
unexpectedOrder: ORDER_ERROR_ID,
|
|
265
|
+
},
|
|
266
|
+
newlinesBetweenValueGetter: overloadSignatureNewlinesBetweenValueGetter,
|
|
267
|
+
sortNodesExcludingEslintDisabled,
|
|
268
|
+
nodes: sortingNodes,
|
|
269
|
+
options,
|
|
270
|
+
context,
|
|
271
|
+
})
|
|
260
272
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
261
|
-
let nodesSortedByGroups =
|
|
273
|
+
let nodesSortedByGroups = sortingNodeGroups.flatMap(sortingNodeGroup =>
|
|
262
274
|
sortNodesByGroups({
|
|
263
275
|
isNodeIgnored: sortingNode =>
|
|
264
276
|
getGroupIndex(options.groups, sortingNode) ===
|
|
265
277
|
options.groups.length,
|
|
266
|
-
optionsByGroupIndexComputer:
|
|
267
|
-
buildDefaultOptionsByGroupIndexComputer(options),
|
|
268
278
|
comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
|
|
279
|
+
optionsByGroupIndexComputer,
|
|
269
280
|
ignoreEslintDisabledNodes,
|
|
281
|
+
nodes: sortingNodeGroup,
|
|
270
282
|
groups: options.groups,
|
|
271
|
-
nodes: nodes2,
|
|
272
283
|
}),
|
|
273
284
|
)
|
|
274
285
|
return sortNodesByDependencies(nodesSortedByGroups, {
|
|
275
286
|
ignoreEslintDisabledNodes,
|
|
276
287
|
})
|
|
277
288
|
}
|
|
278
|
-
let nodes = formattedNodes.flat()
|
|
279
|
-
reportAllErrors({
|
|
280
|
-
newlinesBetweenValueGetter: ({
|
|
281
|
-
computedNewlinesBetween,
|
|
282
|
-
right,
|
|
283
|
-
left,
|
|
284
|
-
}) => {
|
|
285
|
-
if (
|
|
286
|
-
left.overloadSignaturesGroupId !== null &&
|
|
287
|
-
left.overloadSignaturesGroupId === right.overloadSignaturesGroupId
|
|
288
|
-
) {
|
|
289
|
-
return 0
|
|
290
|
-
}
|
|
291
|
-
return computedNewlinesBetween
|
|
292
|
-
},
|
|
293
|
-
availableMessageIds: {
|
|
294
|
-
missedSpacingBetweenMembers: MISSED_SPACING_ERROR_ID,
|
|
295
|
-
unexpectedDependencyOrder: DEPENDENCY_ORDER_ERROR_ID,
|
|
296
|
-
extraSpacingBetweenMembers: EXTRA_SPACING_ERROR_ID,
|
|
297
|
-
unexpectedGroupOrder: GROUP_ORDER_ERROR_ID,
|
|
298
|
-
unexpectedOrder: ORDER_ERROR_ID,
|
|
299
|
-
},
|
|
300
|
-
sortNodesExcludingEslintDisabled,
|
|
301
|
-
options,
|
|
302
|
-
context,
|
|
303
|
-
nodes,
|
|
304
|
-
})
|
|
305
289
|
},
|
|
306
290
|
}),
|
|
307
291
|
meta: {
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
MISSED_SPACING_ERROR,
|
|
11
11
|
} from '../utils/report-errors.js'
|
|
12
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
13
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
14
|
+
import { buildOptionsByGroupIndexComputer } from '../utils/build-options-by-group-index-computer.js'
|
|
15
15
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
16
16
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
17
17
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
@@ -178,6 +178,7 @@ function sortDecorators$1(context, options, decorators) {
|
|
|
178
178
|
ruleName: id,
|
|
179
179
|
sourceCode,
|
|
180
180
|
})
|
|
181
|
+
let optionsByGroupIndexComputer = buildOptionsByGroupIndexComputer(options)
|
|
181
182
|
let formattedMembers = decorators.reduce(
|
|
182
183
|
(accumulator, decorator) => {
|
|
183
184
|
let name = getDecoratorName({
|
|
@@ -224,9 +225,8 @@ function sortDecorators$1(context, options, decorators) {
|
|
|
224
225
|
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
225
226
|
return formattedMembers.flatMap(nodes2 =>
|
|
226
227
|
sortNodesByGroups({
|
|
227
|
-
optionsByGroupIndexComputer:
|
|
228
|
-
buildDefaultOptionsByGroupIndexComputer(options),
|
|
229
228
|
comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
|
|
229
|
+
optionsByGroupIndexComputer,
|
|
230
230
|
ignoreEslintDisabledNodes,
|
|
231
231
|
groups: options.groups,
|
|
232
232
|
nodes: nodes2,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
+
import { SortEnumsSortingNode } from './types.js'
|
|
3
|
+
type SortingNodeWithoutDependencies = Omit<SortEnumsSortingNode, 'dependencies'>
|
|
4
|
+
export declare function computeDependenciesBySortingNode({
|
|
5
|
+
sortingNodes,
|
|
6
|
+
sourceCode,
|
|
7
|
+
enumName,
|
|
8
|
+
}: {
|
|
9
|
+
sortingNodes: SortingNodeWithoutDependencies[]
|
|
10
|
+
sourceCode: TSESLint.SourceCode
|
|
11
|
+
enumName: string
|
|
12
|
+
}): Map<SortingNodeWithoutDependencies, SortingNodeWithoutDependencies[]>
|
|
13
|
+
export {}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import { computeDependenciesBySortingNode as computeDependenciesBySortingNode$1 } from '../../utils/compute-dependencies-by-sorting-node.js'
|
|
3
|
+
import { doesSortingNodeHaveOneOfDependencyNames } from '../../utils/does-sorting-node-have-one-of-dependency-names.js'
|
|
4
|
+
import { computeParentNodesWithTypes } from '../../utils/compute-parent-nodes-with-types.js'
|
|
5
|
+
function computeDependenciesBySortingNode({
|
|
6
|
+
sortingNodes,
|
|
7
|
+
sourceCode,
|
|
8
|
+
enumName,
|
|
9
|
+
}) {
|
|
10
|
+
return computeDependenciesBySortingNode$1({
|
|
11
|
+
additionalIdentifierDependenciesComputer:
|
|
12
|
+
buildAdditionalIdentifierDependenciesComputer({
|
|
13
|
+
sortingNodes,
|
|
14
|
+
enumName,
|
|
15
|
+
}),
|
|
16
|
+
sortingNodes,
|
|
17
|
+
sourceCode,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
function buildAdditionalIdentifierDependenciesComputer({
|
|
21
|
+
sortingNodes,
|
|
22
|
+
enumName,
|
|
23
|
+
}) {
|
|
24
|
+
return ({ referencingSortingNode, identifier }) => {
|
|
25
|
+
if (identifier.name !== enumName) {
|
|
26
|
+
return []
|
|
27
|
+
}
|
|
28
|
+
let relatedIdentifiers = computeMemberExpressionIdentifiers(
|
|
29
|
+
identifier,
|
|
30
|
+
referencingSortingNode,
|
|
31
|
+
)
|
|
32
|
+
return sortingNodes.filter(sortingNode =>
|
|
33
|
+
doesSortingNodeHaveOneOfDependencyNames(sortingNode, relatedIdentifiers),
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function computeMemberExpressionIdentifiers(
|
|
38
|
+
identifier,
|
|
39
|
+
referencingSortingNode,
|
|
40
|
+
) {
|
|
41
|
+
return computeParentNodesWithTypes({
|
|
42
|
+
allowedTypes: [AST_NODE_TYPES.MemberExpression],
|
|
43
|
+
maxParent: referencingSortingNode.node,
|
|
44
|
+
consecutiveOnly: true,
|
|
45
|
+
node: identifier,
|
|
46
|
+
})
|
|
47
|
+
.map(node => node.property)
|
|
48
|
+
.filter(property => property.type === AST_NODE_TYPES.Identifier)
|
|
49
|
+
.map(property => property.name)
|
|
50
|
+
}
|
|
51
|
+
export { computeDependenciesBySortingNode }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
/**
|
|
3
|
+
* Extract dependencies from an enum.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated - To remove when experimental dependency detection is the only
|
|
6
|
+
* option.
|
|
7
|
+
* @param expression - The enum or class declaration node.
|
|
8
|
+
* @param enumName - The name of the enum being processed.
|
|
9
|
+
* @returns The list of dependencies.
|
|
10
|
+
*/
|
|
11
|
+
export declare function computeDependencies(
|
|
12
|
+
expression: TSESTree.Expression,
|
|
13
|
+
enumName: string,
|
|
14
|
+
): string[]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
function computeDependencies(expression, enumName) {
|
|
3
|
+
let dependencies = []
|
|
4
|
+
let stack = [expression]
|
|
5
|
+
while (stack.length > 0) {
|
|
6
|
+
let node = stack.pop()
|
|
7
|
+
switch (node.type) {
|
|
8
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
9
|
+
if (
|
|
10
|
+
node.object.type === AST_NODE_TYPES.Identifier &&
|
|
11
|
+
node.object.name === enumName &&
|
|
12
|
+
node.property.type === AST_NODE_TYPES.Identifier
|
|
13
|
+
) {
|
|
14
|
+
dependencies.push(node.property.name)
|
|
15
|
+
}
|
|
16
|
+
break
|
|
17
|
+
case AST_NODE_TYPES.Identifier:
|
|
18
|
+
dependencies.push(node.name)
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
if ('alternate' in node && node.alternate) {
|
|
22
|
+
stack.push(node.alternate)
|
|
23
|
+
}
|
|
24
|
+
if ('argument' in node && node.argument) {
|
|
25
|
+
stack.push(node.argument)
|
|
26
|
+
}
|
|
27
|
+
if ('arguments' in node) {
|
|
28
|
+
stack.push(...node.arguments)
|
|
29
|
+
}
|
|
30
|
+
if ('consequent' in node) {
|
|
31
|
+
if (Array.isArray(node.consequent)) {
|
|
32
|
+
stack.push(...node.consequent)
|
|
33
|
+
} else {
|
|
34
|
+
stack.push(node.consequent)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if ('elements' in node) {
|
|
38
|
+
let elements = node.elements.filter(currentNode => currentNode !== null)
|
|
39
|
+
stack.push(...elements)
|
|
40
|
+
}
|
|
41
|
+
if ('expressions' in node) {
|
|
42
|
+
stack.push(...node.expressions)
|
|
43
|
+
}
|
|
44
|
+
if ('key' in node) {
|
|
45
|
+
stack.push(node.key)
|
|
46
|
+
}
|
|
47
|
+
if ('left' in node) {
|
|
48
|
+
stack.push(node.left)
|
|
49
|
+
}
|
|
50
|
+
if ('object' in node) {
|
|
51
|
+
stack.push(node.object)
|
|
52
|
+
}
|
|
53
|
+
if ('properties' in node) {
|
|
54
|
+
stack.push(...node.properties)
|
|
55
|
+
}
|
|
56
|
+
if ('right' in node) {
|
|
57
|
+
stack.push(node.right)
|
|
58
|
+
}
|
|
59
|
+
if ('test' in node && node.test) {
|
|
60
|
+
stack.push(node.test)
|
|
61
|
+
}
|
|
62
|
+
if (
|
|
63
|
+
'value' in node &&
|
|
64
|
+
node.value &&
|
|
65
|
+
typeof node.value === 'object' &&
|
|
66
|
+
'type' in node.value
|
|
67
|
+
) {
|
|
68
|
+
stack.push(node.value)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return dependencies
|
|
72
|
+
}
|
|
73
|
+
export { computeDependencies }
|
|
@@ -19,6 +19,8 @@ export type Options = Partial<
|
|
|
19
19
|
* @default ifNumericEnum
|
|
20
20
|
*/
|
|
21
21
|
sortByValue: 'ifNumericEnum' | 'always' | 'never'
|
|
22
|
+
/** Enables experimental dependency detection. */
|
|
23
|
+
useExperimentalDependencyDetection: boolean
|
|
22
24
|
} & AllCommonOptions<
|
|
23
25
|
TypeOption,
|
|
24
26
|
AdditionalSortOptions,
|