eslint-plugin-perfectionist 3.4.0 → 3.6.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 -9
- package/dist/rules/sort-astro-attributes.js +8 -1
- package/dist/rules/sort-astro-attributes.mjs +8 -1
- package/dist/rules/sort-classes.js +10 -5
- package/dist/rules/sort-classes.mjs +7 -5
- package/dist/rules/sort-enums.js +9 -7
- package/dist/rules/sort-enums.mjs +7 -5
- package/dist/rules/sort-imports.js +32 -15
- package/dist/rules/sort-imports.mjs +31 -14
- package/dist/rules/sort-interfaces.js +16 -1
- package/dist/rules/sort-interfaces.mjs +10 -1
- package/dist/rules/sort-intersection-types.js +8 -1
- package/dist/rules/sort-intersection-types.mjs +8 -1
- package/dist/rules/sort-jsx-props.js +8 -1
- package/dist/rules/sort-jsx-props.mjs +8 -1
- package/dist/rules/sort-object-types.js +8 -1
- package/dist/rules/sort-object-types.mjs +8 -1
- package/dist/rules/sort-objects.js +84 -50
- package/dist/rules/sort-objects.mjs +78 -50
- package/dist/rules/sort-svelte-attributes.js +8 -1
- package/dist/rules/sort-svelte-attributes.mjs +8 -1
- package/dist/rules/sort-union-types.js +8 -1
- package/dist/rules/sort-union-types.mjs +8 -1
- package/dist/rules/sort-variable-declarations.js +39 -9
- package/dist/rules/sort-variable-declarations.mjs +39 -9
- package/dist/rules/sort-vue-attributes.js +8 -1
- package/dist/rules/sort-vue-attributes.mjs +8 -1
- package/dist/utils/get-comments-before.js +12 -0
- package/dist/utils/get-comments-before.mjs +10 -0
- package/dist/utils/get-node-range.js +26 -12
- package/dist/utils/get-node-range.mjs +26 -12
- package/dist/utils/is-partition-comment.js +3 -0
- package/dist/utils/is-partition-comment.mjs +3 -1
- package/package.json +4 -4
- package/readme.md +1 -0
- package/dist/utils/get-comment-before.js +0 -23
- package/dist/utils/get-comment-before.mjs +0 -21
|
@@ -87,6 +87,8 @@ const sortJsxProps = createEslintRule({
|
|
|
87
87
|
},
|
|
88
88
|
],
|
|
89
89
|
messages: {
|
|
90
|
+
unexpectedJSXPropsGroupOrder:
|
|
91
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
90
92
|
unexpectedJSXPropsOrder:
|
|
91
93
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
92
94
|
},
|
|
@@ -168,10 +170,15 @@ const sortJsxProps = createEslintRule({
|
|
|
168
170
|
isPositive(compare(left, right, options)))
|
|
169
171
|
) {
|
|
170
172
|
context.report({
|
|
171
|
-
messageId:
|
|
173
|
+
messageId:
|
|
174
|
+
leftNum !== rightNum
|
|
175
|
+
? 'unexpectedJSXPropsGroupOrder'
|
|
176
|
+
: 'unexpectedJSXPropsOrder',
|
|
172
177
|
data: {
|
|
173
178
|
left: left.name,
|
|
179
|
+
leftGroup: left.group,
|
|
174
180
|
right: right.name,
|
|
181
|
+
rightGroup: right.group,
|
|
175
182
|
},
|
|
176
183
|
node: right.node,
|
|
177
184
|
fix: fixer => {
|
|
@@ -91,6 +91,8 @@ const sortObjectTypes = createEslintRule.createEslintRule({
|
|
|
91
91
|
},
|
|
92
92
|
],
|
|
93
93
|
messages: {
|
|
94
|
+
unexpectedObjectTypesGroupOrder:
|
|
95
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
94
96
|
unexpectedObjectTypesOrder:
|
|
95
97
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
96
98
|
},
|
|
@@ -248,10 +250,15 @@ const sortObjectTypes = createEslintRule.createEslintRule({
|
|
|
248
250
|
}
|
|
249
251
|
if (compareValue) {
|
|
250
252
|
context.report({
|
|
251
|
-
messageId:
|
|
253
|
+
messageId:
|
|
254
|
+
leftNum !== rightNum
|
|
255
|
+
? 'unexpectedObjectTypesGroupOrder'
|
|
256
|
+
: 'unexpectedObjectTypesOrder',
|
|
252
257
|
data: {
|
|
253
258
|
left: toSingleLine.toSingleLine(left.name),
|
|
259
|
+
leftGroup: left.group,
|
|
254
260
|
right: toSingleLine.toSingleLine(right.name),
|
|
261
|
+
rightGroup: right.group,
|
|
255
262
|
},
|
|
256
263
|
node: right.node,
|
|
257
264
|
fix: fixer => {
|
|
@@ -90,6 +90,8 @@ const sortObjectTypes = createEslintRule({
|
|
|
90
90
|
},
|
|
91
91
|
],
|
|
92
92
|
messages: {
|
|
93
|
+
unexpectedObjectTypesGroupOrder:
|
|
94
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
93
95
|
unexpectedObjectTypesOrder:
|
|
94
96
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
95
97
|
},
|
|
@@ -242,10 +244,15 @@ const sortObjectTypes = createEslintRule({
|
|
|
242
244
|
}
|
|
243
245
|
if (compareValue) {
|
|
244
246
|
context.report({
|
|
245
|
-
messageId:
|
|
247
|
+
messageId:
|
|
248
|
+
leftNum !== rightNum
|
|
249
|
+
? 'unexpectedObjectTypesGroupOrder'
|
|
250
|
+
: 'unexpectedObjectTypesOrder',
|
|
246
251
|
data: {
|
|
247
252
|
left: toSingleLine(left.name),
|
|
253
|
+
leftGroup: left.group,
|
|
248
254
|
right: toSingleLine(right.name),
|
|
255
|
+
rightGroup: right.group,
|
|
249
256
|
},
|
|
250
257
|
node: right.node,
|
|
251
258
|
fix: fixer => {
|
|
@@ -3,7 +3,7 @@ const minimatch = require('minimatch')
|
|
|
3
3
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
4
4
|
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
5
5
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
6
|
-
const
|
|
6
|
+
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
7
7
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
8
8
|
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
9
9
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
@@ -123,6 +123,8 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
123
123
|
},
|
|
124
124
|
],
|
|
125
125
|
messages: {
|
|
126
|
+
unexpectedObjectsGroupOrder:
|
|
127
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
126
128
|
unexpectedObjectsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
127
129
|
},
|
|
128
130
|
},
|
|
@@ -220,6 +222,69 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
220
222
|
return
|
|
221
223
|
}
|
|
222
224
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
225
|
+
let extractDependencies = init => {
|
|
226
|
+
let dependencies = []
|
|
227
|
+
let checkNode = nodeValue => {
|
|
228
|
+
if (
|
|
229
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
230
|
+
nodeValue.type === 'FunctionExpression'
|
|
231
|
+
) {
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
if (nodeValue.type === 'Identifier') {
|
|
235
|
+
dependencies.push(nodeValue.name)
|
|
236
|
+
}
|
|
237
|
+
if (nodeValue.type === 'Property') {
|
|
238
|
+
traverseNode(nodeValue.key)
|
|
239
|
+
traverseNode(nodeValue.value)
|
|
240
|
+
}
|
|
241
|
+
if (nodeValue.type === 'ConditionalExpression') {
|
|
242
|
+
traverseNode(nodeValue.test)
|
|
243
|
+
traverseNode(nodeValue.consequent)
|
|
244
|
+
traverseNode(nodeValue.alternate)
|
|
245
|
+
}
|
|
246
|
+
if (
|
|
247
|
+
'expression' in nodeValue &&
|
|
248
|
+
typeof nodeValue.expression !== 'boolean'
|
|
249
|
+
) {
|
|
250
|
+
traverseNode(nodeValue.expression)
|
|
251
|
+
}
|
|
252
|
+
if ('object' in nodeValue) {
|
|
253
|
+
traverseNode(nodeValue.object)
|
|
254
|
+
}
|
|
255
|
+
if ('callee' in nodeValue) {
|
|
256
|
+
traverseNode(nodeValue.callee)
|
|
257
|
+
}
|
|
258
|
+
if ('left' in nodeValue) {
|
|
259
|
+
traverseNode(nodeValue.left)
|
|
260
|
+
}
|
|
261
|
+
if ('right' in nodeValue) {
|
|
262
|
+
traverseNode(nodeValue.right)
|
|
263
|
+
}
|
|
264
|
+
if ('elements' in nodeValue) {
|
|
265
|
+
nodeValue.elements
|
|
266
|
+
.filter(currentNode => currentNode !== null)
|
|
267
|
+
.forEach(traverseNode)
|
|
268
|
+
}
|
|
269
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
270
|
+
traverseNode(nodeValue.argument)
|
|
271
|
+
}
|
|
272
|
+
if ('arguments' in nodeValue) {
|
|
273
|
+
nodeValue.arguments.forEach(traverseNode)
|
|
274
|
+
}
|
|
275
|
+
if ('properties' in nodeValue) {
|
|
276
|
+
nodeValue.properties.forEach(traverseNode)
|
|
277
|
+
}
|
|
278
|
+
if ('expressions' in nodeValue) {
|
|
279
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
let traverseNode = nodeValue => {
|
|
283
|
+
checkNode(nodeValue)
|
|
284
|
+
}
|
|
285
|
+
traverseNode(init)
|
|
286
|
+
return dependencies
|
|
287
|
+
}
|
|
223
288
|
let formatProperties = props =>
|
|
224
289
|
props.reduce(
|
|
225
290
|
(accumulator, prop) => {
|
|
@@ -231,15 +296,17 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
231
296
|
accumulator.push([])
|
|
232
297
|
return accumulator
|
|
233
298
|
}
|
|
234
|
-
let
|
|
299
|
+
let comments = getCommentsBefore.getCommentsBefore(
|
|
300
|
+
prop,
|
|
301
|
+
sourceCode,
|
|
302
|
+
)
|
|
235
303
|
let lastProp =
|
|
236
304
|
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
237
305
|
if (
|
|
238
306
|
options.partitionByComment &&
|
|
239
|
-
|
|
240
|
-
isPartitionComment.isPartitionComment(
|
|
307
|
+
isPartitionComment.hasPartitionComment(
|
|
241
308
|
options.partitionByComment,
|
|
242
|
-
|
|
309
|
+
comments,
|
|
243
310
|
)
|
|
244
311
|
) {
|
|
245
312
|
accumulator.push([])
|
|
@@ -274,50 +341,7 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
274
341
|
accumulator.push([])
|
|
275
342
|
}
|
|
276
343
|
if (prop.value.type === 'AssignmentPattern') {
|
|
277
|
-
|
|
278
|
-
if (value2.right.type === 'Identifier') {
|
|
279
|
-
dependencies.push(value2.right.name)
|
|
280
|
-
}
|
|
281
|
-
let handleComplexExpression = expression => {
|
|
282
|
-
let nodes = []
|
|
283
|
-
switch (expression.type) {
|
|
284
|
-
case 'ArrowFunctionExpression':
|
|
285
|
-
nodes.push(expression.body)
|
|
286
|
-
break
|
|
287
|
-
case 'ConditionalExpression':
|
|
288
|
-
nodes.push(expression.consequent, expression.alternate)
|
|
289
|
-
break
|
|
290
|
-
case 'LogicalExpression':
|
|
291
|
-
case 'BinaryExpression':
|
|
292
|
-
nodes.push(expression.left, expression.right)
|
|
293
|
-
break
|
|
294
|
-
case 'CallExpression':
|
|
295
|
-
nodes.push(...expression.arguments)
|
|
296
|
-
break
|
|
297
|
-
}
|
|
298
|
-
nodes.forEach(nestedNode => {
|
|
299
|
-
if (nestedNode.type === 'Identifier') {
|
|
300
|
-
dependencies.push(nestedNode.name)
|
|
301
|
-
}
|
|
302
|
-
if (
|
|
303
|
-
nestedNode.type === 'BinaryExpression' ||
|
|
304
|
-
nestedNode.type === 'ConditionalExpression'
|
|
305
|
-
) {
|
|
306
|
-
handleComplexExpression(nestedNode)
|
|
307
|
-
}
|
|
308
|
-
})
|
|
309
|
-
}
|
|
310
|
-
switch (value2.right.type) {
|
|
311
|
-
case 'ArrowFunctionExpression':
|
|
312
|
-
case 'ConditionalExpression':
|
|
313
|
-
case 'LogicalExpression':
|
|
314
|
-
case 'BinaryExpression':
|
|
315
|
-
case 'CallExpression':
|
|
316
|
-
handleComplexExpression(value2.right)
|
|
317
|
-
break
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
addDependencies(prop.value)
|
|
344
|
+
dependencies = extractDependencies(prop.value)
|
|
321
345
|
}
|
|
322
346
|
setCustomGroups(options.customGroups, name)
|
|
323
347
|
let value = {
|
|
@@ -360,11 +384,21 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
360
384
|
makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
361
385
|
partitionComment: options.partitionByComment,
|
|
362
386
|
})
|
|
387
|
+
let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
|
|
388
|
+
let rightNum = getGroupNumber.getGroupNumber(
|
|
389
|
+
options.groups,
|
|
390
|
+
right,
|
|
391
|
+
)
|
|
363
392
|
context.report({
|
|
364
|
-
messageId:
|
|
393
|
+
messageId:
|
|
394
|
+
leftNum !== rightNum
|
|
395
|
+
? 'unexpectedObjectsGroupOrder'
|
|
396
|
+
: 'unexpectedObjectsOrder',
|
|
365
397
|
data: {
|
|
366
398
|
left: toSingleLine.toSingleLine(left.name),
|
|
399
|
+
leftGroup: left.group,
|
|
367
400
|
right: toSingleLine.toSingleLine(right.name),
|
|
401
|
+
rightGroup: right.group,
|
|
368
402
|
},
|
|
369
403
|
node: right.node,
|
|
370
404
|
fix,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { minimatch } from 'minimatch'
|
|
2
2
|
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
|
|
3
3
|
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.mjs'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { hasPartitionComment } from '../utils/is-partition-comment.mjs'
|
|
5
|
+
import { getCommentsBefore } from '../utils/get-comments-before.mjs'
|
|
6
6
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
7
7
|
import { getLinesBetween } from '../utils/get-lines-between.mjs'
|
|
8
8
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
@@ -122,6 +122,8 @@ const sortObjects = createEslintRule({
|
|
|
122
122
|
},
|
|
123
123
|
],
|
|
124
124
|
messages: {
|
|
125
|
+
unexpectedObjectsGroupOrder:
|
|
126
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
125
127
|
unexpectedObjectsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
126
128
|
},
|
|
127
129
|
},
|
|
@@ -216,6 +218,69 @@ const sortObjects = createEslintRule({
|
|
|
216
218
|
return
|
|
217
219
|
}
|
|
218
220
|
let sourceCode = getSourceCode(context)
|
|
221
|
+
let extractDependencies = init => {
|
|
222
|
+
let dependencies = []
|
|
223
|
+
let checkNode = nodeValue => {
|
|
224
|
+
if (
|
|
225
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
226
|
+
nodeValue.type === 'FunctionExpression'
|
|
227
|
+
) {
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
if (nodeValue.type === 'Identifier') {
|
|
231
|
+
dependencies.push(nodeValue.name)
|
|
232
|
+
}
|
|
233
|
+
if (nodeValue.type === 'Property') {
|
|
234
|
+
traverseNode(nodeValue.key)
|
|
235
|
+
traverseNode(nodeValue.value)
|
|
236
|
+
}
|
|
237
|
+
if (nodeValue.type === 'ConditionalExpression') {
|
|
238
|
+
traverseNode(nodeValue.test)
|
|
239
|
+
traverseNode(nodeValue.consequent)
|
|
240
|
+
traverseNode(nodeValue.alternate)
|
|
241
|
+
}
|
|
242
|
+
if (
|
|
243
|
+
'expression' in nodeValue &&
|
|
244
|
+
typeof nodeValue.expression !== 'boolean'
|
|
245
|
+
) {
|
|
246
|
+
traverseNode(nodeValue.expression)
|
|
247
|
+
}
|
|
248
|
+
if ('object' in nodeValue) {
|
|
249
|
+
traverseNode(nodeValue.object)
|
|
250
|
+
}
|
|
251
|
+
if ('callee' in nodeValue) {
|
|
252
|
+
traverseNode(nodeValue.callee)
|
|
253
|
+
}
|
|
254
|
+
if ('left' in nodeValue) {
|
|
255
|
+
traverseNode(nodeValue.left)
|
|
256
|
+
}
|
|
257
|
+
if ('right' in nodeValue) {
|
|
258
|
+
traverseNode(nodeValue.right)
|
|
259
|
+
}
|
|
260
|
+
if ('elements' in nodeValue) {
|
|
261
|
+
nodeValue.elements
|
|
262
|
+
.filter(currentNode => currentNode !== null)
|
|
263
|
+
.forEach(traverseNode)
|
|
264
|
+
}
|
|
265
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
266
|
+
traverseNode(nodeValue.argument)
|
|
267
|
+
}
|
|
268
|
+
if ('arguments' in nodeValue) {
|
|
269
|
+
nodeValue.arguments.forEach(traverseNode)
|
|
270
|
+
}
|
|
271
|
+
if ('properties' in nodeValue) {
|
|
272
|
+
nodeValue.properties.forEach(traverseNode)
|
|
273
|
+
}
|
|
274
|
+
if ('expressions' in nodeValue) {
|
|
275
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
let traverseNode = nodeValue => {
|
|
279
|
+
checkNode(nodeValue)
|
|
280
|
+
}
|
|
281
|
+
traverseNode(init)
|
|
282
|
+
return dependencies
|
|
283
|
+
}
|
|
219
284
|
let formatProperties = props =>
|
|
220
285
|
props.reduce(
|
|
221
286
|
(accumulator, prop) => {
|
|
@@ -227,13 +292,12 @@ const sortObjects = createEslintRule({
|
|
|
227
292
|
accumulator.push([])
|
|
228
293
|
return accumulator
|
|
229
294
|
}
|
|
230
|
-
let
|
|
295
|
+
let comments = getCommentsBefore(prop, sourceCode)
|
|
231
296
|
let lastProp =
|
|
232
297
|
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
233
298
|
if (
|
|
234
299
|
options.partitionByComment &&
|
|
235
|
-
|
|
236
|
-
isPartitionComment(options.partitionByComment, comment.value)
|
|
300
|
+
hasPartitionComment(options.partitionByComment, comments)
|
|
237
301
|
) {
|
|
238
302
|
accumulator.push([])
|
|
239
303
|
}
|
|
@@ -261,50 +325,7 @@ const sortObjects = createEslintRule({
|
|
|
261
325
|
accumulator.push([])
|
|
262
326
|
}
|
|
263
327
|
if (prop.value.type === 'AssignmentPattern') {
|
|
264
|
-
|
|
265
|
-
if (value2.right.type === 'Identifier') {
|
|
266
|
-
dependencies.push(value2.right.name)
|
|
267
|
-
}
|
|
268
|
-
let handleComplexExpression = expression => {
|
|
269
|
-
let nodes = []
|
|
270
|
-
switch (expression.type) {
|
|
271
|
-
case 'ArrowFunctionExpression':
|
|
272
|
-
nodes.push(expression.body)
|
|
273
|
-
break
|
|
274
|
-
case 'ConditionalExpression':
|
|
275
|
-
nodes.push(expression.consequent, expression.alternate)
|
|
276
|
-
break
|
|
277
|
-
case 'LogicalExpression':
|
|
278
|
-
case 'BinaryExpression':
|
|
279
|
-
nodes.push(expression.left, expression.right)
|
|
280
|
-
break
|
|
281
|
-
case 'CallExpression':
|
|
282
|
-
nodes.push(...expression.arguments)
|
|
283
|
-
break
|
|
284
|
-
}
|
|
285
|
-
nodes.forEach(nestedNode => {
|
|
286
|
-
if (nestedNode.type === 'Identifier') {
|
|
287
|
-
dependencies.push(nestedNode.name)
|
|
288
|
-
}
|
|
289
|
-
if (
|
|
290
|
-
nestedNode.type === 'BinaryExpression' ||
|
|
291
|
-
nestedNode.type === 'ConditionalExpression'
|
|
292
|
-
) {
|
|
293
|
-
handleComplexExpression(nestedNode)
|
|
294
|
-
}
|
|
295
|
-
})
|
|
296
|
-
}
|
|
297
|
-
switch (value2.right.type) {
|
|
298
|
-
case 'ArrowFunctionExpression':
|
|
299
|
-
case 'ConditionalExpression':
|
|
300
|
-
case 'LogicalExpression':
|
|
301
|
-
case 'BinaryExpression':
|
|
302
|
-
case 'CallExpression':
|
|
303
|
-
handleComplexExpression(value2.right)
|
|
304
|
-
break
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
addDependencies(prop.value)
|
|
328
|
+
dependencies = extractDependencies(prop.value)
|
|
308
329
|
}
|
|
309
330
|
setCustomGroups(options.customGroups, name)
|
|
310
331
|
let value = {
|
|
@@ -343,11 +364,18 @@ const sortObjects = createEslintRule({
|
|
|
343
364
|
makeFixes(fixer, nodes, sortedNodes, sourceCode, {
|
|
344
365
|
partitionComment: options.partitionByComment,
|
|
345
366
|
})
|
|
367
|
+
let leftNum = getGroupNumber(options.groups, left)
|
|
368
|
+
let rightNum = getGroupNumber(options.groups, right)
|
|
346
369
|
context.report({
|
|
347
|
-
messageId:
|
|
370
|
+
messageId:
|
|
371
|
+
leftNum !== rightNum
|
|
372
|
+
? 'unexpectedObjectsGroupOrder'
|
|
373
|
+
: 'unexpectedObjectsOrder',
|
|
348
374
|
data: {
|
|
349
375
|
left: toSingleLine(left.name),
|
|
376
|
+
leftGroup: left.group,
|
|
350
377
|
right: toSingleLine(right.name),
|
|
378
|
+
rightGroup: right.group,
|
|
351
379
|
},
|
|
352
380
|
node: right.node,
|
|
353
381
|
fix,
|
|
@@ -80,6 +80,8 @@ const sortSvelteAttributes = createEslintRule.createEslintRule({
|
|
|
80
80
|
},
|
|
81
81
|
],
|
|
82
82
|
messages: {
|
|
83
|
+
unexpectedSvelteAttributesGroupOrder:
|
|
84
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
83
85
|
unexpectedSvelteAttributesOrder:
|
|
84
86
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
85
87
|
},
|
|
@@ -169,10 +171,15 @@ const sortSvelteAttributes = createEslintRule.createEslintRule({
|
|
|
169
171
|
isPositive.isPositive(compare.compare(left, right, options)))
|
|
170
172
|
) {
|
|
171
173
|
context.report({
|
|
172
|
-
messageId:
|
|
174
|
+
messageId:
|
|
175
|
+
leftNum !== rightNum
|
|
176
|
+
? 'unexpectedSvelteAttributesGroupOrder'
|
|
177
|
+
: 'unexpectedSvelteAttributesOrder',
|
|
173
178
|
data: {
|
|
174
179
|
left: left.name,
|
|
180
|
+
leftGroup: left.group,
|
|
175
181
|
right: right.name,
|
|
182
|
+
rightGroup: right.group,
|
|
176
183
|
},
|
|
177
184
|
node: right.node,
|
|
178
185
|
fix: fixer => {
|
|
@@ -79,6 +79,8 @@ const sortSvelteAttributes = createEslintRule({
|
|
|
79
79
|
},
|
|
80
80
|
],
|
|
81
81
|
messages: {
|
|
82
|
+
unexpectedSvelteAttributesGroupOrder:
|
|
83
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
82
84
|
unexpectedSvelteAttributesOrder:
|
|
83
85
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
84
86
|
},
|
|
@@ -166,10 +168,15 @@ const sortSvelteAttributes = createEslintRule({
|
|
|
166
168
|
isPositive(compare(left, right, options)))
|
|
167
169
|
) {
|
|
168
170
|
context.report({
|
|
169
|
-
messageId:
|
|
171
|
+
messageId:
|
|
172
|
+
leftNum !== rightNum
|
|
173
|
+
? 'unexpectedSvelteAttributesGroupOrder'
|
|
174
|
+
: 'unexpectedSvelteAttributesOrder',
|
|
170
175
|
data: {
|
|
171
176
|
left: left.name,
|
|
177
|
+
leftGroup: left.group,
|
|
172
178
|
right: right.name,
|
|
179
|
+
rightGroup: right.group,
|
|
173
180
|
},
|
|
174
181
|
node: right.node,
|
|
175
182
|
fix: fixer => {
|
|
@@ -63,6 +63,8 @@ const sortUnionTypes = createEslintRule.createEslintRule({
|
|
|
63
63
|
},
|
|
64
64
|
],
|
|
65
65
|
messages: {
|
|
66
|
+
unexpectedUnionTypesGroupOrder:
|
|
67
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
66
68
|
unexpectedUnionTypesOrder:
|
|
67
69
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
68
70
|
},
|
|
@@ -180,10 +182,15 @@ const sortUnionTypes = createEslintRule.createEslintRule({
|
|
|
180
182
|
isPositive.isPositive(compare.compare(left, right, options)))
|
|
181
183
|
) {
|
|
182
184
|
context.report({
|
|
183
|
-
messageId:
|
|
185
|
+
messageId:
|
|
186
|
+
leftNum !== rightNum
|
|
187
|
+
? 'unexpectedUnionTypesGroupOrder'
|
|
188
|
+
: 'unexpectedUnionTypesOrder',
|
|
184
189
|
data: {
|
|
185
190
|
left: toSingleLine.toSingleLine(left.name),
|
|
191
|
+
leftGroup: left.group,
|
|
186
192
|
right: toSingleLine.toSingleLine(right.name),
|
|
193
|
+
rightGroup: right.group,
|
|
187
194
|
},
|
|
188
195
|
node: right.node,
|
|
189
196
|
fix: fixer => {
|
|
@@ -62,6 +62,8 @@ const sortUnionTypes = createEslintRule({
|
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
messages: {
|
|
65
|
+
unexpectedUnionTypesGroupOrder:
|
|
66
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
65
67
|
unexpectedUnionTypesOrder:
|
|
66
68
|
'Expected "{{right}}" to come before "{{left}}".',
|
|
67
69
|
},
|
|
@@ -178,10 +180,15 @@ const sortUnionTypes = createEslintRule({
|
|
|
178
180
|
(leftNum === rightNum && isPositive(compare(left, right, options)))
|
|
179
181
|
) {
|
|
180
182
|
context.report({
|
|
181
|
-
messageId:
|
|
183
|
+
messageId:
|
|
184
|
+
leftNum !== rightNum
|
|
185
|
+
? 'unexpectedUnionTypesGroupOrder'
|
|
186
|
+
: 'unexpectedUnionTypesOrder',
|
|
182
187
|
data: {
|
|
183
188
|
left: toSingleLine(left.name),
|
|
189
|
+
leftGroup: left.group,
|
|
184
190
|
right: toSingleLine(right.name),
|
|
191
|
+
rightGroup: right.group,
|
|
185
192
|
},
|
|
186
193
|
node: right.node,
|
|
187
194
|
fix: fixer => {
|
|
@@ -64,20 +64,37 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
64
64
|
})
|
|
65
65
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
66
66
|
let extractDependencies = init => {
|
|
67
|
-
if (!init) {
|
|
68
|
-
return []
|
|
69
|
-
}
|
|
70
67
|
let dependencies = []
|
|
71
68
|
let checkNode = nodeValue => {
|
|
69
|
+
if (
|
|
70
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
71
|
+
nodeValue.type === 'FunctionExpression'
|
|
72
|
+
) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
72
75
|
if (nodeValue.type === 'Identifier') {
|
|
73
76
|
dependencies.push(nodeValue.name)
|
|
74
77
|
}
|
|
78
|
+
if (nodeValue.type === 'Property') {
|
|
79
|
+
traverseNode(nodeValue.key)
|
|
80
|
+
traverseNode(nodeValue.value)
|
|
81
|
+
}
|
|
82
|
+
if (nodeValue.type === 'ConditionalExpression') {
|
|
83
|
+
traverseNode(nodeValue.test)
|
|
84
|
+
traverseNode(nodeValue.consequent)
|
|
85
|
+
traverseNode(nodeValue.alternate)
|
|
86
|
+
}
|
|
75
87
|
if (
|
|
76
|
-
'
|
|
77
|
-
nodeValue.
|
|
78
|
-
!Array.isArray(nodeValue.body)
|
|
88
|
+
'expression' in nodeValue &&
|
|
89
|
+
typeof nodeValue.expression !== 'boolean'
|
|
79
90
|
) {
|
|
80
|
-
traverseNode(nodeValue.
|
|
91
|
+
traverseNode(nodeValue.expression)
|
|
92
|
+
}
|
|
93
|
+
if ('object' in nodeValue) {
|
|
94
|
+
traverseNode(nodeValue.object)
|
|
95
|
+
}
|
|
96
|
+
if ('callee' in nodeValue) {
|
|
97
|
+
traverseNode(nodeValue.callee)
|
|
81
98
|
}
|
|
82
99
|
if ('left' in nodeValue) {
|
|
83
100
|
traverseNode(nodeValue.left)
|
|
@@ -89,9 +106,19 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
89
106
|
nodeValue.elements
|
|
90
107
|
.filter(currentNode => currentNode !== null)
|
|
91
108
|
.forEach(traverseNode)
|
|
92
|
-
}
|
|
109
|
+
}
|
|
110
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
111
|
+
traverseNode(nodeValue.argument)
|
|
112
|
+
}
|
|
113
|
+
if ('arguments' in nodeValue) {
|
|
93
114
|
nodeValue.arguments.forEach(traverseNode)
|
|
94
115
|
}
|
|
116
|
+
if ('properties' in nodeValue) {
|
|
117
|
+
nodeValue.properties.forEach(traverseNode)
|
|
118
|
+
}
|
|
119
|
+
if ('expressions' in nodeValue) {
|
|
120
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
121
|
+
}
|
|
95
122
|
}
|
|
96
123
|
let traverseNode = nodeValue => {
|
|
97
124
|
checkNode(nodeValue)
|
|
@@ -109,7 +136,10 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
109
136
|
} else {
|
|
110
137
|
;({ name } = declaration.id)
|
|
111
138
|
}
|
|
112
|
-
let dependencies =
|
|
139
|
+
let dependencies = []
|
|
140
|
+
if (declaration.init) {
|
|
141
|
+
dependencies = extractDependencies(declaration.init)
|
|
142
|
+
}
|
|
113
143
|
return {
|
|
114
144
|
size: rangeToDiff.rangeToDiff(declaration.range),
|
|
115
145
|
node: declaration,
|