eslint-plugin-perfectionist 4.1.2 → 4.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/alphabet.d.ts +176 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/rules/sort-array-includes.js +6 -1
- package/dist/rules/sort-classes-utils.js +0 -23
- package/dist/rules/sort-classes.js +19 -43
- package/dist/rules/sort-classes.types.js +5 -37
- package/dist/rules/sort-decorators.js +9 -1
- package/dist/rules/sort-enums.js +11 -1
- package/dist/rules/sort-exports.js +8 -1
- package/dist/rules/sort-heritage-clauses.js +4 -0
- package/dist/rules/sort-imports.js +8 -3
- package/dist/rules/sort-interfaces.js +17 -260
- package/dist/rules/sort-intersection-types.js +9 -1
- package/dist/rules/sort-jsx-props.js +4 -0
- package/dist/rules/sort-maps.js +8 -1
- package/dist/rules/sort-modules-utils.js +0 -23
- package/dist/rules/sort-modules.js +20 -44
- package/dist/rules/sort-modules.types.js +5 -41
- package/dist/rules/sort-named-exports.js +8 -1
- package/dist/rules/sort-named-imports.js +8 -1
- package/dist/rules/sort-object-types-utils.js +37 -0
- package/dist/rules/sort-object-types.js +345 -223
- package/dist/rules/sort-object-types.types.js +20 -0
- package/dist/rules/sort-objects.js +36 -10
- package/dist/rules/sort-switch-case.js +4 -0
- package/dist/rules/sort-union-types.js +9 -1
- package/dist/rules/sort-variable-declarations.js +8 -1
- package/dist/utils/alphabet.js +385 -0
- package/dist/utils/common-json-schemas.js +94 -1
- package/dist/utils/compare.js +88 -39
- package/dist/utils/convert-boolean-to-sign.js +4 -0
- package/dist/utils/get-comments-before.js +4 -4
- package/dist/utils/get-custom-groups-compare-options.js +29 -0
- package/dist/utils/get-matching-context-options.js +18 -0
- package/dist/utils/get-node-range.js +18 -7
- package/dist/utils/get-settings.js +1 -0
- package/dist/utils/is-node-function-type.js +15 -0
- package/dist/utils/make-fixes.js +24 -3
- package/dist/utils/make-newlines-fixes.js +7 -4
- package/dist/utils/validate-custom-sort-configuration.js +11 -0
- package/dist/{rules → utils}/validate-generated-groups-configuration.js +4 -2
- package/package.json +9 -5
- package/readme.md +4 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
4
|
let allSelectors = [
|
|
4
5
|
'enum',
|
|
5
6
|
'function',
|
|
@@ -10,53 +11,16 @@ let allSelectors = [
|
|
|
10
11
|
'class',
|
|
11
12
|
]
|
|
12
13
|
let allModifiers = ['async', 'declare', 'decorated', 'default', 'export']
|
|
13
|
-
let customGroupSortJsonSchema = {
|
|
14
|
-
type: {
|
|
15
|
-
enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
|
|
16
|
-
description: 'Custom group sort type.',
|
|
17
|
-
type: 'string',
|
|
18
|
-
},
|
|
19
|
-
order: {
|
|
20
|
-
description: 'Custom group sort order.',
|
|
21
|
-
enum: ['desc', 'asc'],
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
let customGroupNameJsonSchema = {
|
|
26
|
-
groupName: {
|
|
27
|
-
description: 'Custom group name.',
|
|
28
|
-
type: 'string',
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
14
|
let singleCustomGroupJsonSchema = {
|
|
32
|
-
modifiers: {
|
|
33
|
-
items: {
|
|
34
|
-
enum: allModifiers,
|
|
35
|
-
type: 'string',
|
|
36
|
-
},
|
|
37
|
-
description: 'Modifier filters.',
|
|
38
|
-
type: 'array',
|
|
39
|
-
},
|
|
40
|
-
elementValuePattern: {
|
|
41
|
-
description: 'Element value pattern filter for properties.',
|
|
42
|
-
type: 'string',
|
|
43
|
-
},
|
|
44
15
|
decoratorNamePattern: {
|
|
45
16
|
description: 'Decorator name pattern filter.',
|
|
46
17
|
type: 'string',
|
|
47
18
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
elementNamePattern: {
|
|
54
|
-
description: 'Element name pattern filter.',
|
|
55
|
-
type: 'string',
|
|
56
|
-
},
|
|
19
|
+
modifiers:
|
|
20
|
+
commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
21
|
+
selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
22
|
+
elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
|
|
57
23
|
}
|
|
58
24
|
exports.allModifiers = allModifiers
|
|
59
25
|
exports.allSelectors = allSelectors
|
|
60
|
-
exports.customGroupNameJsonSchema = customGroupNameJsonSchema
|
|
61
|
-
exports.customGroupSortJsonSchema = customGroupSortJsonSchema
|
|
62
26
|
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
3
4
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
4
5
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
5
6
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
@@ -22,6 +23,7 @@ let defaultOptions = {
|
|
|
22
23
|
groupKind: 'mixed',
|
|
23
24
|
ignoreCase: true,
|
|
24
25
|
locales: 'en-US',
|
|
26
|
+
alphabet: '',
|
|
25
27
|
order: 'asc',
|
|
26
28
|
}
|
|
27
29
|
const sortNamedExports = createEslintRule.createEslintRule({
|
|
@@ -37,6 +39,7 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
37
39
|
settings,
|
|
38
40
|
defaultOptions,
|
|
39
41
|
)
|
|
42
|
+
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
40
43
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
41
44
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
42
45
|
ruleName: context.id,
|
|
@@ -67,7 +70,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
67
70
|
(options.partitionByComment &&
|
|
68
71
|
isPartitionComment.hasPartitionComment(
|
|
69
72
|
options.partitionByComment,
|
|
70
|
-
getCommentsBefore.getCommentsBefore(
|
|
73
|
+
getCommentsBefore.getCommentsBefore({
|
|
74
|
+
node: specifier,
|
|
75
|
+
sourceCode,
|
|
76
|
+
}),
|
|
71
77
|
)) ||
|
|
72
78
|
(options.partitionByNewLine &&
|
|
73
79
|
lastSortingNode &&
|
|
@@ -153,6 +159,7 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
153
159
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
154
160
|
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
155
161
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
162
|
+
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
156
163
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
157
164
|
order: commonJsonSchemas.orderJsonSchema,
|
|
158
165
|
type: commonJsonSchemas.typeJsonSchema,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
3
4
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
4
5
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
5
6
|
const isPartitionComment = require('../utils/is-partition-comment.js')
|
|
@@ -23,6 +24,7 @@ let defaultOptions = {
|
|
|
23
24
|
groupKind: 'mixed',
|
|
24
25
|
ignoreCase: true,
|
|
25
26
|
locales: 'en-US',
|
|
27
|
+
alphabet: '',
|
|
26
28
|
order: 'asc',
|
|
27
29
|
}
|
|
28
30
|
const sortNamedImports = createEslintRule.createEslintRule({
|
|
@@ -41,6 +43,7 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
41
43
|
settings,
|
|
42
44
|
defaultOptions,
|
|
43
45
|
)
|
|
46
|
+
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
44
47
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
45
48
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
46
49
|
ruleName: context.id,
|
|
@@ -76,7 +79,10 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
76
79
|
(options.partitionByComment &&
|
|
77
80
|
isPartitionComment.hasPartitionComment(
|
|
78
81
|
options.partitionByComment,
|
|
79
|
-
getCommentsBefore.getCommentsBefore(
|
|
82
|
+
getCommentsBefore.getCommentsBefore({
|
|
83
|
+
node: specifier,
|
|
84
|
+
sourceCode,
|
|
85
|
+
}),
|
|
80
86
|
)) ||
|
|
81
87
|
(options.partitionByNewLine &&
|
|
82
88
|
lastSortingNode &&
|
|
@@ -166,6 +172,7 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
166
172
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
167
173
|
specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
|
|
168
174
|
ignoreCase: commonJsonSchemas.ignoreCaseJsonSchema,
|
|
175
|
+
alphabet: commonJsonSchemas.alphabetJsonSchema,
|
|
169
176
|
locales: commonJsonSchemas.localesJsonSchema,
|
|
170
177
|
order: commonJsonSchemas.orderJsonSchema,
|
|
171
178
|
type: commonJsonSchemas.typeJsonSchema,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const matches = require('../utils/matches.js')
|
|
4
|
+
let customGroupMatches = props => {
|
|
5
|
+
if ('anyOf' in props.customGroup) {
|
|
6
|
+
return props.customGroup.anyOf.some(subgroup =>
|
|
7
|
+
customGroupMatches({ ...props, customGroup: subgroup }),
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
if (
|
|
11
|
+
props.customGroup.selector &&
|
|
12
|
+
!props.selectors.includes(props.customGroup.selector)
|
|
13
|
+
) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
if (props.customGroup.modifiers) {
|
|
17
|
+
for (let modifier of props.customGroup.modifiers) {
|
|
18
|
+
if (!props.modifiers.includes(modifier)) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (
|
|
24
|
+
'elementNamePattern' in props.customGroup &&
|
|
25
|
+
props.customGroup.elementNamePattern
|
|
26
|
+
) {
|
|
27
|
+
let matchesElementNamePattern = matches.matches(
|
|
28
|
+
props.elementName,
|
|
29
|
+
props.customGroup.elementNamePattern,
|
|
30
|
+
)
|
|
31
|
+
if (!matchesElementNamePattern) {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
exports.customGroupMatches = customGroupMatches
|