eslint-plugin-perfectionist 3.0.0 → 3.1.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 +20 -6
- package/dist/rules/sort-array-includes.js +1 -1
- package/dist/rules/sort-array-includes.mjs +1 -1
- package/dist/rules/sort-astro-attributes.js +1 -1
- package/dist/rules/sort-astro-attributes.mjs +1 -1
- package/dist/rules/sort-classes.js +21 -1
- package/dist/rules/sort-classes.mjs +21 -1
- package/dist/rules/sort-enums.js +5 -5
- package/dist/rules/sort-enums.mjs +5 -5
- package/dist/rules/sort-exports.js +1 -1
- package/dist/rules/sort-exports.mjs +1 -1
- package/dist/rules/sort-imports.js +21 -8
- package/dist/rules/sort-imports.mjs +19 -8
- package/dist/rules/sort-interfaces.js +1 -1
- package/dist/rules/sort-interfaces.mjs +1 -1
- package/dist/rules/sort-intersection-types.js +1 -1
- package/dist/rules/sort-intersection-types.mjs +1 -1
- package/dist/rules/sort-jsx-props.js +102 -117
- package/dist/rules/sort-jsx-props.mjs +91 -104
- package/dist/rules/sort-maps.js +1 -1
- package/dist/rules/sort-maps.mjs +1 -1
- package/dist/rules/sort-named-exports.js +1 -1
- package/dist/rules/sort-named-exports.mjs +1 -1
- package/dist/rules/sort-named-imports.js +1 -1
- package/dist/rules/sort-named-imports.mjs +1 -1
- package/dist/rules/sort-object-types.js +1 -1
- package/dist/rules/sort-object-types.mjs +1 -1
- package/dist/rules/sort-objects.js +9 -12
- package/dist/rules/sort-objects.mjs +9 -12
- package/dist/rules/sort-svelte-attributes.js +1 -1
- package/dist/rules/sort-svelte-attributes.mjs +1 -1
- package/dist/rules/sort-switch-case.js +68 -15
- package/dist/rules/sort-switch-case.mjs +63 -15
- package/dist/rules/sort-union-types.js +1 -1
- package/dist/rules/sort-union-types.mjs +1 -1
- package/dist/rules/sort-variable-declarations.js +1 -1
- package/dist/rules/sort-variable-declarations.mjs +1 -1
- package/dist/rules/sort-vue-attributes.js +1 -1
- package/dist/rules/sort-vue-attributes.mjs +1 -1
- package/dist/utils/get-group-number.js +1 -1
- package/dist/utils/get-group-number.mjs +1 -1
- package/dist/utils/make-fixes.js +1 -1
- package/dist/utils/make-fixes.mjs +1 -1
- package/package.json +3 -3
- package/readme.md +49 -24
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const minimatch = require('minimatch')
|
|
3
|
-
const path = require('node:path')
|
|
4
3
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
5
4
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
6
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
@@ -101,127 +100,113 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
101
100
|
customGroups: {},
|
|
102
101
|
},
|
|
103
102
|
],
|
|
104
|
-
create: context => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
minimatch.minimatch(tagName, pattern),
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
if (!shouldIgnore && node.openingElement.attributes.length > 1) {
|
|
132
|
-
let parts = node.openingElement.attributes.reduce(
|
|
133
|
-
(accumulator, attribute) => {
|
|
134
|
-
if (attribute.type === 'JSXSpreadAttribute') {
|
|
135
|
-
accumulator.push([])
|
|
136
|
-
return accumulator
|
|
137
|
-
}
|
|
138
|
-
let name =
|
|
139
|
-
attribute.name.type === 'JSXNamespacedName'
|
|
140
|
-
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
141
|
-
: attribute.name.name
|
|
142
|
-
let { getGroup, defineGroup, setCustomGroups } =
|
|
143
|
-
useGroups.useGroups(options.groups)
|
|
144
|
-
setCustomGroups(options.customGroups, name)
|
|
145
|
-
if (attribute.value === null) {
|
|
146
|
-
defineGroup('shorthand')
|
|
147
|
-
}
|
|
148
|
-
if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
149
|
-
defineGroup('multiline')
|
|
150
|
-
}
|
|
151
|
-
let jsxNode = {
|
|
152
|
-
size: rangeToDiff.rangeToDiff(attribute.range),
|
|
153
|
-
group: getGroup(),
|
|
154
|
-
node: attribute,
|
|
155
|
-
name,
|
|
156
|
-
}
|
|
157
|
-
accumulator.at(-1).push(jsxNode)
|
|
103
|
+
create: context => ({
|
|
104
|
+
JSXElement: node => {
|
|
105
|
+
if (node.openingElement.attributes.length > 1) {
|
|
106
|
+
let options = complete.complete(context.options.at(0), {
|
|
107
|
+
type: 'alphabetical',
|
|
108
|
+
ignorePattern: [],
|
|
109
|
+
ignoreCase: true,
|
|
110
|
+
customGroups: {},
|
|
111
|
+
order: 'asc',
|
|
112
|
+
groups: [],
|
|
113
|
+
})
|
|
114
|
+
let sourceCode = getSourceCode.getSourceCode(context)
|
|
115
|
+
let shouldIgnore = false
|
|
116
|
+
if (options.ignorePattern.length) {
|
|
117
|
+
let tagName = sourceCode.text.slice(...node.openingElement.name.range)
|
|
118
|
+
shouldIgnore = options.ignorePattern.some(pattern =>
|
|
119
|
+
minimatch.minimatch(tagName, pattern),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
if (!shouldIgnore && node.openingElement.attributes.length > 1) {
|
|
123
|
+
let parts = node.openingElement.attributes.reduce(
|
|
124
|
+
(accumulator, attribute) => {
|
|
125
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
126
|
+
accumulator.push([])
|
|
158
127
|
return accumulator
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
128
|
+
}
|
|
129
|
+
let name =
|
|
130
|
+
attribute.name.type === 'JSXNamespacedName'
|
|
131
|
+
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
132
|
+
: attribute.name.name
|
|
133
|
+
let { getGroup, defineGroup, setCustomGroups } =
|
|
134
|
+
useGroups.useGroups(options.groups)
|
|
135
|
+
setCustomGroups(options.customGroups, name)
|
|
136
|
+
if (attribute.value === null) {
|
|
137
|
+
defineGroup('shorthand')
|
|
138
|
+
}
|
|
139
|
+
if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
140
|
+
defineGroup('multiline')
|
|
141
|
+
}
|
|
142
|
+
let jsxNode = {
|
|
143
|
+
size: rangeToDiff.rangeToDiff(attribute.range),
|
|
144
|
+
node: structuredClone(attribute),
|
|
145
|
+
group: getGroup(),
|
|
146
|
+
name,
|
|
147
|
+
}
|
|
148
|
+
accumulator.at(-1).push(jsxNode)
|
|
149
|
+
return accumulator
|
|
150
|
+
},
|
|
151
|
+
[[]],
|
|
152
|
+
)
|
|
153
|
+
for (let nodes of parts) {
|
|
154
|
+
pairwise.pairwise(nodes, (left, right) => {
|
|
155
|
+
let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
|
|
156
|
+
let rightNum = getGroupNumber.getGroupNumber(
|
|
157
|
+
options.groups,
|
|
158
|
+
right,
|
|
159
|
+
)
|
|
160
|
+
if (
|
|
161
|
+
leftNum > rightNum ||
|
|
162
|
+
(leftNum === rightNum &&
|
|
163
|
+
isPositive.isPositive(compare.compare(left, right, options)))
|
|
164
|
+
) {
|
|
165
|
+
context.report({
|
|
166
|
+
messageId: 'unexpectedJSXPropsOrder',
|
|
167
|
+
data: {
|
|
168
|
+
left: left.name,
|
|
169
|
+
right: right.name,
|
|
170
|
+
},
|
|
171
|
+
node: right.node,
|
|
172
|
+
fix: fixer => {
|
|
173
|
+
let grouped = {}
|
|
174
|
+
for (let currentNode of nodes) {
|
|
175
|
+
let groupNum = getGroupNumber.getGroupNumber(
|
|
176
|
+
options.groups,
|
|
177
|
+
currentNode,
|
|
178
|
+
)
|
|
179
|
+
if (!(groupNum in grouped)) {
|
|
180
|
+
grouped[groupNum] = [currentNode]
|
|
181
|
+
} else {
|
|
182
|
+
grouped[groupNum] = sortNodes.sortNodes(
|
|
183
|
+
[...grouped[groupNum], currentNode],
|
|
184
|
+
options,
|
|
208
185
|
)
|
|
209
186
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
187
|
+
}
|
|
188
|
+
let sortedNodes = []
|
|
189
|
+
for (let group of Object.keys(grouped).sort(
|
|
190
|
+
(a, b) => Number(a) - Number(b),
|
|
191
|
+
)) {
|
|
192
|
+
sortedNodes.push(
|
|
193
|
+
...sortNodes.sortNodes(grouped[group], options),
|
|
215
194
|
)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
195
|
+
}
|
|
196
|
+
return makeFixes.makeFixes(
|
|
197
|
+
fixer,
|
|
198
|
+
nodes,
|
|
199
|
+
sortedNodes,
|
|
200
|
+
sourceCode,
|
|
201
|
+
)
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
})
|
|
221
206
|
}
|
|
222
207
|
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
},
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
}),
|
|
226
211
|
})
|
|
227
212
|
module.exports = sortJsxProps
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { minimatch } from 'minimatch'
|
|
2
|
-
import path from 'node:path'
|
|
3
2
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
4
3
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
5
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
@@ -100,113 +99,101 @@ const sortJsxProps = createEslintRule({
|
|
|
100
99
|
customGroups: {},
|
|
101
100
|
},
|
|
102
101
|
],
|
|
103
|
-
create: context => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
minimatch(tagName, pattern),
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
if (!shouldIgnore && node.openingElement.attributes.length > 1) {
|
|
131
|
-
let parts = node.openingElement.attributes.reduce(
|
|
132
|
-
(accumulator, attribute) => {
|
|
133
|
-
if (attribute.type === 'JSXSpreadAttribute') {
|
|
134
|
-
accumulator.push([])
|
|
135
|
-
return accumulator
|
|
136
|
-
}
|
|
137
|
-
let name =
|
|
138
|
-
attribute.name.type === 'JSXNamespacedName'
|
|
139
|
-
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
140
|
-
: attribute.name.name
|
|
141
|
-
let { getGroup, defineGroup, setCustomGroups } = useGroups(
|
|
142
|
-
options.groups,
|
|
143
|
-
)
|
|
144
|
-
setCustomGroups(options.customGroups, name)
|
|
145
|
-
if (attribute.value === null) {
|
|
146
|
-
defineGroup('shorthand')
|
|
147
|
-
}
|
|
148
|
-
if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
149
|
-
defineGroup('multiline')
|
|
150
|
-
}
|
|
151
|
-
let jsxNode = {
|
|
152
|
-
size: rangeToDiff(attribute.range),
|
|
153
|
-
group: getGroup(),
|
|
154
|
-
node: attribute,
|
|
155
|
-
name,
|
|
156
|
-
}
|
|
157
|
-
accumulator.at(-1).push(jsxNode)
|
|
102
|
+
create: context => ({
|
|
103
|
+
JSXElement: node => {
|
|
104
|
+
if (node.openingElement.attributes.length > 1) {
|
|
105
|
+
let options = complete(context.options.at(0), {
|
|
106
|
+
type: 'alphabetical',
|
|
107
|
+
ignorePattern: [],
|
|
108
|
+
ignoreCase: true,
|
|
109
|
+
customGroups: {},
|
|
110
|
+
order: 'asc',
|
|
111
|
+
groups: [],
|
|
112
|
+
})
|
|
113
|
+
let sourceCode = getSourceCode(context)
|
|
114
|
+
let shouldIgnore = false
|
|
115
|
+
if (options.ignorePattern.length) {
|
|
116
|
+
let tagName = sourceCode.text.slice(...node.openingElement.name.range)
|
|
117
|
+
shouldIgnore = options.ignorePattern.some(pattern =>
|
|
118
|
+
minimatch(tagName, pattern),
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
if (!shouldIgnore && node.openingElement.attributes.length > 1) {
|
|
122
|
+
let parts = node.openingElement.attributes.reduce(
|
|
123
|
+
(accumulator, attribute) => {
|
|
124
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
125
|
+
accumulator.push([])
|
|
158
126
|
return accumulator
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
127
|
+
}
|
|
128
|
+
let name =
|
|
129
|
+
attribute.name.type === 'JSXNamespacedName'
|
|
130
|
+
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
131
|
+
: attribute.name.name
|
|
132
|
+
let { getGroup, defineGroup, setCustomGroups } = useGroups(
|
|
133
|
+
options.groups,
|
|
134
|
+
)
|
|
135
|
+
setCustomGroups(options.customGroups, name)
|
|
136
|
+
if (attribute.value === null) {
|
|
137
|
+
defineGroup('shorthand')
|
|
138
|
+
}
|
|
139
|
+
if (attribute.loc.start.line !== attribute.loc.end.line) {
|
|
140
|
+
defineGroup('multiline')
|
|
141
|
+
}
|
|
142
|
+
let jsxNode = {
|
|
143
|
+
size: rangeToDiff(attribute.range),
|
|
144
|
+
node: structuredClone(attribute),
|
|
145
|
+
group: getGroup(),
|
|
146
|
+
name,
|
|
147
|
+
}
|
|
148
|
+
accumulator.at(-1).push(jsxNode)
|
|
149
|
+
return accumulator
|
|
150
|
+
},
|
|
151
|
+
[[]],
|
|
152
|
+
)
|
|
153
|
+
for (let nodes of parts) {
|
|
154
|
+
pairwise(nodes, (left, right) => {
|
|
155
|
+
let leftNum = getGroupNumber(options.groups, left)
|
|
156
|
+
let rightNum = getGroupNumber(options.groups, right)
|
|
157
|
+
if (
|
|
158
|
+
leftNum > rightNum ||
|
|
159
|
+
(leftNum === rightNum &&
|
|
160
|
+
isPositive(compare(left, right, options)))
|
|
161
|
+
) {
|
|
162
|
+
context.report({
|
|
163
|
+
messageId: 'unexpectedJSXPropsOrder',
|
|
164
|
+
data: {
|
|
165
|
+
left: left.name,
|
|
166
|
+
right: right.name,
|
|
167
|
+
},
|
|
168
|
+
node: right.node,
|
|
169
|
+
fix: fixer => {
|
|
170
|
+
let grouped = {}
|
|
171
|
+
for (let currentNode of nodes) {
|
|
172
|
+
let groupNum = getGroupNumber(options.groups, currentNode)
|
|
173
|
+
if (!(groupNum in grouped)) {
|
|
174
|
+
grouped[groupNum] = [currentNode]
|
|
175
|
+
} else {
|
|
176
|
+
grouped[groupNum] = sortNodes(
|
|
177
|
+
[...grouped[groupNum], currentNode],
|
|
178
|
+
options,
|
|
184
179
|
)
|
|
185
|
-
if (!(groupNum in grouped)) {
|
|
186
|
-
grouped[groupNum] = [currentNode]
|
|
187
|
-
} else {
|
|
188
|
-
grouped[groupNum] = sortNodes(
|
|
189
|
-
[...grouped[groupNum], currentNode],
|
|
190
|
-
options,
|
|
191
|
-
)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
let sortedNodes = []
|
|
195
|
-
for (let group of Object.keys(grouped).sort(
|
|
196
|
-
(a, b) => Number(a) - Number(b),
|
|
197
|
-
)) {
|
|
198
|
-
sortedNodes.push(...sortNodes(grouped[group], options))
|
|
199
180
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
181
|
+
}
|
|
182
|
+
let sortedNodes = []
|
|
183
|
+
for (let group of Object.keys(grouped).sort(
|
|
184
|
+
(a, b) => Number(a) - Number(b),
|
|
185
|
+
)) {
|
|
186
|
+
sortedNodes.push(...sortNodes(grouped[group], options))
|
|
187
|
+
}
|
|
188
|
+
return makeFixes(fixer, nodes, sortedNodes, sourceCode)
|
|
189
|
+
},
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
})
|
|
206
193
|
}
|
|
207
194
|
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
},
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
211
198
|
})
|
|
212
199
|
export { sortJsxProps as default }
|
package/dist/rules/sort-maps.js
CHANGED
package/dist/rules/sort-maps.mjs
CHANGED
|
@@ -164,7 +164,7 @@ const sortObjectTypes = createEslintRule.createEslintRule({
|
|
|
164
164
|
let endSize = endsWithComma ? 1 : 0
|
|
165
165
|
let memberSortingNode = {
|
|
166
166
|
size: rangeToDiff.rangeToDiff(member.range) - endSize,
|
|
167
|
-
node: member,
|
|
167
|
+
node: structuredClone(member),
|
|
168
168
|
name,
|
|
169
169
|
}
|
|
170
170
|
if (
|
|
@@ -71,6 +71,10 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
71
71
|
description: 'Controls whether to sort styled components.',
|
|
72
72
|
type: 'boolean',
|
|
73
73
|
},
|
|
74
|
+
destructureOnly: {
|
|
75
|
+
description: 'Controls whether to sort only destructured objects.',
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
},
|
|
74
78
|
ignorePattern: {
|
|
75
79
|
description:
|
|
76
80
|
'Specifies names or patterns for nodes that should be ignored by rule.',
|
|
@@ -79,10 +83,6 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
79
83
|
},
|
|
80
84
|
type: 'array',
|
|
81
85
|
},
|
|
82
|
-
customIgnore: {
|
|
83
|
-
description: 'Specifies custom ignore functions.',
|
|
84
|
-
type: 'array',
|
|
85
|
-
},
|
|
86
86
|
groups: {
|
|
87
87
|
description: 'Specifies the order of the groups.',
|
|
88
88
|
type: 'array',
|
|
@@ -133,8 +133,8 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
133
133
|
partitionByComment: false,
|
|
134
134
|
partitionByNewLine: false,
|
|
135
135
|
styledComponents: true,
|
|
136
|
+
destructureOnly: false,
|
|
136
137
|
ignorePattern: [],
|
|
137
|
-
customIgnore: [],
|
|
138
138
|
groups: [],
|
|
139
139
|
customGroups: {},
|
|
140
140
|
},
|
|
@@ -145,20 +145,17 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
145
145
|
partitionByNewLine: false,
|
|
146
146
|
partitionByComment: false,
|
|
147
147
|
styledComponents: true,
|
|
148
|
+
destructureOnly: false,
|
|
148
149
|
type: 'alphabetical',
|
|
149
150
|
ignorePattern: [],
|
|
150
151
|
ignoreCase: true,
|
|
151
152
|
customGroups: {},
|
|
152
|
-
customIgnore: [],
|
|
153
153
|
order: 'asc',
|
|
154
154
|
groups: [],
|
|
155
155
|
})
|
|
156
156
|
let shouldIgnore = false
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
options.customIgnore.some(fn => fn(node, context.filename))
|
|
160
|
-
) {
|
|
161
|
-
shouldIgnore = true
|
|
157
|
+
if (options.destructureOnly) {
|
|
158
|
+
shouldIgnore = node.type !== 'ObjectPattern'
|
|
162
159
|
}
|
|
163
160
|
if (!shouldIgnore && options.ignorePattern.length) {
|
|
164
161
|
let varParent = getNodeParent.getNodeParent(node, [
|
|
@@ -255,7 +252,7 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
255
252
|
}
|
|
256
253
|
let propSortingNode = {
|
|
257
254
|
size: rangeToDiff.rangeToDiff(prop.range),
|
|
258
|
-
node: prop,
|
|
255
|
+
node: structuredClone(prop),
|
|
259
256
|
name,
|
|
260
257
|
}
|
|
261
258
|
if (
|
|
@@ -70,6 +70,10 @@ const sortObjects = createEslintRule({
|
|
|
70
70
|
description: 'Controls whether to sort styled components.',
|
|
71
71
|
type: 'boolean',
|
|
72
72
|
},
|
|
73
|
+
destructureOnly: {
|
|
74
|
+
description: 'Controls whether to sort only destructured objects.',
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
},
|
|
73
77
|
ignorePattern: {
|
|
74
78
|
description:
|
|
75
79
|
'Specifies names or patterns for nodes that should be ignored by rule.',
|
|
@@ -78,10 +82,6 @@ const sortObjects = createEslintRule({
|
|
|
78
82
|
},
|
|
79
83
|
type: 'array',
|
|
80
84
|
},
|
|
81
|
-
customIgnore: {
|
|
82
|
-
description: 'Specifies custom ignore functions.',
|
|
83
|
-
type: 'array',
|
|
84
|
-
},
|
|
85
85
|
groups: {
|
|
86
86
|
description: 'Specifies the order of the groups.',
|
|
87
87
|
type: 'array',
|
|
@@ -132,8 +132,8 @@ const sortObjects = createEslintRule({
|
|
|
132
132
|
partitionByComment: false,
|
|
133
133
|
partitionByNewLine: false,
|
|
134
134
|
styledComponents: true,
|
|
135
|
+
destructureOnly: false,
|
|
135
136
|
ignorePattern: [],
|
|
136
|
-
customIgnore: [],
|
|
137
137
|
groups: [],
|
|
138
138
|
customGroups: {},
|
|
139
139
|
},
|
|
@@ -144,20 +144,17 @@ const sortObjects = createEslintRule({
|
|
|
144
144
|
partitionByNewLine: false,
|
|
145
145
|
partitionByComment: false,
|
|
146
146
|
styledComponents: true,
|
|
147
|
+
destructureOnly: false,
|
|
147
148
|
type: 'alphabetical',
|
|
148
149
|
ignorePattern: [],
|
|
149
150
|
ignoreCase: true,
|
|
150
151
|
customGroups: {},
|
|
151
|
-
customIgnore: [],
|
|
152
152
|
order: 'asc',
|
|
153
153
|
groups: [],
|
|
154
154
|
})
|
|
155
155
|
let shouldIgnore = false
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
options.customIgnore.some(fn => fn(node, context.filename))
|
|
159
|
-
) {
|
|
160
|
-
shouldIgnore = true
|
|
156
|
+
if (options.destructureOnly) {
|
|
157
|
+
shouldIgnore = node.type !== 'ObjectPattern'
|
|
161
158
|
}
|
|
162
159
|
if (!shouldIgnore && options.ignorePattern.length) {
|
|
163
160
|
let varParent = getNodeParent(node, ['VariableDeclarator', 'Property'])
|
|
@@ -246,7 +243,7 @@ const sortObjects = createEslintRule({
|
|
|
246
243
|
}
|
|
247
244
|
let propSortingNode = {
|
|
248
245
|
size: rangeToDiff(prop.range),
|
|
249
|
-
node: prop,
|
|
246
|
+
node: structuredClone(prop),
|
|
250
247
|
name,
|
|
251
248
|
}
|
|
252
249
|
if (
|