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,8 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CommonOptions, RegexOption } from './common-options.js'
|
|
2
|
+
export interface CommonGroupsOptions<
|
|
3
|
+
CustomTypeOption extends string,
|
|
4
|
+
AdditionalSortOptions,
|
|
5
|
+
AdditionalCustomGroupMatchOptions,
|
|
6
|
+
> {
|
|
7
|
+
/** Specify the exact number of newlines required between elements of groups. */
|
|
8
|
+
newlinesInside:
|
|
9
|
+
| NewlinesInsideOption
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated The `newlinesBetween` value is deprecated and will be removed
|
|
12
|
+
* in V6.
|
|
13
|
+
*/
|
|
14
|
+
| 'newlinesBetween'
|
|
15
|
+
/** Custom groups for organizing nodes. */
|
|
16
|
+
customGroups: CustomGroupsOption<
|
|
17
|
+
CustomTypeOption,
|
|
18
|
+
AdditionalSortOptions,
|
|
19
|
+
AdditionalCustomGroupMatchOptions
|
|
20
|
+
>
|
|
21
|
+
/**
|
|
22
|
+
* Defines the order and grouping of nodes. Nodes are sorted within their
|
|
23
|
+
* groups and groups are ordered as specified.
|
|
24
|
+
*/
|
|
25
|
+
groups: GroupsOptions<CustomTypeOption, AdditionalSortOptions>
|
|
26
|
+
/** Specify the exact number of newlines required between groups. */
|
|
27
|
+
newlinesBetween: NewlinesBetweenOption
|
|
28
|
+
}
|
|
6
29
|
/**
|
|
7
30
|
* Configuration for custom groups with sorting and newline options.
|
|
8
31
|
*
|
|
@@ -26,22 +49,16 @@ import {
|
|
|
26
49
|
* },
|
|
27
50
|
* ]
|
|
28
51
|
*
|
|
29
|
-
* @template
|
|
30
|
-
* group.
|
|
31
|
-
* @template
|
|
52
|
+
* @template AdditionalMatchOptions - Options for matching elements to the
|
|
53
|
+
* custom group.
|
|
54
|
+
* @template AdditionalSortOptions - Additional sort options that extend the
|
|
32
55
|
* base configuration.
|
|
33
56
|
*/
|
|
34
57
|
export type CustomGroupsOption<
|
|
35
|
-
SingleCustomGroup,
|
|
36
|
-
AdditionalSortProperties,
|
|
37
58
|
CustomTypeOption extends string,
|
|
59
|
+
AdditionalSortOptions,
|
|
60
|
+
AdditionalMatchOptions,
|
|
38
61
|
> = ({
|
|
39
|
-
/**
|
|
40
|
-
* Fallback sorting configuration used when primary sort returns equal.
|
|
41
|
-
* Useful for stable sorting when elements have identical primary sort
|
|
42
|
-
* values.
|
|
43
|
-
*/
|
|
44
|
-
fallbackSort?: FallbackSortOption<CustomTypeOption, AdditionalSortProperties>
|
|
45
62
|
/** Specify the exact number of newlines required between elements of groups. */
|
|
46
63
|
newlinesInside?: NewlinesInsideOption
|
|
47
64
|
/**
|
|
@@ -49,23 +66,19 @@ export type CustomGroupsOption<
|
|
|
49
66
|
* this pattern will be included in this custom group.
|
|
50
67
|
*/
|
|
51
68
|
elementNamePattern?: RegexOption
|
|
52
|
-
/**
|
|
53
|
-
* Sorting algorithm type for this custom group. Overrides the global type
|
|
54
|
-
* setting for elements in this group.
|
|
55
|
-
*/
|
|
56
|
-
type?: CustomTypeOption
|
|
57
|
-
/**
|
|
58
|
-
* Sort direction for this custom group. Overrides the global order setting
|
|
59
|
-
* for elements in this group.
|
|
60
|
-
*/
|
|
61
|
-
order?: OrderOption
|
|
62
69
|
/**
|
|
63
70
|
* Name identifier for the custom group. Used to reference this group in the
|
|
64
71
|
* groups configuration array.
|
|
65
72
|
*/
|
|
66
73
|
groupName: string
|
|
67
|
-
} &
|
|
68
|
-
|
|
74
|
+
} & Partial<
|
|
75
|
+
Pick<
|
|
76
|
+
CommonOptions<CustomTypeOption, AdditionalSortOptions>,
|
|
77
|
+
'fallbackSort' | 'order' | 'type'
|
|
78
|
+
>
|
|
79
|
+
> &
|
|
80
|
+
(AnyOfCustomGroup<AdditionalMatchOptions> | Partial<AdditionalMatchOptions>) &
|
|
81
|
+
Partial<AdditionalSortOptions>)[]
|
|
69
82
|
/**
|
|
70
83
|
* Configuration for groups with overriding settings.
|
|
71
84
|
*
|
|
@@ -78,58 +91,24 @@ export type CustomGroupsOption<
|
|
|
78
91
|
*/
|
|
79
92
|
export type GroupWithOverridesOption<
|
|
80
93
|
CustomTypeOption extends string,
|
|
81
|
-
|
|
94
|
+
AdditionalSortOptions,
|
|
82
95
|
> = {
|
|
83
|
-
/**
|
|
84
|
-
* Fallback sorting configuration used when primary sort returns equal.
|
|
85
|
-
* Useful for stable sorting when elements have identical primary sort
|
|
86
|
-
* values.
|
|
87
|
-
*/
|
|
88
|
-
fallbackSort?: FallbackSortOption<CustomTypeOption, AdditionalSortProperties>
|
|
89
96
|
/** Specify the exact number of newlines required inside the group. */
|
|
90
97
|
newlinesInside?: NewlinesInsideOption
|
|
91
98
|
/** Name of the group or array of group names for composite groups. */
|
|
92
99
|
group: string[] | string
|
|
93
|
-
/**
|
|
94
|
-
* Same as `type` in CommonOptions - Sorting algorithm to use for this
|
|
95
|
-
* group.
|
|
96
|
-
*/
|
|
97
|
-
type?: CustomTypeOption
|
|
98
100
|
/**
|
|
99
101
|
* Text of the comment to insert above the group. The comment will be
|
|
100
102
|
* formatted as a line comment (// ...).
|
|
101
103
|
*/
|
|
102
104
|
commentAbove?: string
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
SingleCustomGroup,
|
|
108
|
-
AdditionalSortProperties,
|
|
109
|
-
CustomTypeOption extends string,
|
|
110
|
-
> {
|
|
111
|
-
/** Specify the exact number of newlines required between elements of groups. */
|
|
112
|
-
newlinesInside:
|
|
113
|
-
| NewlinesInsideOption
|
|
114
|
-
/**
|
|
115
|
-
* @deprecated The `newlinesBetween` value is deprecated and will be removed
|
|
116
|
-
* in V6.
|
|
117
|
-
*/
|
|
118
|
-
| 'newlinesBetween'
|
|
119
|
-
/** Custom groups for organizing nodes. */
|
|
120
|
-
customGroups: CustomGroupsOption<
|
|
121
|
-
SingleCustomGroup,
|
|
122
|
-
AdditionalSortProperties,
|
|
123
|
-
CustomTypeOption
|
|
105
|
+
} & Partial<
|
|
106
|
+
Pick<
|
|
107
|
+
CommonOptions<CustomTypeOption, AdditionalSortOptions>,
|
|
108
|
+
'fallbackSort' | 'order' | 'type'
|
|
124
109
|
>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* groups and groups are ordered as specified.
|
|
128
|
-
*/
|
|
129
|
-
groups: GroupsOptions<CustomTypeOption, AdditionalSortProperties>
|
|
130
|
-
/** Specify the exact number of newlines required between groups. */
|
|
131
|
-
newlinesBetween: NewlinesBetweenOption
|
|
132
|
-
}
|
|
110
|
+
> &
|
|
111
|
+
Partial<AdditionalSortOptions>
|
|
133
112
|
/**
|
|
134
113
|
* Configuration for matching multiple patterns in custom groups.
|
|
135
114
|
*
|
|
@@ -141,9 +120,9 @@ export interface CommonGroupsOptions<
|
|
|
141
120
|
* anyOf: ['react', 'react-*', '@react/*'],
|
|
142
121
|
* }
|
|
143
122
|
*
|
|
144
|
-
* @template
|
|
123
|
+
* @template MatchOptions - Options for matching elements to the custom group.
|
|
145
124
|
*/
|
|
146
|
-
export interface AnyOfCustomGroup<
|
|
125
|
+
export interface AnyOfCustomGroup<MatchOptions> {
|
|
147
126
|
/**
|
|
148
127
|
* Regular expression pattern to match the element's name. Elements matching
|
|
149
128
|
* this pattern will be included in this custom group.
|
|
@@ -153,7 +132,7 @@ export interface AnyOfCustomGroup<SingleCustomGroup> {
|
|
|
153
132
|
* Array of patterns where matching any single pattern includes the element
|
|
154
133
|
* in the group. Provides OR logic for group membership.
|
|
155
134
|
*/
|
|
156
|
-
anyOf:
|
|
135
|
+
anyOf: Partial<MatchOptions>[]
|
|
157
136
|
}
|
|
158
137
|
/**
|
|
159
138
|
* Configuration for managing newlines between sorted elements.
|
|
@@ -180,27 +159,6 @@ export type NewlinesBetweenOption =
|
|
|
180
159
|
* consistent spacing with the specified line count.
|
|
181
160
|
*/
|
|
182
161
|
| number
|
|
183
|
-
/**
|
|
184
|
-
* Configuration for controlling newlines between groups.
|
|
185
|
-
*
|
|
186
|
-
* Placed between group names in the groups array to specify how many blank
|
|
187
|
-
* lines should separate adjacent groups in the sorted output.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* const groups = [
|
|
191
|
-
* 'imports',
|
|
192
|
-
* { newlinesBetween: 1 }, // One newline after imports
|
|
193
|
-
* 'types',
|
|
194
|
-
* ]
|
|
195
|
-
*/
|
|
196
|
-
export interface GroupNewlinesBetweenOption {
|
|
197
|
-
/**
|
|
198
|
-
* Specifies the newline requirement between adjacent groups. This option is
|
|
199
|
-
* placed between group names to control their spacing.
|
|
200
|
-
*/
|
|
201
|
-
newlinesBetween: NewlinesBetweenOption
|
|
202
|
-
group?: never
|
|
203
|
-
}
|
|
204
162
|
/**
|
|
205
163
|
* Configuration for organizing elements into groups with optional formatting.
|
|
206
164
|
*
|
|
@@ -221,13 +179,33 @@ export interface GroupNewlinesBetweenOption {
|
|
|
221
179
|
*/
|
|
222
180
|
export type GroupsOptions<
|
|
223
181
|
CustomTypeOption extends string = string,
|
|
224
|
-
|
|
182
|
+
AdditionalSortOptions = object,
|
|
225
183
|
> = (
|
|
226
|
-
| GroupWithOverridesOption<CustomTypeOption,
|
|
184
|
+
| GroupWithOverridesOption<CustomTypeOption, AdditionalSortOptions>
|
|
227
185
|
| GroupNewlinesBetweenOption
|
|
228
186
|
| string[]
|
|
229
187
|
| string
|
|
230
188
|
)[]
|
|
189
|
+
/**
|
|
190
|
+
* Configuration for controlling newlines between groups.
|
|
191
|
+
*
|
|
192
|
+
* Placed between group names in the groups array to specify how many blank
|
|
193
|
+
* lines should separate adjacent groups in the sorted output.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const groups = [
|
|
197
|
+
* 'imports',
|
|
198
|
+
* { newlinesBetween: 1 }, // One newline after imports
|
|
199
|
+
* 'types',
|
|
200
|
+
* ]
|
|
201
|
+
*/
|
|
202
|
+
export interface GroupNewlinesBetweenOption {
|
|
203
|
+
/**
|
|
204
|
+
* Specifies the newline requirement between adjacent groups. This option is
|
|
205
|
+
* placed between group names to control their spacing.
|
|
206
|
+
*/
|
|
207
|
+
newlinesBetween: NewlinesBetweenOption
|
|
208
|
+
}
|
|
231
209
|
export type NewlinesInsideOption =
|
|
232
210
|
/** Preserve existing newlines without modification. */
|
|
233
211
|
| 'ignore'
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export type CommonOptions<
|
|
24
24
|
CustomTypeOption extends string = string,
|
|
25
|
-
|
|
25
|
+
AdditionalSortOptions = object,
|
|
26
26
|
> = {
|
|
27
27
|
/**
|
|
28
28
|
* Secondary sorting method applied when primary comparison returns equal.
|
|
29
29
|
* Ensures stable and predictable sorting when elements have identical
|
|
30
30
|
* primary values.
|
|
31
31
|
*/
|
|
32
|
-
fallbackSort: FallbackSortOption<CustomTypeOption,
|
|
32
|
+
fallbackSort: FallbackSortOption<CustomTypeOption, AdditionalSortOptions>
|
|
33
33
|
/**
|
|
34
34
|
* Specifies how to handle special characters during sorting.
|
|
35
35
|
*
|
|
@@ -67,7 +67,7 @@ export type CommonOptions<
|
|
|
67
67
|
* alphabet are sorted after those in the alphabet.
|
|
68
68
|
*/
|
|
69
69
|
alphabet: string
|
|
70
|
-
} &
|
|
70
|
+
} & AdditionalSortOptions
|
|
71
71
|
/**
|
|
72
72
|
* Sorting algorithm type that determines how elements are ordered.
|
|
73
73
|
*
|
|
@@ -85,6 +85,11 @@ export type CommonOptions<
|
|
|
85
85
|
* // Shorter lines appear before longer lines
|
|
86
86
|
*/
|
|
87
87
|
export type TypeOption =
|
|
88
|
+
/**
|
|
89
|
+
* Sort by the subgroup order defined in `groups` arrays. Useful as a fallback
|
|
90
|
+
* when elements are equal under the primary comparison.
|
|
91
|
+
*/
|
|
92
|
+
| 'subgroup-order'
|
|
88
93
|
/**
|
|
89
94
|
* Traditional alphabetical sorting using locale-aware comparison. Best for
|
|
90
95
|
* standard text sorting where consistency is important.
|
|
@@ -110,6 +115,33 @@ export type TypeOption =
|
|
|
110
115
|
* 'alphabet' option to specify character precedence.
|
|
111
116
|
*/
|
|
112
117
|
| 'custom'
|
|
118
|
+
/**
|
|
119
|
+
* Regular expression pattern configuration for matching strings.
|
|
120
|
+
*
|
|
121
|
+
* Supports multiple formats for flexibility in pattern definition, from simple
|
|
122
|
+
* string patterns to complex regular expressions with flags.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* // Simple string pattern
|
|
126
|
+
* const pattern: RegexOption = '^TODO:'
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Pattern with flags
|
|
130
|
+
* const pattern: RegexOption = {
|
|
131
|
+
* pattern: '^(TODO|FIXME):',
|
|
132
|
+
* flags: 'i',
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Multiple patterns (OR logic)
|
|
137
|
+
* const patterns: RegexOption = [
|
|
138
|
+
* '^TODO:',
|
|
139
|
+
* { pattern: '^FIXME:', flags: 'i' },
|
|
140
|
+
* ]
|
|
141
|
+
*/
|
|
142
|
+
export type RegexOption<AdditionalProperties extends object = object> =
|
|
143
|
+
| SingleRegexOption<AdditionalProperties>[]
|
|
144
|
+
| SingleRegexOption<AdditionalProperties>
|
|
113
145
|
/**
|
|
114
146
|
* Configuration for handling special characters during string comparison.
|
|
115
147
|
*
|
|
@@ -124,7 +156,7 @@ export type TypeOption =
|
|
|
124
156
|
* // With 'trim': '_abc' becomes 'abc', but 'a_bc' stays 'a_bc'
|
|
125
157
|
* const option: SpecialCharactersOption = 'trim'
|
|
126
158
|
*/
|
|
127
|
-
|
|
159
|
+
type SpecialCharactersOption =
|
|
128
160
|
/**
|
|
129
161
|
* Remove all special characters before comparison. Only alphanumeric characters
|
|
130
162
|
* are considered for sorting.
|
|
@@ -140,6 +172,28 @@ export type SpecialCharactersOption =
|
|
|
140
172
|
* participate in the sort comparison.
|
|
141
173
|
*/
|
|
142
174
|
| 'keep'
|
|
175
|
+
/**
|
|
176
|
+
* Single regular expression pattern configuration.
|
|
177
|
+
*
|
|
178
|
+
* Can be either a simple string pattern or an object with pattern and flags for
|
|
179
|
+
* more complex matching requirements.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
type SingleRegexOption<AdditionalProperties> =
|
|
184
|
+
| ({
|
|
185
|
+
/**
|
|
186
|
+
* The regular expression pattern string. Will be compiled into a RegExp for
|
|
187
|
+
* matching.
|
|
188
|
+
*/
|
|
189
|
+
pattern: string
|
|
190
|
+
/**
|
|
191
|
+
* Optional RegExp flags to modify pattern matching behavior. Common flags:
|
|
192
|
+
* 'i' (case-insensitive), 'g' (global), 'm' (multiline).
|
|
193
|
+
*/
|
|
194
|
+
flags?: string
|
|
195
|
+
} & AdditionalProperties)
|
|
196
|
+
| string
|
|
143
197
|
/**
|
|
144
198
|
* Configuration for fallback sorting when primary comparison returns equal.
|
|
145
199
|
*
|
|
@@ -154,7 +208,7 @@ export type SpecialCharactersOption =
|
|
|
154
208
|
* order: 'asc',
|
|
155
209
|
* }
|
|
156
210
|
*/
|
|
157
|
-
|
|
211
|
+
type FallbackSortOption<
|
|
158
212
|
CustomTypeOption extends string,
|
|
159
213
|
AdditionalProperties,
|
|
160
214
|
> = {
|
|
@@ -184,7 +238,7 @@ export type FallbackSortOption<
|
|
|
184
238
|
* // Descending: Z → A, 9 → 0
|
|
185
239
|
* const order: OrderOption = 'desc'
|
|
186
240
|
*/
|
|
187
|
-
|
|
241
|
+
type OrderOption =
|
|
188
242
|
/**
|
|
189
243
|
* Descending order - from largest to smallest. Letters: Z to A, Numbers: 9 to
|
|
190
244
|
* 0, Length: longest to shortest.
|
|
@@ -195,53 +249,4 @@ export type OrderOption =
|
|
|
195
249
|
* Length: shortest to longest.
|
|
196
250
|
*/
|
|
197
251
|
| 'asc'
|
|
198
|
-
/**
|
|
199
|
-
* Regular expression pattern configuration for matching strings.
|
|
200
|
-
*
|
|
201
|
-
* Supports multiple formats for flexibility in pattern definition, from simple
|
|
202
|
-
* string patterns to complex regular expressions with flags.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* // Simple string pattern
|
|
206
|
-
* const pattern: RegexOption = '^TODO:'
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* // Pattern with flags
|
|
210
|
-
* const pattern: RegexOption = {
|
|
211
|
-
* pattern: '^(TODO|FIXME):',
|
|
212
|
-
* flags: 'i',
|
|
213
|
-
* }
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* // Multiple patterns (OR logic)
|
|
217
|
-
* const patterns: RegexOption = [
|
|
218
|
-
* '^TODO:',
|
|
219
|
-
* { pattern: '^FIXME:', flags: 'i' },
|
|
220
|
-
* ]
|
|
221
|
-
*/
|
|
222
|
-
export type RegexOption<AdditionalProperties extends object = object> =
|
|
223
|
-
| SingleRegexOption<AdditionalProperties>[]
|
|
224
|
-
| SingleRegexOption<AdditionalProperties>
|
|
225
|
-
/**
|
|
226
|
-
* Single regular expression pattern configuration.
|
|
227
|
-
*
|
|
228
|
-
* Can be either a simple string pattern or an object with pattern and flags for
|
|
229
|
-
* more complex matching requirements.
|
|
230
|
-
*
|
|
231
|
-
* @internal
|
|
232
|
-
*/
|
|
233
|
-
type SingleRegexOption<AdditionalProperties> =
|
|
234
|
-
| ({
|
|
235
|
-
/**
|
|
236
|
-
* The regular expression pattern string. Will be compiled into a RegExp for
|
|
237
|
-
* matching.
|
|
238
|
-
*/
|
|
239
|
-
pattern: string
|
|
240
|
-
/**
|
|
241
|
-
* Optional RegExp flags to modify pattern matching behavior. Common flags:
|
|
242
|
-
* 'i' (case-insensitive), 'g' (global), 'm' (multiline).
|
|
243
|
-
*/
|
|
244
|
-
flags?: string
|
|
245
|
-
} & AdditionalProperties)
|
|
246
|
-
| string
|
|
247
252
|
export {}
|
|
@@ -2,7 +2,7 @@ import { OptionsByGroupIndexComputer } from './sort-nodes-by-groups.js'
|
|
|
2
2
|
import { CommonGroupsOptions } from '../types/common-groups-options.js'
|
|
3
3
|
import { CommonOptions } from '../types/common-options.js'
|
|
4
4
|
type Options = Pick<
|
|
5
|
-
CommonGroupsOptions<
|
|
5
|
+
CommonGroupsOptions<string, unknown, unknown>,
|
|
6
6
|
'customGroups' | 'groups'
|
|
7
7
|
> &
|
|
8
8
|
CommonOptions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonOptions } from '../../types/common-options.js'
|
|
2
2
|
/**
|
|
3
3
|
* Creates a function that formats strings for comparison.
|
|
4
4
|
*
|
|
@@ -23,7 +23,6 @@ import { SpecialCharactersOption } from '../../types/common-options.js'
|
|
|
23
23
|
export declare function buildStringFormatter({
|
|
24
24
|
specialCharacters,
|
|
25
25
|
ignoreCase,
|
|
26
|
-
}:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}): (value: string) => string
|
|
26
|
+
}: Pick<CommonOptions, 'specialCharacters' | 'ignoreCase'>): (
|
|
27
|
+
value: string,
|
|
28
|
+
) => string
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Comparator } from './default-comparator-by-options-computer.js'
|
|
2
|
+
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
3
|
+
import { SortingNode } from '../../types/sorting-node.js'
|
|
4
|
+
export declare function buildSubgroupOrderComparator({
|
|
5
|
+
groups,
|
|
6
|
+
order,
|
|
7
|
+
}: Pick<
|
|
8
|
+
AllCommonOptions<string, unknown, unknown>,
|
|
9
|
+
'groups' | 'order'
|
|
10
|
+
>): Comparator<SortingNode>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isGroupWithOverridesOption } from '../is-group-with-overrides-option.js'
|
|
2
|
+
import { isNewlinesBetweenOption } from '../is-newlines-between-option.js'
|
|
3
|
+
import { UnreachableCaseError } from '../unreachable-case-error.js'
|
|
4
|
+
import { computeOrderedValue } from './compute-ordered-value.js'
|
|
5
|
+
function buildSubgroupOrderComparator({ groups, order }) {
|
|
6
|
+
return (a, b) => {
|
|
7
|
+
let subgroupContainingA = computeSubgroupContainingNode(a, groups)
|
|
8
|
+
let subgroupContainingB = computeSubgroupContainingNode(b, groups)
|
|
9
|
+
if (
|
|
10
|
+
!subgroupContainingA ||
|
|
11
|
+
!subgroupContainingB ||
|
|
12
|
+
subgroupContainingA !== subgroupContainingB
|
|
13
|
+
) {
|
|
14
|
+
return 0
|
|
15
|
+
}
|
|
16
|
+
let indexOfAInSubgroup = subgroupContainingA.indexOf(a.group)
|
|
17
|
+
let indexOfBInSubgroup = subgroupContainingB.indexOf(b.group)
|
|
18
|
+
let result = indexOfAInSubgroup - indexOfBInSubgroup
|
|
19
|
+
return computeOrderedValue(result, order)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function computeSubgroupContainingNode(sortingNode, groups) {
|
|
23
|
+
for (let group of groups) {
|
|
24
|
+
if (isNewlinesBetweenOption(group)) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
if (typeof group === 'string' || Array.isArray(group)) {
|
|
28
|
+
if (doesStringSubgroupContainsNode(sortingNode, group)) {
|
|
29
|
+
return group
|
|
30
|
+
}
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (isGroupWithOverridesOption(group)) {
|
|
34
|
+
if (doesStringSubgroupContainsNode(sortingNode, group.group)) {
|
|
35
|
+
return group.group
|
|
36
|
+
}
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
throw new UnreachableCaseError(group)
|
|
40
|
+
}
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
function doesStringSubgroupContainsNode(sortingNode, subgroup) {
|
|
44
|
+
if (typeof subgroup === 'string') {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
return subgroup.includes(sortingNode.group)
|
|
48
|
+
}
|
|
49
|
+
export { buildSubgroupOrderComparator }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
2
|
+
import { GroupsOptions } from '../../types/common-groups-options.js'
|
|
2
3
|
import { SortingNode } from '../../types/sorting-node.js'
|
|
3
4
|
export type ComparatorByOptionsComputer<S, T extends SortingNode> = (
|
|
4
5
|
options: S,
|
|
@@ -8,7 +9,9 @@ type Options = Pick<
|
|
|
8
9
|
CommonOptions<TypeOption>,
|
|
9
10
|
'specialCharacters' | 'ignoreCase' | 'alphabet' | 'locales' | 'order' | 'type'
|
|
10
11
|
> &
|
|
11
|
-
Pick<CommonOptions, 'fallbackSort'>
|
|
12
|
+
Pick<CommonOptions, 'fallbackSort'> & {
|
|
13
|
+
groups?: GroupsOptions
|
|
14
|
+
}
|
|
12
15
|
export declare let defaultComparatorByOptionsComputer: ComparatorByOptionsComputer<
|
|
13
16
|
Options,
|
|
14
17
|
SortingNode
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildSubgroupOrderComparator } from './build-subgroup-order-comparator.js'
|
|
1
2
|
import { buildLineLengthComparator } from './build-line-length-comparator.js'
|
|
2
3
|
import { compareAlphabetically } from './compare-alphabetically.js'
|
|
3
4
|
import { UnreachableCaseError } from '../unreachable-case-error.js'
|
|
@@ -6,6 +7,14 @@ import { unsortedComparator } from './unsorted-comparator.js'
|
|
|
6
7
|
import { compareNaturally } from './compare-naturally.js'
|
|
7
8
|
let defaultComparatorByOptionsComputer = options => {
|
|
8
9
|
switch (options.type) {
|
|
10
|
+
case 'subgroup-order':
|
|
11
|
+
if (!options.groups) {
|
|
12
|
+
return unsortedComparator
|
|
13
|
+
}
|
|
14
|
+
return buildSubgroupOrderComparator({
|
|
15
|
+
...options,
|
|
16
|
+
groups: options.groups,
|
|
17
|
+
})
|
|
9
18
|
case 'alphabetical':
|
|
10
19
|
return (a, b) => compareAlphabetically(a.name, b.name, options)
|
|
11
20
|
case 'line-length':
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
/**
|
|
6
6
|
* Parameters for computing the group of an element.
|
|
7
7
|
*
|
|
8
|
-
* @template
|
|
8
|
+
* @template CustomGroupMatchOptions - Type of custom group match options.
|
|
9
9
|
*/
|
|
10
|
-
interface
|
|
10
|
+
interface ComputeGroupParameters<CustomGroupMatchOptions> {
|
|
11
11
|
/** Configuration options for grouping. */
|
|
12
12
|
options: Pick<
|
|
13
|
-
CommonGroupsOptions<
|
|
13
|
+
CommonGroupsOptions<string, unknown, CustomGroupMatchOptions>,
|
|
14
14
|
'customGroups' | 'groups'
|
|
15
15
|
>
|
|
16
16
|
/**
|
|
@@ -19,15 +19,15 @@ interface GetGroupParameters<SingleCustomGroup> {
|
|
|
19
19
|
* @param customGroup - Custom group configuration to test against.
|
|
20
20
|
* @returns True if the element matches the custom group.
|
|
21
21
|
*/
|
|
22
|
-
customGroupMatcher: CustomGroupMatcher<
|
|
22
|
+
customGroupMatcher: CustomGroupMatcher<CustomGroupMatchOptions>
|
|
23
23
|
/**
|
|
24
24
|
* List of predefined groups that the element belongs to. These are checked
|
|
25
25
|
* after custom groups as a fallback.
|
|
26
26
|
*/
|
|
27
27
|
predefinedGroups: string[]
|
|
28
28
|
}
|
|
29
|
-
type CustomGroupMatcher<
|
|
30
|
-
customGroup: AnyOfCustomGroup<
|
|
29
|
+
type CustomGroupMatcher<MatchOptions> = (
|
|
30
|
+
customGroup: AnyOfCustomGroup<MatchOptions> | Partial<MatchOptions>,
|
|
31
31
|
) => boolean
|
|
32
32
|
/**
|
|
33
33
|
* Determines which group an element belongs to based on custom and predefined
|
|
@@ -53,7 +53,7 @@ type CustomGroupMatcher<SingleCustomGroup> = (
|
|
|
53
53
|
* })
|
|
54
54
|
* // Returns: 'react'
|
|
55
55
|
*
|
|
56
|
-
* @template
|
|
56
|
+
* @template CustomGroupMatchOptions - Type of custom group match options.
|
|
57
57
|
* @param params - Parameters for group computation.
|
|
58
58
|
* @param params.options - Configuration with available groups and custom
|
|
59
59
|
* groups.
|
|
@@ -61,9 +61,9 @@ type CustomGroupMatcher<SingleCustomGroup> = (
|
|
|
61
61
|
* @param params.predefinedGroups - Fallback predefined groups to check.
|
|
62
62
|
* @returns The matched group name or 'unknown' if no group matches.
|
|
63
63
|
*/
|
|
64
|
-
export declare function computeGroup<
|
|
64
|
+
export declare function computeGroup<CustomGroupMatchOptions>({
|
|
65
65
|
customGroupMatcher,
|
|
66
66
|
predefinedGroups,
|
|
67
67
|
options,
|
|
68
|
-
}:
|
|
68
|
+
}: ComputeGroupParameters<CustomGroupMatchOptions>): 'unknown' | string
|
|
69
69
|
export {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommonGroupsOptions } from '../types/common-groups-options.js'
|
|
2
2
|
import { CommonOptions } from '../types/common-options.js'
|
|
3
3
|
type Options = Pick<
|
|
4
|
-
CommonGroupsOptions<
|
|
4
|
+
CommonGroupsOptions<string, unknown, unknown>,
|
|
5
5
|
'customGroups' | 'groups'
|
|
6
6
|
> &
|
|
7
7
|
CommonOptions
|
|
@@ -40,7 +40,7 @@ export interface DoesCustomGroupMatchParameters {
|
|
|
40
40
|
* custom group. All specified criteria must match for the element to be
|
|
41
41
|
* considered part of the group.
|
|
42
42
|
*/
|
|
43
|
-
interface
|
|
43
|
+
interface BaseCustomGroupMatchOptions {
|
|
44
44
|
/**
|
|
45
45
|
* Pattern to match against decorator names. Element must have at least one
|
|
46
46
|
* decorator matching this pattern.
|
|
@@ -103,17 +103,19 @@ interface BaseSingleCustomGroup {
|
|
|
103
103
|
* })
|
|
104
104
|
* // Returns: true (matches first subgroup)
|
|
105
105
|
*
|
|
106
|
-
* @template
|
|
106
|
+
* @template CustomGroupMatchOptions - Type of custom group match options.
|
|
107
107
|
* @param props - Combined parameters including the custom group and element
|
|
108
108
|
* properties.
|
|
109
109
|
* @returns True if the element matches the custom group criteria, false
|
|
110
110
|
* otherwise.
|
|
111
111
|
*/
|
|
112
112
|
export declare function doesCustomGroupMatch<
|
|
113
|
-
|
|
113
|
+
CustomGroupMatchOptions extends BaseCustomGroupMatchOptions,
|
|
114
114
|
>(
|
|
115
115
|
props: {
|
|
116
|
-
customGroup:
|
|
116
|
+
customGroup:
|
|
117
|
+
| AnyOfCustomGroup<CustomGroupMatchOptions>
|
|
118
|
+
| CustomGroupMatchOptions
|
|
117
119
|
} & DoesCustomGroupMatchParameters,
|
|
118
120
|
): boolean
|
|
119
121
|
export {}
|
|
@@ -9,7 +9,7 @@ import { SortingNode } from '../types/sorting-node.js'
|
|
|
9
9
|
interface GetCommentAboveMissingParameters<T extends SortingNode> {
|
|
10
10
|
/** Configuration options for grouping. */
|
|
11
11
|
options: Pick<
|
|
12
|
-
CommonGroupsOptions<
|
|
12
|
+
CommonGroupsOptions<string, unknown, unknown>,
|
|
13
13
|
'customGroups' | 'groups'
|
|
14
14
|
>
|
|
15
15
|
/** ESLint source code object for accessing comments. */
|
|
@@ -33,7 +33,7 @@ interface GetNewlinesBetweenErrorsParameters<
|
|
|
33
33
|
/** Optional function to customize newlines between specific nodes. */
|
|
34
34
|
newlinesBetweenValueGetter?: NewlinesBetweenValueGetter<T>
|
|
35
35
|
/** Configuration options for newlines and groups. */
|
|
36
|
-
options: CommonGroupsOptions<
|
|
36
|
+
options: CommonGroupsOptions<string, unknown, unknown>
|
|
37
37
|
/** ESLint source code object for accessing lines. */
|
|
38
38
|
sourceCode: TSESLint.SourceCode
|
|
39
39
|
/** Error message ID for missing required newlines. */
|