eslint-plugin-perfectionist 4.14.0 → 4.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alphabet.d.ts +118 -90
- package/dist/index.js +17 -12
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes.js +23 -16
- package/dist/rules/sort-classes/get-overload-signature-groups.js +1 -1
- package/dist/rules/sort-classes.js +19 -25
- package/dist/rules/sort-decorators.js +10 -8
- package/dist/rules/sort-enums.js +54 -59
- package/dist/rules/sort-exports.js +19 -14
- package/dist/rules/sort-heritage-clauses.js +7 -5
- package/dist/rules/sort-imports/compute-common-selectors.js +47 -40
- package/dist/rules/sort-imports/get-typescript-import.js +1 -1
- package/dist/rules/sort-imports/is-side-effect-only-group.js +1 -1
- package/dist/rules/sort-imports/matches-tsconfig-paths.js +5 -3
- package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +3 -3
- package/dist/rules/sort-imports/validate-side-effects-configuration.js +1 -1
- package/dist/rules/sort-imports.js +152 -140
- package/dist/rules/sort-jsx-props.js +27 -25
- package/dist/rules/sort-maps.js +22 -18
- package/dist/rules/sort-modules.js +34 -27
- package/dist/rules/sort-named-exports.js +17 -13
- package/dist/rules/sort-named-imports.js +17 -13
- package/dist/rules/sort-object-types/build-node-value-getter.js +3 -2
- package/dist/rules/sort-object-types/get-custom-groups-compare-options.js +4 -7
- package/dist/rules/sort-object-types/is-member-optional.js +1 -1
- package/dist/rules/sort-object-types.js +25 -26
- package/dist/rules/sort-objects/get-first-node-parent-with-type.js +1 -1
- package/dist/rules/sort-objects.js +95 -88
- package/dist/rules/sort-sets.js +2 -5
- package/dist/rules/sort-switch-case.js +25 -21
- package/dist/rules/sort-union-types.js +22 -15
- package/dist/rules/sort-variable-declarations.js +27 -29
- package/dist/utils/alphabet.js +122 -130
- package/dist/utils/common-json-schemas.js +132 -102
- package/dist/utils/compare.js +84 -83
- package/dist/utils/complete.js +3 -5
- package/dist/utils/compute-group.js +3 -10
- package/dist/utils/compute-nodes-in-circular-dependencies.js +2 -2
- package/dist/utils/convert-boolean-to-sign.js +3 -1
- package/dist/utils/create-node-index-map.js +1 -1
- package/dist/utils/does-custom-group-match.js +8 -14
- package/dist/utils/generate-predefined-groups.js +3 -3
- package/dist/utils/get-array-combinations.js +2 -2
- package/dist/utils/get-comment-above-that-should-exist.js +5 -4
- package/dist/utils/get-comments-before.js +9 -12
- package/dist/utils/get-custom-groups-compare-options.js +18 -19
- package/dist/utils/get-decorator-name.js +1 -1
- package/dist/utils/get-enum-members.js +2 -3
- package/dist/utils/get-eslint-disabled-lines.js +17 -15
- package/dist/utils/get-eslint-disabled-rules.js +3 -4
- package/dist/utils/get-group-index.js +1 -1
- package/dist/utils/get-lines-between.js +1 -1
- package/dist/utils/get-matching-context-options.js +4 -7
- package/dist/utils/get-newlines-between-errors.js +23 -25
- package/dist/utils/get-newlines-between-option.js +73 -39
- package/dist/utils/get-node-decorators.js +3 -1
- package/dist/utils/get-node-range.js +5 -10
- package/dist/utils/get-options-with-clean-groups.js +15 -10
- package/dist/utils/get-settings.js +2 -2
- package/dist/utils/is-comment-above-option.js +3 -2
- package/dist/utils/is-newlines-between-option.js +3 -2
- package/dist/utils/is-node-dependent-on-other-node.js +1 -1
- package/dist/utils/is-node-eslint-disabled.js +3 -2
- package/dist/utils/is-node-function-type.js +1 -1
- package/dist/utils/is-partition-comment.js +3 -3
- package/dist/utils/is-sortable.js +3 -1
- package/dist/utils/make-comment-above-fixes.js +4 -6
- package/dist/utils/make-comment-after-fixes.js +1 -1
- package/dist/utils/make-fixes.js +4 -4
- package/dist/utils/make-newlines-between-fixes.js +60 -35
- package/dist/utils/make-order-fixes.js +4 -6
- package/dist/utils/make-single-node-comment-after-fixes.js +5 -7
- package/dist/utils/matches.js +1 -1
- package/dist/utils/pairwise.js +2 -3
- package/dist/utils/range-to-diff.js +1 -1
- package/dist/utils/report-all-errors.js +7 -8
- package/dist/utils/report-errors.js +8 -9
- package/dist/utils/should-partition.js +5 -4
- package/dist/utils/sort-nodes-by-dependencies.js +2 -2
- package/dist/utils/sort-nodes-by-groups.js +12 -17
- package/dist/utils/sort-nodes.js +3 -3
- package/dist/utils/unreachable-case-error.js +16 -0
- package/dist/utils/validate-custom-sort-configuration.js +1 -1
- package/dist/utils/validate-generated-groups-configuration.js +5 -5
- package/dist/utils/validate-newlines-and-partition-configuration.js +2 -2
- package/dist/utils/validate-no-duplicated-groups.js +1 -1
- package/dist/utils/validate-objects-inside-groups.js +1 -1
- package/package.json +5 -6
package/dist/alphabet.d.ts
CHANGED
|
@@ -1,81 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Manages a customizable alphabet for sorting operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides methods to generate, modify, and sort alphabets based on various
|
|
5
|
+
* criteria including Unicode ranges, case prioritization, and locale-specific
|
|
6
|
+
* ordering. Used by the 'custom' sort type to define character precedence.
|
|
7
|
+
*
|
|
8
|
+
* The class supports:
|
|
9
|
+
*
|
|
10
|
+
* - Generating alphabets from strings or Unicode ranges
|
|
11
|
+
* - Case prioritization and manipulation
|
|
12
|
+
* - Character positioning and removal
|
|
13
|
+
* - Multiple sorting strategies (natural, locale, char code).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Create a custom alphabet with specific character order
|
|
17
|
+
* const alphabet = Alphabet.generateFrom('aAbBcC')
|
|
18
|
+
* .prioritizeCase('uppercase')
|
|
19
|
+
* .getCharacters()
|
|
20
|
+
* // Returns: 'AaBbCc'
|
|
3
21
|
*/
|
|
4
22
|
export declare class Alphabet {
|
|
5
|
-
private
|
|
23
|
+
private characters
|
|
6
24
|
private constructor()
|
|
7
25
|
/**
|
|
8
26
|
* Generates an alphabet from the given characters.
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
27
|
+
*
|
|
28
|
+
* @param values - The characters to generate the alphabet from.
|
|
29
|
+
* @returns - The wrapped alphabet.
|
|
11
30
|
*/
|
|
12
31
|
static generateFrom(values: string[] | string): Alphabet
|
|
13
32
|
/**
|
|
14
33
|
* Generates an alphabet containing relevant characters from the Unicode
|
|
15
34
|
* standard. Contains the Unicode planes 0 and 1.
|
|
16
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* @returns - The generated alphabet.
|
|
17
37
|
*/
|
|
18
38
|
static generateRecommendedAlphabet(): Alphabet
|
|
19
39
|
/**
|
|
20
40
|
* Generates an alphabet containing all characters from the Unicode standard
|
|
21
|
-
* except for irrelevant Unicode planes.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
41
|
+
* except for irrelevant Unicode planes. Contains the Unicode planes 0, 1, 2
|
|
42
|
+
* and 3.
|
|
43
|
+
*
|
|
44
|
+
* @returns - The generated alphabet.
|
|
24
45
|
*/
|
|
25
46
|
static generateCompleteAlphabet(): Alphabet
|
|
26
|
-
private static
|
|
47
|
+
private static getCharactersWithCase
|
|
27
48
|
/**
|
|
28
49
|
* Generates an alphabet containing relevant characters from the Unicode
|
|
29
50
|
* standard.
|
|
30
|
-
*
|
|
31
|
-
* alphabet to
|
|
32
|
-
* @returns
|
|
51
|
+
*
|
|
52
|
+
* @param maxCodePoint - The maximum code point to generate the alphabet to.
|
|
53
|
+
* @returns - The generated alphabet.
|
|
33
54
|
*/
|
|
34
|
-
private static
|
|
55
|
+
private static generateAlphabetToRange
|
|
35
56
|
/**
|
|
36
|
-
* For each character with a lower and upper case, permutes the two cases
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @returns {Alphabet} - The same alphabet instance with the cases prioritized
|
|
57
|
+
* For each character with a lower and upper case, permutes the two cases so
|
|
58
|
+
* that the alphabet is ordered by the case priority entered.
|
|
59
|
+
*
|
|
40
60
|
* @example
|
|
41
|
-
*
|
|
42
|
-
*
|
|
61
|
+
* Alphabet.generateFrom('aAbBcdCD').prioritizeCase('uppercase') // Returns 'AaBbCDcd'.
|
|
62
|
+
*
|
|
63
|
+
* @param casePriority - The case to prioritize.
|
|
64
|
+
* @returns - The same alphabet instance with the cases prioritized.
|
|
43
65
|
*/
|
|
44
66
|
prioritizeCase(casePriority: 'lowercase' | 'uppercase'): this
|
|
45
67
|
/**
|
|
46
68
|
* Adds specific characters to the end of the alphabet.
|
|
47
|
-
*
|
|
48
|
-
* @returns {Alphabet} - The same alphabet instance without the specified
|
|
49
|
-
* characters
|
|
69
|
+
*
|
|
50
70
|
* @example
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
71
|
+
* Alphabet.generateFrom('ab').pushCharacters('cd')
|
|
72
|
+
* // Returns 'abcd'
|
|
73
|
+
*
|
|
74
|
+
* @param values - The characters to push to the alphabet.
|
|
75
|
+
* @returns - The same alphabet instance without the specified characters.
|
|
54
76
|
*/
|
|
55
77
|
pushCharacters(values: string[] | string): this
|
|
56
78
|
/**
|
|
57
|
-
* Permutes characters with cases so that all characters with the entered
|
|
58
|
-
* are put before the other characters.
|
|
59
|
-
*
|
|
60
|
-
* characters
|
|
61
|
-
* @returns
|
|
62
|
-
*
|
|
79
|
+
* Permutes characters with cases so that all characters with the entered
|
|
80
|
+
* case are put before the other characters.
|
|
81
|
+
*
|
|
82
|
+
* @param caseToComeFirst - The case to put before the other characters.
|
|
83
|
+
* @returns - The same alphabet instance with all characters with case
|
|
84
|
+
* before all the characters with the other case.
|
|
63
85
|
*/
|
|
64
86
|
placeAllWithCaseBeforeAllWithOtherCase(
|
|
65
87
|
caseToComeFirst: 'uppercase' | 'lowercase',
|
|
66
88
|
): this
|
|
67
89
|
/**
|
|
68
|
-
* Places a specific character right before another character in the
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* characterAfter
|
|
72
|
-
* @param {string} params.characterAfter - The target character
|
|
73
|
-
* @returns {Alphabet} - The same alphabet instance with the specific
|
|
74
|
-
* character prioritized
|
|
90
|
+
* Places a specific character right before another character in the
|
|
91
|
+
* alphabet.
|
|
92
|
+
*
|
|
75
93
|
* @example
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
94
|
+
* Alphabet.generateFrom('ab-cd/').placeCharacterBefore({
|
|
95
|
+
* characterBefore: '/',
|
|
96
|
+
* characterAfter: '-',
|
|
97
|
+
* })
|
|
98
|
+
* // Returns 'ab/-cd'
|
|
99
|
+
*
|
|
100
|
+
* @param params - The parameters for the operation.
|
|
101
|
+
* @param params.characterBefore - The character to come before
|
|
102
|
+
* characterAfter.
|
|
103
|
+
* @param params.characterAfter - The target character.
|
|
104
|
+
* @returns - The same alphabet instance with the specific character
|
|
105
|
+
* prioritized.
|
|
79
106
|
*/
|
|
80
107
|
placeCharacterBefore({
|
|
81
108
|
characterBefore,
|
|
@@ -85,17 +112,22 @@ export declare class Alphabet {
|
|
|
85
112
|
characterAfter: string
|
|
86
113
|
}): this
|
|
87
114
|
/**
|
|
88
|
-
* Places a specific character right after another character in the
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param {string} params.characterAfter - The character to come after
|
|
92
|
-
* characterBefore
|
|
93
|
-
* @returns {Alphabet} - The same alphabet instance with the specific
|
|
94
|
-
* character prioritized
|
|
115
|
+
* Places a specific character right after another character in the
|
|
116
|
+
* alphabet.
|
|
117
|
+
*
|
|
95
118
|
* @example
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
119
|
+
* Alphabet.generateFrom('ab-cd/').placeCharacterAfter({
|
|
120
|
+
* characterBefore: '/',
|
|
121
|
+
* characterAfter: '-',
|
|
122
|
+
* })
|
|
123
|
+
* // Returns 'abcd/-'
|
|
124
|
+
*
|
|
125
|
+
* @param params - The parameters for the operation.
|
|
126
|
+
* @param params.characterBefore - The target character.
|
|
127
|
+
* @param params.characterAfter - The character to come after
|
|
128
|
+
* characterBefore.
|
|
129
|
+
* @returns - The same alphabet instance with the specific character
|
|
130
|
+
* prioritized.
|
|
99
131
|
*/
|
|
100
132
|
placeCharacterAfter({
|
|
101
133
|
characterBefore,
|
|
@@ -106,70 +138,66 @@ export declare class Alphabet {
|
|
|
106
138
|
}): this
|
|
107
139
|
/**
|
|
108
140
|
* Removes specific characters from the alphabet by their range.
|
|
109
|
-
*
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
113
|
-
*
|
|
141
|
+
*
|
|
142
|
+
* @param range - The Unicode range to remove characters from.
|
|
143
|
+
* @param range.start - The starting Unicode codepoint.
|
|
144
|
+
* @param range.end - The ending Unicode codepoint.
|
|
145
|
+
* @returns - The same alphabet instance without the characters from the
|
|
146
|
+
* specified range.
|
|
114
147
|
*/
|
|
115
148
|
removeUnicodeRange({ start, end }: { start: number; end: number }): this
|
|
116
149
|
/**
|
|
117
150
|
* Sorts the alphabet by the sorting function provided.
|
|
118
|
-
*
|
|
119
|
-
* @
|
|
151
|
+
*
|
|
152
|
+
* @param sortingFunction - The sorting function to use.
|
|
153
|
+
* @returns - The same alphabet instance sorted by the sorting function
|
|
154
|
+
* provided.
|
|
120
155
|
*/
|
|
121
156
|
sortBy(
|
|
122
157
|
sortingFunction: (characterA: string, characterB: string) => number,
|
|
123
158
|
): this
|
|
124
|
-
/**
|
|
125
|
-
* Removes specific characters from the alphabet.
|
|
126
|
-
* @param {string|string[]} values - The characters to remove from the
|
|
127
|
-
* alphabet
|
|
128
|
-
* @returns {Alphabet} - The same alphabet instance without the specified
|
|
129
|
-
* characters
|
|
130
|
-
* @example
|
|
131
|
-
* Alphabet.generateFrom('abcd')
|
|
132
|
-
* .removeCharacters('dcc')
|
|
133
|
-
* // Returns 'ab'
|
|
134
|
-
*/
|
|
135
|
-
removeCharacters(values: string[] | string): this
|
|
136
159
|
/**
|
|
137
160
|
* Sorts the alphabet by the natural order of the characters using
|
|
138
161
|
* `natural-orderby`.
|
|
139
|
-
*
|
|
140
|
-
* @
|
|
141
|
-
* order of the
|
|
162
|
+
*
|
|
163
|
+
* @param locale - The locale to use for sorting.
|
|
164
|
+
* @returns - The same alphabet instance sorted by the natural order of the
|
|
165
|
+
* characters.
|
|
142
166
|
*/
|
|
143
167
|
sortByNaturalSort(locale?: string): this
|
|
168
|
+
/**
|
|
169
|
+
* Removes specific characters from the alphabet.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* Alphabet.generateFrom('abcd').removeCharacters('dcc')
|
|
173
|
+
* // Returns 'ab'
|
|
174
|
+
*
|
|
175
|
+
* @param values - The characters to remove from the alphabet.
|
|
176
|
+
* @returns - The same alphabet instance without the specified characters.
|
|
177
|
+
*/
|
|
178
|
+
removeCharacters(values: string[] | string): this
|
|
144
179
|
/**
|
|
145
180
|
* Sorts the alphabet by the character code point.
|
|
146
|
-
*
|
|
147
|
-
* code point
|
|
181
|
+
*
|
|
182
|
+
* @returns - The same alphabet instance sorted by the character code point.
|
|
148
183
|
*/
|
|
149
184
|
sortByCharCodeAt(): this
|
|
150
185
|
/**
|
|
151
186
|
* Sorts the alphabet by the locale order of the characters.
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
154
|
-
* order of the
|
|
187
|
+
*
|
|
188
|
+
* @param locales - The locales to use for sorting.
|
|
189
|
+
* @returns - The same alphabet instance sorted by the locale order of the
|
|
190
|
+
* characters.
|
|
155
191
|
*/
|
|
156
192
|
sortByLocaleCompare(locales?: Intl.LocalesArgument): this
|
|
157
193
|
/**
|
|
158
194
|
* Retrieves the characters from the alphabet.
|
|
159
|
-
*
|
|
195
|
+
*
|
|
196
|
+
* @returns The characters from the alphabet.
|
|
160
197
|
*/
|
|
161
198
|
getCharacters(): string
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* @returns {Alphabet} - The same alphabet instance reversed
|
|
165
|
-
* @example
|
|
166
|
-
* Alphabet.generateFrom('ab')
|
|
167
|
-
* .reverse()
|
|
168
|
-
* // Returns 'ba'
|
|
169
|
-
*/
|
|
170
|
-
reverse(): this
|
|
171
|
-
private _placeCharacterBeforeOrAfter
|
|
172
|
-
private _getCharactersWithCase
|
|
199
|
+
private placeCharacterBeforeOrAfter
|
|
200
|
+
private getCharactersWithCase
|
|
173
201
|
}
|
|
174
202
|
|
|
175
203
|
export {}
|
package/dist/index.js
CHANGED
|
@@ -49,23 +49,28 @@ let plugin = {
|
|
|
49
49
|
name: _package.name,
|
|
50
50
|
},
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
Object.fromEntries(
|
|
52
|
+
function getRules(options) {
|
|
53
|
+
return Object.fromEntries(
|
|
54
54
|
Object.keys(plugin.rules).map(ruleName => [
|
|
55
55
|
`${pluginName}/${ruleName}`,
|
|
56
56
|
['error', options],
|
|
57
57
|
]),
|
|
58
58
|
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
}
|
|
60
|
+
function createConfig(options) {
|
|
61
|
+
return {
|
|
62
|
+
plugins: {
|
|
63
|
+
[pluginName]: plugin,
|
|
64
|
+
},
|
|
65
|
+
rules: getRules(options),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function createLegacyConfig(options) {
|
|
69
|
+
return {
|
|
70
|
+
rules: getRules(options),
|
|
71
|
+
plugins: [pluginName],
|
|
72
|
+
}
|
|
73
|
+
}
|
|
69
74
|
const index = {
|
|
70
75
|
...plugin,
|
|
71
76
|
configs: {
|
package/dist/package.json.js
CHANGED
|
@@ -113,7 +113,7 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
|
|
|
113
113
|
defaultOptions: [defaultOptions],
|
|
114
114
|
name: 'sort-array-includes',
|
|
115
115
|
})
|
|
116
|
-
|
|
116
|
+
function sortArray({ availableMessageIds, elements, context }) {
|
|
117
117
|
if (!isSortable.isSortable(elements)) {
|
|
118
118
|
return
|
|
119
119
|
}
|
|
@@ -146,7 +146,6 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
146
146
|
})
|
|
147
147
|
let formattedMembers = elements.reduce(
|
|
148
148
|
(accumulator, element) => {
|
|
149
|
-
var _a
|
|
150
149
|
if (element === null) {
|
|
151
150
|
return accumulator
|
|
152
151
|
}
|
|
@@ -187,8 +186,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
187
186
|
group,
|
|
188
187
|
name,
|
|
189
188
|
}
|
|
190
|
-
let lastSortingNode =
|
|
191
|
-
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
189
|
+
let lastSortingNode = accumulator.at(-1)?.at(-1)
|
|
192
190
|
if (
|
|
193
191
|
shouldPartition.shouldPartition({
|
|
194
192
|
lastSortingNode,
|
|
@@ -199,7 +197,10 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
199
197
|
) {
|
|
200
198
|
accumulator.push([])
|
|
201
199
|
}
|
|
202
|
-
accumulator.at(-1).push(
|
|
200
|
+
accumulator.at(-1).push({
|
|
201
|
+
...sortingNode,
|
|
202
|
+
partitionId: accumulator.length,
|
|
203
|
+
})
|
|
203
204
|
return accumulator
|
|
204
205
|
},
|
|
205
206
|
[[]],
|
|
@@ -213,16 +214,12 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
213
214
|
groupKindOrder = ['any']
|
|
214
215
|
}
|
|
215
216
|
for (let nodes of formattedMembers) {
|
|
216
|
-
let
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
),
|
|
221
|
-
)
|
|
222
|
-
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
223
|
-
filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
217
|
+
let sortNodesExcludingEslintDisabled = function (
|
|
218
|
+
ignoreEslintDisabledNodes,
|
|
219
|
+
) {
|
|
220
|
+
return filteredGroupKindNodes.flatMap(groupedNodes =>
|
|
224
221
|
sortNodesByGroups.sortNodesByGroups({
|
|
225
|
-
|
|
222
|
+
getOptionsByGroupIndex:
|
|
226
223
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
227
224
|
options,
|
|
228
225
|
),
|
|
@@ -231,6 +228,13 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
231
228
|
nodes: groupedNodes,
|
|
232
229
|
}),
|
|
233
230
|
)
|
|
231
|
+
}
|
|
232
|
+
let filteredGroupKindNodes = groupKindOrder.map(groupKind =>
|
|
233
|
+
nodes.filter(
|
|
234
|
+
currentNode =>
|
|
235
|
+
groupKind === 'any' || currentNode.groupKind === groupKind,
|
|
236
|
+
),
|
|
237
|
+
)
|
|
234
238
|
reportAllErrors.reportAllErrors({
|
|
235
239
|
sortNodesExcludingEslintDisabled,
|
|
236
240
|
availableMessageIds,
|
|
@@ -241,8 +245,11 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
|
|
|
241
245
|
})
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
|
-
|
|
245
|
-
element.type === 'Literal'
|
|
248
|
+
function getNodeName({ sourceCode, element }) {
|
|
249
|
+
return element.type === 'Literal'
|
|
250
|
+
? `${element.value}`
|
|
251
|
+
: sourceCode.getText(element)
|
|
252
|
+
}
|
|
246
253
|
exports.default = sortArrayIncludes
|
|
247
254
|
exports.defaultOptions = defaultOptions
|
|
248
255
|
exports.jsonSchema = jsonSchema
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const isSortable = require('../../utils/is-sortable.js')
|
|
4
|
-
|
|
4
|
+
function getOverloadSignatureGroups(members) {
|
|
5
5
|
let methods = members
|
|
6
6
|
.filter(
|
|
7
7
|
member =>
|
|
@@ -67,7 +67,6 @@ let defaultOptions = {
|
|
|
67
67
|
const sortClasses = createEslintRule.createEslintRule({
|
|
68
68
|
create: context => ({
|
|
69
69
|
ClassBody: node => {
|
|
70
|
-
var _a
|
|
71
70
|
if (!isSortable.isSortable(node.body)) {
|
|
72
71
|
return
|
|
73
72
|
}
|
|
@@ -93,9 +92,10 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
93
92
|
ruleName: id,
|
|
94
93
|
sourceCode,
|
|
95
94
|
})
|
|
96
|
-
let className =
|
|
97
|
-
|
|
98
|
-
`${props.isStatic ? 'static ' : ''}${props.isPrivateHash ? '#' : ''}${props.nodeNameWithoutStartingHash}`
|
|
95
|
+
let className = node.parent.id?.name
|
|
96
|
+
function getDependencyName(props) {
|
|
97
|
+
return `${props.isStatic ? 'static ' : ''}${props.isPrivateHash ? '#' : ''}${props.nodeNameWithoutStartingHash}`
|
|
98
|
+
}
|
|
99
99
|
let classMethodsDependencyNames = new Set(
|
|
100
100
|
node.body
|
|
101
101
|
.map(member => {
|
|
@@ -114,9 +114,9 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
114
114
|
})
|
|
115
115
|
.filter(Boolean),
|
|
116
116
|
)
|
|
117
|
-
|
|
117
|
+
function extractDependencies(expression, isMemberStatic) {
|
|
118
118
|
let dependencies = []
|
|
119
|
-
|
|
119
|
+
function checkNode(nodeValue) {
|
|
120
120
|
if (
|
|
121
121
|
nodeValue.type === 'MemberExpression' &&
|
|
122
122
|
(nodeValue.object.type === 'ThisExpression' ||
|
|
@@ -214,7 +214,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
function traverseNode(nodeValue) {
|
|
218
218
|
if (Array.isArray(nodeValue)) {
|
|
219
219
|
for (let nodeItem of nodeValue) {
|
|
220
220
|
traverseNode(nodeItem)
|
|
@@ -230,7 +230,6 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
230
230
|
getOverloadSignatureGroups.getOverloadSignatureGroups(node.body)
|
|
231
231
|
let formattedNodes = node.body.reduce(
|
|
232
232
|
(accumulator, member) => {
|
|
233
|
-
var _a2, _b, _c, _d, _e
|
|
234
233
|
let name
|
|
235
234
|
let dependencies = []
|
|
236
235
|
if (member.type === 'StaticBlock') {
|
|
@@ -238,9 +237,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
238
237
|
} else if (member.type === 'TSIndexSignature') {
|
|
239
238
|
name = sourceCode.text.slice(
|
|
240
239
|
member.range.at(0),
|
|
241
|
-
(
|
|
242
|
-
? void 0
|
|
243
|
-
: _a2.range.at(0)) ?? member.range.at(1),
|
|
240
|
+
member.typeAnnotation?.range.at(0) ?? member.range.at(1),
|
|
244
241
|
)
|
|
245
242
|
} else if (member.key.type === 'Identifier') {
|
|
246
243
|
;({ name } = member.key)
|
|
@@ -302,10 +299,8 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
302
299
|
modifiers.push('optional')
|
|
303
300
|
}
|
|
304
301
|
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
((_c = member.value) == null ? void 0 : _c.type) ===
|
|
308
|
-
'FunctionExpression'
|
|
302
|
+
member.value?.type === 'ArrowFunctionExpression' ||
|
|
303
|
+
member.value?.type === 'FunctionExpression'
|
|
309
304
|
) {
|
|
310
305
|
if (member.value.async) {
|
|
311
306
|
modifiers.push('async')
|
|
@@ -419,10 +414,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
419
414
|
overloadSignatures.includes(member),
|
|
420
415
|
)
|
|
421
416
|
let overloadSignatureGroupMember =
|
|
422
|
-
|
|
423
|
-
null
|
|
424
|
-
? void 0
|
|
425
|
-
: _d.at(-1)
|
|
417
|
+
overloadSignatureGroups[overloadSignatureGroupMemberIndex]?.at(-1)
|
|
426
418
|
let sortingNode = {
|
|
427
419
|
dependencyNames: [
|
|
428
420
|
getDependencyName({
|
|
@@ -453,8 +445,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
453
445
|
group,
|
|
454
446
|
name,
|
|
455
447
|
}
|
|
456
|
-
let lastSortingNode =
|
|
457
|
-
(_e = accumulator.at(-1)) == null ? void 0 : _e.at(-1)
|
|
448
|
+
let lastSortingNode = accumulator.at(-1)?.at(-1)
|
|
458
449
|
if (
|
|
459
450
|
shouldPartition.shouldPartition({
|
|
460
451
|
lastSortingNode,
|
|
@@ -465,18 +456,21 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
465
456
|
) {
|
|
466
457
|
accumulator.push([])
|
|
467
458
|
}
|
|
468
|
-
accumulator.at(-1).push(
|
|
459
|
+
accumulator.at(-1).push({
|
|
460
|
+
...sortingNode,
|
|
461
|
+
partitionId: accumulator.length,
|
|
462
|
+
})
|
|
469
463
|
return accumulator
|
|
470
464
|
},
|
|
471
465
|
[[]],
|
|
472
466
|
)
|
|
473
|
-
|
|
467
|
+
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
474
468
|
let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
|
|
475
469
|
sortNodesByGroups.sortNodesByGroups({
|
|
476
470
|
isNodeIgnored: sortingNode =>
|
|
477
471
|
getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
|
|
478
472
|
options.groups.length,
|
|
479
|
-
|
|
473
|
+
getOptionsByGroupIndex:
|
|
480
474
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
481
475
|
options,
|
|
482
476
|
),
|
|
@@ -503,7 +497,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
503
497
|
left.overloadSignaturesGroupId !== null &&
|
|
504
498
|
left.overloadSignaturesGroupId === right.overloadSignaturesGroupId
|
|
505
499
|
) {
|
|
506
|
-
return
|
|
500
|
+
return 0
|
|
507
501
|
}
|
|
508
502
|
return computedNewlinesBetween
|
|
509
503
|
},
|
|
@@ -151,7 +151,7 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
151
151
|
defaultOptions: [defaultOptions],
|
|
152
152
|
name: 'sort-decorators',
|
|
153
153
|
})
|
|
154
|
-
|
|
154
|
+
function sortDecorators$1(context, options, decorators) {
|
|
155
155
|
if (!isSortable.isSortable(decorators)) {
|
|
156
156
|
return
|
|
157
157
|
}
|
|
@@ -162,7 +162,6 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
162
162
|
})
|
|
163
163
|
let formattedMembers = decorators.reduce(
|
|
164
164
|
(accumulator, decorator) => {
|
|
165
|
-
var _a
|
|
166
165
|
let name = getDecoratorName.getDecoratorName({
|
|
167
166
|
sourceCode,
|
|
168
167
|
decorator,
|
|
@@ -182,8 +181,7 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
182
181
|
group,
|
|
183
182
|
name,
|
|
184
183
|
}
|
|
185
|
-
let lastSortingNode =
|
|
186
|
-
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
184
|
+
let lastSortingNode = accumulator.at(-1)?.at(-1)
|
|
187
185
|
if (
|
|
188
186
|
shouldPartition.shouldPartition({
|
|
189
187
|
lastSortingNode,
|
|
@@ -194,20 +192,24 @@ let sortDecorators$1 = (context, options, decorators) => {
|
|
|
194
192
|
) {
|
|
195
193
|
accumulator.push([])
|
|
196
194
|
}
|
|
197
|
-
accumulator.at(-1).push(
|
|
195
|
+
accumulator.at(-1).push({
|
|
196
|
+
...sortingNode,
|
|
197
|
+
partitionId: accumulator.length,
|
|
198
|
+
})
|
|
198
199
|
return accumulator
|
|
199
200
|
},
|
|
200
201
|
[[]],
|
|
201
202
|
)
|
|
202
|
-
|
|
203
|
-
formattedMembers.flatMap(nodes2 =>
|
|
203
|
+
function sortNodesExcludingEslintDisabled(ignoreEslintDisabledNodes) {
|
|
204
|
+
return formattedMembers.flatMap(nodes2 =>
|
|
204
205
|
sortNodesByGroups.sortNodesByGroups({
|
|
205
|
-
|
|
206
|
+
getOptionsByGroupIndex: () => ({ options }),
|
|
206
207
|
ignoreEslintDisabledNodes,
|
|
207
208
|
groups: options.groups,
|
|
208
209
|
nodes: nodes2,
|
|
209
210
|
}),
|
|
210
211
|
)
|
|
212
|
+
}
|
|
211
213
|
let nodes = formattedMembers.flat()
|
|
212
214
|
reportAllErrors.reportAllErrors({
|
|
213
215
|
availableMessageIds: {
|