eslint-plugin-perfectionist 4.0.1 → 4.0.3
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/rules/sort-decorators.js +22 -5
- package/dist/rules/sort-enums.js +2 -1
- package/dist/rules/sort-heritage-clauses.js +1 -1
- package/dist/rules/sort-imports.js +2 -2
- package/dist/rules/sort-modules.js +8 -6
- package/dist/utils/get-enum-members.js +7 -0
- package/dist/utils/get-node-decorators.js +4 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
|
6
6
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
7
7
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
8
8
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
9
|
+
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
9
10
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
10
11
|
const getDecoratorName = require('../utils/get-decorator-name.js')
|
|
11
12
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
@@ -125,19 +126,35 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
125
126
|
},
|
|
126
127
|
PropertyDefinition: propertyDefinition =>
|
|
127
128
|
options.sortOnProperties
|
|
128
|
-
? sortDecorators$1(
|
|
129
|
+
? sortDecorators$1(
|
|
130
|
+
context,
|
|
131
|
+
options,
|
|
132
|
+
getNodeDecorators.getNodeDecorators(propertyDefinition),
|
|
133
|
+
)
|
|
129
134
|
: null,
|
|
130
135
|
AccessorProperty: accessorDefinition =>
|
|
131
136
|
options.sortOnAccessors
|
|
132
|
-
? sortDecorators$1(
|
|
137
|
+
? sortDecorators$1(
|
|
138
|
+
context,
|
|
139
|
+
options,
|
|
140
|
+
getNodeDecorators.getNodeDecorators(accessorDefinition),
|
|
141
|
+
)
|
|
133
142
|
: null,
|
|
134
143
|
MethodDefinition: methodDefinition =>
|
|
135
144
|
options.sortOnMethods
|
|
136
|
-
? sortDecorators$1(
|
|
145
|
+
? sortDecorators$1(
|
|
146
|
+
context,
|
|
147
|
+
options,
|
|
148
|
+
getNodeDecorators.getNodeDecorators(methodDefinition),
|
|
149
|
+
)
|
|
137
150
|
: null,
|
|
138
|
-
ClassDeclaration:
|
|
151
|
+
ClassDeclaration: declaration =>
|
|
139
152
|
options.sortOnClasses
|
|
140
|
-
? sortDecorators$1(
|
|
153
|
+
? sortDecorators$1(
|
|
154
|
+
context,
|
|
155
|
+
options,
|
|
156
|
+
getNodeDecorators.getNodeDecorators(declaration),
|
|
157
|
+
)
|
|
141
158
|
: null,
|
|
142
159
|
}
|
|
143
160
|
},
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -7,6 +7,7 @@ const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
|
7
7
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
8
8
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
9
9
|
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
10
|
+
const getEnumMembers = require('../utils/get-enum-members.js')
|
|
10
11
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
11
12
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
12
13
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
@@ -30,7 +31,7 @@ let defaultOptions = {
|
|
|
30
31
|
const sortEnums = createEslintRule.createEslintRule({
|
|
31
32
|
create: context => ({
|
|
32
33
|
TSEnumDeclaration: node => {
|
|
33
|
-
let members =
|
|
34
|
+
let members = getEnumMembers.getEnumMembers(node)
|
|
34
35
|
if (
|
|
35
36
|
!isSortable.isSortable(members) ||
|
|
36
37
|
!members.every(({ initializer }) => initializer)
|
|
@@ -78,7 +78,7 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
78
78
|
name: 'sort-heritage-clauses',
|
|
79
79
|
})
|
|
80
80
|
let sortHeritageClauses$1 = (context, options, heritageClauses) => {
|
|
81
|
-
if (!isSortable.isSortable(heritageClauses)) {
|
|
81
|
+
if (!heritageClauses || !isSortable.isSortable(heritageClauses)) {
|
|
82
82
|
return
|
|
83
83
|
}
|
|
84
84
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
@@ -42,7 +42,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
42
42
|
'unknown',
|
|
43
43
|
],
|
|
44
44
|
customGroups: { value: {}, type: {} },
|
|
45
|
-
internalPattern: ['
|
|
45
|
+
internalPattern: ['^~/.+'],
|
|
46
46
|
partitionByComment: false,
|
|
47
47
|
partitionByNewLine: false,
|
|
48
48
|
newlinesBetween: 'always',
|
|
@@ -584,10 +584,10 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
584
584
|
'unknown',
|
|
585
585
|
],
|
|
586
586
|
customGroups: { value: {}, type: {} },
|
|
587
|
+
internalPattern: ['^~/.+'],
|
|
587
588
|
partitionByComment: false,
|
|
588
589
|
partitionByNewLine: false,
|
|
589
590
|
specialCharacters: 'keep',
|
|
590
|
-
internalPattern: ['~/**'],
|
|
591
591
|
newlinesBetween: 'always',
|
|
592
592
|
sortSideEffects: false,
|
|
593
593
|
type: 'alphabetical',
|
|
@@ -14,9 +14,11 @@ const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
|
14
14
|
const getNewlinesErrors = require('../utils/get-newlines-errors.js')
|
|
15
15
|
const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
|
|
16
16
|
const getCommentsBefore = require('../utils/get-comments-before.js')
|
|
17
|
+
const getNodeDecorators = require('../utils/get-node-decorators.js')
|
|
17
18
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
18
19
|
const getLinesBetween = require('../utils/get-lines-between.js')
|
|
19
20
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
21
|
+
const getEnumMembers = require('../utils/get-enum-members.js')
|
|
20
22
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
21
23
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
22
24
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
@@ -239,16 +241,19 @@ let analyzeModule = ({
|
|
|
239
241
|
;({ name } = nodeToParse.id)
|
|
240
242
|
dependencies = [
|
|
241
243
|
...dependencies,
|
|
242
|
-
...
|
|
244
|
+
...getEnumMembers
|
|
245
|
+
.getEnumMembers(nodeToParse)
|
|
246
|
+
.flatMap(extractDependencies),
|
|
243
247
|
]
|
|
244
248
|
break
|
|
245
249
|
case utils.AST_NODE_TYPES.ClassDeclaration:
|
|
246
250
|
selector = 'class'
|
|
247
251
|
name = (_b2 = nodeToParse.id) == null ? void 0 : _b2.name
|
|
248
|
-
|
|
252
|
+
let nodeDecorators = getNodeDecorators.getNodeDecorators(nodeToParse)
|
|
253
|
+
if (nodeDecorators.length > 0) {
|
|
249
254
|
modifiers.push('decorated')
|
|
250
255
|
}
|
|
251
|
-
for (let decorator of
|
|
256
|
+
for (let decorator of nodeDecorators) {
|
|
252
257
|
if (decorator.expression.type === 'Identifier') {
|
|
253
258
|
decorators.push(decorator.expression.name)
|
|
254
259
|
} else if (
|
|
@@ -493,9 +498,6 @@ let extractDependencies = expression => {
|
|
|
493
498
|
if ('right' in nodeValue) {
|
|
494
499
|
checkNode(nodeValue.right)
|
|
495
500
|
}
|
|
496
|
-
if ('members' in nodeValue) {
|
|
497
|
-
traverseNode(nodeValue.members)
|
|
498
|
-
}
|
|
499
501
|
if ('initializer' in nodeValue && nodeValue.initializer) {
|
|
500
502
|
checkNode(nodeValue.initializer)
|
|
501
503
|
}
|