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
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import {
|
|
4
|
-
CommonOptions,
|
|
5
|
-
RegexOption,
|
|
6
|
-
TypeOption,
|
|
7
|
-
} from '../../types/common-options.js'
|
|
8
3
|
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
5
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
11
6
|
/**
|
|
12
7
|
* Configuration options for the sort-enums rule.
|
|
13
8
|
*
|
|
@@ -24,29 +19,31 @@ export type Options = Partial<
|
|
|
24
19
|
* @default ifNumericEnum
|
|
25
20
|
*/
|
|
26
21
|
sortByValue: 'ifNumericEnum' | 'always' | 'never'
|
|
27
|
-
} &
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
>
|
|
32
|
-
CommonOptions<TypeOption> &
|
|
33
|
-
CommonPartitionOptions
|
|
22
|
+
} & AllCommonOptions<
|
|
23
|
+
TypeOption,
|
|
24
|
+
AdditionalSortOptions,
|
|
25
|
+
CustomGroupMatchOptions
|
|
26
|
+
>
|
|
34
27
|
>[]
|
|
35
28
|
export interface SortEnumsSortingNode extends SortingNodeWithDependencies<TSESTree.TSEnumMember> {
|
|
36
29
|
numericValue: number | null
|
|
37
30
|
value: string | null
|
|
38
31
|
}
|
|
39
|
-
/**
|
|
40
|
-
interface
|
|
32
|
+
/** Match options for a custom group. */
|
|
33
|
+
interface CustomGroupMatchOptions {
|
|
41
34
|
/**
|
|
42
35
|
* Regular expression pattern to match enum member values. Members with
|
|
43
36
|
* values matching this pattern will be included in this custom group.
|
|
44
37
|
*/
|
|
45
38
|
elementValuePattern?: RegexOption
|
|
46
39
|
}
|
|
40
|
+
type AdditionalSortOptions = object
|
|
47
41
|
/**
|
|
48
|
-
* JSON schema
|
|
49
|
-
*
|
|
42
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
43
|
+
* rule options at configuration time.
|
|
50
44
|
*/
|
|
51
|
-
export declare let
|
|
45
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
46
|
+
string,
|
|
47
|
+
JSONSchema4
|
|
48
|
+
>
|
|
52
49
|
export {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildRegexJsonSchema } from '../../utils/json-schemas/common-json-schemas.js'
|
|
2
|
-
let
|
|
2
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
3
3
|
elementValuePattern: buildRegexJsonSchema(),
|
|
4
4
|
}
|
|
5
|
-
export {
|
|
5
|
+
export { additionalCustomGroupMatchOptionsJsonSchema }
|
package/dist/rules/sort-enums.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,
|
|
@@ -16,12 +17,12 @@ import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-group
|
|
|
16
17
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
17
18
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
18
19
|
import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
|
|
20
|
+
import { additionalCustomGroupMatchOptionsJsonSchema } from './sort-enums/types.js'
|
|
19
21
|
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.js'
|
|
20
22
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
21
23
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
22
24
|
import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
23
25
|
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
|
|
24
|
-
import { singleCustomGroupJsonSchema } from './sort-enums/types.js'
|
|
25
26
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
26
27
|
import { reportAllErrors } from '../utils/report-all-errors.js'
|
|
27
28
|
import { shouldPartition } from '../utils/should-partition.js'
|
|
@@ -82,13 +83,13 @@ const sortEnums = createEslintRule({
|
|
|
82
83
|
while (stack.length > 0) {
|
|
83
84
|
let node = stack.pop()
|
|
84
85
|
if (
|
|
85
|
-
node.type ===
|
|
86
|
-
node.object.type ===
|
|
86
|
+
node.type === AST_NODE_TYPES.MemberExpression &&
|
|
87
|
+
node.object.type === AST_NODE_TYPES.Identifier &&
|
|
87
88
|
node.object.name === enumName &&
|
|
88
|
-
node.property.type ===
|
|
89
|
+
node.property.type === AST_NODE_TYPES.Identifier
|
|
89
90
|
) {
|
|
90
91
|
dependencies.push(node.property.name)
|
|
91
|
-
} else if (node.type ===
|
|
92
|
+
} else if (node.type === AST_NODE_TYPES.Identifier) {
|
|
92
93
|
dependencies.push(node.name)
|
|
93
94
|
}
|
|
94
95
|
if ('left' in node) {
|
|
@@ -110,7 +111,7 @@ const sortEnums = createEslintRule({
|
|
|
110
111
|
enumDeclaration.id.name,
|
|
111
112
|
)
|
|
112
113
|
let name =
|
|
113
|
-
member.id.type ===
|
|
114
|
+
member.id.type === AST_NODE_TYPES.Literal
|
|
114
115
|
? member.id.value
|
|
115
116
|
: sourceCode.getText(member.id)
|
|
116
117
|
let group = computeGroup({
|
|
@@ -128,7 +129,7 @@ const sortEnums = createEslintRule({
|
|
|
128
129
|
let lastSortingNode = accumulator.at(-1)?.at(-1)
|
|
129
130
|
let sortingNode = {
|
|
130
131
|
value:
|
|
131
|
-
member.initializer?.type ===
|
|
132
|
+
member.initializer?.type === AST_NODE_TYPES.Literal
|
|
132
133
|
? (member.initializer.value?.toString() ?? null)
|
|
133
134
|
: null,
|
|
134
135
|
isEslintDisabled: isNodeEslintDisabled(member, eslintDisabledLines),
|
|
@@ -199,7 +200,8 @@ const sortEnums = createEslintRule({
|
|
|
199
200
|
properties: {
|
|
200
201
|
...buildCommonJsonSchemas(),
|
|
201
202
|
...buildCommonGroupsJsonSchemas({
|
|
202
|
-
|
|
203
|
+
additionalCustomGroupMatchProperties:
|
|
204
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
203
205
|
}),
|
|
204
206
|
sortByValue: {
|
|
205
207
|
description: 'Specifies whether to sort enums by value.',
|
|
@@ -271,18 +273,18 @@ function getBinaryExpressionNumberValue(
|
|
|
271
273
|
}
|
|
272
274
|
function getExpressionNumberValue(expression) {
|
|
273
275
|
switch (expression.type) {
|
|
274
|
-
case
|
|
276
|
+
case AST_NODE_TYPES.BinaryExpression:
|
|
275
277
|
return getBinaryExpressionNumberValue(
|
|
276
278
|
expression.left,
|
|
277
279
|
expression.right,
|
|
278
280
|
expression.operator,
|
|
279
281
|
)
|
|
280
|
-
case
|
|
282
|
+
case AST_NODE_TYPES.UnaryExpression:
|
|
281
283
|
return getUnaryExpressionNumberValue(
|
|
282
284
|
expression.argument,
|
|
283
285
|
expression.operator,
|
|
284
286
|
)
|
|
285
|
-
case
|
|
287
|
+
case AST_NODE_TYPES.Literal:
|
|
286
288
|
return typeof expression.value === 'number' ? expression.value : null
|
|
287
289
|
default:
|
|
288
290
|
return null
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types'
|
|
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
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
6
5
|
export type Options = Partial<
|
|
7
|
-
|
|
8
|
-
CommonOptions<TypeOption> &
|
|
9
|
-
CommonPartitionOptions
|
|
6
|
+
AllCommonOptions<TypeOption, AdditionalSortOptions, CustomGroupMatchOptions>
|
|
10
7
|
>[]
|
|
11
8
|
export type SortExportAttributesSortingNode =
|
|
12
9
|
SortingNode<TSESTree.ImportAttribute>
|
|
13
|
-
/**
|
|
14
|
-
type
|
|
10
|
+
/** Match options for a custom group. */
|
|
11
|
+
type CustomGroupMatchOptions = object
|
|
12
|
+
type AdditionalSortOptions = object
|
|
15
13
|
export {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
partitionByNewLineJsonSchema,
|
|
3
4
|
partitionByCommentJsonSchema,
|
|
@@ -170,7 +171,7 @@ const sortExportAttributes = createEslintRule({
|
|
|
170
171
|
})
|
|
171
172
|
function getAttributeName(attribute, sourceCode) {
|
|
172
173
|
let { key } = attribute
|
|
173
|
-
if (key.type ===
|
|
174
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
174
175
|
return key.name
|
|
175
176
|
}
|
|
176
177
|
return key.value?.toString() ?? sourceCode.getText(attribute)
|
|
@@ -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-exports rule.
|
|
7
6
|
*
|
|
@@ -9,9 +8,7 @@ import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
|
9
8
|
* From '...'`) to improve code organization and maintainability.
|
|
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 available export modifiers. Distinguishes between value exports
|
|
@@ -35,7 +32,7 @@ export type Selector = (typeof allSelectors)[number]
|
|
|
35
32
|
* "selector": "export"
|
|
36
33
|
* }
|
|
37
34
|
*/
|
|
38
|
-
interface
|
|
35
|
+
interface CustomGroupMatchOptions {
|
|
39
36
|
/**
|
|
40
37
|
* List of modifiers that exports must have to be included in this group.
|
|
41
38
|
* Can include 'value' for value exports or 'type' for type exports.
|
|
@@ -47,6 +44,7 @@ interface SingleCustomGroup {
|
|
|
47
44
|
*/
|
|
48
45
|
selector?: Selector
|
|
49
46
|
}
|
|
47
|
+
type AdditionalSortOptions = object
|
|
50
48
|
/**
|
|
51
49
|
* Complete list of available export selectors. Used for validation and JSON
|
|
52
50
|
* schema generation.
|
|
@@ -65,8 +63,11 @@ export declare let allModifiers: readonly [
|
|
|
65
63
|
'singleline',
|
|
66
64
|
]
|
|
67
65
|
/**
|
|
68
|
-
* JSON schema
|
|
69
|
-
*
|
|
66
|
+
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
67
|
+
* rule options at configuration time.
|
|
70
68
|
*/
|
|
71
|
-
export declare let
|
|
69
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
70
|
+
string,
|
|
71
|
+
JSONSchema4
|
|
72
|
+
>
|
|
72
73
|
export {}
|
|
@@ -11,8 +11,12 @@ let allModifiers = [
|
|
|
11
11
|
'multiline',
|
|
12
12
|
'singleline',
|
|
13
13
|
]
|
|
14
|
-
let
|
|
14
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
15
15
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
16
16
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
17
17
|
}
|
|
18
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
20
|
+
allModifiers,
|
|
21
|
+
allSelectors,
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import {
|
|
3
3
|
ORDER_ERROR,
|
|
4
4
|
GROUP_ORDER_ERROR,
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
partitionByNewLineJsonSchema,
|
|
11
11
|
partitionByCommentJsonSchema,
|
|
12
12
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
13
|
-
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
14
|
-
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
15
|
-
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
16
13
|
import {
|
|
17
|
-
|
|
14
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
18
15
|
allSelectors,
|
|
19
16
|
allModifiers,
|
|
20
17
|
} from './sort-exports/types.js'
|
|
18
|
+
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration.js'
|
|
19
|
+
import { buildDefaultOptionsByGroupIndexComputer } from '../utils/build-default-options-by-group-index-computer.js'
|
|
20
|
+
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
21
21
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
22
22
|
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration.js'
|
|
23
23
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.js'
|
|
@@ -143,7 +143,8 @@ const sortExports = createEslintRule({
|
|
|
143
143
|
properties: {
|
|
144
144
|
...buildCommonJsonSchemas(),
|
|
145
145
|
...buildCommonGroupsJsonSchemas({
|
|
146
|
-
|
|
146
|
+
additionalCustomGroupMatchProperties:
|
|
147
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
147
148
|
}),
|
|
148
149
|
partitionByComment: partitionByCommentJsonSchema,
|
|
149
150
|
partitionByNewLine: partitionByNewLineJsonSchema,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
1
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
2
|
+
import { TypeOption } from '../../types/common-options.js'
|
|
4
3
|
export type Options = Partial<
|
|
5
|
-
|
|
6
|
-
CommonOptions<TypeOption> &
|
|
7
|
-
CommonPartitionOptions
|
|
4
|
+
AllCommonOptions<TypeOption, AdditionalSortOptions, CustomGroupMatchOptions>
|
|
8
5
|
>[]
|
|
9
|
-
/**
|
|
10
|
-
type
|
|
6
|
+
/** Match options for a custom group. */
|
|
7
|
+
type CustomGroupMatchOptions = object
|
|
8
|
+
type AdditionalSortOptions = object
|
|
11
9
|
export {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
partitionByCommentJsonSchema,
|
|
3
4
|
partitionByNewLineJsonSchema,
|
|
@@ -172,7 +173,7 @@ function sortHeritageClauses$1(context, options, heritageClauses) {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
function getHeritageClauseExpressionName(expression) {
|
|
175
|
-
if (expression.type ===
|
|
176
|
+
if (expression.type === AST_NODE_TYPES.Identifier) {
|
|
176
177
|
return expression.name
|
|
177
178
|
}
|
|
178
179
|
if ('property' in expression) {
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types'
|
|
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
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
6
5
|
export type Options = Partial<
|
|
7
|
-
|
|
8
|
-
CommonOptions<TypeOption> &
|
|
9
|
-
CommonPartitionOptions
|
|
6
|
+
AllCommonOptions<TypeOption, AdditionalSortOptions, CustomGroupMatchOptions>
|
|
10
7
|
>[]
|
|
11
8
|
export type SortImportAttributesSortingNode =
|
|
12
9
|
SortingNode<TSESTree.ImportAttribute>
|
|
13
|
-
/**
|
|
14
|
-
type
|
|
10
|
+
/** Match options for a custom group. */
|
|
11
|
+
type CustomGroupMatchOptions = object
|
|
12
|
+
type AdditionalSortOptions = object
|
|
15
13
|
export {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
2
|
import {
|
|
2
3
|
partitionByNewLineJsonSchema,
|
|
3
4
|
partitionByCommentJsonSchema,
|
|
@@ -170,7 +171,7 @@ const sortImportAttributes = createEslintRule({
|
|
|
170
171
|
})
|
|
171
172
|
function getAttributeName(attribute, sourceCode) {
|
|
172
173
|
let { key } = attribute
|
|
173
|
-
if (key.type ===
|
|
174
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
174
175
|
return key.name
|
|
175
176
|
}
|
|
176
177
|
return key.value?.toString() ?? sourceCode.getText(attribute)
|
|
@@ -10,6 +10,8 @@ let comparatorByOptionsComputer = options => {
|
|
|
10
10
|
switch (options.type) {
|
|
11
11
|
case 'type-import-first':
|
|
12
12
|
return (a, b) => compareTypeImportFirst(a, b, options)
|
|
13
|
+
/* v8 ignore next -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
14
|
+
case 'subgroup-order':
|
|
13
15
|
case 'alphabetical':
|
|
14
16
|
case 'line-length':
|
|
15
17
|
case 'unsorted':
|
|
@@ -46,6 +48,9 @@ function compareTypeImportFirst(a, b, options) {
|
|
|
46
48
|
}
|
|
47
49
|
let bySpecifierComparatorByOptionsComputer = options => {
|
|
48
50
|
switch (options.type) {
|
|
51
|
+
/* v8 ignore next 2 -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
52
|
+
case 'subgroup-order':
|
|
53
|
+
return defaultComparatorByOptionsComputer(options)
|
|
49
54
|
case 'alphabetical':
|
|
50
55
|
return (a, b) =>
|
|
51
56
|
compareAlphabetically(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
3
3
|
function isSideEffectImport({ sourceCode, node }) {
|
|
4
4
|
switch (node.type) {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
-
import {
|
|
4
|
-
CommonOptions,
|
|
5
|
-
RegexOption,
|
|
6
|
-
TypeOption,
|
|
7
|
-
} from '../../types/common-options.js'
|
|
8
3
|
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
5
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
11
6
|
/**
|
|
12
7
|
* Configuration options for the sort-imports rule.
|
|
13
8
|
*
|
|
@@ -53,20 +48,11 @@ export type Options = Partial<
|
|
|
53
48
|
* sorting instead of the entire line.
|
|
54
49
|
*/
|
|
55
50
|
maxLineLength: number
|
|
56
|
-
} &
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
CustomTypeOption
|
|
62
|
-
> &
|
|
63
|
-
CommonOptions<
|
|
64
|
-
CustomTypeOption,
|
|
65
|
-
{
|
|
66
|
-
sortBy: 'specifier' | 'path'
|
|
67
|
-
}
|
|
68
|
-
> &
|
|
69
|
-
CommonPartitionOptions
|
|
51
|
+
} & AllCommonOptions<
|
|
52
|
+
CustomTypeOption,
|
|
53
|
+
AdditionalSortOptions,
|
|
54
|
+
CustomGroupMatchOptions
|
|
55
|
+
>
|
|
70
56
|
>[]
|
|
71
57
|
/**
|
|
72
58
|
* Represents a sorting node for an import statement. Extends the base sorting
|
|
@@ -107,12 +93,15 @@ export type Modifier = (typeof allModifiers)[number]
|
|
|
107
93
|
* "selector": "external"
|
|
108
94
|
* }
|
|
109
95
|
*/
|
|
110
|
-
interface
|
|
96
|
+
interface CustomGroupMatchOptions {
|
|
111
97
|
/** List of modifiers that imports must have to be included in this group. */
|
|
112
98
|
modifiers?: Modifier[]
|
|
113
99
|
/** The selector type that imports must match to be included in this group. */
|
|
114
100
|
selector?: Selector
|
|
115
101
|
}
|
|
102
|
+
interface AdditionalSortOptions {
|
|
103
|
+
sortBy: SortByOption
|
|
104
|
+
}
|
|
116
105
|
/**
|
|
117
106
|
* Complete list of available active import selectors. Used for validation and
|
|
118
107
|
* JSON schema generation.
|
|
@@ -152,7 +141,12 @@ export declare let allModifiers: readonly [
|
|
|
152
141
|
* Ideally, we should generate as many schemas as there are selectors, and
|
|
153
142
|
* ensure that users do not enter invalid modifiers for a given selector.
|
|
154
143
|
*/
|
|
155
|
-
export declare let
|
|
156
|
-
|
|
144
|
+
export declare let additionalCustomGroupMatchOptionsJsonSchema: Record<
|
|
145
|
+
string,
|
|
146
|
+
JSONSchema4
|
|
147
|
+
>
|
|
148
|
+
declare const SORT_BY_OPTION: readonly ['specifier', 'path']
|
|
149
|
+
type SortByOption = (typeof SORT_BY_OPTION)[number]
|
|
150
|
+
export declare let additionalSortOptionsJsonSchema: Record<string, JSONSchema4>
|
|
157
151
|
export declare const TYPE_IMPORT_FIRST_TYPE_OPTION = 'type-import-first'
|
|
158
152
|
export {}
|
|
@@ -29,19 +29,22 @@ let allModifiers = [
|
|
|
29
29
|
'value',
|
|
30
30
|
'wildcard',
|
|
31
31
|
]
|
|
32
|
-
let
|
|
32
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
33
33
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
34
34
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const SORT_BY_OPTION = ['specifier', 'path']
|
|
37
|
+
let additionalSortOptionsJsonSchema = {
|
|
38
|
+
sortBy: {
|
|
39
|
+
enum: [...SORT_BY_OPTION],
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
39
42
|
}
|
|
40
43
|
const TYPE_IMPORT_FIRST_TYPE_OPTION = 'type-import-first'
|
|
41
44
|
export {
|
|
42
45
|
TYPE_IMPORT_FIRST_TYPE_OPTION,
|
|
46
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
47
|
+
additionalSortOptionsJsonSchema,
|
|
43
48
|
allModifiers,
|
|
44
49
|
allSelectors,
|
|
45
|
-
singleCustomGroupJsonSchema,
|
|
46
|
-
sortByJsonSchema,
|
|
47
50
|
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import {
|
|
3
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
4
|
+
TYPE_IMPORT_FIRST_TYPE_OPTION,
|
|
5
|
+
additionalSortOptionsJsonSchema,
|
|
6
|
+
allSelectors,
|
|
7
|
+
allModifiers,
|
|
8
|
+
} from './sort-imports/types.js'
|
|
1
9
|
import {
|
|
2
10
|
ORDER_ERROR,
|
|
3
11
|
GROUP_ORDER_ERROR,
|
|
@@ -6,13 +14,6 @@ import {
|
|
|
6
14
|
DEPENDENCY_ORDER_ERROR,
|
|
7
15
|
MISSED_COMMENT_ABOVE_ERROR,
|
|
8
16
|
} from '../utils/report-errors.js'
|
|
9
|
-
import {
|
|
10
|
-
singleCustomGroupJsonSchema,
|
|
11
|
-
TYPE_IMPORT_FIRST_TYPE_OPTION,
|
|
12
|
-
sortByJsonSchema,
|
|
13
|
-
allSelectors,
|
|
14
|
-
allModifiers,
|
|
15
|
-
} from './sort-imports/types.js'
|
|
16
17
|
import {
|
|
17
18
|
partitionByNewLineJsonSchema,
|
|
18
19
|
partitionByCommentJsonSchema,
|
|
@@ -138,7 +139,10 @@ const sortImports = createEslintRule({
|
|
|
138
139
|
let selectors = []
|
|
139
140
|
let modifiers = []
|
|
140
141
|
let group = null
|
|
141
|
-
if (
|
|
142
|
+
if (
|
|
143
|
+
node.type !== AST_NODE_TYPES.VariableDeclaration &&
|
|
144
|
+
node.importKind === 'type'
|
|
145
|
+
) {
|
|
142
146
|
selectors.push('type')
|
|
143
147
|
modifiers.push('type')
|
|
144
148
|
}
|
|
@@ -164,10 +168,10 @@ const sortImports = createEslintRule({
|
|
|
164
168
|
if (!modifiers.includes('type')) {
|
|
165
169
|
modifiers.push('value')
|
|
166
170
|
}
|
|
167
|
-
if (node.type ===
|
|
171
|
+
if (node.type === AST_NODE_TYPES.TSImportEqualsDeclaration) {
|
|
168
172
|
modifiers.push('ts-equals')
|
|
169
173
|
}
|
|
170
|
-
if (node.type ===
|
|
174
|
+
if (node.type === AST_NODE_TYPES.VariableDeclaration) {
|
|
171
175
|
modifiers.push('require')
|
|
172
176
|
}
|
|
173
177
|
modifiers.push(...computeSpecifierModifiers(node))
|
|
@@ -183,7 +187,9 @@ const sortImports = createEslintRule({
|
|
|
183
187
|
options,
|
|
184
188
|
name,
|
|
185
189
|
}) ?? 'unknown'
|
|
186
|
-
let hasMultipleImportDeclarations =
|
|
190
|
+
let hasMultipleImportDeclarations =
|
|
191
|
+
node.type === AST_NODE_TYPES.ImportDeclaration &&
|
|
192
|
+
isSortable(node.specifiers)
|
|
187
193
|
let size = rangeToDiff(node, sourceCode)
|
|
188
194
|
if (hasMultipleImportDeclarations && size > options.maxLineLength) {
|
|
189
195
|
size = name.length + 10
|
|
@@ -209,10 +215,11 @@ const sortImports = createEslintRule({
|
|
|
209
215
|
return {
|
|
210
216
|
VariableDeclaration: node => {
|
|
211
217
|
if (
|
|
212
|
-
node.declarations[0].init?.type ===
|
|
213
|
-
node.declarations[0].init.callee.type ===
|
|
218
|
+
node.declarations[0].init?.type === AST_NODE_TYPES.CallExpression &&
|
|
219
|
+
node.declarations[0].init.callee.type === AST_NODE_TYPES.Identifier &&
|
|
214
220
|
node.declarations[0].init.callee.name === 'require' &&
|
|
215
|
-
node.declarations[0].init.arguments[0]?.type ===
|
|
221
|
+
node.declarations[0].init.arguments[0]?.type ===
|
|
222
|
+
AST_NODE_TYPES.Literal
|
|
216
223
|
) {
|
|
217
224
|
registerNode(node)
|
|
218
225
|
}
|
|
@@ -234,12 +241,13 @@ const sortImports = createEslintRule({
|
|
|
234
241
|
properties: {
|
|
235
242
|
...buildCommonJsonSchemas({
|
|
236
243
|
allowedAdditionalTypeValues: [TYPE_IMPORT_FIRST_TYPE_OPTION],
|
|
237
|
-
additionalSortProperties:
|
|
244
|
+
additionalSortProperties: additionalSortOptionsJsonSchema,
|
|
238
245
|
}),
|
|
239
246
|
...buildCommonGroupsJsonSchemas({
|
|
247
|
+
additionalCustomGroupMatchProperties:
|
|
248
|
+
additionalCustomGroupMatchOptionsJsonSchema,
|
|
240
249
|
allowedAdditionalTypeValues: [TYPE_IMPORT_FIRST_TYPE_OPTION],
|
|
241
|
-
additionalSortProperties:
|
|
242
|
-
singleCustomGroupJsonSchema,
|
|
250
|
+
additionalSortProperties: additionalSortOptionsJsonSchema,
|
|
243
251
|
}),
|
|
244
252
|
tsconfig: {
|
|
245
253
|
properties: {
|