eslint-plugin-perfectionist 5.9.0 → 5.10.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.js +1 -1
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes.js +5 -8
- package/dist/rules/sort-arrays/compute-node-name.js +1 -1
- package/dist/rules/sort-arrays/sort-array.js +6 -6
- package/dist/rules/sort-arrays.js +5 -4
- package/dist/rules/sort-classes/compute-dependencies-by-sorting-node.js +4 -4
- package/dist/rules/sort-classes/compute-identifier-name-details.js +1 -1
- package/dist/rules/sort-classes/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-classes/node-info/common-modifiers.d.ts +1 -2
- package/dist/rules/sort-classes/node-info/compute-accessor-details.d.ts +13 -0
- package/dist/rules/sort-classes/node-info/compute-accessor-details.js +41 -1
- package/dist/rules/sort-classes/node-info/compute-property-details.js +1 -10
- package/dist/rules/sort-classes/node-info/is-function-expression.d.ts +11 -0
- package/dist/rules/sort-classes/node-info/is-function-expression.js +18 -0
- package/dist/rules/sort-classes/sort-class.js +27 -16
- package/dist/rules/sort-classes/types.d.ts +1 -3
- package/dist/rules/sort-classes.js +4 -4
- package/dist/rules/sort-decorators.js +8 -8
- package/dist/rules/sort-enums/compute-dependencies-by-sorting-node.js +14 -3
- package/dist/rules/sort-enums/compute-dependencies.js +13 -4
- package/dist/rules/sort-enums/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-enums/sort-enum.js +7 -10
- package/dist/rules/sort-enums.js +8 -8
- package/dist/rules/sort-exports.js +8 -8
- package/dist/rules/sort-heritage-clauses/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-heritage-clauses/compute-node-name.d.ts +2 -2
- package/dist/rules/sort-heritage-clauses/compute-node-name.js +7 -6
- package/dist/rules/sort-heritage-clauses/sort-heritage-clause.js +6 -6
- package/dist/rules/sort-heritage-clauses.js +4 -4
- package/dist/rules/sort-import-attributes/sort-import-or-export-attributes.js +6 -6
- package/dist/rules/sort-import-attributes.js +4 -4
- package/dist/rules/sort-imports/compute-common-selectors.js +6 -2
- package/dist/rules/sort-imports/compute-dependencies.js +7 -5
- package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +1 -1
- package/dist/rules/sort-imports/types.d.ts +1 -1
- package/dist/rules/sort-imports/{validate-side-effects-configuration.d.ts → validate-side-effects-config.d.ts} +1 -1
- package/dist/rules/sort-imports/{validate-side-effects-configuration.js → validate-side-effects-config.js} +2 -2
- package/dist/rules/sort-imports.js +11 -11
- package/dist/rules/sort-intersection-types/types.d.ts +9 -1
- package/dist/rules/sort-intersection-types.d.ts +2 -1
- package/dist/rules/sort-intersection-types.js +4 -3
- package/dist/rules/sort-jsx-props/sort-jsx-object.js +6 -6
- package/dist/rules/sort-jsx-props.js +4 -4
- package/dist/rules/sort-maps/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-maps/sort-potential-map.js +4 -4
- package/dist/rules/sort-maps.js +4 -4
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +0 -1
- package/dist/rules/sort-modules/build-usage-comparator.d.ts +1 -4
- package/dist/rules/sort-modules/build-usage-comparator.js +3 -11
- package/dist/rules/sort-modules/compute-node-details.d.ts +1 -5
- package/dist/rules/sort-modules/compute-node-details.js +26 -45
- package/dist/rules/sort-modules/compute-overload-signature-groups.js +23 -14
- package/dist/rules/sort-modules.js +23 -15
- package/dist/rules/sort-named-exports/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-named-exports/sort-named-export.js +6 -6
- package/dist/rules/sort-named-exports.js +4 -4
- package/dist/rules/sort-named-imports/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-named-imports/sort-named-import.js +6 -6
- package/dist/rules/sort-named-imports.js +4 -4
- package/dist/rules/sort-object-types/compute-node-name.js +1 -1
- package/dist/rules/sort-object-types/is-node-function-type.js +12 -8
- package/dist/rules/sort-object-types/sort-object-type-elements.js +8 -8
- package/dist/rules/sort-object-types.js +4 -4
- package/dist/rules/sort-objects/compute-dependency-names.js +12 -6
- package/dist/rules/sort-objects/compute-property-or-variable-declarator-name.js +1 -1
- package/dist/rules/sort-objects/passes-calling-function-name-pattern-filter.js +1 -1
- package/dist/rules/sort-objects/sort-object.js +6 -6
- package/dist/rules/sort-objects.js +4 -4
- package/dist/rules/sort-sets.js +1 -4
- package/dist/rules/sort-switch-case/is-condition-expression.d.ts +15 -0
- package/dist/rules/sort-switch-case/is-condition-expression.js +26 -0
- package/dist/rules/sort-switch-case.js +11 -6
- package/dist/rules/sort-union-or-intersection-types/build-json-schema.d.ts +6 -0
- package/dist/rules/sort-union-or-intersection-types/build-json-schema.js +39 -0
- package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/compute-matched-context-options.d.ts +1 -1
- package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/sort-union-or-intersection-types.d.ts +1 -1
- package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/sort-union-or-intersection-types.js +25 -18
- package/dist/rules/sort-union-or-intersection-types/type-contains-callable-type.d.ts +10 -0
- package/dist/rules/sort-union-or-intersection-types/type-contains-callable-type.js +38 -0
- package/dist/rules/sort-union-types/types.d.ts +3 -0
- package/dist/rules/sort-union-types.d.ts +0 -2
- package/dist/rules/sort-union-types.js +8 -37
- package/dist/rules/sort-variable-declarations/compute-dependencies.js +12 -1
- package/dist/rules/sort-variable-declarations/compute-matched-context-options.d.ts +3 -5
- package/dist/rules/sort-variable-declarations/sort-variable-declaration.js +6 -6
- package/dist/rules/sort-variable-declarations.js +4 -4
- package/dist/types/sorting-node.d.ts +10 -0
- package/dist/utils/alphabet.js +14 -14
- package/dist/utils/compare/compare-by-custom-sort.js +2 -2
- package/dist/utils/compute-dependencies-by-sorting-node.js +2 -1
- package/dist/utils/compute-dependencies-outside-functions-by-sorting-node.js +11 -10
- package/dist/utils/does-custom-group-match.d.ts +3 -4
- package/dist/utils/does-custom-group-match.js +6 -4
- package/dist/utils/generate-predefined-groups.js +7 -2
- package/dist/utils/get-comments-before.js +1 -1
- package/dist/utils/get-decorator-name.js +1 -1
- package/dist/utils/get-eslint-disabled-lines.js +4 -6
- package/dist/utils/get-node-range.d.ts +11 -0
- package/dist/utils/get-node-range.js +47 -23
- package/dist/utils/get-settings.js +1 -1
- package/dist/utils/is-node-immediately-called.d.ts +14 -0
- package/dist/utils/is-node-immediately-called.js +20 -0
- package/dist/utils/json-schemas/common-groups-json-schemas.js +3 -0
- package/dist/utils/json-schemas/common-json-schemas.d.ts +1 -1
- package/dist/utils/json-schemas/common-json-schemas.js +2 -2
- package/dist/utils/json-schemas/common-partition-json-schemas.d.ts +1 -1
- package/dist/utils/json-schemas/common-partition-json-schemas.js +2 -2
- package/dist/utils/make-order-fixes.js +3 -1
- package/dist/utils/sort-nodes-by-groups.js +3 -2
- package/dist/utils/unreachable-case-error.d.ts +2 -1
- package/dist/utils/unreachable-case-error.js +3 -2
- package/dist/utils/{validate-custom-sort-configuration.d.ts → validate-custom-sort-config.d.ts} +1 -1
- package/dist/utils/{validate-custom-sort-configuration.js → validate-custom-sort-config.js} +2 -2
- package/dist/utils/{validate-groups-configuration.d.ts → validate-groups-config.d.ts} +3 -3
- package/dist/utils/{validate-groups-configuration.js → validate-groups-config.js} +2 -2
- package/dist/utils/{validate-newlines-and-partition-configuration.d.ts → validate-newlines-and-partition-config.d.ts} +7 -7
- package/dist/utils/{validate-newlines-and-partition-configuration.js → validate-newlines-and-partition-config.js} +12 -12
- package/package.json +2 -2
- package/readme.md +0 -1
- /package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/compute-matched-context-options.js +0 -0
- /package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/compute-node-name.d.ts +0 -0
- /package/dist/rules/{sort-union-types → sort-union-or-intersection-types}/compute-node-name.js +0 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { name, version } from './package.json.js'
|
|
2
2
|
import sort_variable_declarations_default from './rules/sort-variable-declarations.js'
|
|
3
|
-
import sort_union_types_default from './rules/sort-union-types.js'
|
|
4
3
|
import sort_intersection_types_default from './rules/sort-intersection-types.js'
|
|
5
4
|
import sort_import_attributes_default from './rules/sort-import-attributes.js'
|
|
6
5
|
import sort_export_attributes_default from './rules/sort-export-attributes.js'
|
|
@@ -10,6 +9,7 @@ import sort_named_imports_default from './rules/sort-named-imports.js'
|
|
|
10
9
|
import sort_named_exports_default from './rules/sort-named-exports.js'
|
|
11
10
|
import sort_object_types_default from './rules/sort-object-types.js'
|
|
12
11
|
import sort_switch_case_default from './rules/sort-switch-case.js'
|
|
12
|
+
import sort_union_types_default from './rules/sort-union-types.js'
|
|
13
13
|
import sort_interfaces_default from './rules/sort-interfaces.js'
|
|
14
14
|
import sort_decorators_default from './rules/sort-decorators.js'
|
|
15
15
|
import sort_jsx_props_default from './rules/sort-jsx-props.js'
|
package/dist/package.json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildCommonJsonSchemas,
|
|
3
|
-
|
|
3
|
+
buildUseConfigIfJsonSchema,
|
|
4
4
|
matchesAstSelectorJsonSchema,
|
|
5
5
|
} from '../utils/json-schemas/common-json-schemas.js'
|
|
6
6
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../utils/report-errors.js'
|
|
13
13
|
import {
|
|
14
14
|
partitionByCommentJsonSchema,
|
|
15
|
-
|
|
15
|
+
partitionByNewlineJsonSchema,
|
|
16
16
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
17
17
|
import { buildAstListeners } from '../utils/build-ast-listeners.js'
|
|
18
18
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
@@ -51,13 +51,13 @@ var jsonSchema = {
|
|
|
51
51
|
additionalCustomGroupMatchProperties:
|
|
52
52
|
additionalCustomGroupMatchOptionsJsonSchema,
|
|
53
53
|
}),
|
|
54
|
-
useConfigurationIf:
|
|
54
|
+
useConfigurationIf: buildUseConfigIfJsonSchema({
|
|
55
55
|
additionalProperties: {
|
|
56
56
|
matchesAstSelector: matchesAstSelectorJsonSchema,
|
|
57
57
|
},
|
|
58
58
|
}),
|
|
59
59
|
partitionByComment: partitionByCommentJsonSchema,
|
|
60
|
-
partitionByNewLine:
|
|
60
|
+
partitionByNewLine: partitionByNewlineJsonSchema,
|
|
61
61
|
},
|
|
62
62
|
additionalProperties: false,
|
|
63
63
|
type: 'object',
|
|
@@ -122,10 +122,7 @@ function sortPotentiallyValidArray({ matchedAstSelectors, context, node }) {
|
|
|
122
122
|
if (node.parent.parent.type !== AST_NODE_TYPES.CallExpression) {
|
|
123
123
|
return false
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
return false
|
|
127
|
-
}
|
|
128
|
-
return true
|
|
125
|
+
return node.parent.parent.callee === node.parent
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
export { sort_array_includes_default as default, defaultOptions, jsonSchema }
|
|
@@ -9,7 +9,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
|
9
9
|
*/
|
|
10
10
|
function computeNodeName({ sourceCode, node }) {
|
|
11
11
|
return node.type === AST_NODE_TYPES.Literal ?
|
|
12
|
-
|
|
12
|
+
String(node.value)
|
|
13
13
|
: sourceCode.getText(node)
|
|
14
14
|
}
|
|
15
15
|
export { computeNodeName }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { validateNewlinesAndPartitionConfiguration } from '../../utils/validate-newlines-and-partition-configuration.js'
|
|
2
1
|
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
2
|
+
import { validateNewlinesAndPartitionConfig } from '../../utils/validate-newlines-and-partition-config.js'
|
|
3
3
|
import { buildOptionsByGroupIndexComputer } from '../../utils/build-options-by-group-index-computer.js'
|
|
4
|
-
import {
|
|
5
|
-
import { validateGroupsConfiguration } from '../../utils/validate-groups-configuration.js'
|
|
4
|
+
import { validateCustomSortConfig } from '../../utils/validate-custom-sort-config.js'
|
|
6
5
|
import { generatePredefinedGroups } from '../../utils/generate-predefined-groups.js'
|
|
7
6
|
import { getEslintDisabledLines } from '../../utils/get-eslint-disabled-lines.js'
|
|
8
7
|
import { doesCustomGroupMatch } from '../../utils/does-custom-group-match.js'
|
|
9
8
|
import { isNodeEslintDisabled } from '../../utils/is-node-eslint-disabled.js'
|
|
9
|
+
import { validateGroupsConfig } from '../../utils/validate-groups-config.js'
|
|
10
10
|
import { sortNodesByGroups } from '../../utils/sort-nodes-by-groups.js'
|
|
11
11
|
import { reportAllErrors } from '../../utils/report-all-errors.js'
|
|
12
12
|
import { shouldPartition } from '../../utils/should-partition.js'
|
|
@@ -47,13 +47,13 @@ function sortArray({
|
|
|
47
47
|
return
|
|
48
48
|
}
|
|
49
49
|
let options = complete(matchedContextOptions, settings, defaultOptions)
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
validateCustomSortConfig(options)
|
|
51
|
+
validateGroupsConfig({
|
|
52
52
|
selectors: allSelectors,
|
|
53
53
|
modifiers: [],
|
|
54
54
|
options,
|
|
55
55
|
})
|
|
56
|
-
|
|
56
|
+
validateNewlinesAndPartitionConfig(options)
|
|
57
57
|
let eslintDisabledLines = getEslintDisabledLines({
|
|
58
58
|
ruleName: id,
|
|
59
59
|
sourceCode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildCommonJsonSchemas,
|
|
3
|
-
|
|
3
|
+
buildUseConfigIfJsonSchema,
|
|
4
4
|
matchesAstSelectorJsonSchema,
|
|
5
5
|
} from '../utils/json-schemas/common-json-schemas.js'
|
|
6
6
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../utils/report-errors.js'
|
|
13
13
|
import {
|
|
14
14
|
partitionByCommentJsonSchema,
|
|
15
|
-
|
|
15
|
+
partitionByNewlineJsonSchema,
|
|
16
16
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
17
17
|
import { buildAstListeners } from '../utils/build-ast-listeners.js'
|
|
18
18
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
@@ -51,13 +51,13 @@ var jsonSchema = {
|
|
|
51
51
|
additionalCustomGroupMatchProperties:
|
|
52
52
|
additionalCustomGroupMatchOptionsJsonSchema,
|
|
53
53
|
}),
|
|
54
|
-
useConfigurationIf:
|
|
54
|
+
useConfigurationIf: buildUseConfigIfJsonSchema({
|
|
55
55
|
additionalProperties: {
|
|
56
56
|
matchesAstSelector: matchesAstSelectorJsonSchema,
|
|
57
57
|
},
|
|
58
58
|
}),
|
|
59
59
|
partitionByComment: partitionByCommentJsonSchema,
|
|
60
|
-
partitionByNewLine:
|
|
60
|
+
partitionByNewLine: partitionByNewlineJsonSchema,
|
|
61
61
|
},
|
|
62
62
|
required: ['useConfigurationIf'],
|
|
63
63
|
additionalProperties: false,
|
|
@@ -65,6 +65,7 @@ var jsonSchema = {
|
|
|
65
65
|
},
|
|
66
66
|
uniqueItems: true,
|
|
67
67
|
type: 'array',
|
|
68
|
+
minItems: 1,
|
|
68
69
|
}
|
|
69
70
|
var sort_arrays_default = createEslintRule({
|
|
70
71
|
meta: {
|
|
@@ -153,15 +153,15 @@ function shouldIgnoreDependencyComputation(node) {
|
|
|
153
153
|
case AST_NODE_TYPES.StaticBlock:
|
|
154
154
|
return false
|
|
155
155
|
case AST_NODE_TYPES.TSAbstractAccessorProperty:
|
|
156
|
-
case AST_NODE_TYPES.AccessorProperty:
|
|
157
|
-
case AST_NODE_TYPES.MethodDefinition:
|
|
158
|
-
case AST_NODE_TYPES.TSIndexSignature:
|
|
159
|
-
return true
|
|
160
156
|
case AST_NODE_TYPES.PropertyDefinition:
|
|
157
|
+
case AST_NODE_TYPES.AccessorProperty:
|
|
161
158
|
return (
|
|
162
159
|
node.value?.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
163
160
|
node.value?.type === AST_NODE_TYPES.FunctionExpression
|
|
164
161
|
)
|
|
162
|
+
case AST_NODE_TYPES.MethodDefinition:
|
|
163
|
+
case AST_NODE_TYPES.TSIndexSignature:
|
|
164
|
+
return true
|
|
165
165
|
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
166
166
|
default:
|
|
167
167
|
throw new UnreachableCaseError(node)
|
|
@@ -18,7 +18,7 @@ function computeIdentifierNameDetails(node) {
|
|
|
18
18
|
case AST_NODE_TYPES.Identifier:
|
|
19
19
|
return buildNonPrivateHashDetails(node.name)
|
|
20
20
|
case AST_NODE_TYPES.Literal:
|
|
21
|
-
return buildNonPrivateHashDetails(
|
|
21
|
+
return buildNonPrivateHashDetails(String(node.value))
|
|
22
22
|
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
23
23
|
default:
|
|
24
24
|
throw new UnreachableCaseError(node)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import { Options } from './types.js'
|
|
3
|
+
import { MessageId, Options } from './types.js'
|
|
4
4
|
/**
|
|
5
5
|
* Computes the matched context options for a given class node.
|
|
6
6
|
*
|
|
@@ -10,14 +10,12 @@ import { Options } from './types.js'
|
|
|
10
10
|
* @param params.context - The rule context.
|
|
11
11
|
* @returns The matched context options or undefined if none match.
|
|
12
12
|
*/
|
|
13
|
-
export declare function computeMatchedContextOptions
|
|
14
|
-
MessageIds extends string,
|
|
15
|
-
>({
|
|
13
|
+
export declare function computeMatchedContextOptions({
|
|
16
14
|
matchedAstSelectors,
|
|
17
15
|
classElements,
|
|
18
16
|
context,
|
|
19
17
|
}: {
|
|
20
|
-
context: Readonly<RuleContext<
|
|
18
|
+
context: Readonly<RuleContext<MessageId, Options>>
|
|
21
19
|
matchedAstSelectors: ReadonlySet<string>
|
|
22
20
|
classElements: TSESTree.ClassElement[]
|
|
23
21
|
}): Options[number] | undefined
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types'
|
|
2
2
|
import { Modifier } from '../types.js'
|
|
3
3
|
type Property =
|
|
4
|
-
| TSESTree.
|
|
5
|
-
| TSESTree.PropertyDefinition
|
|
4
|
+
TSESTree.TSAbstractPropertyDefinition | TSESTree.PropertyDefinition
|
|
6
5
|
type Accessor = TSESTree.TSAbstractAccessorProperty | TSESTree.AccessorProperty
|
|
7
6
|
type Method = TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition
|
|
8
7
|
export declare function computeAccessibilityModifier({
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types'
|
|
2
2
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
3
3
|
import { NodeNameDetails, Modifier, Selector } from '../types.js'
|
|
4
|
+
import { RegexOption } from '../../../types/common-options.js'
|
|
4
5
|
/**
|
|
5
6
|
* Computes details related to an accessor property.
|
|
6
7
|
*
|
|
7
8
|
* @param params - Parameters object.
|
|
8
9
|
* @param params.isDecorated - Whether the accessor is decorated.
|
|
10
|
+
* @param params.ignoreCallbackDependenciesPatterns - Patterns to ignore when
|
|
11
|
+
* computing dependencies.
|
|
12
|
+
* @param params.useExperimentalDependencyDetection - Whether to use
|
|
13
|
+
* experimental dependency detection.
|
|
9
14
|
* @param params.sourceCode - The source code object.
|
|
15
|
+
* @param params.className - The name of the class containing the accessor.
|
|
10
16
|
* @param params.accessor - The accessor node to compute information for.
|
|
11
17
|
* @returns An object containing various details about the accessor.
|
|
12
18
|
*/
|
|
13
19
|
export declare function computeAccessorDetails({
|
|
20
|
+
ignoreCallbackDependenciesPatterns,
|
|
21
|
+
useExperimentalDependencyDetection,
|
|
14
22
|
isDecorated,
|
|
15
23
|
sourceCode,
|
|
24
|
+
className,
|
|
16
25
|
accessor,
|
|
17
26
|
}: {
|
|
18
27
|
accessor: TSESTree.TSAbstractAccessorProperty | TSESTree.AccessorProperty
|
|
28
|
+
ignoreCallbackDependenciesPatterns: RegexOption
|
|
29
|
+
useExperimentalDependencyDetection: boolean
|
|
19
30
|
sourceCode: TSESLint.SourceCode
|
|
31
|
+
className: undefined | string
|
|
20
32
|
isDecorated: boolean
|
|
21
33
|
}): {
|
|
22
34
|
nameDetails: NodeNameDetails
|
|
23
35
|
dependencyNames: string[]
|
|
36
|
+
dependencies: string[]
|
|
24
37
|
modifiers: Modifier[]
|
|
25
38
|
selectors: Selector[]
|
|
26
39
|
isStatic: boolean
|
|
@@ -6,17 +6,31 @@ import {
|
|
|
6
6
|
computeStaticModifier,
|
|
7
7
|
} from './common-modifiers.js'
|
|
8
8
|
import { computeDependencyName } from '../compute-dependency-name.js'
|
|
9
|
+
import { computeDependencies } from '../compute-dependencies.js'
|
|
9
10
|
import { computeMethodOrPropertyNameDetails } from './compute-method-or-property-name-details.js'
|
|
11
|
+
import { isFunctionExpression } from './is-function-expression.js'
|
|
10
12
|
/**
|
|
11
13
|
* Computes details related to an accessor property.
|
|
12
14
|
*
|
|
13
15
|
* @param params - Parameters object.
|
|
14
16
|
* @param params.isDecorated - Whether the accessor is decorated.
|
|
17
|
+
* @param params.ignoreCallbackDependenciesPatterns - Patterns to ignore when
|
|
18
|
+
* computing dependencies.
|
|
19
|
+
* @param params.useExperimentalDependencyDetection - Whether to use
|
|
20
|
+
* experimental dependency detection.
|
|
15
21
|
* @param params.sourceCode - The source code object.
|
|
22
|
+
* @param params.className - The name of the class containing the accessor.
|
|
16
23
|
* @param params.accessor - The accessor node to compute information for.
|
|
17
24
|
* @returns An object containing various details about the accessor.
|
|
18
25
|
*/
|
|
19
|
-
function computeAccessorDetails({
|
|
26
|
+
function computeAccessorDetails({
|
|
27
|
+
ignoreCallbackDependenciesPatterns,
|
|
28
|
+
useExperimentalDependencyDetection,
|
|
29
|
+
isDecorated,
|
|
30
|
+
sourceCode,
|
|
31
|
+
className,
|
|
32
|
+
accessor,
|
|
33
|
+
}) {
|
|
20
34
|
let nameDetails = computeMethodOrPropertyNameDetails(accessor, sourceCode)
|
|
21
35
|
let modifiers = computeModifiers({
|
|
22
36
|
hasPrivateHash: nameDetails.hasPrivateHash,
|
|
@@ -31,12 +45,38 @@ function computeAccessorDetails({ isDecorated, sourceCode, accessor }) {
|
|
|
31
45
|
isStatic: modifiers.includes('static'),
|
|
32
46
|
}),
|
|
33
47
|
],
|
|
48
|
+
dependencies: computeAccessorDependencies({
|
|
49
|
+
ignoreCallbackDependenciesPatterns,
|
|
50
|
+
useExperimentalDependencyDetection,
|
|
51
|
+
className,
|
|
52
|
+
accessor,
|
|
53
|
+
}),
|
|
34
54
|
selectors: ['accessor-property'],
|
|
35
55
|
isStatic: accessor.static,
|
|
36
56
|
nameDetails,
|
|
37
57
|
modifiers,
|
|
38
58
|
}
|
|
39
59
|
}
|
|
60
|
+
function computeAccessorDependencies({
|
|
61
|
+
ignoreCallbackDependenciesPatterns,
|
|
62
|
+
useExperimentalDependencyDetection,
|
|
63
|
+
className,
|
|
64
|
+
accessor,
|
|
65
|
+
}) {
|
|
66
|
+
if (isFunctionExpression(accessor.value)) {
|
|
67
|
+
return []
|
|
68
|
+
}
|
|
69
|
+
if (!accessor.value) {
|
|
70
|
+
return []
|
|
71
|
+
}
|
|
72
|
+
return computeDependencies({
|
|
73
|
+
ignoreCallbackDependenciesPatterns,
|
|
74
|
+
useExperimentalDependencyDetection,
|
|
75
|
+
isMemberStatic: accessor.static,
|
|
76
|
+
expression: accessor.value,
|
|
77
|
+
className,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
40
80
|
function computeModifiers({ hasPrivateHash, isDecorated, accessor }) {
|
|
41
81
|
return [
|
|
42
82
|
...computeStaticModifier(accessor),
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { computeDependencyName } from '../compute-dependency-name.js'
|
|
12
12
|
import { computeDependencies } from '../compute-dependencies.js'
|
|
13
13
|
import { computeMethodOrPropertyNameDetails } from './compute-method-or-property-name-details.js'
|
|
14
|
-
import {
|
|
14
|
+
import { isFunctionExpression } from './is-function-expression.js'
|
|
15
15
|
/**
|
|
16
16
|
* Computes details related to a property.
|
|
17
17
|
*
|
|
@@ -115,13 +115,4 @@ function computeSelectors(property) {
|
|
|
115
115
|
return isFunctionExpression(property.value) ? ['function-property'] : []
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
function isFunctionExpression(node) {
|
|
119
|
-
if (!node) {
|
|
120
|
-
return false
|
|
121
|
-
}
|
|
122
|
-
return (
|
|
123
|
-
node.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
124
|
-
node.type === AST_NODE_TYPES.FunctionExpression
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
118
|
export { computePropertyDetails }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a node is a function expression or an arrow function
|
|
4
|
+
* expression.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The AST node to check.
|
|
7
|
+
* @returns Whether the node is a function expression.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isFunctionExpression(
|
|
10
|
+
node: TSESTree.Node | null,
|
|
11
|
+
): node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a node is a function expression or an arrow function
|
|
4
|
+
* expression.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The AST node to check.
|
|
7
|
+
* @returns Whether the node is a function expression.
|
|
8
|
+
*/
|
|
9
|
+
function isFunctionExpression(node) {
|
|
10
|
+
if (!node) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
return (
|
|
14
|
+
node.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
15
|
+
node.type === AST_NODE_TYPES.FunctionExpression
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
export { isFunctionExpression }
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
2
2
|
import { getGroupIndex } from '../../utils/get-group-index.js'
|
|
3
3
|
import { populateSortingNodeGroupsWithDependencies } from '../../utils/populate-sorting-node-groups-with-dependencies.js'
|
|
4
|
-
import { validateNewlinesAndPartitionConfiguration } from '../../utils/validate-newlines-and-partition-configuration.js'
|
|
5
4
|
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
5
|
+
import { validateNewlinesAndPartitionConfig } from '../../utils/validate-newlines-and-partition-config.js'
|
|
6
6
|
import { buildOptionsByGroupIndexComputer } from '../../utils/build-options-by-group-index-computer.js'
|
|
7
|
-
import {
|
|
8
|
-
import { validateGroupsConfiguration } from '../../utils/validate-groups-configuration.js'
|
|
7
|
+
import { validateCustomSortConfig } from '../../utils/validate-custom-sort-config.js'
|
|
9
8
|
import { generatePredefinedGroups } from '../../utils/generate-predefined-groups.js'
|
|
10
9
|
import { sortNodesByDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
11
10
|
import { getEslintDisabledLines } from '../../utils/get-eslint-disabled-lines.js'
|
|
12
11
|
import { doesCustomGroupMatch } from '../../utils/does-custom-group-match.js'
|
|
13
12
|
import { isNodeEslintDisabled } from '../../utils/is-node-eslint-disabled.js'
|
|
13
|
+
import { validateGroupsConfig } from '../../utils/validate-groups-config.js'
|
|
14
14
|
import { sortNodesByGroups } from '../../utils/sort-nodes-by-groups.js'
|
|
15
15
|
import { reportAllErrors } from '../../utils/report-all-errors.js'
|
|
16
16
|
import { shouldPartition } from '../../utils/should-partition.js'
|
|
@@ -103,13 +103,13 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
103
103
|
settings,
|
|
104
104
|
defaultOptions,
|
|
105
105
|
)
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
validateCustomSortConfig(options)
|
|
107
|
+
validateGroupsConfig({
|
|
108
108
|
modifiers: allModifiers,
|
|
109
109
|
selectors: allSelectors,
|
|
110
110
|
options,
|
|
111
111
|
})
|
|
112
|
-
|
|
112
|
+
validateNewlinesAndPartitionConfig(options)
|
|
113
113
|
let { sourceCode, id } = context
|
|
114
114
|
let eslintDisabledLines = getEslintDisabledLines({
|
|
115
115
|
ruleName: id,
|
|
@@ -125,15 +125,15 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
125
125
|
(accumulator, member) => {
|
|
126
126
|
let dependencies = []
|
|
127
127
|
let isDecorated = false
|
|
128
|
-
let
|
|
128
|
+
let decoratorNames = []
|
|
129
129
|
if ('decorators' in member) {
|
|
130
|
-
|
|
130
|
+
decoratorNames = getNodeDecorators(member).map(decorator =>
|
|
131
131
|
getDecoratorName({
|
|
132
132
|
sourceCode,
|
|
133
133
|
decorator,
|
|
134
134
|
}),
|
|
135
135
|
)
|
|
136
|
-
isDecorated =
|
|
136
|
+
isDecorated = decoratorNames.length > 0
|
|
137
137
|
}
|
|
138
138
|
let addSafetySemicolonWhenInline
|
|
139
139
|
let dependencyNames
|
|
@@ -187,12 +187,23 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
187
187
|
case AST_NODE_TYPES.TSAbstractAccessorProperty:
|
|
188
188
|
case AST_NODE_TYPES.AccessorProperty:
|
|
189
189
|
addSafetySemicolonWhenInline = true
|
|
190
|
-
;({
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
;({
|
|
191
|
+
dependencyNames,
|
|
192
|
+
dependencies,
|
|
193
|
+
nameDetails,
|
|
194
|
+
modifiers,
|
|
195
|
+
selectors,
|
|
196
|
+
isStatic,
|
|
197
|
+
} = computeAccessorDetails({
|
|
198
|
+
ignoreCallbackDependenciesPatterns:
|
|
199
|
+
options.ignoreCallbackDependenciesPatterns,
|
|
200
|
+
useExperimentalDependencyDetection:
|
|
201
|
+
options.useExperimentalDependencyDetection,
|
|
202
|
+
accessor: member,
|
|
203
|
+
isDecorated,
|
|
204
|
+
sourceCode,
|
|
205
|
+
className,
|
|
206
|
+
}))
|
|
196
207
|
;({ name } = nameDetails)
|
|
197
208
|
break
|
|
198
209
|
case AST_NODE_TYPES.TSIndexSignature:
|
|
@@ -229,8 +240,8 @@ function sortClass({ matchedAstSelectors, context, node }) {
|
|
|
229
240
|
doesCustomGroupMatch({
|
|
230
241
|
elementValue: memberValue,
|
|
231
242
|
elementName: name,
|
|
243
|
+
decoratorNames,
|
|
232
244
|
customGroup,
|
|
233
|
-
decorators,
|
|
234
245
|
modifiers,
|
|
235
246
|
selectors,
|
|
236
247
|
}),
|
|
@@ -61,9 +61,7 @@ export type Options = Partial<
|
|
|
61
61
|
>[]
|
|
62
62
|
export interface SortClassesSortingNode extends SortingNodeWithDependencies<TSESTree.ClassElement> {
|
|
63
63
|
overloadSignatureImplementation:
|
|
64
|
-
| TSESTree.
|
|
65
|
-
| TSESTree.MethodDefinition
|
|
66
|
-
| null
|
|
64
|
+
TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition | null
|
|
67
65
|
nameDetails: NodeNameDetails | null
|
|
68
66
|
isStatic: boolean
|
|
69
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildCommonJsonSchemas,
|
|
3
3
|
buildRegexJsonSchema,
|
|
4
|
-
|
|
4
|
+
buildUseConfigIfJsonSchema,
|
|
5
5
|
matchesAstSelectorJsonSchema,
|
|
6
6
|
useExperimentalDependencyDetectionJsonSchema,
|
|
7
7
|
} from '../utils/json-schemas/common-json-schemas.js'
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '../utils/report-errors.js'
|
|
19
19
|
import {
|
|
20
20
|
partitionByCommentJsonSchema,
|
|
21
|
-
|
|
21
|
+
partitionByNewlineJsonSchema,
|
|
22
22
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
23
23
|
import { buildAstListeners } from '../utils/build-ast-listeners.js'
|
|
24
24
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
@@ -42,7 +42,7 @@ var sort_classes_default = createEslintRule({
|
|
|
42
42
|
additionalCustomGroupMatchProperties:
|
|
43
43
|
additionalCustomGroupMatchOptionsJsonSchema,
|
|
44
44
|
}),
|
|
45
|
-
useConfigurationIf:
|
|
45
|
+
useConfigurationIf: buildUseConfigIfJsonSchema({
|
|
46
46
|
additionalProperties: {
|
|
47
47
|
matchesAstSelector: matchesAstSelectorJsonSchema,
|
|
48
48
|
},
|
|
@@ -52,7 +52,7 @@ var sort_classes_default = createEslintRule({
|
|
|
52
52
|
newlinesBetweenOverloadSignatures: newlinesBetweenJsonSchema,
|
|
53
53
|
ignoreCallbackDependenciesPatterns: buildRegexJsonSchema(),
|
|
54
54
|
partitionByComment: partitionByCommentJsonSchema,
|
|
55
|
-
partitionByNewLine:
|
|
55
|
+
partitionByNewLine: partitionByNewlineJsonSchema,
|
|
56
56
|
},
|
|
57
57
|
additionalProperties: false,
|
|
58
58
|
type: 'object',
|
|
@@ -8,16 +8,16 @@ import {
|
|
|
8
8
|
} from '../utils/report-errors.js'
|
|
9
9
|
import {
|
|
10
10
|
partitionByCommentJsonSchema,
|
|
11
|
-
|
|
11
|
+
partitionByNewlineJsonSchema,
|
|
12
12
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
13
|
-
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
14
13
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
14
|
+
import { validateNewlinesAndPartitionConfig } from '../utils/validate-newlines-and-partition-config.js'
|
|
15
15
|
import { buildOptionsByGroupIndexComputer } from '../utils/build-options-by-group-index-computer.js'
|
|
16
|
-
import {
|
|
17
|
-
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
16
|
+
import { validateCustomSortConfig } from '../utils/validate-custom-sort-config.js'
|
|
18
17
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
19
18
|
import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
20
19
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
20
|
+
import { validateGroupsConfig } from '../utils/validate-groups-config.js'
|
|
21
21
|
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
|
|
22
22
|
import { reportAllErrors } from '../utils/report-all-errors.js'
|
|
23
23
|
import { shouldPartition } from '../utils/should-partition.js'
|
|
@@ -87,7 +87,7 @@ var sort_decorators_default = createEslintRule({
|
|
|
87
87
|
type: 'boolean',
|
|
88
88
|
},
|
|
89
89
|
partitionByComment: partitionByCommentJsonSchema,
|
|
90
|
-
partitionByNewLine:
|
|
90
|
+
partitionByNewLine: partitionByNewlineJsonSchema,
|
|
91
91
|
},
|
|
92
92
|
additionalProperties: false,
|
|
93
93
|
type: 'object',
|
|
@@ -112,13 +112,13 @@ var sort_decorators_default = createEslintRule({
|
|
|
112
112
|
create: context => {
|
|
113
113
|
let settings = getSettings(context.settings)
|
|
114
114
|
let options = complete(context.options.at(0), settings, defaultOptions)
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
validateCustomSortConfig(options)
|
|
116
|
+
validateGroupsConfig({
|
|
117
117
|
modifiers: [],
|
|
118
118
|
selectors: [],
|
|
119
119
|
options,
|
|
120
120
|
})
|
|
121
|
-
|
|
121
|
+
validateNewlinesAndPartitionConfig(options)
|
|
122
122
|
return {
|
|
123
123
|
Decorator: decorator => {
|
|
124
124
|
if (!options.sortOnParameters) {
|
|
@@ -44,8 +44,19 @@ function computeMemberExpressionIdentifiers(
|
|
|
44
44
|
consecutiveOnly: true,
|
|
45
45
|
node: identifier,
|
|
46
46
|
})
|
|
47
|
-
.map(node => node.property)
|
|
48
|
-
.filter(
|
|
49
|
-
|
|
47
|
+
.map(node => computeMemberExpressionPropertyName(node.property))
|
|
48
|
+
.filter(name => name !== null)
|
|
49
|
+
}
|
|
50
|
+
function computeMemberExpressionPropertyName(property) {
|
|
51
|
+
if (property.type === AST_NODE_TYPES.Identifier) {
|
|
52
|
+
return property.name
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
property.type === AST_NODE_TYPES.Literal &&
|
|
56
|
+
typeof property.value === 'string'
|
|
57
|
+
) {
|
|
58
|
+
return property.value
|
|
59
|
+
}
|
|
60
|
+
return null
|
|
50
61
|
}
|
|
51
62
|
export { computeDependenciesBySortingNode }
|
|
@@ -17,10 +17,16 @@ function computeDependencies(expression, enumName) {
|
|
|
17
17
|
case AST_NODE_TYPES.MemberExpression:
|
|
18
18
|
if (
|
|
19
19
|
node.object.type === AST_NODE_TYPES.Identifier &&
|
|
20
|
-
node.object.name === enumName
|
|
21
|
-
node.property.type === AST_NODE_TYPES.Identifier
|
|
20
|
+
node.object.name === enumName
|
|
22
21
|
) {
|
|
23
|
-
|
|
22
|
+
if (node.property.type === AST_NODE_TYPES.Identifier) {
|
|
23
|
+
dependencies.push(node.property.name)
|
|
24
|
+
} else if (
|
|
25
|
+
node.property.type === AST_NODE_TYPES.Literal &&
|
|
26
|
+
typeof node.property.value === 'string'
|
|
27
|
+
) {
|
|
28
|
+
dependencies.push(node.property.value)
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
break
|
|
26
32
|
case AST_NODE_TYPES.Identifier:
|
|
@@ -38,9 +44,12 @@ function computeDependencies(expression, enumName) {
|
|
|
38
44
|
if ('arguments' in node) {
|
|
39
45
|
stack.push(...node.arguments)
|
|
40
46
|
}
|
|
47
|
+
if ('callee' in node) {
|
|
48
|
+
stack.push(node.callee)
|
|
49
|
+
}
|
|
41
50
|
if ('consequent' in node) {
|
|
51
|
+
/* v8 ignore if -- @preserve Unsure if we can reach it. */
|
|
42
52
|
if (Array.isArray(node.consequent)) {
|
|
43
|
-
/* v8 ignore if -- @preserve Unsure if we can reach it. */
|
|
44
53
|
stack.push(...node.consequent)
|
|
45
54
|
} else {
|
|
46
55
|
stack.push(node.consequent)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import { Options } from './types.js'
|
|
3
|
+
import { MessageId, Options } from './types.js'
|
|
4
4
|
/**
|
|
5
5
|
* Computes the matched context options for a given enum node.
|
|
6
6
|
*
|
|
@@ -11,14 +11,12 @@ import { Options } from './types.js'
|
|
|
11
11
|
* @param params.context - The rule context.
|
|
12
12
|
* @returns The matched context options or undefined if none match.
|
|
13
13
|
*/
|
|
14
|
-
export declare function computeMatchedContextOptions
|
|
15
|
-
MessageIds extends string,
|
|
16
|
-
>({
|
|
14
|
+
export declare function computeMatchedContextOptions({
|
|
17
15
|
matchedAstSelectors,
|
|
18
16
|
enumMembers,
|
|
19
17
|
context,
|
|
20
18
|
}: {
|
|
21
|
-
context: Readonly<RuleContext<
|
|
19
|
+
context: Readonly<RuleContext<MessageId, Options>>
|
|
22
20
|
matchedAstSelectors: ReadonlySet<string>
|
|
23
21
|
enumMembers: TSESTree.TSEnumMember[]
|
|
24
22
|
}): Options[number] | undefined
|