eslint-plugin-perfectionist 3.3.0 → 3.4.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 (44) hide show
  1. package/dist/index.d.ts +242 -21
  2. package/dist/index.js +3 -1
  3. package/dist/index.mjs +2 -0
  4. package/dist/rules/sort-array-includes.js +108 -107
  5. package/dist/rules/sort-array-includes.mjs +100 -100
  6. package/dist/rules/sort-astro-attributes.js +6 -0
  7. package/dist/rules/sort-astro-attributes.mjs +6 -0
  8. package/dist/rules/sort-classes-utils.js +71 -0
  9. package/dist/rules/sort-classes-utils.mjs +75 -1
  10. package/dist/rules/sort-classes.js +231 -79
  11. package/dist/rules/sort-classes.mjs +229 -69
  12. package/dist/rules/sort-classes.types.js +71 -0
  13. package/dist/rules/sort-classes.types.mjs +71 -0
  14. package/dist/rules/sort-enums.js +11 -15
  15. package/dist/rules/sort-enums.mjs +11 -11
  16. package/dist/rules/sort-imports.js +28 -0
  17. package/dist/rules/sort-imports.mjs +28 -0
  18. package/dist/rules/sort-interfaces.js +6 -0
  19. package/dist/rules/sort-interfaces.mjs +6 -0
  20. package/dist/rules/sort-intersection-types.js +20 -0
  21. package/dist/rules/sort-intersection-types.mjs +20 -0
  22. package/dist/rules/sort-jsx-props.js +6 -0
  23. package/dist/rules/sort-jsx-props.mjs +6 -0
  24. package/dist/rules/sort-object-types.js +6 -0
  25. package/dist/rules/sort-object-types.mjs +6 -0
  26. package/dist/rules/sort-objects.js +34 -43
  27. package/dist/rules/sort-objects.mjs +28 -30
  28. package/dist/rules/sort-sets.js +48 -0
  29. package/dist/rules/sort-sets.mjs +47 -0
  30. package/dist/rules/sort-svelte-attributes.js +6 -0
  31. package/dist/rules/sort-svelte-attributes.mjs +6 -0
  32. package/dist/rules/sort-union-types.js +20 -0
  33. package/dist/rules/sort-union-types.mjs +20 -0
  34. package/dist/rules/sort-variable-declarations.js +8 -9
  35. package/dist/rules/sort-variable-declarations.mjs +6 -5
  36. package/dist/rules/sort-vue-attributes.js +6 -0
  37. package/dist/rules/sort-vue-attributes.mjs +6 -0
  38. package/dist/utils/compare.js +0 -6
  39. package/dist/utils/compare.mjs +0 -6
  40. package/dist/utils/sort-nodes-by-dependencies.js +30 -0
  41. package/dist/utils/sort-nodes-by-dependencies.mjs +28 -0
  42. package/dist/utils/validate-groups-configuration.js +19 -0
  43. package/dist/utils/validate-groups-configuration.mjs +17 -0
  44. package/package.json +4 -4
@@ -1,3 +1,4 @@
1
+ import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.mjs'
1
2
  import { isPartitionComment } from '../utils/is-partition-comment.mjs'
2
3
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
3
4
  import { getCommentBefore } from '../utils/get-comment-before.mjs'
@@ -5,12 +6,10 @@ import { getSourceCode } from '../utils/get-source-code.mjs'
5
6
  import { toSingleLine } from '../utils/to-single-line.mjs'
6
7
  import { rangeToDiff } from '../utils/range-to-diff.mjs'
7
8
  import { getSettings } from '../utils/get-settings.mjs'
8
- import { isPositive } from '../utils/is-positive.mjs'
9
9
  import { sortNodes } from '../utils/sort-nodes.mjs'
10
10
  import { makeFixes } from '../utils/make-fixes.mjs'
11
11
  import { complete } from '../utils/complete.mjs'
12
12
  import { pairwise } from '../utils/pairwise.mjs'
