eslint-plugin-perfectionist 3.1.3 → 3.3.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 +13 -9
- package/dist/rules/sort-array-includes.js +3 -1
- package/dist/rules/sort-array-includes.mjs +3 -1
- package/dist/rules/sort-astro-attributes.js +3 -1
- package/dist/rules/sort-astro-attributes.mjs +3 -1
- package/dist/rules/sort-classes-utils.js +99 -0
- package/dist/rules/sort-classes-utils.mjs +96 -0
- package/dist/rules/sort-classes.js +154 -77
- package/dist/rules/sort-classes.mjs +158 -77
- package/dist/rules/sort-enums.js +93 -6
- package/dist/rules/sort-enums.mjs +89 -6
- package/dist/rules/sort-exports.js +3 -1
- package/dist/rules/sort-exports.mjs +3 -1
- package/dist/rules/sort-imports.js +3 -1
- package/dist/rules/sort-imports.mjs +3 -1
- package/dist/rules/sort-interfaces.js +3 -1
- package/dist/rules/sort-interfaces.mjs +3 -1
- package/dist/rules/sort-intersection-types.js +3 -1
- package/dist/rules/sort-intersection-types.mjs +3 -1
- package/dist/rules/sort-jsx-props.js +3 -1
- package/dist/rules/sort-jsx-props.mjs +3 -1
- package/dist/rules/sort-maps.js +3 -1
- package/dist/rules/sort-maps.mjs +3 -1
- package/dist/rules/sort-named-exports.js +3 -1
- package/dist/rules/sort-named-exports.mjs +3 -1
- package/dist/rules/sort-named-imports.js +3 -1
- package/dist/rules/sort-named-imports.mjs +3 -1
- package/dist/rules/sort-object-types.js +3 -1
- package/dist/rules/sort-object-types.mjs +3 -1
- package/dist/rules/sort-objects.js +3 -1
- package/dist/rules/sort-objects.mjs +3 -1
- package/dist/rules/sort-svelte-attributes.js +3 -1
- package/dist/rules/sort-svelte-attributes.mjs +3 -1
- package/dist/rules/sort-switch-case.js +9 -4
- package/dist/rules/sort-switch-case.mjs +9 -4
- package/dist/rules/sort-union-types.js +3 -1
- package/dist/rules/sort-union-types.mjs +3 -1
- package/dist/rules/sort-variable-declarations.js +3 -1
- package/dist/rules/sort-variable-declarations.mjs +3 -1
- package/dist/rules/sort-vue-attributes.js +2 -1
- package/dist/rules/sort-vue-attributes.mjs +2 -1
- package/dist/utils/compare.js +12 -7
- package/dist/utils/compare.mjs +12 -7
- package/dist/utils/complete.js +2 -1
- package/dist/utils/complete.mjs +2 -1
- package/dist/utils/get-settings.js +30 -0
- package/dist/utils/get-settings.mjs +28 -0
- package/dist/utils/use-groups.js +2 -1
- package/dist/utils/use-groups.mjs +2 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -266,7 +266,7 @@ declare const _default: {
|
|
|
266
266
|
RuleListener
|
|
267
267
|
>
|
|
268
268
|
'sort-classes': RuleModule<
|
|
269
|
-
'unexpectedClassesOrder',
|
|
269
|
+
'unexpectedClassesGroupOrder' | 'unexpectedClassesOrder',
|
|
270
270
|
[
|
|
271
271
|
Partial<{
|
|
272
272
|
customGroups: {
|
|
@@ -348,14 +348,7 @@ declare const _default: {
|
|
|
348
348
|
>
|
|
349
349
|
'sort-enums': RuleModule<
|
|
350
350
|
'unexpectedEnumsOrder',
|
|
351
|
-
|
|
352
|
-
Partial<{
|
|
353
|
-
type: 'alphabetical' | 'line-length' | 'natural'
|
|
354
|
-
partitionByComment: string[] | boolean | string
|
|
355
|
-
order: 'desc' | 'asc'
|
|
356
|
-
ignoreCase: boolean
|
|
357
|
-
}>,
|
|
358
|
-
],
|
|
351
|
+
Options,
|
|
359
352
|
unknown,
|
|
360
353
|
RuleListener
|
|
361
354
|
>
|
|
@@ -375,5 +368,16 @@ declare const _default: {
|
|
|
375
368
|
name: string
|
|
376
369
|
}
|
|
377
370
|
|
|
371
|
+
declare type Options = [
|
|
372
|
+
Partial<{
|
|
373
|
+
type: 'alphabetical' | 'line-length' | 'natural'
|
|
374
|
+
partitionByComment: string[] | boolean | string
|
|
375
|
+
forceNumericSort: boolean
|
|
376
|
+
order: 'desc' | 'asc'
|
|
377
|
+
sortByValue: boolean
|
|
378
|
+
ignoreCase: boolean
|
|
379
|
+
}>,
|
|
380
|
+
]
|
|
381
|
+
|
|
378
382
|
export {}
|
|
379
383
|
export = _default
|
|
@@ -4,6 +4,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
4
4
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
5
5
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
9
10
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -72,8 +73,9 @@ const sortArrayIncludes = createEslintRule.createEslintRule({
|
|
|
72
73
|
node.object.type === 'ArrayExpression'
|
|
73
74
|
? node.object.elements
|
|
74
75
|
: node.object.arguments
|
|
76
|
+
let settings = getSettings.getSettings(context.settings)
|
|
75
77
|
if (elements.length > 1) {
|
|
76
|
-
let options = complete.complete(context.options.at(0), {
|
|
78
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
77
79
|
groupKind: 'literals-first',
|
|
78
80
|
type: 'alphabetical',
|
|
79
81
|
ignoreCase: true,
|
|
@@ -3,6 +3,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
3
3
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
4
4
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
8
9
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -71,8 +72,9 @@ const sortArrayIncludes = createEslintRule({
|
|
|
71
72
|
node.object.type === 'ArrayExpression'
|
|
72
73
|
? node.object.elements
|
|
73
74
|
: node.object.arguments
|
|
75
|
+
let settings = getSettings(context.settings)
|
|
74
76
|
if (elements.length > 1) {
|
|
75
|
-
let options = complete(context.options.at(0), {
|
|
77
|
+
let options = complete(context.options.at(0), settings, {
|
|
76
78
|
groupKind: 'literals-first',
|
|
77
79
|
type: 'alphabetical',
|
|
78
80
|
ignoreCase: true,
|
|
@@ -4,6 +4,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
4
4
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
5
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const useGroups = require('../utils/use-groups.js')
|
|
9
10
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -100,7 +101,8 @@ const sortAstroAttributes = createEslintRule.createEslintRule({
|
|
|
100
101
|
JSXElement: node => {
|
|
101
102
|
let { attributes } = node.openingElement
|
|
102
103
|
if (attributes.length > 1) {
|
|
103
|
-
let
|
|
104
|
+
let settings = getSettings.getSettings(context.settings)
|
|
105
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
104
106
|
type: 'alphabetical',
|
|
105
107
|
ignoreCase: true,
|
|
106
108
|
customGroups: {},
|
|
@@ -3,6 +3,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
3
3
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
4
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
8
9
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -99,7 +100,8 @@ const sortAstroAttributes = createEslintRule({
|
|
|
99
100
|
JSXElement: node => {
|
|
100
101
|
let { attributes } = node.openingElement
|
|
101
102
|
if (attributes.length > 1) {
|
|
102
|
-
let
|
|
103
|
+
let settings = getSettings(context.settings)
|
|
104
|
+
let options = complete(context.options.at(0), settings, {
|
|
103
105
|
type: 'alphabetical',
|
|
104
106
|
ignoreCase: true,
|
|
105
107
|
customGroups: {},
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
4
|
+
const generateOfficialGroups = (modifiers, selectors) => {
|
|
5
|
+
let modifiersAndSelectorsKey = modifiers.join('&') + '/' + selectors.join('&')
|
|
6
|
+
let cachedValue = cachedGroupsByModifiersAndSelectors.get(
|
|
7
|
+
modifiersAndSelectorsKey,
|
|
8
|
+
)
|
|
9
|
+
if (cachedValue) {
|
|
10
|
+
return cachedValue
|
|
11
|
+
}
|
|
12
|
+
let allModifiersCombinations = []
|
|
13
|
+
for (let i = modifiers.length; i > 0; i--) {
|
|
14
|
+
allModifiersCombinations = [
|
|
15
|
+
...allModifiersCombinations,
|
|
16
|
+
...getCombinations(modifiers, i),
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
let allModifiersCombinationPermutations = allModifiersCombinations.flatMap(
|
|
20
|
+
result => getPermutations(result),
|
|
21
|
+
)
|
|
22
|
+
let returnValue = []
|
|
23
|
+
for (let selector of selectors) {
|
|
24
|
+
returnValue = [
|
|
25
|
+
...returnValue,
|
|
26
|
+
...allModifiersCombinationPermutations.map(
|
|
27
|
+
modifiersCombinationPermutation =>
|
|
28
|
+
[...modifiersCombinationPermutation, selector].join('-'),
|
|
29
|
+
),
|
|
30
|
+
selector,
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
cachedGroupsByModifiersAndSelectors.set(modifiersAndSelectorsKey, returnValue)
|
|
34
|
+
return returnValue
|
|
35
|
+
}
|
|
36
|
+
const getCombinations = (array, n) => {
|
|
37
|
+
let result = []
|
|
38
|
+
let backtrack = (start, comb) => {
|
|
39
|
+
if (comb.length === n) {
|
|
40
|
+
result.push([...comb])
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
for (let i = start; i < array.length; i++) {
|
|
44
|
+
comb.push(array[i])
|
|
45
|
+
backtrack(i + 1, comb)
|
|
46
|
+
comb.pop()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
backtrack(0, [])
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
const getPermutations = elements => {
|
|
53
|
+
let result = []
|
|
54
|
+
let backtrack = first => {
|
|
55
|
+
if (first === elements.length) {
|
|
56
|
+
result.push([...elements])
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
for (let i = first; i < elements.length; i++) {
|
|
60
|
+
;[elements[first], elements[i]] = [elements[i], elements[first]]
|
|
61
|
+
backtrack(first + 1)
|
|
62
|
+
;[elements[first], elements[i]] = [elements[i], elements[first]]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
backtrack(0)
|
|
66
|
+
return result
|
|
67
|
+
}
|
|
68
|
+
const getOverloadSignatureGroups = members => {
|
|
69
|
+
let methods = members
|
|
70
|
+
.filter(
|
|
71
|
+
member =>
|
|
72
|
+
member.type === 'MethodDefinition' ||
|
|
73
|
+
member.type === 'TSAbstractMethodDefinition',
|
|
74
|
+
)
|
|
75
|
+
.filter(member => member.kind === 'method')
|
|
76
|
+
let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
77
|
+
let overloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
78
|
+
for (let method of methods) {
|
|
79
|
+
if (method.key.type !== 'Identifier') {
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
let { name } = method.key
|
|
83
|
+
let mapToUse = method.static
|
|
84
|
+
? staticOverloadSignaturesByName
|
|
85
|
+
: overloadSignaturesByName
|
|
86
|
+
let signatureOverloadsGroup = mapToUse.get(name)
|
|
87
|
+
if (!signatureOverloadsGroup) {
|
|
88
|
+
signatureOverloadsGroup = []
|
|
89
|
+
mapToUse.set(name, signatureOverloadsGroup)
|
|
90
|
+
}
|
|
91
|
+
signatureOverloadsGroup.push(method)
|
|
92
|
+
}
|
|
93
|
+
return [
|
|
94
|
+
...overloadSignaturesByName.values(),
|
|
95
|
+
...staticOverloadSignaturesByName.values(),
|
|
96
|
+
].filter(group => group.length > 1)
|
|
97
|
+
}
|
|
98
|
+
exports.generateOfficialGroups = generateOfficialGroups
|
|
99
|
+
exports.getOverloadSignatureGroups = getOverloadSignatureGroups
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
2
|
+
const generateOfficialGroups = (modifiers, selectors) => {
|
|
3
|
+
let modifiersAndSelectorsKey = modifiers.join('&') + '/' + selectors.join('&')
|
|
4
|
+
let cachedValue = cachedGroupsByModifiersAndSelectors.get(
|
|
5
|
+
modifiersAndSelectorsKey,
|
|
6
|
+
)
|
|
7
|
+
if (cachedValue) {
|
|
8
|
+
return cachedValue
|
|
9
|
+
}
|
|
10
|
+
let allModifiersCombinations = []
|
|
11
|
+
for (let i = modifiers.length; i > 0; i--) {
|
|
12
|
+
allModifiersCombinations = [
|
|
13
|
+
...allModifiersCombinations,
|
|
14
|
+
...getCombinations(modifiers, i),
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
let allModifiersCombinationPermutations = allModifiersCombinations.flatMap(
|
|
18
|
+
result => getPermutations(result),
|
|
19
|
+
)
|
|
20
|
+
let returnValue = []
|
|
21
|
+
for (let selector of selectors) {
|
|
22
|
+
returnValue = [
|
|
23
|
+
...returnValue,
|
|
24
|
+
...allModifiersCombinationPermutations.map(
|
|
25
|
+
modifiersCombinationPermutation =>
|
|
26
|
+
[...modifiersCombinationPermutation, selector].join('-'),
|
|
27
|
+
),
|
|
28
|
+
selector,
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
cachedGroupsByModifiersAndSelectors.set(modifiersAndSelectorsKey, returnValue)
|
|
32
|
+
return returnValue
|
|
33
|
+
}
|
|
34
|
+
const getCombinations = (array, n) => {
|
|
35
|
+
let result = []
|
|
36
|
+
let backtrack = (start, comb) => {
|
|
37
|
+
if (comb.length === n) {
|
|
38
|
+
result.push([...comb])
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
for (let i = start; i < array.length; i++) {
|
|
42
|
+
comb.push(array[i])
|
|
43
|
+
backtrack(i + 1, comb)
|
|
44
|
+
comb.pop()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
backtrack(0, [])
|
|
48
|
+
return result
|
|
49
|
+
}
|
|
50
|
+
const getPermutations = elements => {
|
|
51
|
+
let result = []
|
|
52
|
+
let backtrack = first => {
|
|
53
|
+
if (first === elements.length) {
|
|
54
|
+
result.push([...elements])
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
for (let i = first; i < elements.length; i++) {
|
|
58
|
+
;[elements[first], elements[i]] = [elements[i], elements[first]]
|
|
59
|
+
backtrack(first + 1)
|
|
60
|
+
;[elements[first], elements[i]] = [elements[i], elements[first]]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
backtrack(0)
|
|
64
|
+
return result
|
|
65
|
+
}
|
|
66
|
+
const getOverloadSignatureGroups = members => {
|
|
67
|
+
let methods = members
|
|
68
|
+
.filter(
|
|
69
|
+
member =>
|
|
70
|
+
member.type === 'MethodDefinition' ||
|
|
71
|
+
member.type === 'TSAbstractMethodDefinition',
|
|
72
|
+
)
|
|
73
|
+
.filter(member => member.kind === 'method')
|
|
74
|
+
let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
75
|
+
let overloadSignaturesByName = /* @__PURE__ */ new Map()
|
|
76
|
+
for (let method of methods) {
|
|
77
|
+
if (method.key.type !== 'Identifier') {
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
let { name } = method.key
|
|
81
|
+
let mapToUse = method.static
|
|
82
|
+
? staticOverloadSignaturesByName
|
|
83
|
+
: overloadSignaturesByName
|
|
84
|
+
let signatureOverloadsGroup = mapToUse.get(name)
|
|
85
|
+
if (!signatureOverloadsGroup) {
|
|
86
|
+
signatureOverloadsGroup = []
|
|
87
|
+
mapToUse.set(name, signatureOverloadsGroup)
|
|
88
|
+
}
|
|
89
|
+
signatureOverloadsGroup.push(method)
|
|
90
|
+
}
|
|
91
|
+
return [
|
|
92
|
+
...overloadSignaturesByName.values(),
|
|
93
|
+
...staticOverloadSignaturesByName.values(),
|
|
94
|
+
].filter(group => group.length > 1)
|
|
95
|
+
}
|
|
96
|
+
export { generateOfficialGroups, getOverloadSignatureGroups }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const sortClassesUtils = require('./sort-classes-utils.js')
|
|
2
3
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
3
4
|
const getCommentBefore = require('../utils/get-comment-before.js')
|
|
4
5
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
@@ -6,6 +7,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
6
7
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
7
8
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
8
9
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
10
|
+
const getSettings = require('../utils/get-settings.js')
|
|
9
11
|
const isPositive = require('../utils/is-positive.js')
|
|
10
12
|
const useGroups = require('../utils/use-groups.js')
|
|
11
13
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -98,6 +100,8 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
98
100
|
},
|
|
99
101
|
],
|
|
100
102
|
messages: {
|
|
103
|
+
unexpectedClassesGroupOrder:
|
|
104
|
+
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
101
105
|
unexpectedClassesOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
102
106
|
},
|
|
103
107
|
},
|
|
@@ -108,11 +112,12 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
108
112
|
ignoreCase: true,
|
|
109
113
|
partitionByComment: false,
|
|
110
114
|
groups: [
|
|
115
|
+
'static-block',
|
|
111
116
|
'index-signature',
|
|
112
117
|
'static-property',
|
|
113
|
-
'protected-property',
|
|
114
|
-
'private-property',
|
|
115
|
-
'property',
|
|
118
|
+
['protected-property', 'protected-accessor-property'],
|
|
119
|
+
['private-property', 'private-accessor-property'],
|
|
120
|
+
['property', 'accessor-property'],
|
|
116
121
|
'constructor',
|
|
117
122
|
'static-method',
|
|
118
123
|
'protected-method',
|
|
@@ -127,13 +132,15 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
127
132
|
create: context => ({
|
|
128
133
|
ClassBody: node => {
|
|
129
134
|
if (node.body.length > 1) {
|
|
130
|
-
let
|
|
135
|
+
let settings = getSettings.getSettings(context.settings)
|
|
136
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
131
137
|
groups: [
|
|
138
|
+
'static-block',
|
|
132
139
|
'index-signature',
|
|
133
140
|
'static-property',
|
|
134
|
-
'protected-property',
|
|
135
|
-
'private-property',
|
|
136
|
-
'property',
|
|
141
|
+
['protected-property', 'protected-accessor-property'],
|
|
142
|
+
['private-property', 'private-accessor-property'],
|
|
143
|
+
['property', 'accessor-property'],
|
|
137
144
|
'constructor',
|
|
138
145
|
'static-method',
|
|
139
146
|
'protected-method',
|
|
@@ -187,9 +194,11 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
187
194
|
traverseNode(expression)
|
|
188
195
|
return dependencies
|
|
189
196
|
}
|
|
197
|
+
let overloadSignatureGroups =
|
|
198
|
+
sortClassesUtils.getOverloadSignatureGroups(node.body)
|
|
190
199
|
let formattedNodes = node.body.reduce(
|
|
191
200
|
(accumulator, member) => {
|
|
192
|
-
var _a
|
|
201
|
+
var _a, _b, _c, _d
|
|
193
202
|
let comment = getCommentBefore.getCommentBefore(member, sourceCode)
|
|
194
203
|
if (
|
|
195
204
|
options.partitionByComment &&
|
|
@@ -221,80 +230,126 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
221
230
|
name = sourceCode.text.slice(...member.key.range)
|
|
222
231
|
}
|
|
223
232
|
}
|
|
224
|
-
let
|
|
233
|
+
let isPrivateHash =
|
|
234
|
+
'key' in member && member.key.type === 'PrivateIdentifier'
|
|
225
235
|
let decorated =
|
|
226
236
|
'decorators' in member && member.decorators.length > 0
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
237
|
+
let modifiers = []
|
|
238
|
+
let selectors = []
|
|
239
|
+
if (
|
|
240
|
+
member.type === 'MethodDefinition' ||
|
|
241
|
+
member.type === 'TSAbstractMethodDefinition'
|
|
242
|
+
) {
|
|
243
|
+
if (member.static) {
|
|
244
|
+
modifiers.push('static')
|
|
230
245
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
member.accessibility === 'private' || isPrivate
|
|
234
|
-
let isStaticMethod = member.static
|
|
235
|
-
if (decorated) {
|
|
236
|
-
if (member.kind === 'get') {
|
|
237
|
-
defineGroup('decorated-get-method')
|
|
238
|
-
}
|
|
239
|
-
if (member.kind === 'set') {
|
|
240
|
-
defineGroup('decorated-set-method')
|
|
241
|
-
}
|
|
242
|
-
defineGroup('decorated-method')
|
|
246
|
+
if (member.type === 'TSAbstractMethodDefinition') {
|
|
247
|
+
modifiers.push('abstract')
|
|
243
248
|
}
|
|
244
|
-
if (
|
|
245
|
-
|
|
249
|
+
if (decorated) {
|
|
250
|
+
modifiers.push('decorated')
|
|
246
251
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
252
|
+
if (member.override) {
|
|
253
|
+
modifiers.push('override')
|
|
249
254
|
}
|
|
250
|
-
if (
|
|
251
|
-
|
|
255
|
+
if (member.accessibility === 'protected') {
|
|
256
|
+
modifiers.push('protected')
|
|
257
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
258
|
+
modifiers.push('private')
|
|
259
|
+
} else {
|
|
260
|
+
modifiers.push('public')
|
|
252
261
|
}
|
|
253
|
-
if (
|
|
254
|
-
|
|
262
|
+
if (member.optional) {
|
|
263
|
+
modifiers.push('optional')
|
|
255
264
|
}
|
|
256
|
-
if (
|
|
257
|
-
|
|
265
|
+
if (member.kind === 'constructor') {
|
|
266
|
+
selectors.push('constructor')
|
|
258
267
|
}
|
|
259
268
|
if (member.kind === 'get') {
|
|
260
|
-
|
|
269
|
+
selectors.push('get-method')
|
|
261
270
|
}
|
|
262
271
|
if (member.kind === 'set') {
|
|
263
|
-
|
|
272
|
+
selectors.push('set-method')
|
|
264
273
|
}
|
|
265
|
-
|
|
274
|
+
selectors.push('method')
|
|
266
275
|
} else if (member.type === 'TSIndexSignature') {
|
|
267
|
-
|
|
268
|
-
|
|
276
|
+
if (member.static) {
|
|
277
|
+
modifiers.push('static')
|
|
278
|
+
}
|
|
279
|
+
if (member.readonly) {
|
|
280
|
+
modifiers.push('readonly')
|
|
281
|
+
}
|
|
282
|
+
selectors.push('index-signature')
|
|
283
|
+
} else if (member.type === 'StaticBlock') {
|
|
284
|
+
selectors.push('static-block')
|
|
285
|
+
} else if (
|
|
286
|
+
member.type === 'AccessorProperty' ||
|
|
287
|
+
member.type === 'TSAbstractAccessorProperty'
|
|
288
|
+
) {
|
|
289
|
+
if (member.static) {
|
|
290
|
+
modifiers.push('static')
|
|
291
|
+
}
|
|
292
|
+
if (member.type === 'TSAbstractAccessorProperty') {
|
|
293
|
+
modifiers.push('abstract')
|
|
294
|
+
}
|
|
269
295
|
if (decorated) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
296
|
+
modifiers.push('decorated')
|
|
297
|
+
}
|
|
298
|
+
if (member.override) {
|
|
299
|
+
modifiers.push('override')
|
|
300
|
+
}
|
|
301
|
+
if (member.accessibility === 'protected') {
|
|
302
|
+
modifiers.push('protected')
|
|
303
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
304
|
+
modifiers.push('private')
|
|
305
|
+
} else {
|
|
306
|
+
modifiers.push('public')
|
|
307
|
+
}
|
|
308
|
+
selectors.push('accessor-property')
|
|
309
|
+
} else {
|
|
310
|
+
if (member.static) {
|
|
311
|
+
modifiers.push('static')
|
|
312
|
+
}
|
|
313
|
+
if (member.declare) {
|
|
314
|
+
modifiers.push('declare')
|
|
315
|
+
}
|
|
316
|
+
if (member.type === 'TSAbstractPropertyDefinition') {
|
|
317
|
+
modifiers.push('abstract')
|
|
277
318
|
}
|
|
278
|
-
} else if (member.type === 'PropertyDefinition') {
|
|
279
319
|
if (decorated) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
320
|
+
modifiers.push('decorated')
|
|
321
|
+
}
|
|
322
|
+
if (member.override) {
|
|
323
|
+
modifiers.push('override')
|
|
324
|
+
}
|
|
325
|
+
if (member.readonly) {
|
|
326
|
+
modifiers.push('readonly')
|
|
287
327
|
}
|
|
288
328
|
if (member.accessibility === 'protected') {
|
|
289
|
-
|
|
329
|
+
modifiers.push('protected')
|
|
330
|
+
} else if (member.accessibility === 'private' || isPrivateHash) {
|
|
331
|
+
modifiers.push('private')
|
|
332
|
+
} else {
|
|
333
|
+
modifiers.push('public')
|
|
290
334
|
}
|
|
291
|
-
if (member.
|
|
292
|
-
|
|
335
|
+
if (member.optional) {
|
|
336
|
+
modifiers.push('optional')
|
|
293
337
|
}
|
|
294
|
-
if (
|
|
295
|
-
|
|
338
|
+
if (
|
|
339
|
+
((_b = member.value) == null ? void 0 : _b.type) ===
|
|
340
|
+
'ArrowFunctionExpression' ||
|
|
341
|
+
((_c = member.value) == null ? void 0 : _c.type) ===
|
|
342
|
+
'FunctionExpression'
|
|
343
|
+
) {
|
|
344
|
+
selectors.push('function-property')
|
|
296
345
|
}
|
|
297
|
-
|
|
346
|
+
selectors.push('property')
|
|
347
|
+
}
|
|
348
|
+
for (let officialGroup of sortClassesUtils.generateOfficialGroups(
|
|
349
|
+
modifiers,
|
|
350
|
+
selectors,
|
|
351
|
+
)) {
|
|
352
|
+
defineGroup(officialGroup)
|
|
298
353
|
}
|
|
299
354
|
setCustomGroups(options.customGroups, name, {
|
|
300
355
|
override: true,
|
|
@@ -302,8 +357,16 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
302
357
|
if (member.type === 'PropertyDefinition' && member.value) {
|
|
303
358
|
dependencies = extractDependencies(member.value)
|
|
304
359
|
}
|
|
360
|
+
let overloadSignatureGroupMember =
|
|
361
|
+
(_d = overloadSignatureGroups.find(overloadSignatures =>
|
|
362
|
+
overloadSignatures.includes(member),
|
|
363
|
+
)) == null
|
|
364
|
+
? void 0
|
|
365
|
+
: _d.at(-1)
|
|
305
366
|
let value = {
|
|
306
|
-
size:
|
|
367
|
+
size: overloadSignatureGroupMember
|
|
368
|
+
? rangeToDiff.rangeToDiff(overloadSignatureGroupMember.range)
|
|
369
|
+
: rangeToDiff.rangeToDiff(member.range),
|
|
307
370
|
group: getGroup(),
|
|
308
371
|
node: member,
|
|
309
372
|
dependencies,
|
|
@@ -318,43 +381,57 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
318
381
|
pairwise.pairwise(nodes, (left, right) => {
|
|
319
382
|
let leftNum = getGroupNumber.getGroupNumber(options.groups, left)
|
|
320
383
|
let rightNum = getGroupNumber.getGroupNumber(options.groups, right)
|
|
384
|
+
let isLeftOrRightIgnored =
|
|
385
|
+
leftNum === options.groups.length ||
|
|
386
|
+
rightNum === options.groups.length
|
|
321
387
|
if (
|
|
322
|
-
|
|
388
|
+
!isLeftOrRightIgnored &&
|
|
323
389
|
(leftNum > rightNum ||
|
|
324
390
|
(leftNum === rightNum &&
|
|
325
391
|
isPositive.isPositive(compare.compare(left, right, options))))
|
|
326
392
|
) {
|
|
327
393
|
context.report({
|
|
328
|
-
messageId:
|
|
394
|
+
messageId:
|
|
395
|
+
leftNum !== rightNum
|
|
396
|
+
? 'unexpectedClassesGroupOrder'
|
|
397
|
+
: 'unexpectedClassesOrder',
|
|
329
398
|
data: {
|
|
330
399
|
left: toSingleLine.toSingleLine(left.name),
|
|
400
|
+
leftGroup: left.group,
|
|
331
401
|
right: toSingleLine.toSingleLine(right.name),
|
|
402
|
+
rightGroup: right.group,
|
|
332
403
|
},
|
|
333
404
|
node: right.node,
|
|
334
405
|
fix: fixer => {
|
|
335
|
-
let
|
|
406
|
+
let nodesByNonIgnoredGroupNumber = {}
|
|
407
|
+
let ignoredNodeIndices = []
|
|
408
|
+
for (let [index, sortingNode] of nodes.entries()) {
|
|
336
409
|
let groupNum = getGroupNumber.getGroupNumber(
|
|
337
410
|
options.groups,
|
|
338
411
|
sortingNode,
|
|
339
412
|
)
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
accumulator[groupNum] = sortNodes.sortNodes(
|
|
344
|
-
[...accumulator[groupNum], sortingNode],
|
|
345
|
-
options,
|
|
346
|
-
)
|
|
413
|
+
if (groupNum === options.groups.length) {
|
|
414
|
+
ignoredNodeIndices.push(index)
|
|
415
|
+
continue
|
|
347
416
|
}
|
|
348
|
-
|
|
349
|
-
|
|
417
|
+
nodesByNonIgnoredGroupNumber[groupNum] =
|
|
418
|
+
nodesByNonIgnoredGroupNumber[groupNum] ?? []
|
|
419
|
+
nodesByNonIgnoredGroupNumber[groupNum].push(sortingNode)
|
|
420
|
+
}
|
|
350
421
|
let sortedNodes = []
|
|
351
|
-
for (let
|
|
352
|
-
|
|
353
|
-
)) {
|
|
422
|
+
for (let groupNumber of Object.keys(
|
|
423
|
+
nodesByNonIgnoredGroupNumber,
|
|
424
|
+
).sort((a, b) => Number(a) - Number(b))) {
|
|
354
425
|
sortedNodes.push(
|
|
355
|
-
...sortNodes.sortNodes(
|
|
426
|
+
...sortNodes.sortNodes(
|
|
427
|
+
nodesByNonIgnoredGroupNumber[Number(groupNumber)],
|
|
428
|
+
options,
|
|
429
|
+
),
|
|
356
430
|
)
|
|
357
431
|
}
|
|
432
|
+
for (let ignoredIndex of ignoredNodeIndices) {
|
|
433
|
+
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
|
|
434
|
+
}
|
|
358
435
|
return makeFixes.makeFixes(
|
|
359
436
|
fixer,
|
|
360
437
|
nodes,
|