eslint-plugin-perfectionist 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +14 -10
- package/dist/rules/sort-array-includes.js +3 -1
- package/dist/rules/sort-array-includes.mjs +3 -1
- package/dist/rules/sort-astro-attributes.js +3 -1
- package/dist/rules/sort-astro-attributes.mjs +3 -1
- package/dist/rules/sort-classes-utils.js +68 -0
- package/dist/rules/sort-classes-utils.mjs +66 -0
- package/dist/rules/sort-classes.js +106 -57
- package/dist/rules/sort-classes.mjs +106 -57
- package/dist/rules/sort-enums.js +62 -6
- package/dist/rules/sort-enums.mjs +58 -6
- package/dist/rules/sort-exports.js +3 -1
- package/dist/rules/sort-exports.mjs +3 -1
- package/dist/rules/sort-imports.js +3 -1
- package/dist/rules/sort-imports.mjs +3 -1
- package/dist/rules/sort-interfaces.js +3 -1
- package/dist/rules/sort-interfaces.mjs +3 -1
- package/dist/rules/sort-intersection-types.js +3 -1
- package/dist/rules/sort-intersection-types.mjs +3 -1
- package/dist/rules/sort-jsx-props.js +3 -1
- package/dist/rules/sort-jsx-props.mjs +3 -1
- package/dist/rules/sort-maps.js +3 -1
- package/dist/rules/sort-maps.mjs +3 -1
- package/dist/rules/sort-named-exports.js +3 -1
- package/dist/rules/sort-named-exports.mjs +3 -1
- package/dist/rules/sort-named-imports.js +3 -1
- package/dist/rules/sort-named-imports.mjs +3 -1
- package/dist/rules/sort-object-types.js +3 -1
- package/dist/rules/sort-object-types.mjs +3 -1
- package/dist/rules/sort-objects.js +3 -1
- package/dist/rules/sort-objects.mjs +3 -1
- package/dist/rules/sort-svelte-attributes.js +3 -1
- package/dist/rules/sort-svelte-attributes.mjs +3 -1
- package/dist/rules/sort-switch-case.js +3 -1
- package/dist/rules/sort-switch-case.mjs +3 -1
- package/dist/rules/sort-union-types.js +3 -1
- package/dist/rules/sort-union-types.mjs +3 -1
- package/dist/rules/sort-variable-declarations.js +3 -1
- package/dist/rules/sort-variable-declarations.mjs +3 -1
- package/dist/rules/sort-vue-attributes.js +2 -1
- package/dist/rules/sort-vue-attributes.mjs +2 -1
- package/dist/utils/compare.js +12 -7
- package/dist/utils/compare.mjs +12 -7
- package/dist/utils/complete.js +2 -1
- package/dist/utils/complete.mjs +2 -1
- package/dist/utils/get-settings.js +30 -0
- package/dist/utils/get-settings.mjs +28 -0
- package/dist/utils/use-groups.js +2 -1
- package/dist/utils/use-groups.mjs +2 -1
- package/package.json +4 -4
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { isPartitionComment } from '../utils/is-partition-comment.mjs'
|
|
2
2
|
import { getCommentBefore } from '../utils/get-comment-before.mjs'
|
|
3
3
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
4
|
+
import { generateOfficialGroups } from './sort-classes-utils.mjs'
|
|
4
5
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
5
6
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
6
7
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
7
8
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
9
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
8
10
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
9
11
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
10
12
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -97,6 +99,8 @@ const sortClasses = createEslintRule({
|
|
|
97
99
|
},
|
|
98
100
|
],
|
|
99
101
|
messages: {
|
|
102
|
+
unexpectedClassesGroupOrder:
|
|
103
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
100
104
|
unexpectedClassesOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
101
105
|
},
|
|
102
106
|
},
|
|
@@ -126,7 +130,8 @@ const sortClasses = createEslintRule({
|
|
|
126
130
|
create: context => ({
|
|
127
131
|
ClassBody: node => {
|
|
128
132
|
if (node.body.length > 1) {
|
|
129
|
-
let
|
|
133
|
+
let settings = getSettings(context.settings)
|
|
134
|
+
let options = complete(context.options.at(0), settings, {
|
|
130
135
|
groups: [
|
|
131
136
|
'index-signature',
|
|
132
137
|
'static-property',
|
|
@@ -188,7 +193,7 @@ const sortClasses = createEslintRule({
|
|
|
188
193
|
}
|
|
189
194
|
let formattedNodes = node.body.reduce(
|
|
190
195
|
(accumulator, member) => {
|
|
191
|
-
var _a
|
|
196
|
+
var _a, _b, _c
|
|
192
197
|
let comment = getCommentBefore(member, sourceCode)
|
|
193
198
|
if (
|
|
194
199
|
options.partitionByComment &&
|
|
@@ -218,80 +223,119 @@ const sortClasses = createEslintRule({
|
|
|
218
223
|
name = sourceCode.text.slice(...member.key.range)
|
|
219
224
|
}
|
|
220
225
|
}
|
|
221
|
-
let
|
|
226
|
+
let isPrivateName = name.startsWith('#')
|
|
222
227
|
let decorated =
|
|
223
228
|
'decorators' in member && member.decorators.length > 0
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (decorated) {
|
|
233
|
-
if (member.kind === 'get') {
|
|
234
|
-
defineGroup('decorated-get-method')
|
|
235
|
-
}
|
|
236
|
-
if (member.kind === 'set') {
|
|
237
|
-
defineGroup('decorated-set-method')
|
|
238
|
-
}
|
|
239
|
-
defineGroup('decorated-method')
|
|
229
|
+
let modifiers = []
|
|
230
|
+
let selectors = []
|
|
231
|
+
if (
|
|
232
|
+
member.type === 'MethodDefinition' ||
|
|
233
|
+
member.type === 'TSAbstractMethodDefinition'
|
|
234
|
+
) {
|
|
235
|
+
if (member.static) {
|
|
236
|
+
modifiers.push('static')
|
|
240
237
|
}
|
|
241
|
-
if (
|
|
242
|
-
|
|
238
|
+
if (member.type === 'TSAbstractMethodDefinition') {
|
|
239
|
+
modifiers.push('abstract')
|
|
243
240
|
}
|
|
244
|
-
if (
|
|
245
|
-
|
|
241
|
+
if (decorated) {
|
|
242
|
+
modifiers.push('decorated')
|
|
246
243
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
244
|
+
if (member.override) {
|
|
245
|
+
modifiers.push('override')
|
|
249
246
|
}
|
|
250
|
-
if (
|
|
251
|
-
|
|
247
|
+
if (member.accessibility === 'protected') {
|
|
248
|
+
modifiers.push('protected')
|
|
249
|
+
} else if (member.accessibility === 'private' || isPrivateName) {
|
|
250
|
+
modifiers.push('private')
|
|
251
|
+
} else {
|
|
252
|
+
modifiers.push('public')
|
|
252
253
|
}
|
|
253
|
-
if (
|
|
254
|
-
|
|
254
|
+
if (member.kind === 'constructor') {
|
|
255
|
+
selectors.push('constructor')
|
|
255
256
|
}
|
|
256
257
|
if (member.kind === 'get') {
|
|
257
|
-
|
|
258
|
+
selectors.push('get-method')
|
|
258
259
|
}
|
|
259
260
|
if (member.kind === 'set') {
|
|
260
|
-
|
|
261
|
+
selectors.push('set-method')
|
|
261
262
|
}
|
|
262
|
-
|
|
263
|
+
selectors.push('method')
|
|
263
264
|
} else if (member.type === 'TSIndexSignature') {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
265
|
+
if (member.static) {
|
|
266
|
+
modifiers.push('static')
|
|
267
|
+
}
|
|
268
|
+
if (member.readonly) {
|
|
269
|
+
modifiers.push('readonly')
|
|
270
|
+
}
|
|
271
|
+
selectors.push('index-signature')
|
|
272
|
+
} else if (member.type === 'StaticBlock') {
|
|
273
|
+
selectors.push('static-block')
|
|
274
|
+
} else if (
|
|
275
|
+
member.type === 'AccessorProperty' ||
|
|
276
|
+
member.type === 'TSAbstractAccessorProperty'
|
|
277
|
+
) {
|
|
278
|
+
if (member.static) {
|
|
279
|
+
modifiers.push('static')
|
|
280
|
+
}
|
|
281
|
+
if (member.type === 'TSAbstractAccessorProperty') {
|
|
282
|
+
modifiers.push('abstract')
|
|
274
283
|
}
|
|
275
|
-
} else if (member.type === 'PropertyDefinition') {
|
|
276
284
|
if (decorated) {
|
|
277
|
-
|
|
278
|
-
defineGroup('protected-decorated-property')
|
|
279
|
-
}
|
|
280
|
-
if (member.accessibility === 'private' || isPrivate) {
|
|
281
|
-
defineGroup('private-decorated-property')
|
|
282
|
-
}
|
|
283
|
-
defineGroup('decorated-property')
|
|
285
|
+
modifiers.push('decorated')
|
|
284
286
|
}
|
|
285
|
-
if (member.
|
|
286
|
-
|
|
287
|
+
if (member.override) {
|
|
288
|
+
modifiers.push('override')
|
|
287
289
|
}
|
|
288
|
-
if (member.accessibility === '
|
|
289
|
-
|
|
290
|
+
if (member.accessibility === 'protected') {
|
|
291
|
+
modifiers.push('protected')
|
|
292
|
+
} else if (member.accessibility === 'private' || isPrivateName) {
|
|
293
|
+
modifiers.push('private')
|
|
294
|
+
} else {
|
|
295
|
+
modifiers.push('public')
|
|
290
296
|
}
|
|
297
|
+
selectors.push('accessor-property')
|
|
298
|
+
} else {
|
|
291
299
|
if (member.static) {
|
|
292
|
-
|
|
300
|
+
modifiers.push('static')
|
|
301
|
+
}
|
|
302
|
+
if (member.declare) {
|
|
303
|
+
modifiers.push('declare')
|
|
304
|
+
}
|
|
305
|
+
if (member.type === 'TSAbstractPropertyDefinition') {
|
|
306
|
+
modifiers.push('abstract')
|
|
307
|
+
}
|
|
308
|
+
if (decorated) {
|
|
309
|
+
modifiers.push('decorated')
|
|
310
|
+
}
|
|
311
|
+
if (member.override) {
|
|
312
|
+
modifiers.push('override')
|
|
313
|
+
}
|
|
314
|
+
if (member.readonly) {
|
|
315
|
+
modifiers.push('readonly')
|
|
316
|
+
}
|
|
317
|
+
if (member.accessibility === 'protected') {
|
|
318
|
+
modifiers.push('protected')
|
|
319
|
+
} else if (member.accessibility === 'private' || isPrivateName) {
|
|
320
|
+
modifiers.push('private')
|
|
321
|
+
} else {
|
|
322
|
+
modifiers.push('public')
|
|
293
323
|
}
|
|
294
|
-
|
|
324
|
+
if (
|
|
325
|
+
((_b = member.value) == null ? void 0 : _b.type) ===
|
|
326
|
+
'ArrowFunctionExpression' ||
|
|
327
|
+
((_c = member.value) == null ? void 0 : _c.type) ===
|
|
328
|
+
'FunctionExpression'
|
|
329
|
+
) {
|
|
330
|
+
selectors.push('function-property')
|
|
331
|
+
}
|
|
332
|
+
selectors.push('property')
|
|
333
|
+
}
|
|
334
|
+
for (let officialGroup of generateOfficialGroups(
|
|
335
|
+
modifiers,
|
|
336
|
+
selectors,
|
|
337
|
+
)) {
|
|
338
|
+
defineGroup(officialGroup)
|
|
295
339
|
}
|
|
296
340
|
setCustomGroups(options.customGroups, name, {
|
|
297
341
|
override: true,
|
|
@@ -322,10 +366,15 @@ const sortClasses = createEslintRule({
|
|
|
322
366
|
isPositive(compare(left, right, options))))
|
|
323
367
|
) {
|
|
324
368
|
context.report({
|
|
325
|
-
messageId:
|
|
369
|
+
messageId:
|
|
370
|
+
leftNum !== rightNum
|
|
371
|
+
? 'unexpectedClassesGroupOrder'
|
|
372
|
+
: 'unexpectedClassesOrder',
|
|
326
373
|
data: {
|
|
327
374
|
left: toSingleLine(left.name),
|
|
375
|
+
leftGroup: left.group,
|
|
328
376
|
right: toSingleLine(right.name),
|
|
377
|
+
rightGroup: right.group,
|
|
329
378
|
},
|
|
330
379
|
node: right.node,
|
|
331
380
|
fix: fixer => {
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -5,6 +5,7 @@ const getCommentBefore = require('../utils/get-comment-before.js')
|
|
|
5
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
6
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
7
7
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
8
|
+
const getSettings = require('../utils/get-settings.js')
|
|
8
9
|
const isPositive = require('../utils/is-positive.js')
|
|
9
10
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
10
11
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -39,6 +40,15 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
39
40
|
'Controls whether sorting should be case-sensitive or not.',
|
|
40
41
|
type: 'boolean',
|
|
41
42
|
},
|
|
43
|
+
sortByValue: {
|
|
44
|
+
description: 'Compare enum values instead of names.',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
},
|
|
47
|
+
forceNumericSort: {
|
|
48
|
+
description:
|
|
49
|
+
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
},
|
|
42
52
|
partitionByComment: {
|
|
43
53
|
description:
|
|
44
54
|
'Allows you to use comments to separate the class members into logical groups.',
|
|
@@ -70,7 +80,9 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
70
80
|
type: 'alphabetical',
|
|
71
81
|
order: 'asc',
|
|
72
82
|
ignoreCase: true,
|
|
83
|
+
sortByValue: false,
|
|
73
84
|
partitionByComment: false,
|
|
85
|
+
forceNumericSort: false,
|
|
74
86
|
},
|
|
75
87
|
],
|
|
76
88
|
create: context => ({
|
|
@@ -85,19 +97,23 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
85
97
|
[]
|
|
86
98
|
)
|
|
87
99
|
}
|
|
100
|
+
let members = getMembers(node)
|
|
88
101
|
if (
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
members.length > 1 &&
|
|
103
|
+
members.every(({ initializer }) => initializer)
|
|
91
104
|
) {
|
|
92
|
-
let
|
|
105
|
+
let settings = getSettings.getSettings(context.settings)
|
|
106
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
93
107
|
partitionByComment: false,
|
|
94
108
|
type: 'alphabetical',
|
|
95
109
|
ignoreCase: true,
|
|
96
110
|
order: 'asc',
|
|
111
|
+
sortByValue: false,
|
|
112
|
+
forceNumericSort: false,
|
|
97
113
|
})
|
|
98
114
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
99
115
|
let partitionComment = options.partitionByComment
|
|
100
|
-
let formattedMembers =
|
|
116
|
+
let formattedMembers = members.reduce(
|
|
101
117
|
(accumulator, member) => {
|
|
102
118
|
let comment = getCommentBefore.getCommentBefore(member, sourceCode)
|
|
103
119
|
if (
|
|
@@ -124,9 +140,49 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
124
140
|
},
|
|
125
141
|
[[]],
|
|
126
142
|
)
|
|
143
|
+
let isNumericEnum = members.every(member => {
|
|
144
|
+
var _a
|
|
145
|
+
return (
|
|
146
|
+
((_a = member.initializer) == null ? void 0 : _a.type) ===
|
|
147
|
+
'Literal' && typeof member.initializer.value === 'number'
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
let compareOptions = {
|
|
151
|
+
// If the enum is numeric, and we sort by value, always use the `natural` sort type, which will correctly sort them.
|
|
152
|
+
type:
|
|
153
|
+
isNumericEnum && (options.forceNumericSort || options.sortByValue)
|
|
154
|
+
? 'natural'
|
|
155
|
+
: options.type,
|
|
156
|
+
order: options.order,
|
|
157
|
+
ignoreCase: options.ignoreCase,
|
|
158
|
+
// Get the enum value rather than the name if needed
|
|
159
|
+
nodeValueGetter:
|
|
160
|
+
options.sortByValue || (isNumericEnum && options.forceNumericSort)
|
|
161
|
+
? sortingNode => {
|
|
162
|
+
var _a, _b
|
|
163
|
+
if (
|
|
164
|
+
sortingNode.node.type === 'TSEnumMember' &&
|
|
165
|
+
((_a = sortingNode.node.initializer) == null
|
|
166
|
+
? void 0
|
|
167
|
+
: _a.type) === 'Literal'
|
|
168
|
+
) {
|
|
169
|
+
return (
|
|
170
|
+
((_b = sortingNode.node.initializer.value) == null
|
|
171
|
+
? void 0
|
|
172
|
+
: _b.toString()) ?? ''
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
return ''
|
|
176
|
+
}
|
|
177
|
+
: void 0,
|
|
178
|
+
}
|
|
127
179
|
for (let nodes of formattedMembers) {
|
|
128
180
|
pairwise.pairwise(nodes, (left, right) => {
|
|
129
|
-
if (
|
|
181
|
+
if (
|
|
182
|
+
isPositive.isPositive(
|
|
183
|
+
compare.compare(left, right, compareOptions),
|
|
184
|
+
)
|
|
185
|
+
) {
|
|
130
186
|
context.report({
|
|
131
187
|
messageId: 'unexpectedEnumsOrder',
|
|
132
188
|
data: {
|
|
@@ -138,7 +194,7 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
138
194
|
makeFixes.makeFixes(
|
|
139
195
|
fixer,
|
|
140
196
|
nodes,
|
|
141
|
-
sortNodes.sortNodes(nodes,
|
|
197
|
+
sortNodes.sortNodes(nodes, compareOptions),
|
|
142
198
|
sourceCode,
|
|
143
199
|
{ partitionComment },
|
|
144
200
|
),
|
|
@@ -4,6 +4,7 @@ import { getCommentBefore } from '../utils/get-comment-before.mjs'
|
|
|
4
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
5
5
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
6
6
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
7
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
7
8
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
8
9
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
9
10
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -38,6 +39,15 @@ const sortEnums = createEslintRule({
|
|
|
38
39
|
'Controls whether sorting should be case-sensitive or not.',
|
|
39
40
|
type: 'boolean',
|
|
40
41
|
},
|
|
42
|
+
sortByValue: {
|
|
43
|
+
description: 'Compare enum values instead of names.',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
},
|
|
46
|
+
forceNumericSort: {
|
|
47
|
+
description:
|
|
48
|
+
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
},
|
|
41
51
|
partitionByComment: {
|
|
42
52
|
description:
|
|
43
53
|
'Allows you to use comments to separate the class members into logical groups.',
|
|
@@ -69,7 +79,9 @@ const sortEnums = createEslintRule({
|
|
|
69
79
|
type: 'alphabetical',
|
|
70
80
|
order: 'asc',
|
|
71
81
|
ignoreCase: true,
|
|
82
|
+
sortByValue: false,
|
|
72
83
|
partitionByComment: false,
|
|
84
|
+
forceNumericSort: false,
|
|
73
85
|
},
|
|
74
86
|
],
|
|
75
87
|
create: context => ({
|
|
@@ -84,19 +96,23 @@ const sortEnums = createEslintRule({
|
|
|
84
96
|
[]
|
|
85
97
|
)
|
|
86
98
|
}
|
|
99
|
+
let members = getMembers(node)
|
|
87
100
|
if (
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
members.length > 1 &&
|
|
102
|
+
members.every(({ initializer }) => initializer)
|
|
90
103
|
) {
|
|
91
|
-
let
|
|
104
|
+
let settings = getSettings(context.settings)
|
|
105
|
+
let options = complete(context.options.at(0), settings, {
|
|
92
106
|
partitionByComment: false,
|
|
93
107
|
type: 'alphabetical',
|
|
94
108
|
ignoreCase: true,
|
|
95
109
|
order: 'asc',
|
|
110
|
+
sortByValue: false,
|
|
111
|
+
forceNumericSort: false,
|
|
96
112
|
})
|
|
97
113
|
let sourceCode = getSourceCode(context)
|
|
98
114
|
let partitionComment = options.partitionByComment
|
|
99
|
-
let formattedMembers =
|
|
115
|
+
let formattedMembers = members.reduce(
|
|
100
116
|
(accumulator, member) => {
|
|
101
117
|
let comment = getCommentBefore(member, sourceCode)
|
|
102
118
|
if (
|
|
@@ -120,9 +136,45 @@ const sortEnums = createEslintRule({
|
|
|
120
136
|
},
|
|
121
137
|
[[]],
|
|
122
138
|
)
|
|
139
|
+
let isNumericEnum = members.every(member => {
|
|
140
|
+
var _a
|
|
141
|
+
return (
|
|
142
|
+
((_a = member.initializer) == null ? void 0 : _a.type) ===
|
|
143
|
+
'Literal' && typeof member.initializer.value === 'number'
|
|
144
|
+
)
|
|
145
|
+
})
|
|
146
|
+
let compareOptions = {
|
|
147
|
+
// If the enum is numeric, and we sort by value, always use the `natural` sort type, which will correctly sort them.
|
|
148
|
+
type:
|
|
149
|
+
isNumericEnum && (options.forceNumericSort || options.sortByValue)
|
|
150
|
+
? 'natural'
|
|
151
|
+
: options.type,
|
|
152
|
+
order: options.order,
|
|
153
|
+
ignoreCase: options.ignoreCase,
|
|
154
|
+
// Get the enum value rather than the name if needed
|
|
155
|
+
nodeValueGetter:
|
|
156
|
+
options.sortByValue || (isNumericEnum && options.forceNumericSort)
|
|
157
|
+
? sortingNode => {
|
|
158
|
+
var _a, _b
|
|
159
|
+
if (
|
|
160
|
+
sortingNode.node.type === 'TSEnumMember' &&
|
|
161
|
+
((_a = sortingNode.node.initializer) == null
|
|
162
|
+
? void 0
|
|
163
|
+
: _a.type) === 'Literal'
|
|
164
|
+
) {
|
|
165
|
+
return (
|
|
166
|
+
((_b = sortingNode.node.initializer.value) == null
|
|
167
|
+
? void 0
|
|
168
|
+
: _b.toString()) ?? ''
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
return ''
|
|
172
|
+
}
|
|
173
|
+
: void 0,
|
|
174
|
+
}
|
|
123
175
|
for (let nodes of formattedMembers) {
|
|
124
176
|
pairwise(nodes, (left, right) => {
|
|
125
|
-
if (isPositive(compare(left, right,
|
|
177
|
+
if (isPositive(compare(left, right, compareOptions))) {
|
|
126
178
|
context.report({
|
|
127
179
|
messageId: 'unexpectedEnumsOrder',
|
|
128
180
|
data: {
|
|
@@ -134,7 +186,7 @@ const sortEnums = createEslintRule({
|
|
|
134
186
|
makeFixes(
|
|
135
187
|
fixer,
|
|
136
188
|
nodes,
|
|
137
|
-
sortNodes(nodes,
|
|
189
|
+
sortNodes(nodes, compareOptions),
|
|
138
190
|
sourceCode,
|
|
139
191
|
{ partitionComment },
|
|
140
192
|
),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
3
3
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
4
4
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
5
|
+
const getSettings = require('../utils/get-settings.js')
|
|
5
6
|
const isPositive = require('../utils/is-positive.js')
|
|
6
7
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
7
8
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -52,7 +53,8 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
52
53
|
},
|
|
53
54
|
],
|
|
54
55
|
create: context => {
|
|
55
|
-
let
|
|
56
|
+
let settings = getSettings.getSettings(context.settings)
|
|
57
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
56
58
|
type: 'alphabetical',
|
|
57
59
|
ignoreCase: true,
|
|
58
60
|
order: 'asc',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
2
2
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
3
3
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
4
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
4
5
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
5
6
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
6
7
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -51,7 +52,8 @@ const sortExports = createEslintRule({
|
|
|
51
52
|
},
|
|
52
53
|
],
|
|
53
54
|
create: context => {
|
|
54
|
-
let
|
|
55
|
+
let settings = getSettings(context.settings)
|
|
56
|
+
let options = complete(context.options.at(0), settings, {
|
|
55
57
|
type: 'alphabetical',
|
|
56
58
|
ignoreCase: true,
|
|
57
59
|
order: 'asc',
|
|
@@ -8,6 +8,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
8
8
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
9
9
|
const getNodeRange = require('../utils/get-node-range.js')
|
|
10
10
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
11
|
+
const getSettings = require('../utils/get-settings.js')
|
|
11
12
|
const isPositive = require('../utils/is-positive.js')
|
|
12
13
|
const useGroups = require('../utils/use-groups.js')
|
|
13
14
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -163,7 +164,8 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
163
164
|
},
|
|
164
165
|
],
|
|
165
166
|
create: context => {
|
|
166
|
-
let
|
|
167
|
+
let settings = getSettings.getSettings(context.settings)
|
|
168
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
167
169
|
groups: [
|
|
168
170
|
'type',
|
|
169
171
|
['builtin', 'external'],
|
|
@@ -7,6 +7,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
7
7
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
8
8
|
import { getNodeRange } from '../utils/get-node-range.mjs'
|
|
9
9
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
10
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
10
11
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
11
12
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
12
13
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -162,7 +163,8 @@ const sortImports = createEslintRule({
|
|
|
162
163
|
},
|
|
163
164
|
],
|
|
164
165
|
create: context => {
|
|
165
|
-
let
|
|
166
|
+
let settings = getSettings(context.settings)
|
|
167
|
+
let options = complete(context.options.at(0), settings, {
|
|
166
168
|
groups: [
|
|
167
169
|
'type',
|
|
168
170
|
['builtin', 'external'],
|
|
@@ -7,6 +7,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
7
7
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
8
8
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
9
9
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
10
|
+
const getSettings = require('../utils/get-settings.js')
|
|
10
11
|
const isPositive = require('../utils/is-positive.js')
|
|
11
12
|
const useGroups = require('../utils/use-groups.js')
|
|
12
13
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -118,7 +119,8 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
118
119
|
create: context => ({
|
|
119
120
|
TSInterfaceDeclaration: node => {
|
|
120
121
|
if (node.body.body.length > 1) {
|
|
121
|
-
let
|
|
122
|
+
let settings = getSettings.getSettings(context.settings)
|
|
123
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
122
124
|
partitionByNewLine: false,
|
|
123
125
|
type: 'alphabetical',
|
|
124
126
|
groupKind: 'mixed',
|
|
@@ -6,6 +6,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
6
6
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
7
7
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
8
8
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
9
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
9
10
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
10
11
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
11
12
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -117,7 +118,8 @@ const sortInterfaces = createEslintRule({
|
|
|
117
118
|
create: context => ({
|
|
118
119
|
TSInterfaceDeclaration: node => {
|
|
119
120
|
if (node.body.body.length > 1) {
|
|
120
|
-
let
|
|
121
|
+
let settings = getSettings(context.settings)
|
|
122
|
+
let options = complete(context.options.at(0), settings, {
|
|
121
123
|
partitionByNewLine: false,
|
|
122
124
|
type: 'alphabetical',
|
|
123
125
|
groupKind: 'mixed',
|
|
@@ -4,6 +4,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
4
4
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
5
5
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
9
10
|
const useGroups = require('../utils/use-groups.js')
|
|
@@ -75,7 +76,8 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
75
76
|
],
|
|
76
77
|
create: context => ({
|
|
77
78
|
TSIntersectionType: node => {
|
|
78
|
-
let
|
|
79
|
+
let settings = getSettings.getSettings(context.settings)
|
|
80
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
79
81
|
type: 'alphabetical',
|
|
80
82
|
ignoreCase: true,
|
|
81
83
|
order: 'asc',
|
|
@@ -3,6 +3,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
3
3
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
4
4
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
8
9
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
@@ -74,7 +75,8 @@ const sortIntersectionTypes = createEslintRule({
|
|
|
74
75
|
],
|
|
75
76
|
create: context => ({
|
|
76
77
|
TSIntersectionType: node => {
|
|
77
|
-
let
|
|
78
|
+
let settings = getSettings(context.settings)
|
|
79
|
+
let options = complete(context.options.at(0), settings, {
|
|
78
80
|
type: 'alphabetical',
|
|
79
81
|
ignoreCase: true,
|
|
80
82
|
order: 'asc',
|
|
@@ -4,6 +4,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
4
4
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
5
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const useGroups = require('../utils/use-groups.js')
|
|
9
10
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -103,7 +104,8 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
103
104
|
create: context => ({
|
|
104
105
|
JSXElement: node => {
|
|
105
106
|
if (node.openingElement.attributes.length > 1) {
|
|
106
|
-
let
|
|
107
|
+
let settings = getSettings.getSettings(context.settings)
|
|
108
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
107
109
|
type: 'alphabetical',
|
|
108
110
|
ignorePattern: [],
|
|
109
111
|
ignoreCase: true,
|
|
@@ -3,6 +3,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
3
3
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
4
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
8
9
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -102,7 +103,8 @@ const sortJsxProps = createEslintRule({
|
|
|
102
103
|
create: context => ({
|
|
103
104
|
JSXElement: node => {
|
|
104
105
|
if (node.openingElement.attributes.length > 1) {
|
|
105
|
-
let
|
|
106
|
+
let settings = getSettings(context.settings)
|
|
107
|
+
let options = complete(context.options.at(0), settings, {
|
|
106
108
|
type: 'alphabetical',
|
|
107
109
|
ignorePattern: [],
|
|
108
110
|
ignoreCase: true,
|