13
- import { compare } from '../utils/compare.mjs'
14
13
  const sortEnums = createEslintRule({
15
14
  name: 'sort-enums',
16
15
  meta: {
@@ -149,7 +148,7 @@ const sortEnums = createEslintRule({
149
148
  member.id.type === 'Literal'
150
149
  ? `${member.id.value}`
151
150
  : `${sourceCode.text.slice(...member.id.range)}`
152
- let dependencies
151
+ let dependencies = []
153
152
  if (member.initializer) {
154
153
  dependencies = extractDependencies(
155
154
  member.initializer,
@@ -204,8 +203,13 @@ const sortEnums = createEslintRule({
204
203
  : void 0,
205
204
  }
206
205
  for (let nodes of formattedMembers) {
206
+ let sortedNodes = sortNodesByDependencies(
207
+ sortNodes(nodes, compareOptions),
208
+ )
207
209
  pairwise(nodes, (left, right) => {
208
- if (isPositive(compare(left, right, compareOptions))) {
210
+ let indexOfLeft = sortedNodes.indexOf(left)
211
+ let indexOfRight = sortedNodes.indexOf(right)
212
+ if (indexOfLeft > indexOfRight) {
209
213
  context.report({
210
214
  messageId: 'unexpectedEnumsOrder',
211
215
  data: {
@@ -214,13 +218,9 @@ const sortEnums = createEslintRule({
214
218
  },
215
219
  node: right.node,
216
220
  fix: fixer =>
217
- makeFixes(
218
- fixer,
219
- nodes,
220
- sortNodes(nodes, compareOptions),
221
- sourceCode,
222
- { partitionComment },
223
- ),
221
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, {
222
+ partitionComment,
223
+ }),
224
224
  })
225
225
  }
226
226
  })
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
  const node_module = require('node:module')
3
3
  const minimatch = require('minimatch')
4
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
4
5
  const getCommentBefore = require('../utils/get-comment-before.js')
5
6
  const createEslintRule = require('../utils/create-eslint-rule.js')
6
7
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -202,6 +203,33 @@ const sortImports = createEslintRule.createEslintRule({
202
203
  if (!hasUnknownGroup) {
203
204
  options.groups = [...options.groups, 'unknown']
204
205
  }
206
+ validateGroupsConfiguration.validateGroupsConfiguration(
207
+ options.groups,
208
+ [
209
+ 'side-effect-style',
210
+ 'external-type',
211
+ 'internal-type',
212
+ 'builtin-type',
213
+ 'sibling-type',
214
+ 'parent-type',
215
+ 'side-effect',
216
+ 'index-type',
217
+ 'internal',
218
+ 'external',
219
+ 'sibling',
220
+ 'unknown',
221
+ 'builtin',
222
+ 'parent',
223
+ 'object',
224
+ 'index',
225
+ 'style',
226
+ 'type',
227
+ ],
228
+ [
229
+ ...Object.keys(options.customGroups.type ?? {}),
230
+ ...Object.keys(options.customGroups.value ?? {}),
231
+ ],
232
+ )
205
233
  let nodes = []
206
234
  let isSideEffectImport = node =>
207
235
  node.type === 'ImportDeclaration' &&
@@ -1,5 +1,6 @@
1
1
  import { builtinModules } from 'node:module'
2
2
  import { minimatch } from 'minimatch'
3
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
3
4
  import { getCommentBefore } from '../utils/get-comment-before.mjs'
4
5
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
5
6
  import { getLinesBetween } from '../utils/get-lines-between.mjs'
@@ -201,6 +202,33 @@ const sortImports = createEslintRule({
201
202
  if (!hasUnknownGroup) {
202
203
  options.groups = [...options.groups, 'unknown']
203
204
  }
205
+ validateGroupsConfiguration(
206
+ options.groups,
207
+ [
208
+ 'side-effect-style',
209
+ 'external-type',
210
+ 'internal-type',
211
+ 'builtin-type',
212
+ 'sibling-type',
213
+ 'parent-type',
214
+ 'side-effect',
215
+ 'index-type',
216
+ 'internal',
217
+ 'external',
218
+ 'sibling',
219
+ 'unknown',
220
+ 'builtin',
221
+ 'parent',
222
+ 'object',
223
+ 'index',
224
+ 'style',
225
+ 'type',
226
+ ],
227
+ [
228
+ ...Object.keys(options.customGroups.type ?? {}),
229
+ ...Object.keys(options.customGroups.value ?? {}),
230
+ ],
231
+ )
204
232
  let nodes = []
205
233
  let isSideEffectImport = node =>
206
234
  node.type === 'ImportDeclaration' &&
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  const minimatch = require('minimatch')
3
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
3
4
  const createEslintRule = require('../utils/create-eslint-rule.js')
4
5
  const isMemberOptional = require('../utils/is-member-optional.js')
5
6
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -130,6 +131,11 @@ const sortInterfaces = createEslintRule.createEslintRule({
130
131
  order: 'asc',
131
132
  groups: [],
132
133
  })
134
+ validateGroupsConfiguration.validateGroupsConfiguration(
135
+ options.groups,
136
+ ['multiline', 'unknown'],
137
+ Object.keys(options.customGroups),
138
+ )
133
139
  let sourceCode = getSourceCode.getSourceCode(context)
134
140
  if (
135
141
  !options.ignorePattern.some(pattern =>
@@ -1,4 +1,5 @@
1
1
  import { minimatch } from 'minimatch'
2
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
2
3
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
3
4
  import { isMemberOptional } from '../utils/is-member-optional.mjs'
4
5
  import { getLinesBetween } from '../utils/get-lines-between.mjs'
@@ -129,6 +130,11 @@ const sortInterfaces = createEslintRule({
129
130
  order: 'asc',
130
131
  groups: [],
131
132
  })
133
+ validateGroupsConfiguration(
134
+ options.groups,
135
+ ['multiline', 'unknown'],
136
+ Object.keys(options.customGroups),
137
+ )
132
138
  let sourceCode = getSourceCode(context)
133
139
  if (
134
140
  !options.ignorePattern.some(pattern =>
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
2
3
  const createEslintRule = require('../utils/create-eslint-rule.js')
3
4
  const getGroupNumber = require('../utils/get-group-number.js')
4
5
  const getSourceCode = require('../utils/get-source-code.js')
@@ -83,6 +84,25 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
83
84
  order: 'asc',
84
85
  groups: [],
85
86
  })
87
+ validateGroupsConfiguration.validateGroupsConfiguration(
88
+ options.groups,
89
+ [
90
+ 'intersection',
91
+ 'conditional',
92
+ 'function',
93
+ 'operator',
94
+ 'keyword',
95
+ 'literal',
96
+ 'nullish',
97
+ 'unknown',
98
+ 'import',
99
+ 'object',
100
+ 'named',
101
+ 'tuple',
102
+ 'union',
103
+ ],
104
+ [],
105
+ )
86
106
  let sourceCode = getSourceCode.getSourceCode(context)
87
107
  let nodes = node.types.map(type => {
88
108
  let { getGroup, defineGroup } = useGroups.useGroups(options.groups)
@@ -1,3 +1,4 @@
1
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
1
2
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
2
3
  import { getGroupNumber } from '../utils/get-group-number.mjs'
3
4
  import { getSourceCode } from '../utils/get-source-code.mjs'
@@ -82,6 +83,25 @@ const sortIntersectionTypes = createEslintRule({
82
83
  order: 'asc',
83
84
  groups: [],
84
85
  })
86
+ validateGroupsConfiguration(
87
+ options.groups,
88
+ [
89
+ 'intersection',
90
+ 'conditional',
91
+ 'function',
92
+ 'operator',
93
+ 'keyword',
94
+ 'literal',
95
+ 'nullish',
96
+ 'unknown',
97
+ 'import',
98
+ 'object',
99
+ 'named',
100
+ 'tuple',
101
+ 'union',
102
+ ],
103
+ [],
104
+ )
85
105
  let sourceCode = getSourceCode(context)
86
106
  let nodes = node.types.map(type => {
87
107
  let { getGroup, defineGroup } = useGroups(options.groups)
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  const minimatch = require('minimatch')
3
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
3
4
  const createEslintRule = require('../utils/create-eslint-rule.js')
4
5
  const getGroupNumber = require('../utils/get-group-number.js')
5
6
  const getSourceCode = require('../utils/get-source-code.js')
@@ -113,6 +114,11 @@ const sortJsxProps = createEslintRule.createEslintRule({
113
114
  order: 'asc',
114
115
  groups: [],
115
116
  })
117
+ validateGroupsConfiguration.validateGroupsConfiguration(
118
+ options.groups,
119
+ ['multiline', 'shorthand', 'unknown'],
120
+ Object.keys(options.customGroups),
121
+ )
116
122
  let sourceCode = getSourceCode.getSourceCode(context)
117
123
  let shouldIgnore = false
118
124
  if (options.ignorePattern.length) {
@@ -1,4 +1,5 @@
1
1
  import { minimatch } from 'minimatch'
2
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
2
3
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
3
4
  import { getGroupNumber } from '../utils/get-group-number.mjs'
4
5
  import { getSourceCode } from '../utils/get-source-code.mjs'
@@ -112,6 +113,11 @@ const sortJsxProps = createEslintRule({
112
113
  order: 'asc',
113
114
  groups: [],
114
115
  })
116
+ validateGroupsConfiguration(
117
+ options.groups,
118
+ ['multiline', 'shorthand', 'unknown'],
119
+ Object.keys(options.customGroups),
120
+ )
115
121
  let sourceCode = getSourceCode(context)
116
122
  let shouldIgnore = false
117
123
  if (options.ignorePattern.length) {
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
2
3
  const createEslintRule = require('../utils/create-eslint-rule.js')
3
4
  const getLinesBetween = require('../utils/get-lines-between.js')
4
5
  const getGroupNumber = require('../utils/get-group-number.js')
@@ -118,6 +119,11 @@ const sortObjectTypes = createEslintRule.createEslintRule({
118
119
  order: 'asc',
119
120
  groups: [],
120
121
  })
122
+ validateGroupsConfiguration.validateGroupsConfiguration(
123
+ options.groups,
124
+ ['multiline', 'unknown'],
125
+ Object.keys(options.customGroups),
126
+ )
121
127
  let sourceCode = getSourceCode.getSourceCode(context)
122
128
  let formattedMembers = node.members.reduce(
123
129
  (accumulator, member) => {
@@ -1,3 +1,4 @@
1
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
1
2
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
2
3
  import { getLinesBetween } from '../utils/get-lines-between.mjs'
3
4
  import { getGroupNumber } from '../utils/get-group-number.mjs'
@@ -117,6 +118,11 @@ const sortObjectTypes = createEslintRule({
117
118
  order: 'asc',
118
119
  groups: [],
119
120
  })
121
+ validateGroupsConfiguration(
122
+ options.groups,
123
+ ['multiline', 'unknown'],
124
+ Object.keys(options.customGroups),
125
+ )
120
126
  let sourceCode = getSourceCode(context)
121
127
  let formattedMembers = node.members.reduce(
122
128
  (accumulator, member) => {
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
  const minimatch = require('minimatch')
3
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
4
+ const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
3
5
  const isPartitionComment = require('../utils/is-partition-comment.js')
4
6
  const getCommentBefore = require('../utils/get-comment-before.js')
5
7
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -10,13 +12,11 @@ const getNodeParent = require('../utils/get-node-parent.js')
10
12
  const toSingleLine = require('../utils/to-single-line.js')
11
13
  const rangeToDiff = require('../utils/range-to-diff.js')
12
14
  const getSettings = require('../utils/get-settings.js')
13
- const isPositive = require('../utils/is-positive.js')
14
15
  const useGroups = require('../utils/use-groups.js')
15
16
  const makeFixes = require('../utils/make-fixes.js')
16
17
  const sortNodes = require('../utils/sort-nodes.js')
17
18
  const complete = require('../utils/complete.js')
18
19
  const pairwise = require('../utils/pairwise.js')
19
- const compare = require('../utils/compare.js')
20
20
  const sortObjects = createEslintRule.createEslintRule({
21
21
  name: 'sort-objects',
22
22
  meta: {
@@ -155,6 +155,11 @@ const sortObjects = createEslintRule.createEslintRule({
155
155
  order: 'asc',
156
156
  groups: [],
157
157
  })
158
+ validateGroupsConfiguration.validateGroupsConfiguration(
159
+ options.groups,
160
+ ['unknown'],
161
+ Object.keys(options.customGroups),
162
+ )
158
163
  let shouldIgnore = false
159
164
  if (options.destructureOnly) {
160
165
  shouldIgnore = node.type !== 'ObjectPattern'
@@ -327,48 +332,34 @@ const sortObjects = createEslintRule.createEslintRule({
327
332
  [[]],
328
333
  )
329
334
  for (let nodes of formatProperties(node.properties)) {
335
+ let grouped = {}
336
+ for (let currentNode of nodes) {
337
+ let groupNum = getGroupNumber.getGroupNumber(
338
+ options.groups,
339
+ currentNode,
340
+ )
341
+ if (!(groupNum in grouped)) {
342
+ grouped[groupNum] = [currentNode]
343
+ } else {
344
+ grouped[groupNum].push(currentNode)
345
+ }
346
+ }
347
+ let sortedNodes = []
348
+ for (let group of Object.keys(grouped).sort(
349
+ (a, b) => Number(a) - Number(b),
350
+ )) {
351
+ sortedNodes.push(...sortNodes.sortNodes(grouped[group], options))
352
+ }
353
+ sortedNodes =
354
+ sortNodesByDependencies.sortNodesByDependencies(sortedNodes)
330
355
  pairwise.pairwise(nodes, (left, right) => {
331
- let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
332
- let rightNum = getGroupNumber.getGroupNumber(options.groups, right)
333
- if (
334
- leftNum > rightNum ||
335
- (leftNum === rightNum &&
336
- isPositive.isPositive(compare.compare(left, right, options)))
337
- ) {
338
- let fix = fixer => {
339
- let grouped = {}
340
- for (let currentNode of nodes) {
341
- let groupNum = getGroupNumber.getGroupNumber(
342
- options.groups,
343
- currentNode,
344
- )
345
- if (!(groupNum in grouped)) {
346
- grouped[groupNum] = [currentNode]
347
- } else {
348
- grouped[groupNum] = sortNodes.sortNodes(
349
- [...grouped[groupNum], currentNode],
350
- options,
351
- )
352
- }
353
- }
354
- let sortedNodes = []
355
- for (let group of Object.keys(grouped).sort(
356
- (a, b) => Number(a) - Number(b),
357
- )) {
358
- sortedNodes.push(
359
- ...sortNodes.sortNodes(grouped[group], options),
360
- )
361
- }
362
- return makeFixes.makeFixes(
363
- fixer,
364
- nodes,
365
- sortedNodes,
366
- sourceCode,
367
- {
368
- partitionComment: options.partitionByComment,
369
- },
370
- )
371
- }
356
+ let indexOfLeft = sortedNodes.indexOf(left)
357
+ let indexOfRight = sortedNodes.indexOf(right)
358
+ if (indexOfLeft > indexOfRight) {
359
+ let fix = fixer =>
360
+ makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
361
+ partitionComment: options.partitionByComment,
362
+ })
372
363
  context.report({
373
364
  messageId: 'unexpectedObjectsOrder',
374
365
  data: {
@@ -1,4 +1,6 @@
1
1
  import { minimatch } from 'minimatch'
2
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
3
+ import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.mjs'
2
4
  import { isPartitionComment } from '../utils/is-partition-comment.mjs'
3
5
  import { getCommentBefore } from '../utils/get-comment-before.mjs'
4
6
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
@@ -9,13 +11,11 @@ import { getNodeParent } from '../utils/get-node-parent.mjs'
9
11
  import { toSingleLine } from '../utils/to-single-line.mjs'
10
12
  import { rangeToDiff } from '../utils/range-to-diff.mjs'
11
13
  import { getSettings } from '../utils/get-settings.mjs'
12
- import { isPositive } from '../utils/is-positive.mjs'
13
14
  import { useGroups } from '../utils/use-groups.mjs'
14
15
  import { makeFixes } from '../utils/make-fixes.mjs'
15
16
  import { sortNodes } from '../utils/sort-nodes.mjs'
16
17
  import { complete } from '../utils/complete.mjs'
17
18
  import { pairwise } from '../utils/pairwise.mjs'
18
- import { compare } from '../utils/compare.mjs'
19
19
  const sortObjects = createEslintRule({
20
20
  name: 'sort-objects',
21
21
  meta: {
@@ -154,6 +154,11 @@ const sortObjects = createEslintRule({
154
154
  order: 'asc',
155
155
  groups: [],
156
156
  })
157
+ validateGroupsConfiguration(
158
+ options.groups,
159
+ ['unknown'],
160
+ Object.keys(options.customGroups),
161
+ )
157
162
  let shouldIgnore = false
158
163
  if (options.destructureOnly) {
159
164
  shouldIgnore = node.type !== 'ObjectPattern'
@@ -314,37 +319,30 @@ const sortObjects = createEslintRule({
314
319
  [[]],
315
320
  )
316
321
  for (let nodes of formatProperties(node.properties)) {
322
+ let grouped = {}
323
+ for (let currentNode of nodes) {
324
+ let groupNum = getGroupNumber(options.groups, currentNode)
325
+ if (!(groupNum in grouped)) {
326
+ grouped[groupNum] = [currentNode]
327
+ } else {
328
+ grouped[groupNum].push(currentNode)
329
+ }
330
+ }
331
+ let sortedNodes = []
332
+ for (let group of Object.keys(grouped).sort(
333
+ (a, b) => Number(a) - Number(b),
334
+ )) {
335
+ sortedNodes.push(...sortNodes(grouped[group], options))
336
+ }
337
+ sortedNodes = sortNodesByDependencies(sortedNodes)
317
338
  pairwise(nodes, (left, right) => {
318
- let leftNum = getGroupNumber(options.groups, left)
319
- let rightNum = getGroupNumber(options.groups, right)
320
- if (
321
- leftNum > rightNum ||
322
- (leftNum === rightNum &&
323
- isPositive(compare(left, right, options)))
324
- ) {
325
- let fix = fixer => {
326
- let grouped = {}
327
- for (let currentNode of nodes) {
328
- let groupNum = getGroupNumber(options.groups, currentNode)
329
- if (!(groupNum in grouped)) {
330
- grouped[groupNum] = [currentNode]
331
- } else {
332
- grouped[groupNum] = sortNodes(
333
- [...grouped[groupNum], currentNode],
334
- options,
335
- )
336
- }
337
- }
338
- let sortedNodes = []
339
- for (let group of Object.keys(grouped).sort(
340
- (a, b) => Number(a) - Number(b),
341
- )) {
342
- sortedNodes.push(...sortNodes(grouped[group], options))
343
- }
344
- return makeFixes(fixer, nodes, sortedNodes, sourceCode, {
339
+ let indexOfLeft = sortedNodes.indexOf(left)
340
+ let indexOfRight = sortedNodes.indexOf(right)
341
+ if (indexOfLeft > indexOfRight) {
342
+ let fix = fixer =>
343
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, {
345
344
  partitionComment: options.partitionByComment,
346
345
  })
347
- }
348
346
  context.report({
349
347
  messageId: 'unexpectedObjectsOrder',
350
348
  data: {
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+ const createEslintRule = require('../utils/create-eslint-rule.js')
3
+ const sortArrayIncludes = require('./sort-array-includes.js')
4
+ const sortSets = createEslintRule.createEslintRule({
5
+ name: 'sort-sets',
6
+ meta: {
7
+ type: 'suggestion',
8
+ docs: {
9
+ description: 'Enforce sorted sets.',
10
+ },
11
+ fixable: 'code',
12
+ schema: [sortArrayIncludes.jsonSchema],
13
+ messages: {
14
+ unexpectedSetsOrder: 'Expected "{{right}}" to come before "{{left}}".',
15
+ },
16
+ },
17
+ defaultOptions: [
18
+ {
19
+ type: 'alphabetical',
20
+ order: 'asc',
21
+ ignoreCase: true,
22
+ groupKind: 'literals-first',
23
+ },
24
+ ],
25
+ create: context => ({
26
+ NewExpression: node => {
27
+ var _a, _b
28
+ if (
29
+ node.callee.type === 'Identifier' &&
30
+ node.callee.name === 'Set' &&
31
+ node.arguments.length &&
32
+ (((_a = node.arguments[0]) == null ? void 0 : _a.type) ===
33
+ 'ArrayExpression' ||
34
+ (((_b = node.arguments[0]) == null ? void 0 : _b.type) ===
35
+ 'NewExpression' &&
36
+ 'name' in node.arguments[0].callee &&
37
+ node.arguments[0].callee.name === 'Array'))
38
+ ) {
39
+ let elements =
40
+ node.arguments[0].type === 'ArrayExpression'
41
+ ? node.arguments[0].elements
42
+ : node.arguments[0].arguments
43
+ sortArrayIncludes.sortArray(context, 'unexpectedSetsOrder', elements)
44
+ }
45
+ },
46
+ }),
47
+ })
48
+ module.exports = sortSets
@@ -0,0 +1,47 @@
1
+ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
2
+ import { jsonSchema, sortArray } from './sort-array-includes.mjs'
3
+ const sortSets = createEslintRule({
4
+ name: 'sort-sets',
5
+ meta: {
6
+ type: 'suggestion',
7
+ docs: {
8
+ description: 'Enforce sorted sets.',
9
+ },
10
+ fixable: 'code',
11
+ schema: [jsonSchema],
12
+ messages: {
13
+ unexpectedSetsOrder: 'Expected "{{right}}" to come before "{{left}}".',
14
+ },
15
+ },
16
+ defaultOptions: [
17
+ {
18
+ type: 'alphabetical',
19
+ order: 'asc',
20
+ ignoreCase: true,
21
+ groupKind: 'literals-first',
22
+ },
23
+ ],
24
+ create: context => ({
25
+ NewExpression: node => {
26
+ var _a, _b
27
+ if (
28
+ node.callee.type === 'Identifier' &&
29
+ node.callee.name === 'Set' &&
30
+ node.arguments.length &&
31
+ (((_a = node.arguments[0]) == null ? void 0 : _a.type) ===
32
+ 'ArrayExpression' ||
33
+ (((_b = node.arguments[0]) == null ? void 0 : _b.type) ===
34
+ 'NewExpression' &&
35
+ 'name' in node.arguments[0].callee &&
36
+ node.arguments[0].callee.name === 'Array'))
37
+ ) {
38
+ let elements =
39
+ node.arguments[0].type === 'ArrayExpression'
40
+ ? node.arguments[0].elements
41
+ : node.arguments[0].arguments
42
+ sortArray(context, 'unexpectedSetsOrder', elements)
43
+ }
44
+ },
45
+ }),
46
+ })
47
+ export { sortSets as default }
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  const path = require('node:path')
3
+ const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
3
4
  const createEslintRule = require('../utils/create-eslint-rule.js')
4
5
  const getGroupNumber = require('../utils/get-group-number.js')
5
6
  const getSourceCode = require('../utils/get-source-code.js')
@@ -107,6 +108,11 @@ const sortSvelteAttributes = createEslintRule.createEslintRule({
107
108
  order: 'asc',
108
109
  groups: [],
109
110
  })
111
+ validateGroupsConfiguration.validateGroupsConfiguration(
112
+ options.groups,
113
+ ['svelte-shorthand', 'multiline', 'shorthand', 'unknown'],
114
+ Object.keys(options.customGroups),
115
+ )
110
116
  let sourceCode = getSourceCode.getSourceCode(context)
111
117
  let parts = node.attributes.reduce(
112
118
  (accumulator, attribute) => {
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path'
2
+ import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
2
3
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
3
4
  import { getGroupNumber } from '../utils/get-group-number.mjs'
4
5
  import { getSourceCode } from '../utils/get-source-code.mjs'
@@ -106,6 +107,11 @@ const sortSvelteAttributes = createEslintRule({
106
107
  order: 'asc',
107
108
  groups: [],
108
109
  })
110
+ validateGroupsConfiguration(
111
+ options.groups,
112
+ ['svelte-shorthand', 'multiline', 'shorthand', 'unknown'],
113
+ Object.keys(options.customGroups),
114
+ )
109
115
  let sourceCode = getSourceCode(context)
110
116
  let parts = node.attributes.reduce(
111
117
  (accumulator, attribute) => {