eslint-plugin-perfectionist 5.0.0 → 5.2.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/alphabet.d.ts +1 -1
- package/dist/index.d.ts +15 -244
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes/types.d.ts +3 -3
- package/dist/rules/sort-array-includes.d.ts +5 -3
- package/dist/rules/sort-array-includes.js +1 -1
- package/dist/rules/sort-classes/types.d.ts +3 -3
- package/dist/rules/sort-classes.d.ts +5 -3
- package/dist/rules/sort-classes.js +1 -1
- package/dist/rules/sort-decorators/types.d.ts +4 -4
- package/dist/rules/sort-decorators.d.ts +5 -3
- package/dist/rules/sort-decorators.js +1 -1
- package/dist/rules/sort-enums/build-comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-enums/types.d.ts +4 -4
- package/dist/rules/sort-enums.d.ts +5 -3
- package/dist/rules/sort-enums.js +1 -1
- package/dist/rules/sort-export-attributes/types.d.ts +4 -4
- package/dist/rules/sort-export-attributes.d.ts +5 -3
- package/dist/rules/sort-export-attributes.js +1 -1
- package/dist/rules/sort-exports/types.d.ts +3 -3
- package/dist/rules/sort-exports.d.ts +5 -3
- package/dist/rules/sort-exports.js +14 -12
- package/dist/rules/sort-heritage-clauses/types.d.ts +3 -3
- package/dist/rules/sort-heritage-clauses.d.ts +5 -3
- package/dist/rules/sort-heritage-clauses.js +1 -1
- package/dist/rules/sort-import-attributes/types.d.ts +4 -4
- package/dist/rules/sort-import-attributes.d.ts +5 -3
- package/dist/rules/sort-import-attributes.js +1 -1
- package/dist/rules/sort-imports/comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-imports/comparator-by-options-computer.js +48 -4
- package/dist/rules/sort-imports/compute-common-selectors.d.ts +3 -3
- package/dist/rules/sort-imports/compute-specifier-name.d.ts +12 -0
- package/dist/rules/sort-imports/compute-specifier-name.js +64 -0
- package/dist/rules/sort-imports/is-side-effect-only-group.d.ts +1 -1
- package/dist/rules/sort-imports/matches-tsconfig-paths.d.ts +1 -1
- package/dist/rules/sort-imports/types.d.ts +16 -6
- package/dist/rules/sort-imports/types.js +5 -0
- package/dist/rules/sort-imports/validate-side-effects-configuration.d.ts +1 -1
- package/dist/rules/sort-imports.d.ts +5 -3
- package/dist/rules/sort-imports.js +7 -1
- package/dist/rules/sort-interfaces.d.ts +5 -3
- package/dist/rules/sort-interfaces.js +0 -1
- package/dist/rules/sort-intersection-types.d.ts +5 -3
- package/dist/rules/sort-intersection-types.js +1 -1
- package/dist/rules/sort-jsx-props/types.d.ts +3 -3
- package/dist/rules/sort-jsx-props.d.ts +5 -3
- package/dist/rules/sort-jsx-props.js +1 -1
- package/dist/rules/sort-maps/types.d.ts +3 -3
- package/dist/rules/sort-maps.d.ts +5 -3
- package/dist/rules/sort-maps.js +1 -1
- package/dist/rules/sort-modules/build-comparator-by-options-computer.d.ts +12 -0
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +66 -0
- package/dist/rules/sort-modules/compute-dependencies.d.ts +27 -0
- package/dist/rules/sort-modules/compute-dependencies.js +195 -0
- package/dist/rules/sort-modules/is-arrow-function-node.d.ts +12 -0
- package/dist/rules/sort-modules/is-arrow-function-node.js +10 -0
- package/dist/rules/sort-modules/is-property-or-accessor-node.d.ts +11 -0
- package/dist/rules/sort-modules/is-property-or-accessor-node.js +8 -0
- package/dist/rules/sort-modules/types.d.ts +16 -5
- package/dist/rules/sort-modules/types.js +7 -1
- package/dist/rules/sort-modules.d.ts +5 -3
- package/dist/rules/sort-modules.js +34 -142
- package/dist/rules/sort-named-exports/compute-node-name.d.ts +12 -0
- package/dist/rules/sort-named-exports/compute-node-name.js +15 -0
- package/dist/rules/sort-named-exports/types.d.ts +4 -4
- package/dist/rules/sort-named-exports.d.ts +5 -3
- package/dist/rules/sort-named-exports.js +18 -21
- package/dist/rules/sort-named-imports/compute-node-name.d.ts +12 -0
- package/dist/rules/sort-named-imports/compute-node-name.js +17 -0
- package/dist/rules/sort-named-imports/types.d.ts +4 -4
- package/dist/rules/sort-named-imports.d.ts +5 -3
- package/dist/rules/sort-named-imports.js +20 -19
- package/dist/rules/sort-object-types/comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-object-types/compute-matched-context-options.d.ts +1 -1
- package/dist/rules/sort-object-types/compute-node-parent-name.d.ts +1 -1
- package/dist/rules/sort-object-types/passes-declaration-comment-matches-filter.d.ts +2 -2
- package/dist/rules/sort-object-types/passes-declaration-matches-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-object-types/types.d.ts +14 -35
- package/dist/rules/sort-object-types/types.js +0 -1
- package/dist/rules/sort-object-types.d.ts +5 -3
- package/dist/rules/sort-object-types.js +24 -26
- package/dist/rules/sort-objects/compute-matched-context-options.d.ts +1 -1
- package/dist/rules/sort-objects/passes-calling-function-name-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-objects/passes-declaration-comment-matches-filter.d.ts +2 -2
- package/dist/rules/sort-objects/passes-declaration-matches-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-objects/types.d.ts +5 -5
- package/dist/rules/sort-objects.d.ts +5 -3
- package/dist/rules/sort-objects.js +1 -1
- package/dist/rules/sort-sets.d.ts +5 -3
- package/dist/rules/sort-sets.js +0 -1
- package/dist/rules/sort-switch-case.d.ts +5 -3
- package/dist/rules/sort-switch-case.js +0 -1
- package/dist/rules/sort-union-types/types.d.ts +3 -3
- package/dist/rules/sort-union-types.d.ts +5 -3
- package/dist/rules/sort-union-types.js +1 -1
- package/dist/rules/sort-variable-declarations/types.d.ts +3 -3
- package/dist/rules/sort-variable-declarations.d.ts +5 -3
- package/dist/rules/sort-variable-declarations.js +1 -1
- package/dist/types/common-groups-options.d.ts +47 -18
- package/dist/types/common-options.d.ts +11 -5
- package/dist/types/common-partition-options.d.ts +1 -1
- package/dist/types/scoped-regex-option.d.ts +1 -1
- package/dist/utils/build-default-options-by-group-index-computer.d.ts +3 -3
- package/dist/utils/compare/build-line-length-comparator.d.ts +3 -3
- package/dist/utils/compare/build-string-formatter.d.ts +1 -1
- package/dist/utils/compare/compare-alphabetically.d.ts +1 -1
- package/dist/utils/compare/compare-by-custom-sort.d.ts +1 -1
- package/dist/utils/compare/compare-naturally.d.ts +1 -1
- package/dist/utils/compare/compute-comparators.d.ts +3 -3
- package/dist/utils/compare/compute-ordered-value.d.ts +1 -1
- package/dist/utils/compare/default-comparator-by-options-computer.d.ts +2 -2
- package/dist/utils/compare/unsorted-comparator.d.ts +2 -2
- package/dist/utils/complete.d.ts +1 -1
- package/dist/utils/complete.js +1 -52
- package/dist/utils/compute-group-name.d.ts +1 -1
- package/dist/utils/compute-group.d.ts +7 -7
- package/dist/utils/compute-group.js +22 -19
- package/dist/utils/compute-groups-names.d.ts +1 -1
- package/dist/utils/compute-nodes-in-circular-dependencies.d.ts +5 -2
- package/dist/utils/compute-overridden-options-by-group-index.d.ts +2 -2
- package/dist/utils/compute-overridden-options-by-group-index.js +38 -19
- package/dist/utils/compute-parent-nodes-with-types.d.ts +1 -1
- package/dist/utils/create-eslint-rule.d.ts +3 -1
- package/dist/utils/create-node-index-map.d.ts +1 -1
- package/dist/utils/does-custom-group-match.d.ts +2 -2
- package/dist/utils/filter-options-by-all-names-match.d.ts +1 -1
- package/dist/utils/get-comment-above-that-should-exist.d.ts +2 -2
- package/dist/utils/get-group-index.d.ts +2 -2
- package/dist/utils/get-lines-between.d.ts +1 -1
- package/dist/utils/get-newlines-between-errors.d.ts +2 -2
- package/dist/utils/get-newlines-between-option.d.ts +8 -2
- package/dist/utils/get-newlines-between-option.js +17 -31
- package/dist/utils/get-node-range.d.ts +1 -1
- package/dist/utils/get-options-with-clean-groups.d.ts +1 -1
- package/dist/utils/get-settings.d.ts +11 -13
- package/dist/utils/get-settings.js +2 -0
- package/dist/utils/is-group-with-overrides-option.d.ts +10 -3
- package/dist/utils/is-newlines-between-option.d.ts +1 -1
- package/dist/utils/is-node-dependent-on-other-node.d.ts +9 -3
- package/dist/utils/is-partition-comment.d.ts +1 -1
- package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +14 -11
- package/dist/utils/json-schemas/common-groups-json-schemas.js +81 -54
- package/dist/utils/json-schemas/common-json-schemas.d.ts +4 -4
- package/dist/utils/json-schemas/common-json-schemas.js +3 -2
- package/dist/utils/make-comment-above-fixes.d.ts +2 -2
- package/dist/utils/make-comment-after-fixes.d.ts +1 -1
- package/dist/utils/make-fixes.d.ts +7 -9
- package/dist/utils/make-newlines-between-fixes.d.ts +3 -3
- package/dist/utils/make-order-fixes.d.ts +2 -2
- package/dist/utils/matches.d.ts +1 -1
- package/dist/utils/report-all-errors.d.ts +21 -23
- package/dist/utils/report-errors.d.ts +4 -4
- package/dist/utils/scoped-regex/matches-scoped-expressions.d.ts +2 -2
- package/dist/utils/scoped-regex/partition-patterns-by-scope.d.ts +1 -1
- package/dist/utils/should-partition.d.ts +4 -4
- package/dist/utils/sort-nodes-by-dependencies.d.ts +5 -2
- package/dist/utils/sort-nodes-by-groups.d.ts +4 -4
- package/dist/utils/sort-nodes.d.ts +3 -3
- package/dist/utils/validate-custom-sort-configuration.d.ts +2 -2
- package/dist/utils/validate-groups-configuration.d.ts +1 -1
- package/dist/utils/validate-newlines-and-partition-configuration.d.ts +5 -3
- package/dist/utils/validate-newlines-and-partition-configuration.js +61 -9
- package/dist/utils/validate-no-duplicated-groups.d.ts +1 -1
- package/dist/utils/validate-objects-inside-groups.d.ts +1 -1
- package/package.json +2 -2
- package/dist/rules/sort-object-types/build-options-by-group-index-computer.d.ts +0 -18
- package/dist/rules/sort-object-types/build-options-by-group-index-computer.js +0 -33
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
2
|
+
import { sortNodesByDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
3
|
+
import { computeOrderedValue } from '../../utils/compare/compute-ordered-value.js'
|
|
4
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
5
|
+
import { computeDependencies } from './compute-dependencies.js'
|
|
6
|
+
function buildComparatorByOptionsComputer({
|
|
7
|
+
ignoreEslintDisabledNodes,
|
|
8
|
+
sortingNodes,
|
|
9
|
+
}) {
|
|
10
|
+
return options => {
|
|
11
|
+
switch (options.type) {
|
|
12
|
+
case 'alphabetical':
|
|
13
|
+
case 'line-length':
|
|
14
|
+
case 'unsorted':
|
|
15
|
+
case 'natural':
|
|
16
|
+
case 'custom':
|
|
17
|
+
return defaultComparatorByOptionsComputer({
|
|
18
|
+
...options,
|
|
19
|
+
type: options.type,
|
|
20
|
+
})
|
|
21
|
+
case 'usage':
|
|
22
|
+
return buildUsageComparator({
|
|
23
|
+
ignoreEslintDisabledNodes,
|
|
24
|
+
sortingNodes,
|
|
25
|
+
options,
|
|
26
|
+
})
|
|
27
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
28
|
+
default:
|
|
29
|
+
throw new UnreachableCaseError(options.type)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function buildUsageComparator({
|
|
34
|
+
ignoreEslintDisabledNodes,
|
|
35
|
+
sortingNodes,
|
|
36
|
+
options,
|
|
37
|
+
}) {
|
|
38
|
+
let orderByNode = buildOrderByNodeMap()
|
|
39
|
+
return (a, b) => {
|
|
40
|
+
let nodeA = a.node
|
|
41
|
+
let nodeB = b.node
|
|
42
|
+
let orderA = orderByNode.get(nodeA)
|
|
43
|
+
let orderB = orderByNode.get(nodeB)
|
|
44
|
+
return computeOrderedValue(orderA - orderB, options.order)
|
|
45
|
+
}
|
|
46
|
+
function buildOrderByNodeMap() {
|
|
47
|
+
let sortingNodesWithUpdatedDependencies = sortingNodes.map(
|
|
48
|
+
({ isEslintDisabled, dependencyNames, node }) => ({
|
|
49
|
+
dependencies: computeDependencies(node, { type: 'soft' }),
|
|
50
|
+
isEslintDisabled,
|
|
51
|
+
dependencyNames,
|
|
52
|
+
node,
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
let sortedSortingNodes = sortNodesByDependencies(
|
|
56
|
+
sortingNodesWithUpdatedDependencies,
|
|
57
|
+
{ ignoreEslintDisabledNodes },
|
|
58
|
+
)
|
|
59
|
+
let orderByNodeMap = /* @__PURE__ */ new Map()
|
|
60
|
+
for (let [i, { node }] of sortedSortingNodes.entries()) {
|
|
61
|
+
orderByNodeMap.set(node, i)
|
|
62
|
+
}
|
|
63
|
+
return orderByNodeMap
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export { buildComparatorByOptionsComputer }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
interface HardDependencyDetection {
|
|
3
|
+
searchStaticMethodsAndFunctionProperties: boolean
|
|
4
|
+
type: 'hard'
|
|
5
|
+
}
|
|
6
|
+
interface SoftDependencyDetection {
|
|
7
|
+
searchStaticMethodsAndFunctionProperties?: never
|
|
8
|
+
type: 'soft'
|
|
9
|
+
}
|
|
10
|
+
type DependencyDetection = HardDependencyDetection | SoftDependencyDetection
|
|
11
|
+
/**
|
|
12
|
+
* Computes the dependencies of a given AST node.
|
|
13
|
+
*
|
|
14
|
+
* @param node - The AST node to analyze.
|
|
15
|
+
* @param dependencyDetection - The dependency detection strategy. Hard
|
|
16
|
+
* dependencies consider dependencies impacting compilation, while soft
|
|
17
|
+
* dependencies also consider type references.
|
|
18
|
+
* @returns The names of the dependencies.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeDependencies(
|
|
21
|
+
node:
|
|
22
|
+
| TSESTree.ClassDeclaration
|
|
23
|
+
| TSESTree.ProgramStatement
|
|
24
|
+
| TSESTree.TSEnumMember,
|
|
25
|
+
dependencyDetection: DependencyDetection,
|
|
26
|
+
): string[]
|
|
27
|
+
export {}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
3
|
+
import { isArrowFunctionNode } from './is-arrow-function-node.js'
|
|
4
|
+
function computeDependencies(node, dependencyDetection) {
|
|
5
|
+
let dependencies = []
|
|
6
|
+
checkNode(node)
|
|
7
|
+
return dependencies
|
|
8
|
+
function checkNode(nodeToCheck, options) {
|
|
9
|
+
switch (dependencyDetection.type) {
|
|
10
|
+
case 'hard':
|
|
11
|
+
if (
|
|
12
|
+
(nodeToCheck.type === AST_NODE_TYPES.MethodDefinition ||
|
|
13
|
+
isArrowFunctionNode(nodeToCheck)) &&
|
|
14
|
+
(!nodeToCheck.static ||
|
|
15
|
+
!dependencyDetection.searchStaticMethodsAndFunctionProperties)
|
|
16
|
+
) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
break
|
|
20
|
+
case 'soft':
|
|
21
|
+
checkNodesForSoftDependencies()
|
|
22
|
+
break
|
|
23
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
24
|
+
default:
|
|
25
|
+
throw new UnreachableCaseError(dependencyDetection)
|
|
26
|
+
}
|
|
27
|
+
checkNodesForCommonDependencies()
|
|
28
|
+
function checkNodesForCommonDependencies() {
|
|
29
|
+
if (
|
|
30
|
+
!options?.ignoreNextIdentifier &&
|
|
31
|
+
nodeToCheck.type === AST_NODE_TYPES.Identifier
|
|
32
|
+
) {
|
|
33
|
+
dependencies.push(nodeToCheck.name)
|
|
34
|
+
}
|
|
35
|
+
if ('alternate' in nodeToCheck && nodeToCheck.alternate) {
|
|
36
|
+
checkNode(nodeToCheck.alternate)
|
|
37
|
+
}
|
|
38
|
+
if ('argument' in nodeToCheck && nodeToCheck.argument) {
|
|
39
|
+
checkNode(nodeToCheck.argument)
|
|
40
|
+
}
|
|
41
|
+
if ('arguments' in nodeToCheck) {
|
|
42
|
+
traverseNode(nodeToCheck.arguments)
|
|
43
|
+
}
|
|
44
|
+
if ('body' in nodeToCheck && nodeToCheck.body) {
|
|
45
|
+
traverseNode(nodeToCheck.body)
|
|
46
|
+
}
|
|
47
|
+
if ('callee' in nodeToCheck) {
|
|
48
|
+
checkNode(nodeToCheck.callee)
|
|
49
|
+
}
|
|
50
|
+
if ('consequent' in nodeToCheck) {
|
|
51
|
+
traverseNode(nodeToCheck.consequent)
|
|
52
|
+
}
|
|
53
|
+
if ('declarations' in nodeToCheck) {
|
|
54
|
+
traverseNode(nodeToCheck.declarations)
|
|
55
|
+
}
|
|
56
|
+
if ('decorators' in nodeToCheck) {
|
|
57
|
+
traverseNode(nodeToCheck.decorators)
|
|
58
|
+
}
|
|
59
|
+
if ('elements' in nodeToCheck) {
|
|
60
|
+
let elements = nodeToCheck.elements.filter(
|
|
61
|
+
currentNode => currentNode !== null,
|
|
62
|
+
)
|
|
63
|
+
traverseNode(elements)
|
|
64
|
+
}
|
|
65
|
+
if (
|
|
66
|
+
'expression' in nodeToCheck &&
|
|
67
|
+
typeof nodeToCheck.expression !== 'boolean'
|
|
68
|
+
) {
|
|
69
|
+
checkNode(nodeToCheck.expression)
|
|
70
|
+
}
|
|
71
|
+
if ('expressions' in nodeToCheck) {
|
|
72
|
+
traverseNode(nodeToCheck.expressions)
|
|
73
|
+
}
|
|
74
|
+
if ('init' in nodeToCheck && nodeToCheck.init) {
|
|
75
|
+
checkNode(nodeToCheck.init)
|
|
76
|
+
}
|
|
77
|
+
if ('initializer' in nodeToCheck && nodeToCheck.initializer) {
|
|
78
|
+
checkNode(nodeToCheck.initializer)
|
|
79
|
+
}
|
|
80
|
+
if ('left' in nodeToCheck) {
|
|
81
|
+
checkNode(nodeToCheck.left)
|
|
82
|
+
}
|
|
83
|
+
if ('members' in nodeToCheck) {
|
|
84
|
+
traverseNode(nodeToCheck.members)
|
|
85
|
+
}
|
|
86
|
+
if ('object' in nodeToCheck) {
|
|
87
|
+
checkNode(nodeToCheck.object)
|
|
88
|
+
}
|
|
89
|
+
if ('properties' in nodeToCheck) {
|
|
90
|
+
traverseNode(nodeToCheck.properties)
|
|
91
|
+
}
|
|
92
|
+
if ('right' in nodeToCheck) {
|
|
93
|
+
checkNode(nodeToCheck.right)
|
|
94
|
+
}
|
|
95
|
+
if ('superClass' in nodeToCheck && nodeToCheck.superClass) {
|
|
96
|
+
checkNode(nodeToCheck.superClass)
|
|
97
|
+
}
|
|
98
|
+
if ('test' in nodeToCheck && nodeToCheck.test) {
|
|
99
|
+
checkNode(nodeToCheck.test)
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
'value' in nodeToCheck &&
|
|
103
|
+
nodeToCheck.value &&
|
|
104
|
+
typeof nodeToCheck.value === 'object' &&
|
|
105
|
+
'type' in nodeToCheck.value
|
|
106
|
+
) {
|
|
107
|
+
checkNode(nodeToCheck.value)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function checkNodesForSoftDependencies() {
|
|
111
|
+
if ('checkType' in nodeToCheck) {
|
|
112
|
+
checkNode(nodeToCheck.checkType)
|
|
113
|
+
}
|
|
114
|
+
if ('constraint' in nodeToCheck && nodeToCheck.constraint) {
|
|
115
|
+
checkNode(nodeToCheck.constraint)
|
|
116
|
+
}
|
|
117
|
+
if ('declaration' in nodeToCheck && nodeToCheck.declaration) {
|
|
118
|
+
checkNode(nodeToCheck.declaration)
|
|
119
|
+
}
|
|
120
|
+
if ('elementTypes' in nodeToCheck) {
|
|
121
|
+
traverseNode(nodeToCheck.elementTypes)
|
|
122
|
+
}
|
|
123
|
+
if ('elementType' in nodeToCheck) {
|
|
124
|
+
checkNode(nodeToCheck.elementType)
|
|
125
|
+
}
|
|
126
|
+
if ('extends' in nodeToCheck) {
|
|
127
|
+
traverseNode(nodeToCheck.extends)
|
|
128
|
+
}
|
|
129
|
+
if ('extendsType' in nodeToCheck) {
|
|
130
|
+
checkNode(nodeToCheck.extendsType)
|
|
131
|
+
}
|
|
132
|
+
if ('exprName' in nodeToCheck) {
|
|
133
|
+
checkNode(nodeToCheck.exprName)
|
|
134
|
+
}
|
|
135
|
+
if ('falseType' in nodeToCheck) {
|
|
136
|
+
checkNode(nodeToCheck.falseType)
|
|
137
|
+
}
|
|
138
|
+
if ('key' in nodeToCheck) {
|
|
139
|
+
checkNode(nodeToCheck.key, { ignoreNextIdentifier: true })
|
|
140
|
+
}
|
|
141
|
+
if ('id' in nodeToCheck && nodeToCheck.id) {
|
|
142
|
+
checkNode(nodeToCheck.id)
|
|
143
|
+
}
|
|
144
|
+
if ('implements' in nodeToCheck) {
|
|
145
|
+
traverseNode(nodeToCheck.implements)
|
|
146
|
+
}
|
|
147
|
+
if ('indexType' in nodeToCheck) {
|
|
148
|
+
checkNode(nodeToCheck.indexType)
|
|
149
|
+
}
|
|
150
|
+
if ('name' in nodeToCheck && typeof nodeToCheck.name !== 'string') {
|
|
151
|
+
checkNode(nodeToCheck.name)
|
|
152
|
+
}
|
|
153
|
+
if ('objectType' in nodeToCheck) {
|
|
154
|
+
checkNode(nodeToCheck.objectType)
|
|
155
|
+
}
|
|
156
|
+
if ('params' in nodeToCheck) {
|
|
157
|
+
traverseNode(nodeToCheck.params, { ignoreNextIdentifier: true })
|
|
158
|
+
}
|
|
159
|
+
if ('returnType' in nodeToCheck && nodeToCheck.returnType) {
|
|
160
|
+
checkNode(nodeToCheck.returnType)
|
|
161
|
+
}
|
|
162
|
+
if ('trueType' in nodeToCheck) {
|
|
163
|
+
checkNode(nodeToCheck.trueType)
|
|
164
|
+
}
|
|
165
|
+
if ('typeAnnotation' in nodeToCheck && nodeToCheck.typeAnnotation) {
|
|
166
|
+
checkNode(nodeToCheck.typeAnnotation)
|
|
167
|
+
}
|
|
168
|
+
if ('typeArguments' in nodeToCheck && nodeToCheck.typeArguments) {
|
|
169
|
+
checkNode(nodeToCheck.typeArguments)
|
|
170
|
+
}
|
|
171
|
+
if ('typeName' in nodeToCheck) {
|
|
172
|
+
checkNode(nodeToCheck.typeName)
|
|
173
|
+
}
|
|
174
|
+
if ('typeParameters' in nodeToCheck && nodeToCheck.typeParameters) {
|
|
175
|
+
traverseNode(nodeToCheck.typeParameters)
|
|
176
|
+
}
|
|
177
|
+
if ('typeParameter' in nodeToCheck) {
|
|
178
|
+
checkNode(nodeToCheck.typeParameter)
|
|
179
|
+
}
|
|
180
|
+
if ('types' in nodeToCheck) {
|
|
181
|
+
traverseNode(nodeToCheck.types)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function traverseNode(nodeToTraverse, options) {
|
|
186
|
+
if (Array.isArray(nodeToTraverse)) {
|
|
187
|
+
for (let nodeItem of nodeToTraverse) {
|
|
188
|
+
traverseNode(nodeItem, options)
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
checkNode(nodeToTraverse, options)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export { computeDependencies }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a node is a property or accessor node with an
|
|
4
|
+
* ArrowFunctionExpression value.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The AST node to check.
|
|
7
|
+
* @returns True if the node is a property or accessor node with an
|
|
8
|
+
* ArrowFunctionExpression value, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isArrowFunctionNode(
|
|
11
|
+
node: TSESTree.Node,
|
|
12
|
+
): node is TSESTree.PropertyDefinition | TSESTree.AccessorProperty
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types'
|
|
2
|
+
import { isPropertyOrAccessorNode } from './is-property-or-accessor-node.js'
|
|
3
|
+
function isArrowFunctionNode(node) {
|
|
4
|
+
return (
|
|
5
|
+
isPropertyOrAccessorNode(node) &&
|
|
6
|
+
node.value !== null &&
|
|
7
|
+
node.value.type === AST_NODE_TYPES.ArrowFunctionExpression
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
export { isArrowFunctionNode }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a node is a PropertyDefinition or AccessorProperty.
|
|
4
|
+
*
|
|
5
|
+
* @param node - The AST node to check.
|
|
6
|
+
* @returns True if the node is a PropertyDefinition or AccessorProperty, false
|
|
7
|
+
* otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPropertyOrAccessorNode(
|
|
10
|
+
node: TSESTree.Node,
|
|
11
|
+
): node is TSESTree.PropertyDefinition | TSESTree.AccessorProperty
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
3
|
import {
|
|
3
4
|
CommonOptions,
|
|
4
5
|
RegexOption,
|
|
5
6
|
TypeOption,
|
|
6
|
-
} from '../../types/common-options'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
} from '../../types/common-options.js'
|
|
8
|
+
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
9
|
+
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
10
|
+
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
9
11
|
/**
|
|
10
12
|
* Configuration options for the sort-modules rule.
|
|
11
13
|
*
|
|
@@ -14,11 +16,18 @@ import { CommonGroupsOptions } from '../../types/common-groups-options'
|
|
|
14
16
|
*/
|
|
15
17
|
export type SortModulesOptions = [
|
|
16
18
|
Partial<
|
|
17
|
-
CommonGroupsOptions<
|
|
18
|
-
|
|
19
|
+
CommonGroupsOptions<
|
|
20
|
+
SingleCustomGroup,
|
|
21
|
+
Record<string, never>,
|
|
22
|
+
CustomTypeOption
|
|
23
|
+
> &
|
|
24
|
+
CommonOptions<CustomTypeOption> &
|
|
19
25
|
CommonPartitionOptions
|
|
20
26
|
>,
|
|
21
27
|
]
|
|
28
|
+
/** Represents a sorting node for a module statement. */
|
|
29
|
+
export type SortModulesSortingNode =
|
|
30
|
+
SortingNodeWithDependencies<TSESTree.ProgramStatement>
|
|
22
31
|
/**
|
|
23
32
|
* Union type of all available module member selectors. Used to categorize
|
|
24
33
|
* different types of module-level declarations.
|
|
@@ -46,6 +55,7 @@ interface SingleCustomGroup {
|
|
|
46
55
|
/** The type of module member this group applies to. */
|
|
47
56
|
selector?: Selector
|
|
48
57
|
}
|
|
58
|
+
type CustomTypeOption = typeof USAGE_TYPE_OPTION | TypeOption
|
|
49
59
|
/**
|
|
50
60
|
* Complete list of available module member selectors. Used for validation and
|
|
51
61
|
* JSON schema generation.
|
|
@@ -73,4 +83,5 @@ export declare let allModifiers: readonly [
|
|
|
73
83
|
* ensure that users do not enter invalid modifiers for a given selector.
|
|
74
84
|
*/
|
|
75
85
|
export declare let singleCustomGroupJsonSchema: Record<string, JSONSchema4>
|
|
86
|
+
export declare const USAGE_TYPE_OPTION = 'usage'
|
|
76
87
|
export {}
|
|
@@ -18,4 +18,10 @@ let singleCustomGroupJsonSchema = {
|
|
|
18
18
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
19
19
|
decoratorNamePattern: buildRegexJsonSchema(),
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
const USAGE_TYPE_OPTION = 'usage'
|
|
22
|
+
export {
|
|
23
|
+
USAGE_TYPE_OPTION,
|
|
24
|
+
allModifiers,
|
|
25
|
+
allSelectors,
|
|
26
|
+
singleCustomGroupJsonSchema,
|
|
27
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
-
import { SortModulesOptions } from './sort-modules/types'
|
|
2
|
+
import { SortModulesOptions } from './sort-modules/types.js'
|
|
3
3
|
declare const ORDER_ERROR_ID = 'unexpectedModulesOrder'
|
|
4
4
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedModulesGroupOrder'
|
|
5
5
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenModulesMembers'
|
|
@@ -14,7 +14,9 @@ type MessageId =
|
|
|
14
14
|
declare const _default: TSESLint.RuleModule<
|
|
15
15
|
MessageId,
|
|
16
16
|
SortModulesOptions,
|
|
17
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
17
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
18
18
|
TSESLint.RuleListener
|
|
19
|
-
>
|
|
19
|
+
> & {
|
|
20
|
+
name: string
|
|
21
|
+
}
|
|
20
22
|
export default _default
|