eslint-plugin-perfectionist 3.4.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.
- package/dist/index.d.ts +1 -0
- package/dist/rules/sort-classes.js +3 -0
- package/dist/rules/sort-classes.mjs +3 -0
- package/dist/rules/sort-imports.js +18 -5
- package/dist/rules/sort-imports.mjs +18 -5
- package/dist/rules/sort-variable-declarations.js +35 -5
- package/dist/rules/sort-variable-declarations.mjs +35 -5
- package/package.json +1 -1
- package/readme.md +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -292,6 +292,9 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
292
292
|
if ('properties' in nodeValue) {
|
|
293
293
|
nodeValue.properties.forEach(traverseNode)
|
|
294
294
|
}
|
|
295
|
+
if ('expressions' in nodeValue) {
|
|
296
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
297
|
+
}
|
|
295
298
|
}
|
|
296
299
|
let traverseNode = nodeValue => {
|
|
297
300
|
if (Array.isArray(nodeValue)) {
|
|
@@ -300,6 +300,9 @@ const sortClasses = createEslintRule({
|
|
|
300
300
|
if ('properties' in nodeValue) {
|
|
301
301
|
nodeValue.properties.forEach(traverseNode)
|
|
302
302
|
}
|
|
303
|
+
if ('expressions' in nodeValue) {
|
|
304
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
305
|
+
}
|
|
303
306
|
}
|
|
304
307
|
let traverseNode = nodeValue => {
|
|
305
308
|
if (Array.isArray(nodeValue)) {
|
|
@@ -52,6 +52,11 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
52
52
|
},
|
|
53
53
|
type: 'array',
|
|
54
54
|
},
|
|
55
|
+
sortSideEffects: {
|
|
56
|
+
description:
|
|
57
|
+
'Controls whether side-effect imports should be sorted.',
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
},
|
|
55
60
|
newlinesBetween: {
|
|
56
61
|
description:
|
|
57
62
|
'Specifies how new lines should be handled between import groups.',
|
|
@@ -148,6 +153,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
148
153
|
order: 'asc',
|
|
149
154
|
ignoreCase: true,
|
|
150
155
|
internalPattern: ['~/**'],
|
|
156
|
+
sortSideEffects: false,
|
|
151
157
|
newlinesBetween: 'always',
|
|
152
158
|
maxLineLength: void 0,
|
|
153
159
|
groups: [
|
|
@@ -180,6 +186,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
180
186
|
customGroups: { type: {}, value: {} },
|
|
181
187
|
internalPattern: ['~/**'],
|
|
182
188
|
newlinesBetween: 'always',
|
|
189
|
+
sortSideEffects: false,
|
|
183
190
|
type: 'alphabetical',
|
|
184
191
|
environment: 'node',
|
|
185
192
|
ignoreCase: true,
|
|
@@ -418,10 +425,14 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
418
425
|
if (!(groupNum in grouped)) {
|
|
419
426
|
grouped[groupNum] = [node]
|
|
420
427
|
} else {
|
|
421
|
-
|
|
422
|
-
[...grouped[groupNum], node]
|
|
423
|
-
|
|
424
|
-
|
|
428
|
+
if (!options.sortSideEffects && isSideEffectImport(node.node)) {
|
|
429
|
+
grouped[groupNum] = [...grouped[groupNum], node]
|
|
430
|
+
} else {
|
|
431
|
+
grouped[groupNum] = sortNodes.sortNodes(
|
|
432
|
+
[...grouped[groupNum], node],
|
|
433
|
+
options,
|
|
434
|
+
)
|
|
435
|
+
}
|
|
425
436
|
}
|
|
426
437
|
}
|
|
427
438
|
let formatted = Object.keys(grouped)
|
|
@@ -529,7 +540,9 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
529
540
|
)
|
|
530
541
|
if (
|
|
531
542
|
!(
|
|
532
|
-
|
|
543
|
+
!options.sortSideEffects &&
|
|
544
|
+
isSideEffectImport(left.node) &&
|
|
545
|
+
isSideEffectImport(right.node)
|
|
533
546
|
) &&
|
|
534
547
|
!hasContentBetweenNodes(left, right) &&
|
|
535
548
|
(leftNum > rightNum ||
|
|
@@ -51,6 +51,11 @@ const sortImports = createEslintRule({
|
|
|
51
51
|
},
|
|
52
52
|
type: 'array',
|
|
53
53
|
},
|
|
54
|
+
sortSideEffects: {
|
|
55
|
+
description:
|
|
56
|
+
'Controls whether side-effect imports should be sorted.',
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
},
|
|
54
59
|
newlinesBetween: {
|
|
55
60
|
description:
|
|
56
61
|
'Specifies how new lines should be handled between import groups.',
|
|
@@ -147,6 +152,7 @@ const sortImports = createEslintRule({
|
|
|
147
152
|
order: 'asc',
|
|
148
153
|
ignoreCase: true,
|
|
149
154
|
internalPattern: ['~/**'],
|
|
155
|
+
sortSideEffects: false,
|
|
150
156
|
newlinesBetween: 'always',
|
|
151
157
|
maxLineLength: void 0,
|
|
152
158
|
groups: [
|
|
@@ -179,6 +185,7 @@ const sortImports = createEslintRule({
|
|
|
179
185
|
customGroups: { type: {}, value: {} },
|
|
180
186
|
internalPattern: ['~/**'],
|
|
181
187
|
newlinesBetween: 'always',
|
|
188
|
+
sortSideEffects: false,
|
|
182
189
|
type: 'alphabetical',
|
|
183
190
|
environment: 'node',
|
|
184
191
|
ignoreCase: true,
|
|
@@ -412,10 +419,14 @@ const sortImports = createEslintRule({
|
|
|
412
419
|
if (!(groupNum in grouped)) {
|
|
413
420
|
grouped[groupNum] = [node]
|
|
414
421
|
} else {
|
|
415
|
-
|
|
416
|
-
[...grouped[groupNum], node]
|
|
417
|
-
|
|
418
|
-
|
|
422
|
+
if (!options.sortSideEffects && isSideEffectImport(node.node)) {
|
|
423
|
+
grouped[groupNum] = [...grouped[groupNum], node]
|
|
424
|
+
} else {
|
|
425
|
+
grouped[groupNum] = sortNodes(
|
|
426
|
+
[...grouped[groupNum], node],
|
|
427
|
+
options,
|
|
428
|
+
)
|
|
429
|
+
}
|
|
419
430
|
}
|
|
420
431
|
}
|
|
421
432
|
let formatted = Object.keys(grouped)
|
|
@@ -514,7 +525,9 @@ const sortImports = createEslintRule({
|
|
|
514
525
|
)
|
|
515
526
|
if (
|
|
516
527
|
!(
|
|
517
|
-
|
|
528
|
+
!options.sortSideEffects &&
|
|
529
|
+
isSideEffectImport(left.node) &&
|
|
530
|
+
isSideEffectImport(right.node)
|
|
518
531
|
) &&
|
|
519
532
|
!hasContentBetweenNodes(left, right) &&
|
|
520
533
|
(leftNum > rightNum ||
|
|
@@ -69,15 +69,35 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
69
69
|
}
|
|
70
70
|
let dependencies = []
|
|
71
71
|
let checkNode = nodeValue => {
|
|
72
|
+
if (
|
|
73
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
74
|
+
nodeValue.type === 'FunctionExpression'
|
|
75
|
+
) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
72
78
|
if (nodeValue.type === 'Identifier') {
|
|
73
79
|
dependencies.push(nodeValue.name)
|
|
74
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
|
+
}
|
|
75
90
|
if (
|
|
76
|
-
'
|
|
77
|
-
nodeValue.
|
|
78
|
-
!Array.isArray(nodeValue.body)
|
|
91
|
+
'expression' in nodeValue &&
|
|
92
|
+
typeof nodeValue.expression !== 'boolean'
|
|
79
93
|
) {
|
|
80
|
-
traverseNode(nodeValue.
|
|
94
|
+
traverseNode(nodeValue.expression)
|
|
95
|
+
}
|
|
96
|
+
if ('object' in nodeValue) {
|
|
97
|
+
traverseNode(nodeValue.object)
|
|
98
|
+
}
|
|
99
|
+
if ('callee' in nodeValue) {
|
|
100
|
+
traverseNode(nodeValue.callee)
|
|
81
101
|
}
|
|
82
102
|
if ('left' in nodeValue) {
|
|
83
103
|
traverseNode(nodeValue.left)
|
|
@@ -89,9 +109,19 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
89
109
|
nodeValue.elements
|
|
90
110
|
.filter(currentNode => currentNode !== null)
|
|
91
111
|
.forEach(traverseNode)
|
|
92
|
-
}
|
|
112
|
+
}
|
|
113
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
114
|
+
traverseNode(nodeValue.argument)
|
|
115
|
+
}
|
|
116
|
+
if ('arguments' in nodeValue) {
|
|
93
117
|
nodeValue.arguments.forEach(traverseNode)
|
|
94
118
|
}
|
|
119
|
+
if ('properties' in nodeValue) {
|
|
120
|
+
nodeValue.properties.forEach(traverseNode)
|
|
121
|
+
}
|
|
122
|
+
if ('expressions' in nodeValue) {
|
|
123
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
124
|
+
}
|
|
95
125
|
}
|
|
96
126
|
let traverseNode = nodeValue => {
|
|
97
127
|
checkNode(nodeValue)
|
|
@@ -68,15 +68,35 @@ const sortVariableDeclarations = createEslintRule({
|
|
|
68
68
|
}
|
|
69
69
|
let dependencies = []
|
|
70
70
|
let checkNode = nodeValue => {
|
|
71
|
+
if (
|
|
72
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
73
|
+
nodeValue.type === 'FunctionExpression'
|
|
74
|
+
) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
71
77
|
if (nodeValue.type === 'Identifier') {
|
|
72
78
|
dependencies.push(nodeValue.name)
|
|
73
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
|
+
}
|
|
74
89
|
if (
|
|
75
|
-
'
|
|
76
|
-
nodeValue.
|
|
77
|
-
!Array.isArray(nodeValue.body)
|
|
90
|
+
'expression' in nodeValue &&
|
|
91
|
+
typeof nodeValue.expression !== 'boolean'
|
|
78
92
|
) {
|
|
79
|
-
traverseNode(nodeValue.
|
|
93
|
+
traverseNode(nodeValue.expression)
|
|
94
|
+
}
|
|
95
|
+
if ('object' in nodeValue) {
|
|
96
|
+
traverseNode(nodeValue.object)
|
|
97
|
+
}
|
|
98
|
+
if ('callee' in nodeValue) {
|
|
99
|
+
traverseNode(nodeValue.callee)
|
|
80
100
|
}
|
|
81
101
|
if ('left' in nodeValue) {
|
|
82
102
|
traverseNode(nodeValue.left)
|
|
@@ -88,9 +108,19 @@ const sortVariableDeclarations = createEslintRule({
|
|
|
88
108
|
nodeValue.elements
|
|
89
109
|
.filter(currentNode => currentNode !== null)
|
|
90
110
|
.forEach(traverseNode)
|
|
91
|
-
}
|
|
111
|
+
}
|
|
112
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
113
|
+
traverseNode(nodeValue.argument)
|
|
114
|
+
}
|
|
115
|
+
if ('arguments' in nodeValue) {
|
|
92
116
|
nodeValue.arguments.forEach(traverseNode)
|
|
93
117
|
}
|
|
118
|
+
if ('properties' in nodeValue) {
|
|
119
|
+
nodeValue.properties.forEach(traverseNode)
|
|
120
|
+
}
|
|
121
|
+
if ('expressions' in nodeValue) {
|
|
122
|
+
nodeValue.expressions.forEach(traverseNode)
|
|
123
|
+
}
|
|
94
124
|
}
|
|
95
125
|
let traverseNode = nodeValue => {
|
|
96
126
|
checkNode(nodeValue)
|
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.
|
|
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>",
|
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 | 🔧 |
|