eslint-plugin-perfectionist 4.1.2 → 4.2.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.js +1 -1
- package/dist/rules/get-custom-groups-compare-options.js +28 -0
- package/dist/rules/sort-array-includes.js +4 -1
- package/dist/rules/sort-classes-utils.js +0 -23
- package/dist/rules/sort-classes.js +15 -43
- package/dist/rules/sort-classes.types.js +5 -37
- package/dist/rules/sort-decorators.js +5 -1
- package/dist/rules/sort-enums.js +6 -1
- package/dist/rules/sort-exports.js +4 -1
- package/dist/rules/sort-imports.js +3 -3
- package/dist/rules/sort-interfaces.js +16 -260
- package/dist/rules/sort-intersection-types.js +5 -1
- package/dist/rules/sort-maps.js +4 -1
- package/dist/rules/sort-modules-utils.js +0 -23
- package/dist/rules/sort-modules.js +15 -43
- package/dist/rules/sort-modules.types.js +5 -41
- package/dist/rules/sort-named-exports.js +4 -1
- package/dist/rules/sort-named-imports.js +4 -1
- package/dist/rules/sort-object-types-utils.js +37 -0
- package/dist/rules/sort-object-types.js +346 -223
- package/dist/rules/sort-object-types.types.js +20 -0
- package/dist/rules/sort-objects.js +4 -5
- package/dist/rules/sort-union-types.js +5 -1
- package/dist/rules/sort-variable-declarations.js +4 -1
- package/dist/rules/validate-generated-groups-configuration.js +3 -1
- package/dist/utils/common-json-schemas.js +78 -0
- package/dist/utils/compare.js +0 -1
- package/dist/utils/get-comments-before.js +4 -4
- package/dist/utils/get-node-range.js +18 -7
- package/dist/utils/make-fixes.js +24 -3
- package/dist/utils/make-newlines-fixes.js +7 -4
- package/package.json +5 -5
|
@@ -96,7 +96,85 @@ let newlinesBetweenJsonSchema = {
|
|
|
96
96
|
enum: ['ignore', 'always', 'never'],
|
|
97
97
|
type: 'string',
|
|
98
98
|
}
|
|
99
|
+
let customGroupSortJsonSchema = {
|
|
100
|
+
type: {
|
|
101
|
+
enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
|
|
102
|
+
description: 'Custom group sort type.',
|
|
103
|
+
type: 'string',
|
|
104
|
+
},
|
|
105
|
+
order: {
|
|
106
|
+
description: 'Custom group sort order.',
|
|
107
|
+
enum: ['desc', 'asc'],
|
|
108
|
+
type: 'string',
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
let customGroupNameJsonSchema = {
|
|
112
|
+
groupName: {
|
|
113
|
+
description: 'Custom group name.',
|
|
114
|
+
type: 'string',
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
|
|
118
|
+
items: {
|
|
119
|
+
oneOf: [
|
|
120
|
+
{
|
|
121
|
+
properties: {
|
|
122
|
+
...customGroupNameJsonSchema,
|
|
123
|
+
...customGroupSortJsonSchema,
|
|
124
|
+
anyOf: {
|
|
125
|
+
items: {
|
|
126
|
+
properties: {
|
|
127
|
+
...singleCustomGroupJsonSchema,
|
|
128
|
+
},
|
|
129
|
+
description: 'Custom group.',
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
type: 'object',
|
|
132
|
+
},
|
|
133
|
+
type: 'array',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
description: 'Custom group block.',
|
|
137
|
+
additionalProperties: false,
|
|
138
|
+
type: 'object',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
properties: {
|
|
142
|
+
...customGroupNameJsonSchema,
|
|
143
|
+
...customGroupSortJsonSchema,
|
|
144
|
+
...singleCustomGroupJsonSchema,
|
|
145
|
+
},
|
|
146
|
+
description: 'Custom group.',
|
|
147
|
+
additionalProperties: false,
|
|
148
|
+
type: 'object',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
description: 'Specifies custom groups.',
|
|
153
|
+
type: 'array',
|
|
154
|
+
})
|
|
155
|
+
let buildCustomGroupModifiersJsonSchema = modifiers => ({
|
|
156
|
+
items: {
|
|
157
|
+
enum: modifiers,
|
|
158
|
+
type: 'string',
|
|
159
|
+
},
|
|
160
|
+
description: 'Modifier filters.',
|
|
161
|
+
type: 'array',
|
|
162
|
+
})
|
|
163
|
+
let buildCustomGroupSelectorJsonSchema = selectors => ({
|
|
164
|
+
description: 'Selector filter.',
|
|
165
|
+
enum: selectors,
|
|
166
|
+
type: 'string',
|
|
167
|
+
})
|
|
168
|
+
let elementNamePatternJsonSchema = {
|
|
169
|
+
description: 'Element name pattern filter.',
|
|
170
|
+
type: 'string',
|
|
171
|
+
}
|
|
172
|
+
exports.buildCustomGroupModifiersJsonSchema =
|
|
173
|
+
buildCustomGroupModifiersJsonSchema
|
|
174
|
+
exports.buildCustomGroupSelectorJsonSchema = buildCustomGroupSelectorJsonSchema
|
|
175
|
+
exports.buildCustomGroupsArrayJsonSchema = buildCustomGroupsArrayJsonSchema
|
|
99
176
|
exports.customGroupsJsonSchema = customGroupsJsonSchema
|
|
177
|
+
exports.elementNamePatternJsonSchema = elementNamePatternJsonSchema
|
|
100
178
|
exports.groupsJsonSchema = groupsJsonSchema
|
|
101
179
|
exports.ignoreCaseJsonSchema = ignoreCaseJsonSchema
|
|
102
180
|
exports.localesJsonSchema = localesJsonSchema
|
package/dist/utils/compare.js
CHANGED
|
@@ -18,7 +18,6 @@ let compare = (a, b, options) => {
|
|
|
18
18
|
} else if (options.type === 'natural') {
|
|
19
19
|
let naturalCompare = naturalOrderby.compare({
|
|
20
20
|
locale: options.locales.toString(),
|
|
21
|
-
order: options.order,
|
|
22
21
|
})
|
|
23
22
|
let formatString = getFormatStringFunction(
|
|
24
23
|
options.ignoreCase,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
-
let getCommentsBefore = (
|
|
4
|
-
let commentsBefore = getCommentsBeforeNodeOrToken(
|
|
5
|
-
let tokenBeforeNode =
|
|
3
|
+
let getCommentsBefore = ({ tokenValueToIgnoreBefore, sourceCode, node }) => {
|
|
4
|
+
let commentsBefore = getCommentsBeforeNodeOrToken(sourceCode, node)
|
|
5
|
+
let tokenBeforeNode = sourceCode.getTokenBefore(node)
|
|
6
6
|
if (
|
|
7
7
|
commentsBefore.length ||
|
|
8
8
|
!tokenValueToIgnoreBefore ||
|
|
@@ -11,7 +11,7 @@ let getCommentsBefore = (node, source, tokenValueToIgnoreBefore) => {
|
|
|
11
11
|
) {
|
|
12
12
|
return commentsBefore
|
|
13
13
|
}
|
|
14
|
-
return getCommentsBeforeNodeOrToken(
|
|
14
|
+
return getCommentsBeforeNodeOrToken(sourceCode, tokenBeforeNode)
|
|
15
15
|
}
|
|
16
16
|
let getCommentsBeforeNodeOrToken = (source, node) =>
|
|
17
17
|
source.getCommentsBefore(node).filter(comment => {
|
|
@@ -4,7 +4,12 @@ const utils = require('@typescript-eslint/utils')
|
|
|
4
4
|
const getEslintDisabledRules = require('./get-eslint-disabled-rules.js')
|
|
5
5
|
const isPartitionComment = require('./is-partition-comment.js')
|
|
6
6
|
const getCommentsBefore = require('./get-comments-before.js')
|
|
7
|
-
let getNodeRange = (
|
|
7
|
+
let getNodeRange = ({
|
|
8
|
+
ignoreHighestBlockComment,
|
|
9
|
+
sourceCode,
|
|
10
|
+
options,
|
|
11
|
+
node,
|
|
12
|
+
}) => {
|
|
8
13
|
let start = node.range.at(0)
|
|
9
14
|
let end = node.range.at(1)
|
|
10
15
|
if (utils.ASTUtils.isParenthesized(node, sourceCode)) {
|
|
@@ -19,11 +24,11 @@ let getNodeRange = (node, sourceCode, additionalOptions) => {
|
|
|
19
24
|
start = bodyOpeningParen.range.at(0)
|
|
20
25
|
end = bodyClosingParen.range.at(1)
|
|
21
26
|
}
|
|
22
|
-
let comments = getCommentsBefore.getCommentsBefore(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
let comments = getCommentsBefore.getCommentsBefore({
|
|
28
|
+
sourceCode,
|
|
29
|
+
node,
|
|
30
|
+
})
|
|
31
|
+
let highestBlockComment = comments.find(comment => comment.type === 'Block')
|
|
27
32
|
let relevantTopComment
|
|
28
33
|
for (let i = comments.length - 1; i >= 0; i--) {
|
|
29
34
|
let comment = comments[i]
|
|
@@ -31,7 +36,10 @@ let getNodeRange = (node, sourceCode, additionalOptions) => {
|
|
|
31
36
|
comment.value,
|
|
32
37
|
)
|
|
33
38
|
if (
|
|
34
|
-
isPartitionComment.isPartitionComment(
|
|
39
|
+
isPartitionComment.isPartitionComment(
|
|
40
|
+
(options == null ? void 0 : options.partitionByComment) ?? false,
|
|
41
|
+
comment.value,
|
|
42
|
+
) ||
|
|
35
43
|
(eslintDisabledRules == null
|
|
36
44
|
? void 0
|
|
37
45
|
: eslintDisabledRules.eslintDisableDirective) === 'eslint-disable' ||
|
|
@@ -48,6 +56,9 @@ let getNodeRange = (node, sourceCode, additionalOptions) => {
|
|
|
48
56
|
if (comment.loc.end.line !== previousCommentOrNodeStartLine - 1) {
|
|
49
57
|
break
|
|
50
58
|
}
|
|
59
|
+
if (ignoreHighestBlockComment && comment === highestBlockComment) {
|
|
60
|
+
break
|
|
61
|
+
}
|
|
51
62
|
relevantTopComment = comment
|
|
52
63
|
}
|
|
53
64
|
if (relevantTopComment) {
|
package/dist/utils/make-fixes.js
CHANGED
|
@@ -2,18 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const makeCommentAfterFixes = require('./make-comment-after-fixes.js')
|
|
4
4
|
const getNodeRange = require('./get-node-range.js')
|
|
5
|
-
let makeFixes = ({
|
|
5
|
+
let makeFixes = ({
|
|
6
|
+
ignoreFirstNodeHighestBlockComment,
|
|
7
|
+
sortedNodes,
|
|
8
|
+
sourceCode,
|
|
9
|
+
options,
|
|
10
|
+
fixer,
|
|
11
|
+
nodes,
|
|
12
|
+
}) => {
|
|
6
13
|
let fixes = []
|
|
7
14
|
for (let max = nodes.length, i = 0; i < max; i++) {
|
|
8
15
|
let sortingNode = nodes.at(i)
|
|
9
16
|
let sortedSortingNode = sortedNodes.at(i)
|
|
10
17
|
let { node } = sortingNode
|
|
11
18
|
let { addSafetySemicolonWhenInline, node: sortedNode } = sortedSortingNode
|
|
19
|
+
let isNodeFirstNode = node === nodes.at(0).node
|
|
20
|
+
let isSortedNodeFirstNode = sortedNode === nodes.at(0).node
|
|
12
21
|
if (node === sortedNode) {
|
|
13
22
|
continue
|
|
14
23
|
}
|
|
15
24
|
let sortedNodeCode = sourceCode.text.slice(
|
|
16
|
-
...getNodeRange.getNodeRange(
|
|
25
|
+
...getNodeRange.getNodeRange({
|
|
26
|
+
ignoreHighestBlockComment:
|
|
27
|
+
ignoreFirstNodeHighestBlockComment && isSortedNodeFirstNode,
|
|
28
|
+
node: sortedNode,
|
|
29
|
+
sourceCode,
|
|
30
|
+
options,
|
|
31
|
+
}),
|
|
17
32
|
)
|
|
18
33
|
let sortedNodeText = sourceCode.getText(sortedNode)
|
|
19
34
|
let tokensAfter = sourceCode.getTokensAfter(node, {
|
|
@@ -39,7 +54,13 @@ let makeFixes = ({ sortedNodes, sourceCode, options, fixer, nodes }) => {
|
|
|
39
54
|
}
|
|
40
55
|
fixes.push(
|
|
41
56
|
fixer.replaceTextRange(
|
|
42
|
-
getNodeRange.getNodeRange(
|
|
57
|
+
getNodeRange.getNodeRange({
|
|
58
|
+
ignoreHighestBlockComment:
|
|
59
|
+
ignoreFirstNodeHighestBlockComment && isNodeFirstNode,
|
|
60
|
+
sourceCode,
|
|
61
|
+
options,
|
|
62
|
+
node,
|
|
63
|
+
}),
|
|
43
64
|
sortedNodeCode,
|
|
44
65
|
),
|
|
45
66
|
)
|
|
@@ -25,12 +25,15 @@ let makeNewlinesFixes = ({
|
|
|
25
25
|
options.groups,
|
|
26
26
|
nextSortingNode,
|
|
27
27
|
)
|
|
28
|
-
let currentNodeRange = getNodeRange.getNodeRange(
|
|
29
|
-
nodes.at(i).node,
|
|
28
|
+
let currentNodeRange = getNodeRange.getNodeRange({
|
|
29
|
+
node: nodes.at(i).node,
|
|
30
30
|
sourceCode,
|
|
31
|
-
)
|
|
31
|
+
})
|
|
32
32
|
let nextNodeRangeStart = getNodeRange
|
|
33
|
-
.getNodeRange(
|
|
33
|
+
.getNodeRange({
|
|
34
|
+
node: nodes.at(i + 1).node,
|
|
35
|
+
sourceCode,
|
|
36
|
+
})
|
|
34
37
|
.at(0)
|
|
35
38
|
let rangeToReplace = [currentNodeRange.at(1), nextNodeRangeStart]
|
|
36
39
|
let textBetweenNodes = sourceCode.text.slice(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
19
|
},
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"./dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@typescript-eslint/types": "^8.
|
|
27
|
-
"@typescript-eslint/utils": "^8.
|
|
26
|
+
"@typescript-eslint/types": "^8.17.0",
|
|
27
|
+
"@typescript-eslint/utils": "^8.17.0",
|
|
28
28
|
"natural-orderby": "^5.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|