eslint-plugin-perfectionist 3.5.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.
Files changed (36) hide show
  1. package/dist/index.d.ts +13 -9
  2. package/dist/rules/sort-astro-attributes.js +8 -1
  3. package/dist/rules/sort-astro-attributes.mjs +8 -1
  4. package/dist/rules/sort-classes.js +7 -5
  5. package/dist/rules/sort-classes.mjs +4 -5
  6. package/dist/rules/sort-enums.js +9 -7
  7. package/dist/rules/sort-enums.mjs +7 -5
  8. package/dist/rules/sort-imports.js +14 -10
  9. package/dist/rules/sort-imports.mjs +13 -9
  10. package/dist/rules/sort-interfaces.js +16 -1
  11. package/dist/rules/sort-interfaces.mjs +10 -1
  12. package/dist/rules/sort-intersection-types.js +8 -1
  13. package/dist/rules/sort-intersection-types.mjs +8 -1
  14. package/dist/rules/sort-jsx-props.js +8 -1
  15. package/dist/rules/sort-jsx-props.mjs +8 -1
  16. package/dist/rules/sort-object-types.js +8 -1
  17. package/dist/rules/sort-object-types.mjs +8 -1
  18. package/dist/rules/sort-objects.js +84 -50
  19. package/dist/rules/sort-objects.mjs +78 -50
  20. package/dist/rules/sort-svelte-attributes.js +8 -1
  21. package/dist/rules/sort-svelte-attributes.mjs +8 -1
  22. package/dist/rules/sort-union-types.js +8 -1
  23. package/dist/rules/sort-union-types.mjs +8 -1
  24. package/dist/rules/sort-variable-declarations.js +4 -4
  25. package/dist/rules/sort-variable-declarations.mjs +4 -4
  26. package/dist/rules/sort-vue-attributes.js +8 -1
  27. package/dist/rules/sort-vue-attributes.mjs +8 -1
  28. package/dist/utils/get-comments-before.js +12 -0
  29. package/dist/utils/get-comments-before.mjs +10 -0
  30. package/dist/utils/get-node-range.js +26 -12
  31. package/dist/utils/get-node-range.mjs +26 -12
  32. package/dist/utils/is-partition-comment.js +3 -0
  33. package/dist/utils/is-partition-comment.mjs +3 -1
  34. package/package.json +4 -4
  35. package/dist/utils/get-comment-before.js +0 -23
  36. package/dist/utils/get-comment-before.mjs +0 -21
