eslint-plugin-perfectionist 3.3.0 → 3.5.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 (45) hide show
  1. package/dist/index.d.ts +243 -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 +234 -79
  11. package/dist/rules/sort-classes.mjs +232 -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 +46 -5
  17. package/dist/rules/sort-imports.mjs +46 -5
  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 +43 -14
  35. package/dist/rules/sort-variable-declarations.mjs +41 -10
  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
  45. package/readme.md +1 -0
@@ -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) => {
@@ -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 sortUnionTypes = 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 sortUnionTypes = 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,15 +1,14 @@
1
1
  'use strict'
2
+ const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
2
3
  const createEslintRule = require('../utils/create-eslint-rule.js')
3
4
  const getSourceCode = require('../utils/get-source-code.js')
4
5
  const toSingleLine = require('../utils/to-single-line.js')
5
6
  const rangeToDiff = require('../utils/range-to-diff.js')
6
7
  const getSettings = require('../utils/get-settings.js')
7
- const isPositive = require('../utils/is-positive.js')
8
8
  const sortNodes = require('../utils/sort-nodes.js')
9
9
  const makeFixes = require('../utils/make-fixes.js')
10
10
  const complete = require('../utils/complete.js')
11
11
  const pairwise = require('../utils/pairwise.js')
12
- const compare = require('../utils/compare.js')
13
12
  const sortVariableDeclarations = createEslintRule.createEslintRule({
14
13
  name: 'sort-variable-declarations',
15
14
  meta: {
@@ -70,15 +69,35 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
70
69
  }
71
70
  let dependencies = []
72
71
  let checkNode = nodeValue => {
72
+ if (
73
+ nodeValue.type === 'ArrowFunctionExpression' ||
74
+ nodeValue.type === 'FunctionExpression'
75
+ ) {
76
+ return
77
+ }
73
78
  if (nodeValue.type === 'Identifier') {
74
79
  dependencies.push(nodeValue.name)
75
80
  }
81
+ if (nodeValue.type === 'Property') {
82
+ traverseNode(nodeValue.key)
83
+ traverseNode(nodeValue.value)
84
+ }
85
+ if (nodeValue.type === 'ConditionalExpression') {
86
+ traverseNode(nodeValue.test)
87
+ traverseNode(nodeValue.consequent)
88
+ traverseNode(nodeValue.alternate)
89
+ }
76
90
  if (
77
- 'body' in nodeValue &&
78
- nodeValue.body &&
79
- !Array.isArray(nodeValue.body)
91
+ 'expression' in nodeValue &&
92
+ typeof nodeValue.expression !== 'boolean'
80
93
  ) {
81
- traverseNode(nodeValue.body)
94
+ traverseNode(nodeValue.expression)
95
+ }
96
+ if ('object' in nodeValue) {
97
+ traverseNode(nodeValue.object)
98
+ }
99
+ if ('callee' in nodeValue) {
100
+ traverseNode(nodeValue.callee)
82
101
  }
83
102
  if ('left' in nodeValue) {
84
103
  traverseNode(nodeValue.left)
@@ -90,9 +109,19 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
90
109
  nodeValue.elements
91
110
  .filter(currentNode => currentNode !== null)
92
111
  .forEach(traverseNode)
93
- } else if ('arguments' in nodeValue) {
112
+ }
113
+ if ('argument' in nodeValue && nodeValue.argument) {
114
+ traverseNode(nodeValue.argument)
115
+ }
116
+ if ('arguments' in nodeValue) {
94
117
  nodeValue.arguments.forEach(traverseNode)
95
118
  }
119
+ if ('properties' in nodeValue) {
120
+ nodeValue.properties.forEach(traverseNode)
121
+ }
122
+ if ('expressions' in nodeValue) {
123
+ nodeValue.expressions.forEach(traverseNode)
124
+ }
96
125
  }
97
126
  let traverseNode = nodeValue => {
98
127
  checkNode(nodeValue)
@@ -118,8 +147,13 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
118
147
  name,
119
148
  }
120
149
  })
150
+ let sortedNodes = sortNodesByDependencies.sortNodesByDependencies(
151
+ sortNodes.sortNodes(nodes, options),
152
+ )
121
153
  pairwise.pairwise(nodes, (left, right) => {
122
- if (isPositive.isPositive(compare.compare(left, right, options))) {
154
+ let indexOfLeft = sortedNodes.indexOf(left)
155
+ let indexOfRight = sortedNodes.indexOf(right)
156
+ if (indexOfLeft > indexOfRight) {
123
157
  context.report({
124
158
  messageId: 'unexpectedVariableDeclarationsOrder',
125
159
  data: {
@@ -128,12 +162,7 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
128
162
  },
129
163
  node: right.node,
130
164
  fix: fixer =>
131
- makeFixes.makeFixes(
132
- fixer,
133
- nodes,
134
- sortNodes.sortNodes(nodes, options),
135
- sourceCode,
136
- ),
165
+ makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode),
137
166
  })
138
167
  }
139
168
  })
@@ -1,14 +1,13 @@
1
+ import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.mjs'
1
2
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
2
3
  import { getSourceCode } from '../utils/get-source-code.mjs'
3
4
  import { toSingleLine } from '../utils/to-single-line.mjs'
4
5
  import { rangeToDiff } from '../utils/range-to-diff.mjs'
5
6
  import { getSettings } from '../utils/get-settings.mjs'
6
- import { isPositive } from '../utils/is-positive.mjs'
7
7
  import { sortNodes } from '../utils/sort-nodes.mjs'
8
8
  import { makeFixes } from '../utils/make-fixes.mjs'
9
9
  import { complete } from '../utils/complete.mjs'
10
10
  import { pairwise } from '../utils/pairwise.mjs'
11
- import { compare } from '../utils/compare.mjs'
12
11
  const sortVariableDeclarations = createEslintRule({
13
12
  name: 'sort-variable-declarations',
14
13
  meta: {
@@ -69,15 +68,35 @@ const sortVariableDeclarations = createEslintRule({
69
68
  }
70
69
  let dependencies = []
71
70
  let checkNode = nodeValue => {
71
+ if (
72
+ nodeValue.type === 'ArrowFunctionExpression' ||
73
+ nodeValue.type === 'FunctionExpression'
74
+ ) {
75
+ return
76
+ }
72
77
  if (nodeValue.type === 'Identifier') {
73
78
  dependencies.push(nodeValue.name)
74
79
  }
80
+ if (nodeValue.type === 'Property') {
81
+ traverseNode(nodeValue.key)
82
+ traverseNode(nodeValue.value)
83
+ }
84
+ if (nodeValue.type === 'ConditionalExpression') {
85
+ traverseNode(nodeValue.test)
86
+ traverseNode(nodeValue.consequent)
87
+ traverseNode(nodeValue.alternate)
88
+ }
75
89
  if (
76
- 'body' in nodeValue &&
77
- nodeValue.body &&
78
- !Array.isArray(nodeValue.body)
90
+ 'expression' in nodeValue &&
91
+ typeof nodeValue.expression !== 'boolean'
79
92
  ) {
80
- traverseNode(nodeValue.body)
93
+ traverseNode(nodeValue.expression)
94
+ }
95
+ if ('object' in nodeValue) {
96
+ traverseNode(nodeValue.object)
97
+ }
98
+ if ('callee' in nodeValue) {
99
+ traverseNode(nodeValue.callee)
81
100
  }
82
101
  if ('left' in nodeValue) {
83
102
  traverseNode(nodeValue.left)
@@ -89,9 +108,19 @@ const sortVariableDeclarations = createEslintRule({
89
108
  nodeValue.elements
90
109
  .filter(currentNode => currentNode !== null)
91
110
  .forEach(traverseNode)
92
- } else if ('arguments' in nodeValue) {
111
+ }
112
+ if ('argument' in nodeValue && nodeValue.argument) {
113
+ traverseNode(nodeValue.argument)
114
+ }
115
+ if ('arguments' in nodeValue) {
93
116
  nodeValue.arguments.forEach(traverseNode)
94
117
  }
118
+ if ('properties' in nodeValue) {
119
+ nodeValue.properties.forEach(traverseNode)
120
+ }
121
+ if ('expressions' in nodeValue) {
122
+ nodeValue.expressions.forEach(traverseNode)
123
+ }
95
124
  }
96
125
  let traverseNode = nodeValue => {
97
126
  checkNode(nodeValue)
@@ -117,8 +146,11 @@ const sortVariableDeclarations = createEslintRule({
117
146
  name,
118
147
  }
119
148
  })
149
+ let sortedNodes = sortNodesByDependencies(sortNodes(nodes, options))
120
150
  pairwise(nodes, (left, right) => {
121
- if (isPositive(compare(left, right, options))) {
151
+ let indexOfLeft = sortedNodes.indexOf(left)
152
+ let indexOfRight = sortedNodes.indexOf(right)
153
+ if (indexOfLeft > indexOfRight) {
122
154
  context.report({
123
155
  messageId: 'unexpectedVariableDeclarationsOrder',
124
156
  data: {
@@ -126,8 +158,7 @@ const sortVariableDeclarations = createEslintRule({
126
158
  right: toSingleLine(right.name),
127
159
  },
128
160
  node: right.node,
129
- fix: fixer =>
130
- makeFixes(fixer, nodes, sortNodes(nodes, options), sourceCode),
161
+ fix: fixer => makeFixes(fixer, nodes, sortedNodes, sourceCode),
131
162
  })
132
163
  }
133
164
  })
@@ -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')
@@ -111,6 +112,11 @@ const sortVueAttributes = createEslintRule.createEslintRule({
111
112
  order: 'asc',
112
113
  groups: [],
113
114
  })
115
+ validateGroupsConfiguration.validateGroupsConfiguration(
116
+ options.groups,
117
+ ['multiline', 'shorthand', 'unknown'],
118
+ Object.keys(options.customGroups),
119
+ )
114
120
  let parts = node.attributes.reduce(
115
121
  (accumulator, attribute) => {
116
122
  if (
@@ -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'
@@ -110,6 +111,11 @@ const sortVueAttributes = createEslintRule({
110
111
  order: 'asc',
111
112
  groups: [],
112
113
  })
114
+ validateGroupsConfiguration(
115
+ options.groups,
116
+ ['multiline', 'shorthand', 'unknown'],
117
+ Object.keys(options.customGroups),
118
+ )
113
119
  let parts = node.attributes.reduce(
114
120
  (accumulator, attribute) => {
115
121
  if (
@@ -2,12 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const naturalCompare = require('natural-compare-lite')
4
4
  let compare = (a, b, options) => {
5
- var _a, _b
6
- if ((_a = b.dependencies) == null ? void 0 : _a.includes(a.name)) {
7
- return -1
8
- } else if ((_b = a.dependencies) == null ? void 0 : _b.includes(b.name)) {
9
- return 1
10
- }
11
5
  let orderCoefficient = options.order === 'asc' ? 1 : -1
12
6
  let sortingFunction
13
7
  let formatString =
@@ -1,11 +1,5 @@
1
1
  import naturalCompare from 'natural-compare-lite'
2
2
  let compare = (a, b, options) => {
3
- var _a, _b
4
- if ((_a = b.dependencies) == null ? void 0 : _a.includes(a.name)) {
5
- return -1
6
- } else if ((_b = a.dependencies) == null ? void 0 : _b.includes(b.name)) {
7
- return 1
8
- }
9
3
  let orderCoefficient = options.order === 'asc' ? 1 : -1
10
4
  let sortingFunction
11
5
  let formatString =
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let sortNodesByDependencies = nodes => {
4
+ let result = []
5
+ let visitedNodes = /* @__PURE__ */ new Set()
6
+ let inProcessNodes = /* @__PURE__ */ new Set()
7
+ let visitNode = node => {
8
+ if (visitedNodes.has(node)) {
9
+ return
10
+ }
11
+ if (inProcessNodes.has(node)) {
12
+ return
13
+ }
14
+ inProcessNodes.add(node)
15
+ let dependentNodes = nodes.filter(n =>
16
+ node.dependencies.includes(n.dependencyName ?? n.name),
17
+ )
18
+ for (let dependentNode of dependentNodes) {
19
+ visitNode(dependentNode)
20
+ }
21
+ visitedNodes.add(node)
22
+ inProcessNodes.delete(node)
23
+ result.push(node)
24
+ }
25
+ for (let node of nodes) {
26
+ visitNode(node)
27
+ }
28
+ return result
29
+ }
30
+ exports.sortNodesByDependencies = sortNodesByDependencies
@@ -0,0 +1,28 @@
1
+ let sortNodesByDependencies = nodes => {
2
+ let result = []
3
+ let visitedNodes = /* @__PURE__ */ new Set()
4
+ let inProcessNodes = /* @__PURE__ */ new Set()
5
+ let visitNode = node => {
6
+ if (visitedNodes.has(node)) {
7
+ return
8
+ }
9
+ if (inProcessNodes.has(node)) {
10
+ return
11
+ }
12
+ inProcessNodes.add(node)
13
+ let dependentNodes = nodes.filter(n =>
14
+ node.dependencies.includes(n.dependencyName ?? n.name),
15
+ )
16
+ for (let dependentNode of dependentNodes) {
17
+ visitNode(dependentNode)
18
+ }
19
+ visitedNodes.add(node)
20
+ inProcessNodes.delete(node)
21
+ result.push(node)
22
+ }
23
+ for (let node of nodes) {
24
+ visitNode(node)
25
+ }
26
+ return result
27
+ }
28
+ export { sortNodesByDependencies }
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let validateGroupsConfiguration = (
4
+ groups,
5
+ allowedPredefinedGroups,
6
+ allowedCustomGroups,
7
+ ) => {
8
+ let allowedGroupsSet = /* @__PURE__ */ new Set([
9
+ ...allowedPredefinedGroups,
10
+ ...allowedCustomGroups,
11
+ ])
12
+ let invalidGroups = groups
13
+ .flat()
14
+ .filter(group => !allowedGroupsSet.has(group))
15
+ if (invalidGroups.length) {
16
+ throw new Error('Invalid group(s): ' + invalidGroups.join(', '))
17
+ }
18
+ }
19
+ exports.validateGroupsConfiguration = validateGroupsConfiguration
@@ -0,0 +1,17 @@
1
+ let validateGroupsConfiguration = (
2
+ groups,
3
+ allowedPredefinedGroups,
4
+ allowedCustomGroups,
5
+ ) => {
6
+ let allowedGroupsSet = /* @__PURE__ */ new Set([
7
+ ...allowedPredefinedGroups,
8
+ ...allowedCustomGroups,
9
+ ])
10
+ let invalidGroups = groups
11
+ .flat()
12
+ .filter(group => !allowedGroupsSet.has(group))
13
+ if (invalidGroups.length) {
14
+ throw new Error('Invalid group(s): ' + invalidGroups.join(', '))
15
+ }
16
+ }
17
+ export { validateGroupsConfiguration }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-perfectionist",
3
3
  "description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
4
- "version": "3.3.0",
4
+ "version": "3.5.0",
5
5
  "homepage": "https://perfectionist.dev",
6
6
  "repository": "azat-io/eslint-plugin-perfectionist",
7
7
  "author": "Azat S. <to@azat.io>",
@@ -53,9 +53,9 @@
53
53
  "vue-eslint-parser": ">=9.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@typescript-eslint/types": "^8.3.0",
57
- "@typescript-eslint/utils": "^8.3.0",
58
- "minimatch": "^10.0.1",
56
+ "@typescript-eslint/types": "^8.4.0",
57
+ "@typescript-eslint/utils": "^8.4.0",
58
+ "minimatch": "^9.0.5",
59
59
  "natural-compare-lite": "^1.4.0"
60
60
  }
61
61
  }
package/readme.md CHANGED
@@ -188,6 +188,7 @@ module.exports = {
188
188
  | [sort-named-imports](https://perfectionist.dev/rules/sort-named-imports) | Enforce sorted named imports | 🔧 |
189
189
  | [sort-object-types](https://perfectionist.dev/rules/sort-object-types) | Enforce sorted object types | 🔧 |
190
190
  | [sort-objects](https://perfectionist.dev/rules/sort-objects) | Enforce sorted objects | 🔧 |
191
+ | [sort-sets](https://perfectionist.dev/rules/sort-sets) | Enforce sorted Set elements | 🔧 |
191
192
  | [sort-svelte-attributes](https://perfectionist.dev/rules/sort-svelte-attributes) | Enforce sorted Svelte attributes | 🔧 |
192
193
  | [sort-switch-case](https://perfectionist.dev/rules/sort-switch-case) | Enforce sorted switch case statements | 🔧 |
193
194
  | [sort-union-types](https://perfectionist.dev/rules/sort-union-types) | Enforce sorted union types | 🔧 |