eslint-plugin-perfectionist 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes/types.d.ts +15 -18
- package/dist/rules/sort-array-includes/types.js +2 -2
- package/dist/rules/sort-array-includes.js +13 -10
- package/dist/rules/sort-classes/compute-dependencies.d.ts +24 -0
- package/dist/rules/sort-classes/compute-dependencies.js +147 -0
- package/dist/rules/sort-classes/compute-dependency-name.d.ts +9 -0
- package/dist/rules/sort-classes/compute-dependency-name.js +8 -0
- package/dist/rules/sort-classes/compute-identifier-name-details.d.ts +16 -0
- package/dist/rules/sort-classes/compute-identifier-name-details.js +27 -0
- package/dist/rules/sort-classes/get-overload-signature-groups.js +4 -3
- package/dist/rules/sort-classes/node-info/common-modifiers.d.ts +39 -0
- package/dist/rules/sort-classes/node-info/common-modifiers.js +62 -0
- package/dist/rules/sort-classes/node-info/compute-accessor-details.d.ts +26 -0
- package/dist/rules/sort-classes/node-info/compute-accessor-details.js +43 -0
- package/dist/rules/sort-classes/node-info/compute-index-signature-details.d.ts +23 -0
- package/dist/rules/sort-classes/node-info/compute-index-signature-details.js +21 -0
- package/dist/rules/sort-classes/node-info/compute-method-details.d.ts +29 -0
- package/dist/rules/sort-classes/node-info/compute-method-details.js +80 -0
- package/dist/rules/sort-classes/node-info/compute-method-or-property-name-details.d.ts +21 -0
- package/dist/rules/sort-classes/node-info/compute-method-or-property-name-details.js +17 -0
- package/dist/rules/sort-classes/node-info/compute-property-details.d.ts +36 -0
- package/dist/rules/sort-classes/node-info/compute-property-details.js +109 -0
- package/dist/rules/sort-classes/node-info/compute-static-block-details.d.ts +26 -0
- package/dist/rules/sort-classes/node-info/compute-static-block-details.js +18 -0
- package/dist/rules/sort-classes/types.d.ts +15 -18
- package/dist/rules/sort-classes/types.js +6 -2
- package/dist/rules/sort-classes.js +79 -291
- package/dist/rules/sort-decorators/types.d.ts +10 -12
- package/dist/rules/sort-decorators.js +57 -56
- package/dist/rules/sort-enums/build-comparator-by-options-computer.js +6 -0
- package/dist/rules/sort-enums/types.d.ts +16 -19
- package/dist/rules/sort-enums/types.js +2 -2
- package/dist/rules/sort-enums.js +13 -11
- package/dist/rules/sort-export-attributes/types.d.ts +6 -8
- package/dist/rules/sort-export-attributes.js +2 -1
- package/dist/rules/sort-exports/types.d.ts +11 -10
- package/dist/rules/sort-exports/types.js +6 -2
- package/dist/rules/sort-exports.js +7 -6
- package/dist/rules/sort-heritage-clauses/types.d.ts +6 -8
- package/dist/rules/sort-heritage-clauses.js +2 -1
- package/dist/rules/sort-import-attributes/types.d.ts +6 -8
- package/dist/rules/sort-import-attributes.js +2 -1
- package/dist/rules/sort-imports/comparator-by-options-computer.js +5 -0
- package/dist/rules/sort-imports/compute-specifier-modifiers.js +1 -1
- package/dist/rules/sort-imports/is-non-external-reference-ts-import-equals.js +1 -1
- package/dist/rules/sort-imports/is-side-effect-import.js +1 -1
- package/dist/rules/sort-imports/types.d.ts +18 -24
- package/dist/rules/sort-imports/types.js +9 -6
- package/dist/rules/sort-imports.js +25 -17
- package/dist/rules/sort-jsx-props/types.d.ts +18 -18
- package/dist/rules/sort-jsx-props/types.js +6 -2
- package/dist/rules/sort-jsx-props.js +14 -7
- package/dist/rules/sort-maps/types.d.ts +10 -16
- package/dist/rules/sort-maps.js +11 -6
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +2 -0
- package/dist/rules/sort-modules/compute-dependencies.d.ts +2 -5
- package/dist/rules/sort-modules/compute-dependencies.js +3 -0
- package/dist/rules/sort-modules/compute-node-details.d.ts +38 -0
- package/dist/rules/sort-modules/compute-node-details.js +127 -0
- package/dist/rules/sort-modules/is-arrow-function-node.js +1 -1
- package/dist/rules/sort-modules/is-property-or-accessor-node.js +1 -1
- package/dist/rules/sort-modules/types.d.ts +24 -17
- package/dist/rules/sort-modules/types.js +2 -2
- package/dist/rules/sort-modules.js +72 -141
- package/dist/rules/sort-named-exports/compute-node-name.js +1 -1
- package/dist/rules/sort-named-exports/types.d.ts +16 -16
- package/dist/rules/sort-named-exports/types.js +6 -2
- package/dist/rules/sort-named-exports.js +6 -5
- package/dist/rules/sort-named-imports/compute-node-name.js +1 -1
- package/dist/rules/sort-named-imports/types.d.ts +16 -17
- package/dist/rules/sort-named-imports/types.js +6 -2
- package/dist/rules/sort-named-imports.js +7 -6
- package/dist/rules/sort-object-types/comparator-by-options-computer.js +3 -0
- package/dist/rules/sort-object-types/is-member-optional.js +1 -1
- package/dist/rules/sort-object-types/is-node-function-type.js +20 -0
- package/dist/rules/sort-object-types/types.d.ts +21 -34
- package/dist/rules/sort-object-types/types.js +9 -6
- package/dist/rules/sort-object-types.js +7 -6
- package/dist/rules/sort-objects/types.d.ts +17 -21
- package/dist/rules/sort-objects/types.js +3 -3
- package/dist/rules/sort-objects.js +5 -3
- package/dist/rules/sort-sets.js +5 -4
- package/dist/rules/sort-switch-case.js +6 -4
- package/dist/rules/sort-union-types/types.d.ts +12 -12
- package/dist/rules/sort-union-types/types.js +2 -2
- package/dist/rules/sort-union-types.js +37 -35
- package/dist/rules/sort-variable-declarations/types.d.ts +12 -13
- package/dist/rules/sort-variable-declarations/types.js +2 -2
- package/dist/rules/sort-variable-declarations.js +14 -12
- package/dist/types/all-common-options.d.ts +14 -0
- package/dist/types/common-groups-options.d.ts +73 -95
- package/dist/types/common-options.d.ts +60 -55
- package/dist/utils/build-default-options-by-group-index-computer.d.ts +1 -1
- package/dist/utils/compare/build-string-formatter.d.ts +4 -5
- package/dist/utils/compare/build-subgroup-order-comparator.d.ts +10 -0
- package/dist/utils/compare/build-subgroup-order-comparator.js +49 -0
- package/dist/utils/compare/default-comparator-by-options-computer.d.ts +4 -1
- package/dist/utils/compare/default-comparator-by-options-computer.js +9 -0
- package/dist/utils/compute-group.d.ts +9 -9
- package/dist/utils/compute-overridden-options-by-group-index.d.ts +1 -1
- package/dist/utils/does-custom-group-match.d.ts +6 -4
- package/dist/utils/get-comment-above-that-should-exist.d.ts +1 -1
- package/dist/utils/get-newlines-between-errors.d.ts +1 -1
- package/dist/utils/get-newlines-between-option.d.ts +1 -7
- package/dist/utils/get-node-range.d.ts +2 -9
- package/dist/utils/get-settings.d.ts +1 -1
- package/dist/utils/is-group-with-overrides-option.d.ts +3 -6
- package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +6 -6
- package/dist/utils/json-schemas/common-groups-json-schemas.js +12 -10
- package/dist/utils/json-schemas/common-json-schemas.d.ts +5 -5
- package/dist/utils/json-schemas/common-json-schemas.js +13 -12
- package/dist/utils/make-comment-above-fixes.d.ts +1 -1
- package/dist/utils/make-fixes.d.ts +3 -5
- package/dist/utils/make-newlines-between-fixes.d.ts +1 -1
- package/dist/utils/make-order-fixes.d.ts +2 -5
- package/dist/utils/report-all-errors.d.ts +19 -17
- package/dist/utils/report-errors.d.ts +3 -1
- package/dist/utils/should-partition.d.ts +2 -5
- package/dist/utils/validate-custom-sort-configuration.d.ts +1 -1
- package/dist/utils/validate-groups-configuration.d.ts +1 -1
- package/dist/utils/validate-newlines-and-partition-configuration.d.ts +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/types/join.d.ts +0 -19
- package/dist/utils/is-node-function-type.js +0 -13
- /package/dist/{utils → rules/sort-object-types}/is-node-function-type.d.ts +0 -0
|
@@ -13,19 +13,22 @@ let objectTypeParentTypes = [
|
|
|
13
13
|
]
|
|
14
14
|
let allSelectors = ['index-signature', 'member', 'method', 'property']
|
|
15
15
|
let allModifiers = ['optional', 'required', 'multiline']
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const SORT_BY_OPTION = ['name', 'value']
|
|
17
|
+
let additionalSortOptionsJsonSchema = {
|
|
18
|
+
sortBy: {
|
|
19
|
+
enum: [...SORT_BY_OPTION],
|
|
20
|
+
type: 'string',
|
|
21
|
+
},
|
|
19
22
|
}
|
|
20
|
-
let
|
|
23
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
21
24
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
22
25
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
23
26
|
elementValuePattern: buildRegexJsonSchema(),
|
|
24
27
|
}
|
|
25
28
|
export {
|
|
29
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
30
|
+
additionalSortOptionsJsonSchema,
|
|
26
31
|
allModifiers,
|
|
27
32
|
allSelectors,
|
|
28
33
|
objectTypeParentTypes,
|
|
29
|
-
singleCustomGroupJsonSchema,
|
|
30
|
-
sortByJsonSchema,
|
|
31
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
4
|
+
additionalSortOptionsJsonSchema,
|
|
5
5
|
allSelectors,
|
|
6
6
|
allModifiers,
|
|
7
7
|
objectTypeParentTypes,
|
|
@@ -30,6 +30,7 @@ import { computeParentNodesWithTypes } from '../utils/compute-parent-nodes-with-
|
|
|
30
30
|
import { scopedRegexJsonSchema } from '../utils/json-schemas/scoped-regex-json-schema.js'
|
|
31
31
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
32
32
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
33
|
+
import { isNodeFunctionType } from './sort-object-types/is-node-function-type.js'
|
|
33
34
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
34
35
|
import { isMemberOptional } from './sort-object-types/is-member-optional.js'
|
|
35
36
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
@@ -37,7 +38,6 @@ import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
|
37
38
|
import { computeNodeName } from './sort-object-types/compute-node-name.js'
|
|
38
39
|
import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
|
|
39
40
|
import { isNodeOnSingleLine } from '../utils/is-node-on-single-line.js'
|
|
40
|
-
import { isNodeFunctionType } from '../utils/is-node-function-type.js'
|
|
41
41
|
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
|
|
42
42
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
43
43
|
import { reportAllErrors } from '../utils/report-all-errors.js'
|
|
@@ -73,11 +73,12 @@ let jsonSchema = {
|
|
|
73
73
|
items: {
|
|
74
74
|
properties: {
|
|
75
75
|
...buildCommonJsonSchemas({
|
|
76
|
-
additionalSortProperties:
|
|
76
|
+
additionalSortProperties: additionalSortOptionsJsonSchema,
|
|
77
77
|
}),
|
|
78
78
|
...buildCommonGroupsJsonSchemas({
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
additionalCustomGroupMatchProperties:
|
|
80
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
81
|
+
additionalSortProperties: additionalSortOptionsJsonSchema,
|
|
81
82
|
}),
|
|
82
83
|
useConfigurationIf: buildUseConfigurationIfJsonSchema({
|
|
83
84
|
additionalProperties: {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
3
|
-
import {
|
|
4
|
-
CommonOptions,
|
|
5
|
-
RegexOption,
|
|
6
|
-
TypeOption,
|
|
7
|
-
} from '../../types/common-options.js'
|
|
8
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
9
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
3
|
+
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
10
4
|
import { ScopedRegexOption } from '../../types/scoped-regex-option.js'
|
|
5
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
11
6
|
import { NodeOfType } from '../../types/node-of-type.js'
|
|
12
7
|
export type MessageId =
|
|
13
8
|
| typeof DEPENDENCY_ORDER_ERROR_ID
|
|
@@ -74,14 +69,13 @@ export type Options = Partial<
|
|
|
74
69
|
* @default true
|
|
75
70
|
*/
|
|
76
71
|
styledComponents: boolean
|
|
77
|
-
} &
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
>
|
|
82
|
-
CommonOptions<TypeOption> &
|
|
83
|
-
CommonPartitionOptions
|
|
72
|
+
} & AllCommonOptions<
|
|
73
|
+
TypeOption,
|
|
74
|
+
AdditionalSortOptions,
|
|
75
|
+
CustomGroupMatchOptions
|
|
76
|
+
>
|
|
84
77
|
>[]
|
|
78
|
+
type AdditionalSortOptions = object
|
|
85
79
|
export declare let objectParentTypes: readonly [
|
|
86
80
|
AST_NODE_TYPES.VariableDeclarator,
|
|
87
81
|
AST_NODE_TYPES.CallExpression,
|
|
@@ -103,8 +97,8 @@ export type Modifier = (typeof allModifiers)[number]
|
|
|
103
97
|
* purposes.
|
|
104
98
|
*/
|
|
105
99
|
export type Selector = (typeof allSelectors)[number]
|
|
106
|
-
/**
|
|
107
|
-
interface
|
|
100
|
+
/** Match options for a custom group. */
|
|
101
|
+
interface CustomGroupMatchOptions {
|
|
108
102
|
/**
|
|
109
103
|
* Regular expression pattern to match against the member's value. Only
|
|
110
104
|
* applicable to properties with literal values.
|
|
@@ -132,11 +126,13 @@ export declare let allSelectors: readonly ['member', 'method', 'property']
|
|
|
132
126
|
*
|
|
133
127
|
* Used for validation and configuration in the ESLint rule.
|
|
134
128
|
*/
|
|
135
|
-
export declare let allModifiers: readonly ['
|
|
129
|
+
export declare let allModifiers: readonly ['multiline']
|
|
136
130
|
/**
|
|
137
|
-
* JSON
|
|
138
|
-
*
|
|
139
|
-
* Provides additional schema properties specific to the sort-objects rule.
|
|
131
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
132
|
+
* rule options at configuration time.
|
|
140
133
|
*/
|
|
141
|
-
export declare let
|
|
134
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
135
|
+
string,
|
|
136
|
+
JSONSchema4
|
|
137
|
+
>
|
|
142
138
|
export {}
|
|
@@ -15,8 +15,8 @@ let objectParentTypes = [
|
|
|
15
15
|
AST_NODE_TYPES.Property,
|
|
16
16
|
]
|
|
17
17
|
let allSelectors = ['member', 'method', 'property']
|
|
18
|
-
let allModifiers = ['
|
|
19
|
-
let
|
|
18
|
+
let allModifiers = ['multiline']
|
|
19
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
20
20
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
21
21
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
22
22
|
elementValuePattern: buildRegexJsonSchema(),
|
|
@@ -27,8 +27,8 @@ export {
|
|
|
27
27
|
GROUP_ORDER_ERROR_ID,
|
|
28
28
|
MISSED_SPACING_ERROR_ID,
|
|
29
29
|
ORDER_ERROR_ID,
|
|
30
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
30
31
|
allModifiers,
|
|
31
32
|
allSelectors,
|
|
32
33
|
objectParentTypes,
|
|
33
|
-
singleCustomGroupJsonSchema,
|
|
34
34
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
EXTRA_SPACING_ERROR_ID,
|
|
6
6
|
MISSED_SPACING_ERROR_ID,
|
|
7
7
|
DEPENDENCY_ORDER_ERROR_ID,
|
|
8
|
-
|
|
8
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
9
9
|
allSelectors,
|
|
10
10
|
allModifiers,
|
|
11
11
|
} from './sort-objects/types.js'
|
|
@@ -76,7 +76,8 @@ const sortObjects = createEslintRule({
|
|
|
76
76
|
if (!isSortable(nodeObject.properties)) {
|
|
77
77
|
return
|
|
78
78
|
}
|
|
79
|
-
let isDestructuredObject =
|
|
79
|
+
let isDestructuredObject =
|
|
80
|
+
nodeObject.type === AST_NODE_TYPES.ObjectPattern
|
|
80
81
|
let matchedContextOptions = computeMatchedContextOptions({
|
|
81
82
|
isDestructuredObject,
|
|
82
83
|
nodeObject,
|
|
@@ -312,7 +313,8 @@ const sortObjects = createEslintRule({
|
|
|
312
313
|
properties: {
|
|
313
314
|
...buildCommonJsonSchemas(),
|
|
314
315
|
...buildCommonGroupsJsonSchemas({
|
|
315
|
-
|
|
316
|
+
additionalCustomGroupMatchProperties:
|
|
317
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
316
318
|
}),
|
|
317
319
|
useConfigurationIf: buildUseConfigurationIfJsonSchema({
|
|
318
320
|
additionalProperties: {
|
package/dist/rules/sort-sets.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
ORDER_ERROR,
|
|
3
4
|
GROUP_ORDER_ERROR,
|
|
@@ -14,16 +15,16 @@ const sortSets = createEslintRule({
|
|
|
14
15
|
create: context => ({
|
|
15
16
|
NewExpression: node => {
|
|
16
17
|
if (
|
|
17
|
-
node.callee.type ===
|
|
18
|
+
node.callee.type === AST_NODE_TYPES.Identifier &&
|
|
18
19
|
node.callee.name === 'Set' &&
|
|
19
20
|
node.arguments.length > 0 &&
|
|
20
|
-
(node.arguments[0]?.type ===
|
|
21
|
-
(node.arguments[0]?.type ===
|
|
21
|
+
(node.arguments[0]?.type === AST_NODE_TYPES.ArrayExpression ||
|
|
22
|
+
(node.arguments[0]?.type === AST_NODE_TYPES.NewExpression &&
|
|
22
23
|
'name' in node.arguments[0].callee &&
|
|
23
24
|
node.arguments[0].callee.name === 'Array'))
|
|
24
25
|
) {
|
|
25
26
|
let elements =
|
|
26
|
-
node.arguments[0].type ===
|
|
27
|
+
node.arguments[0].type === AST_NODE_TYPES.ArrayExpression
|
|
27
28
|
? node.arguments[0].elements
|
|
28
29
|
: node.arguments[0].arguments
|
|
29
30
|
sortArray({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
2
3
|
import { makeSingleNodeCommentAfterFixes } from '../utils/make-single-node-comment-after-fixes.js'
|
|
3
4
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
@@ -39,7 +40,7 @@ const sortSwitchCase = createEslintRule({
|
|
|
39
40
|
validateCustomSortConfiguration(options)
|
|
40
41
|
let { sourceCode } = context
|
|
41
42
|
let isDiscriminantTrue =
|
|
42
|
-
switchNode.discriminant.type ===
|
|
43
|
+
switchNode.discriminant.type === AST_NODE_TYPES.Literal &&
|
|
43
44
|
switchNode.discriminant.value === true
|
|
44
45
|
if (isDiscriminantTrue) {
|
|
45
46
|
return
|
|
@@ -261,7 +262,7 @@ function reduceCaseSortingNodes(caseNodes, endsBlock) {
|
|
|
261
262
|
)
|
|
262
263
|
}
|
|
263
264
|
function getCaseName(sourceCode, caseNode) {
|
|
264
|
-
if (caseNode.test?.type ===
|
|
265
|
+
if (caseNode.test?.type === AST_NODE_TYPES.Literal) {
|
|
265
266
|
return `${caseNode.test.value}`
|
|
266
267
|
} else if (caseNode.test === null) {
|
|
267
268
|
return 'default'
|
|
@@ -270,14 +271,15 @@ function getCaseName(sourceCode, caseNode) {
|
|
|
270
271
|
}
|
|
271
272
|
function caseHasBreakOrReturn(caseNode) {
|
|
272
273
|
let statements =
|
|
273
|
-
caseNode.consequent[0]?.type ===
|
|
274
|
+
caseNode.consequent[0]?.type === AST_NODE_TYPES.BlockStatement
|
|
274
275
|
? caseNode.consequent[0].body
|
|
275
276
|
: caseNode.consequent
|
|
276
277
|
return statements.some(statementIsBreakOrReturn)
|
|
277
278
|
}
|
|
278
279
|
function statementIsBreakOrReturn(statement) {
|
|
279
280
|
return (
|
|
280
|
-
statement.type ===
|
|
281
|
+
statement.type === AST_NODE_TYPES.BreakStatement ||
|
|
282
|
+
statement.type === AST_NODE_TYPES.ReturnStatement
|
|
281
283
|
)
|
|
282
284
|
}
|
|
283
285
|
export { sortSwitchCase as default }
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
2
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
3
|
+
import { TypeOption } from '../../types/common-options.js'
|
|
5
4
|
/**
|
|
6
5
|
* Configuration options for the sort-union-types rule.
|
|
7
6
|
*
|
|
8
7
|
* Controls how TypeScript union type members are sorted.
|
|
9
8
|
*/
|
|
10
9
|
export type Options = Partial<
|
|
11
|
-
|
|
12
|
-
CommonOptions<TypeOption> &
|
|
13
|
-
CommonPartitionOptions
|
|
10
|
+
AllCommonOptions<TypeOption, AdditionalSortOptions, CustomGroupMatchOptions>
|
|
14
11
|
>[]
|
|
15
12
|
/**
|
|
16
13
|
* Union type of all available selectors for union type members.
|
|
@@ -19,14 +16,15 @@ export type Options = Partial<
|
|
|
19
16
|
* union, enabling fine-grained control over sorting.
|
|
20
17
|
*/
|
|
21
18
|
export type Selector = (typeof allSelectors)[number]
|
|
22
|
-
/**
|
|
23
|
-
interface
|
|
19
|
+
/** Match options for a custom group. */
|
|
20
|
+
interface CustomGroupMatchOptions {
|
|
24
21
|
/**
|
|
25
22
|
* The selector type this group matches. Determines what kind of type
|
|
26
23
|
* members belong to this group.
|
|
27
24
|
*/
|
|
28
25
|
selector?: Selector
|
|
29
26
|
}
|
|
27
|
+
type AdditionalSortOptions = object
|
|
30
28
|
/**
|
|
31
29
|
* Array of all available selectors for union type members.
|
|
32
30
|
*
|
|
@@ -47,9 +45,11 @@ export declare let allSelectors: readonly [
|
|
|
47
45
|
'union',
|
|
48
46
|
]
|
|
49
47
|
/**
|
|
50
|
-
* JSON
|
|
51
|
-
*
|
|
52
|
-
* Provides additional schema properties specific to the sort-union-types rule.
|
|
48
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
49
|
+
* rule options at configuration time.
|
|
53
50
|
*/
|
|
54
|
-
export declare let
|
|
51
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
52
|
+
string,
|
|
53
|
+
JSONSchema4
|
|
54
|
+
>
|
|
55
55
|
export {}
|
|
@@ -13,7 +13,7 @@ let allSelectors = [
|
|
|
13
13
|
'tuple',
|
|
14
14
|
'union',
|
|
15
15
|
]
|
|
16
|
-
let
|
|
16
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
17
17
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
18
18
|
}
|
|
19
|
-
export {
|
|
19
|
+
export { additionalCustomGroupMatchOptionsJsonSchema, allSelectors }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
partitionByNewLineJsonSchema,
|
|
3
4
|
partitionByCommentJsonSchema,
|
|
@@ -11,12 +12,12 @@ import {
|
|
|
11
12
|
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
12
13
|
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
13
14
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
14
|
-
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
15
|
-
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
16
15
|
import {
|
|
17
|
-
|
|
16
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
18
17
|
allSelectors,
|
|
19
18
|
} from './sort-union-types/types.js'
|
|
19
|
+
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
20
|
+
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
20
21
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
21
22
|
import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
|
|
22
23
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
@@ -56,7 +57,8 @@ let jsonSchema = {
|
|
|
56
57
|
properties: {
|
|
57
58
|
...buildCommonJsonSchemas(),
|
|
58
59
|
...buildCommonGroupsJsonSchemas({
|
|
59
|
-
|
|
60
|
+
additionalCustomGroupMatchProperties:
|
|
61
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
60
62
|
}),
|
|
61
63
|
partitionByComment: partitionByCommentJsonSchema,
|
|
62
64
|
partitionByNewLine: partitionByNewLineJsonSchema,
|
|
@@ -126,59 +128,59 @@ function sortUnionOrIntersectionTypes({
|
|
|
126
128
|
(accumulator, type) => {
|
|
127
129
|
let selectors = []
|
|
128
130
|
switch (type.type) {
|
|
129
|
-
case
|
|
130
|
-
case
|
|
131
|
+
case AST_NODE_TYPES.TSTemplateLiteralType:
|
|
132
|
+
case AST_NODE_TYPES.TSLiteralType:
|
|
131
133
|
selectors.push('literal')
|
|
132
134
|
break
|
|
133
|
-
case
|
|
134
|
-
case
|
|
135
|
-
case
|
|
136
|
-
case
|
|
137
|
-
case
|
|
135
|
+
case AST_NODE_TYPES.TSIndexedAccessType:
|
|
136
|
+
case AST_NODE_TYPES.TSTypeReference:
|
|
137
|
+
case AST_NODE_TYPES.TSQualifiedName:
|
|
138
|
+
case AST_NODE_TYPES.TSArrayType:
|
|
139
|
+
case AST_NODE_TYPES.TSInferType:
|
|
138
140
|
selectors.push('named')
|
|
139
141
|
break
|
|
140
|
-
case
|
|
142
|
+
case AST_NODE_TYPES.TSIntersectionType:
|
|
141
143
|
selectors.push('intersection')
|
|
142
144
|
break
|
|
143
|
-
case
|
|
144
|
-
case
|
|
145
|
-
case
|
|
145
|
+
case AST_NODE_TYPES.TSUndefinedKeyword:
|
|
146
|
+
case AST_NODE_TYPES.TSNullKeyword:
|
|
147
|
+
case AST_NODE_TYPES.TSVoidKeyword:
|
|
146
148
|
selectors.push('nullish')
|
|
147
149
|
break
|
|
148
|
-
case
|
|
150
|
+
case AST_NODE_TYPES.TSConditionalType:
|
|
149
151
|
selectors.push('conditional')
|
|
150
152
|
break
|
|
151
|
-
case
|
|
152
|
-
case
|
|
153
|
+
case AST_NODE_TYPES.TSConstructorType:
|
|
154
|
+
case AST_NODE_TYPES.TSFunctionType:
|
|
153
155
|
selectors.push('function')
|
|
154
156
|
break
|
|
155
|
-
case
|
|
156
|
-
case
|
|
157
|
-
case
|
|
158
|
-
case
|
|
159
|
-
case
|
|
160
|
-
case
|
|
161
|
-
case
|
|
162
|
-
case
|
|
163
|
-
case
|
|
164
|
-
case
|
|
157
|
+
case AST_NODE_TYPES.TSBooleanKeyword:
|
|
158
|
+
case AST_NODE_TYPES.TSUnknownKeyword:
|
|
159
|
+
case AST_NODE_TYPES.TSBigIntKeyword:
|
|
160
|
+
case AST_NODE_TYPES.TSNumberKeyword:
|
|
161
|
+
case AST_NODE_TYPES.TSObjectKeyword:
|
|
162
|
+
case AST_NODE_TYPES.TSStringKeyword:
|
|
163
|
+
case AST_NODE_TYPES.TSSymbolKeyword:
|
|
164
|
+
case AST_NODE_TYPES.TSNeverKeyword:
|
|
165
|
+
case AST_NODE_TYPES.TSAnyKeyword:
|
|
166
|
+
case AST_NODE_TYPES.TSThisType:
|
|
165
167
|
selectors.push('keyword')
|
|
166
168
|
break
|
|
167
|
-
case
|
|
168
|
-
case
|
|
169
|
+
case AST_NODE_TYPES.TSTypeOperator:
|
|
170
|
+
case AST_NODE_TYPES.TSTypeQuery:
|
|
169
171
|
selectors.push('operator')
|
|
170
172
|
break
|
|
171
|
-
case
|
|
172
|
-
case
|
|
173
|
+
case AST_NODE_TYPES.TSTypeLiteral:
|
|
174
|
+
case AST_NODE_TYPES.TSMappedType:
|
|
173
175
|
selectors.push('object')
|
|
174
176
|
break
|
|
175
|
-
case
|
|
177
|
+
case AST_NODE_TYPES.TSImportType:
|
|
176
178
|
selectors.push('import')
|
|
177
179
|
break
|
|
178
|
-
case
|
|
180
|
+
case AST_NODE_TYPES.TSTupleType:
|
|
179
181
|
selectors.push('tuple')
|
|
180
182
|
break
|
|
181
|
-
case
|
|
183
|
+
case AST_NODE_TYPES.TSUnionType:
|
|
182
184
|
selectors.push('union')
|
|
183
185
|
break
|
|
184
186
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
2
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
3
|
+
import { TypeOption } from '../../types/common-options.js'
|
|
5
4
|
/**
|
|
6
5
|
* Configuration options for the sort-variable-declarations rule.
|
|
7
6
|
*
|
|
@@ -9,9 +8,7 @@ import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
|
9
8
|
* such as `const a = 1, b, c = 3;`.
|
|
10
9
|
*/
|
|
11
10
|
export type Options = Partial<
|
|
12
|
-
|
|
13
|
-
CommonOptions<TypeOption> &
|
|
14
|
-
CommonPartitionOptions
|
|
11
|
+
AllCommonOptions<TypeOption, AdditionalSortOptions, CustomGroupMatchOptions>
|
|
15
12
|
>[]
|
|
16
13
|
/**
|
|
17
14
|
* Union type of all available selectors for variable declarations.
|
|
@@ -19,14 +16,15 @@ export type Options = Partial<
|
|
|
19
16
|
* Distinguishes between variables with and without initial values.
|
|
20
17
|
*/
|
|
21
18
|
export type Selector = (typeof allSelectors)[number]
|
|
22
|
-
/**
|
|
23
|
-
interface
|
|
19
|
+
/** Match options for a custom group. */
|
|
20
|
+
interface CustomGroupMatchOptions {
|
|
24
21
|
/**
|
|
25
22
|
* The selector type this group matches. Can be 'initialized' for variables
|
|
26
23
|
* with values or 'uninitialized' for variables without.
|
|
27
24
|
*/
|
|
28
25
|
selector?: Selector
|
|
29
26
|
}
|
|
27
|
+
type AdditionalSortOptions = object
|
|
30
28
|
/**
|
|
31
29
|
* Array of all available selectors for variable declarations.
|
|
32
30
|
*
|
|
@@ -34,10 +32,11 @@ interface SingleCustomGroup {
|
|
|
34
32
|
*/
|
|
35
33
|
export declare let allSelectors: readonly ['initialized', 'uninitialized']
|
|
36
34
|
/**
|
|
37
|
-
* JSON
|
|
38
|
-
*
|
|
39
|
-
* Provides additional schema properties specific to the
|
|
40
|
-
* sort-variable-declarations rule.
|
|
35
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
36
|
+
* rule options at configuration time.
|
|
41
37
|
*/
|
|
42
|
-
export declare let
|
|
38
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
39
|
+
string,
|
|
40
|
+
JSONSchema4
|
|
41
|
+
>
|
|
43
42
|
export {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildCustomGroupSelectorJsonSchema } from '../../utils/json-schemas/common-groups-json-schemas.js'
|
|
2
2
|
let allSelectors = ['initialized', 'uninitialized']
|
|
3
|
-
let
|
|
3
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
4
4
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
5
5
|
}
|
|
6
|
-
export {
|
|
6
|
+
export { additionalCustomGroupMatchOptionsJsonSchema, allSelectors }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
ORDER_ERROR,
|
|
3
4
|
GROUP_ORDER_ERROR,
|
|
@@ -9,13 +10,13 @@ import {
|
|
|
9
10
|
partitionByNewLineJsonSchema,
|
|
10
11
|
partitionByCommentJsonSchema,
|
|
11
12
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
12
|
-
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
13
|
-
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
14
|
-
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
15
13
|
import {
|
|
16
|
-
|
|
14
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
17
15
|
allSelectors,
|
|
18
16
|
} from './sort-variable-declarations/types.js'
|
|
17
|
+
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
18
|
+
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
19
|
+
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
19
20
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
20
21
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
21
22
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
@@ -81,8 +82,8 @@ const sortVariableDeclarations = createEslintRule({
|
|
|
81
82
|
(accumulator, declaration) => {
|
|
82
83
|
let name
|
|
83
84
|
if (
|
|
84
|
-
declaration.id.type ===
|
|
85
|
-
declaration.id.type ===
|
|
85
|
+
declaration.id.type === AST_NODE_TYPES.ArrayPattern ||
|
|
86
|
+
declaration.id.type === AST_NODE_TYPES.ObjectPattern
|
|
86
87
|
) {
|
|
87
88
|
name = sourceCode.text.slice(...declaration.id.range)
|
|
88
89
|
} else {
|
|
@@ -179,7 +180,8 @@ const sortVariableDeclarations = createEslintRule({
|
|
|
179
180
|
properties: {
|
|
180
181
|
...buildCommonJsonSchemas(),
|
|
181
182
|
...buildCommonGroupsJsonSchemas({
|
|
182
|
-
|
|
183
|
+
additionalCustomGroupMatchProperties:
|
|
184
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
183
185
|
}),
|
|
184
186
|
partitionByComment: partitionByCommentJsonSchema,
|
|
185
187
|
partitionByNewLine: partitionByNewLineJsonSchema,
|
|
@@ -210,19 +212,19 @@ function extractDependencies(init) {
|
|
|
210
212
|
let dependencies = []
|
|
211
213
|
function checkNode(nodeValue) {
|
|
212
214
|
if (
|
|
213
|
-
nodeValue.type ===
|
|
214
|
-
nodeValue.type ===
|
|
215
|
+
nodeValue.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
216
|
+
nodeValue.type === AST_NODE_TYPES.FunctionExpression
|
|
215
217
|
) {
|
|
216
218
|
return
|
|
217
219
|
}
|
|
218
|
-
if (nodeValue.type ===
|
|
220
|
+
if (nodeValue.type === AST_NODE_TYPES.Identifier) {
|
|
219
221
|
dependencies.push(nodeValue.name)
|
|
220
222
|
}
|
|
221
|
-
if (nodeValue.type ===
|
|
223
|
+
if (nodeValue.type === AST_NODE_TYPES.Property) {
|
|
222
224
|
checkNode(nodeValue.key)
|
|
223
225
|
checkNode(nodeValue.value)
|
|
224
226
|
}
|
|
225
|
-
if (nodeValue.type ===
|
|
227
|
+
if (nodeValue.type === AST_NODE_TYPES.ConditionalExpression) {
|
|
226
228
|
checkNode(nodeValue.test)
|
|
227
229
|
checkNode(nodeValue.consequent)
|
|
228
230
|
checkNode(nodeValue.alternate)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CommonPartitionOptions } from './common-partition-options.js'
|
|
2
|
+
import { CommonGroupsOptions } from './common-groups-options.js'
|
|
3
|
+
import { CommonOptions } from './common-options.js'
|
|
4
|
+
export type AllCommonOptions<
|
|
5
|
+
CustomTypeOption extends string,
|
|
6
|
+
AdditionalSortOptions,
|
|
7
|
+
CustomGroupMatchOptions,
|
|
8
|
+
> = CommonGroupsOptions<
|
|
9
|
+
CustomTypeOption,
|
|
10
|
+
AdditionalSortOptions,
|
|
11
|
+
CustomGroupMatchOptions
|
|
12
|
+
> &
|
|
13
|
+
CommonOptions<CustomTypeOption, AdditionalSortOptions> &
|
|
14
|
+
CommonPartitionOptions
|