@@ -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 getCommentBefore = require('../utils/get-comment-before.js')
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 comment = getCommentBefore.getCommentBefore(prop, sourceCode)
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
- comment &&
240
- isPartitionComment.isPartitionComment(
307
+ isPartitionComment.hasPartitionComment(
241
308
  options.partitionByComment,
242
- comment.value,
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
- let addDependencies = value2 => {
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: 'unexpectedObjectsOrder',
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 { isPartitionComment } from '../utils/is-partition-comment.mjs'
5
- import { getCommentBefore } from '../utils/get-comment-before.mjs'
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 comment = getCommentBefore(prop, sourceCode)
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
- comment &&
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
- let addDependencies = value2 => {
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: 'unexpectedObjectsOrder',
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: 'unexpectedSvelteAttributesOrder',
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: 'unexpectedSvelteAttributesOrder',
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: 'unexpectedUnionTypesOrder',
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: 'unexpectedUnionTypesOrder',
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,9 +64,6 @@ 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 => {
72
69
  if (
@@ -139,7 +136,10 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
139
136
  } else {
140
137
  ;({ name } = declaration.id)
141
138
  }
142
- let dependencies = extractDependencies(declaration.init)
139
+ let dependencies = []
140
+ if (declaration.init) {
141
+ dependencies = extractDependencies(declaration.init)
142
+ }
143
143
  return {
144
144
  size: rangeToDiff.rangeToDiff(declaration.range),
145
145
  node: declaration,
@@ -63,9 +63,6 @@ const sortVariableDeclarations = createEslintRule({
63
63
  })
64
64
  let sourceCode = getSourceCode(context)
65
65
  let extractDependencies = init => {
66
- if (!init) {
67
- return []
68
- }
69
66
  let dependencies = []
70
67
  let checkNode = nodeValue => {
71
68
  if (
@@ -138,7 +135,10 @@ const sortVariableDeclarations = createEslintRule({
138
135
  } else {
139
136
  ;({ name } = declaration.id)
140
137
  }
141
- let dependencies = extractDependencies(declaration.init)
138
+ let dependencies = []
139
+ if (declaration.init) {
140
+ dependencies = extractDependencies(declaration.init)
141
+ }
142
142
  return {
143
143
  size: rangeToDiff(declaration.range),
144
144
  node: declaration,
@@ -79,6 +79,8 @@ const sortVueAttributes = createEslintRule.createEslintRule({
79
79
  },
80
80
  ],
81
81
  messages: {
82
+ unexpectedVueAttributesGroupOrder:
83
+ 'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
82
84
  unexpectedVueAttributesOrder:
83
85
  'Expected "{{right}}" to come before "{{left}}".',
84
86
  },
@@ -167,10 +169,15 @@ const sortVueAttributes = createEslintRule.createEslintRule({
167
169
  isPositive.isPositive(compare.compare(left, right, options)))
168
170
  ) {
169
171
  context.report({
170
- messageId: 'unexpectedVueAttributesOrder',
172
+ messageId:
173
+ leftNum !== rightNum
174
+ ? 'unexpectedVueAttributesGroupOrder'
175
+ : 'unexpectedVueAttributesOrder',
171
176
  data: {
172
177
  left: left.name,
178
+ leftGroup: left.group,
173
179
  right: right.name,
180
+ rightGroup: right.group,
174
181
  },
175
182
  // @ts-ignore
176
183
  node: right.node,
@@ -78,6 +78,8 @@ const sortVueAttributes = createEslintRule({
78
78
  },
79
79
  ],
80
80
  messages: {
81
+ unexpectedVueAttributesGroupOrder:
82
+ 'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
81
83
  unexpectedVueAttributesOrder:
82
84
  'Expected "{{right}}" to come before "{{left}}".',
83
85
  },
@@ -164,10 +166,15 @@ const sortVueAttributes = createEslintRule({
164
166
  isPositive(compare(left, right, options)))
165
167
  ) {
166
168
  context.report({
167
- messageId: 'unexpectedVueAttributesOrder',
169
+ messageId:
170
+ leftNum !== rightNum
171
+ ? 'unexpectedVueAttributesGroupOrder'
172
+ : 'unexpectedVueAttributesOrder',
168
173
  data: {
169
174
  left: left.name,
175
+ leftGroup: left.group,
170
176
  right: right.name,
177
+ rightGroup: right.group,
171
178
  },
172
179
  // @ts-ignore
173
180
  node: right.node,
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let getCommentsBefore = (node, source) =>
4
+ source.getCommentsBefore(node).filter(comment => {
5
+ let tokenBeforeComment = source.getTokenBefore(comment)
6
+ return (
7
+ (tokenBeforeComment == null
8
+ ? void 0
9
+ : tokenBeforeComment.loc.end.line) !== comment.loc.end.line
10
+ )
11
+ })
12
+ exports.getCommentsBefore = getCommentsBefore
@@ -0,0 +1,10 @@
1
+ let getCommentsBefore = (node, source) =>
2
+ source.getCommentsBefore(node).filter(comment => {
3
+ let tokenBeforeComment = source.getTokenBefore(comment)
4
+ return (
5
+ (tokenBeforeComment == null
6
+ ? void 0
7
+ : tokenBeforeComment.loc.end.line) !== comment.loc.end.line
8
+ )
9
+ })
10
+ export { getCommentsBefore }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const utils = require('@typescript-eslint/utils')
4
4
  const isPartitionComment = require('./is-partition-comment.js')
5
- const getCommentBefore = require('./get-comment-before.js')
5
+ const getCommentsBefore = require('./get-comments-before.js')
6
6
  let getNodeRange = (node, sourceCode, additionalOptions) => {
7
7
  var _a
8
8
  let start = node.range.at(0)
@@ -20,7 +20,6 @@ let getNodeRange = (node, sourceCode, additionalOptions) => {
20
20
  start = bodyOpeningParen.range.at(0)
21
21
  end = bodyClosingParen.range.at(1)
22
22
  }
23
- let comment = getCommentBefore.getCommentBefore(node, sourceCode)
24
23
  if (raw.endsWith(';') || raw.endsWith(',')) {
25
24
  let tokensAfter = sourceCode.getTokensAfter(node, {
26
25
  includeComments: true,
@@ -33,16 +32,31 @@ let getNodeRange = (node, sourceCode, additionalOptions) => {
33
32
  end -= 1
34
33
  }
35
34
  }
36
- if (
37
- comment &&
38
- !isPartitionComment.isPartitionComment(
39
- (additionalOptions == null
40
- ? void 0
41
- : additionalOptions.partitionComment) ?? false,
42
- comment.value,
43
- )
44
- ) {
45
- start = comment.range.at(0)
35
+ let comments = getCommentsBefore.getCommentsBefore(node, sourceCode)
36
+ let relevantTopComment
37
+ for (let i = comments.length - 1; i >= 0; i--) {
38
+ let comment = comments[i]
39
+ if (
40
+ isPartitionComment.isPartitionComment(
41
+ (additionalOptions == null
42
+ ? void 0
43
+ : additionalOptions.partitionComment) ?? false,
44
+ comment.value,
45
+ )
46
+ ) {
47
+ break
48
+ }
49
+ let previousCommentOrNodeStartLine =
50
+ i === comments.length - 1
51
+ ? node.loc.start.line
52
+ : comments[i + 1].loc.start.line
53
+ if (comment.loc.end.line !== previousCommentOrNodeStartLine - 1) {
54
+ break
55
+ }
56
+ relevantTopComment = comment
57
+ }
58
+ if (relevantTopComment) {
59
+ start = relevantTopComment.range.at(0)
46
60
  }
47
61
  return [start, end]
48
62
  }