eslint-plugin-perfectionist 4.12.2 → 4.13.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/package.json.js +1 -1
- package/dist/rules/sort-decorators.js +5 -5
- package/dist/rules/sort-enums.js +6 -6
- package/dist/rules/sort-heritage-clauses.js +5 -5
- package/dist/rules/sort-imports.js +17 -67
- package/dist/rules/sort-intersection-types.js +2 -1
- package/dist/rules/sort-jsx-props.js +1 -1
- package/dist/rules/sort-object-types.js +4 -2
- package/dist/rules/sort-objects.js +1 -1
- package/dist/rules/sort-union-types/types.js +23 -0
- package/dist/rules/sort-union-types.js +57 -42
- package/dist/rules/sort-variable-declarations/types.js +10 -0
- package/dist/rules/sort-variable-declarations.js +143 -88
- package/dist/utils/common-json-schemas.js +28 -12
- package/dist/utils/get-comments-before.js +16 -11
- package/dist/utils/report-all-errors.js +2 -8
- package/package.json +3 -3
- package/dist/utils/validate-groups-configuration.js +0 -37
package/dist/package.json.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
3
4
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
|
-
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
5
5
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
6
6
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
7
7
|
const reportErrors = require('../utils/report-errors.js')
|
|
@@ -42,9 +42,9 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
42
42
|
defaultOptions,
|
|
43
43
|
)
|
|
44
44
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
46
|
+
selectors: [],
|
|
47
|
+
modifiers: [],
|
|
48
48
|
options,
|
|
49
49
|
})
|
|
50
50
|
return {
|
|
@@ -129,7 +129,7 @@ const sortDecorators = createEslintRule.createEslintRule({
|
|
|
129
129
|
type: 'boolean',
|
|
130
130
|
},
|
|
131
131
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
132
|
-
customGroups: commonJsonSchemas.
|
|
132
|
+
customGroups: commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
133
133
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
134
134
|
},
|
|
135
135
|
additionalProperties: false,
|
package/dist/rules/sort-enums.js
CHANGED
|
@@ -221,19 +221,19 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
221
221
|
{
|
|
222
222
|
properties: {
|
|
223
223
|
...commonJsonSchemas.commonJsonSchemas,
|
|
224
|
-
forceNumericSort: {
|
|
225
|
-
description:
|
|
226
|
-
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
227
|
-
type: 'boolean',
|
|
228
|
-
},
|
|
229
224
|
customGroups: {
|
|
230
225
|
oneOf: [
|
|
231
|
-
commonJsonSchemas.
|
|
226
|
+
commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
232
227
|
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
233
228
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
234
229
|
}),
|
|
235
230
|
],
|
|
236
231
|
},
|
|
232
|
+
forceNumericSort: {
|
|
233
|
+
description:
|
|
234
|
+
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
235
|
+
type: 'boolean',
|
|
236
|
+
},
|
|
237
237
|
sortByValue: {
|
|
238
238
|
description: 'Compare enum values instead of names.',
|
|
239
239
|
type: 'boolean',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
3
4
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
4
|
-
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
5
5
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
6
6
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
7
7
|
const reportErrors = require('../utils/report-errors.js')
|
|
@@ -30,7 +30,7 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
30
30
|
{
|
|
31
31
|
properties: {
|
|
32
32
|
...commonJsonSchemas.commonJsonSchemas,
|
|
33
|
-
customGroups: commonJsonSchemas.
|
|
33
|
+
customGroups: commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
34
34
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
35
35
|
},
|
|
36
36
|
additionalProperties: false,
|
|
@@ -57,9 +57,9 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
57
57
|
defaultOptions,
|
|
58
58
|
)
|
|
59
59
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
61
|
+
selectors: [],
|
|
62
|
+
modifiers: [],
|
|
63
63
|
options,
|
|
64
64
|
})
|
|
65
65
|
return {
|
|
@@ -7,7 +7,6 @@ const validateSideEffectsConfiguration = require('./sort-imports/validate-side-e
|
|
|
7
7
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
8
8
|
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
9
9
|
const readClosestTsConfigByPath = require('./sort-imports/read-closest-ts-config-by-path.js')
|
|
10
|
-
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
11
10
|
const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
|
|
12
11
|
const computeCommonSelectors = require('./sort-imports/compute-common-selectors.js')
|
|
13
12
|
const isSideEffectOnlyGroup = require('./sort-imports/is-side-effect-only-group.js')
|
|
@@ -43,8 +42,8 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
43
42
|
let userOptions = context.options.at(0)
|
|
44
43
|
let options = getOptionsWithCleanGroups.getOptionsWithCleanGroups(
|
|
45
44
|
complete.complete(userOptions, settings, {
|
|
45
|
+
internalPattern: ['^~/.+', '^@/.+'],
|
|
46
46
|
fallbackSort: { type: 'unsorted' },
|
|
47
|
-
internalPattern: ['^~/.+'],
|
|
48
47
|
partitionByComment: false,
|
|
49
48
|
partitionByNewLine: false,
|
|
50
49
|
newlinesBetween: 'always',
|
|
@@ -60,36 +59,19 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
60
59
|
order: 'asc',
|
|
61
60
|
}),
|
|
62
61
|
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
cache: cachedGroupsByModifiersAndSelectors,
|
|
77
|
-
selectors: types.allSelectors,
|
|
78
|
-
modifiers: types.allModifiers,
|
|
79
|
-
})
|
|
80
|
-
validateGroupsConfiguration.validateGroupsConfiguration({
|
|
81
|
-
allowedCustomGroups: [
|
|
82
|
-
...Object.keys(options.customGroups.type ?? {}),
|
|
83
|
-
...Object.keys(options.customGroups.value ?? {}),
|
|
84
|
-
],
|
|
85
|
-
allowedPredefinedGroups: [
|
|
86
|
-
...generatedGroups,
|
|
87
|
-
...types.allDeprecatedSelectors,
|
|
88
|
-
'unknown',
|
|
89
|
-
],
|
|
90
|
-
options,
|
|
91
|
-
})
|
|
92
|
-
}
|
|
62
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
63
|
+
options: {
|
|
64
|
+
...options,
|
|
65
|
+
customGroups: Array.isArray(options.customGroups)
|
|
66
|
+
? options.customGroups
|
|
67
|
+
: {
|
|
68
|
+
...options.customGroups.type,
|
|
69
|
+
...options.customGroups.value,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
selectors: [...types.allSelectors, ...types.allDeprecatedSelectors],
|
|
73
|
+
modifiers: types.allModifiers,
|
|
74
|
+
})
|
|
93
75
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
94
76
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
95
77
|
options,
|
|
@@ -367,12 +349,12 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
367
349
|
{
|
|
368
350
|
properties: {
|
|
369
351
|
value: {
|
|
352
|
+
...commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
370
353
|
description: 'Specifies custom groups for value imports.',
|
|
371
|
-
type: 'object',
|
|
372
354
|
},
|
|
373
355
|
type: {
|
|
356
|
+
...commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
374
357
|
description: 'Specifies custom groups for type imports.',
|
|
375
|
-
type: 'object',
|
|
376
358
|
},
|
|
377
359
|
},
|
|
378
360
|
description: 'Specifies custom groups.',
|
|
@@ -410,41 +392,9 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
410
392
|
internalPattern: commonJsonSchemas.regexJsonSchema,
|
|
411
393
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
412
394
|
},
|
|
413
|
-
allOf: [
|
|
414
|
-
{
|
|
415
|
-
$ref: '#/definitions/max-line-length-requires-line-length-type',
|
|
416
|
-
},
|
|
417
|
-
],
|
|
418
|
-
dependencies: {
|
|
419
|
-
maxLineLength: ['type'],
|
|
420
|
-
},
|
|
421
395
|
additionalProperties: false,
|
|
422
396
|
type: 'object',
|
|
423
397
|
},
|
|
424
|
-
definitions: {
|
|
425
|
-
'max-line-length-requires-line-length-type': {
|
|
426
|
-
anyOf: [
|
|
427
|
-
{
|
|
428
|
-
not: {
|
|
429
|
-
required: ['maxLineLength'],
|
|
430
|
-
type: 'object',
|
|
431
|
-
},
|
|
432
|
-
type: 'object',
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
$ref: '#/definitions/is-line-length',
|
|
436
|
-
},
|
|
437
|
-
],
|
|
438
|
-
},
|
|
439
|
-
'is-line-length': {
|
|
440
|
-
properties: {
|
|
441
|
-
type: { enum: ['line-length'], type: 'string' },
|
|
442
|
-
},
|
|
443
|
-
required: ['type'],
|
|
444
|
-
type: 'object',
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
id: 'sort-imports',
|
|
448
398
|
uniqueItems: true,
|
|
449
399
|
type: 'array',
|
|
450
400
|
},
|
|
@@ -466,7 +416,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
466
416
|
defaultOptions: [
|
|
467
417
|
{
|
|
468
418
|
customGroups: { value: {}, type: {} },
|
|
469
|
-
internalPattern: ['^~/.+'],
|
|
419
|
+
internalPattern: ['^~/.+', '^@/.+'],
|
|
470
420
|
partitionByComment: false,
|
|
471
421
|
partitionByNewLine: false,
|
|
472
422
|
specialCharacters: 'keep',
|
|
@@ -11,6 +11,7 @@ let defaultOptions = {
|
|
|
11
11
|
type: 'alphabetical',
|
|
12
12
|
ignoreCase: true,
|
|
13
13
|
locales: 'en-US',
|
|
14
|
+
customGroups: [],
|
|
14
15
|
alphabet: '',
|
|
15
16
|
order: 'asc',
|
|
16
17
|
groups: [],
|
|
@@ -28,7 +29,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
|
28
29
|
description: 'Enforce sorted intersection types.',
|
|
29
30
|
recommended: true,
|
|
30
31
|
},
|
|
31
|
-
schema:
|
|
32
|
+
schema: sortUnionTypes.jsonSchema,
|
|
32
33
|
type: 'suggestion',
|
|
33
34
|
fixable: 'code',
|
|
34
35
|
},
|
|
@@ -205,7 +205,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
205
205
|
...commonJsonSchemas.commonJsonSchemas,
|
|
206
206
|
customGroups: {
|
|
207
207
|
oneOf: [
|
|
208
|
-
commonJsonSchemas.
|
|
208
|
+
commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
209
209
|
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
210
210
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
211
211
|
}),
|
|
@@ -50,11 +50,13 @@ let jsonSchema = {
|
|
|
50
50
|
items: {
|
|
51
51
|
properties: {
|
|
52
52
|
...commonJsonSchemas.buildCommonJsonSchemas({
|
|
53
|
-
additionalFallbackSortProperties: {
|
|
53
|
+
additionalFallbackSortProperties: {
|
|
54
|
+
sortBy: types.sortByJsonSchema,
|
|
55
|
+
},
|
|
54
56
|
}),
|
|
55
57
|
customGroups: {
|
|
56
58
|
oneOf: [
|
|
57
|
-
commonJsonSchemas.
|
|
59
|
+
commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
58
60
|
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
59
61
|
additionalFallbackSortProperties: {
|
|
60
62
|
sortBy: types.sortByJsonSchema,
|
|
@@ -382,7 +382,7 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
382
382
|
},
|
|
383
383
|
customGroups: {
|
|
384
384
|
oneOf: [
|
|
385
|
-
commonJsonSchemas.
|
|
385
|
+
commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
386
386
|
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
387
387
|
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
388
388
|
}),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
4
|
+
let allSelectors = [
|
|
5
|
+
'intersection',
|
|
6
|
+
'conditional',
|
|
7
|
+
'function',
|
|
8
|
+
'operator',
|
|
9
|
+
'keyword',
|
|
10
|
+
'literal',
|
|
11
|
+
'nullish',
|
|
12
|
+
'import',
|
|
13
|
+
'object',
|
|
14
|
+
'named',
|
|
15
|
+
'tuple',
|
|
16
|
+
'union',
|
|
17
|
+
]
|
|
18
|
+
let singleCustomGroupJsonSchema = {
|
|
19
|
+
selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
20
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
21
|
+
}
|
|
22
|
+
exports.allSelectors = allSelectors
|
|
23
|
+
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
|
@@ -6,10 +6,14 @@ Object.defineProperties(exports, {
|
|
|
6
6
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
7
7
|
const reportErrors = require('../utils/report-errors.js')
|
|
8
8
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
9
|
+
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
10
|
+
const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
9
11
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
10
|
-
const
|
|
12
|
+
const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
|
|
11
13
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
12
14
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
15
|
+
const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
|
|
16
|
+
const types = require('./sort-union-types/types.js')
|
|
13
17
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
14
18
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
15
19
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
@@ -18,6 +22,7 @@ const computeGroup = require('../utils/compute-group.js')
|
|
|
18
22
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
19
23
|
const getSettings = require('../utils/get-settings.js')
|
|
20
24
|
const complete = require('../utils/complete.js')
|
|
25
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
21
26
|
let defaultOptions = {
|
|
22
27
|
fallbackSort: { type: 'unsorted' },
|
|
23
28
|
specialCharacters: 'keep',
|
|
@@ -27,20 +32,28 @@ let defaultOptions = {
|
|
|
27
32
|
type: 'alphabetical',
|
|
28
33
|
ignoreCase: true,
|
|
29
34
|
locales: 'en-US',
|
|
35
|
+
customGroups: [],
|
|
30
36
|
alphabet: '',
|
|
31
37
|
order: 'asc',
|
|
32
38
|
groups: [],
|
|
33
39
|
}
|
|
34
40
|
let jsonSchema = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
items: {
|
|
42
|
+
properties: {
|
|
43
|
+
...commonJsonSchemas.commonJsonSchemas,
|
|
44
|
+
customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
45
|
+
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
46
|
+
}),
|
|
47
|
+
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
48
|
+
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
49
|
+
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
50
|
+
groups: commonJsonSchemas.groupsJsonSchema,
|
|
51
|
+
},
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
type: 'object',
|
|
41
54
|
},
|
|
42
|
-
|
|
43
|
-
type: '
|
|
55
|
+
uniqueItems: true,
|
|
56
|
+
type: 'array',
|
|
44
57
|
}
|
|
45
58
|
const sortUnionTypes = createEslintRule.createEslintRule({
|
|
46
59
|
create: context => ({
|
|
@@ -70,7 +83,7 @@ const sortUnionTypes = createEslintRule.createEslintRule({
|
|
|
70
83
|
description: 'Enforce sorted union types.',
|
|
71
84
|
recommended: true,
|
|
72
85
|
},
|
|
73
|
-
schema:
|
|
86
|
+
schema: jsonSchema,
|
|
74
87
|
type: 'suggestion',
|
|
75
88
|
fixable: 'code',
|
|
76
89
|
},
|
|
@@ -90,23 +103,9 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
90
103
|
defaultOptions,
|
|
91
104
|
)
|
|
92
105
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
'conditional',
|
|
97
|
-
'function',
|
|
98
|
-
'operator',
|
|
99
|
-
'keyword',
|
|
100
|
-
'literal',
|
|
101
|
-
'nullish',
|
|
102
|
-
'unknown',
|
|
103
|
-
'import',
|
|
104
|
-
'object',
|
|
105
|
-
'named',
|
|
106
|
-
'tuple',
|
|
107
|
-
'union',
|
|
108
|
-
],
|
|
109
|
-
allowedCustomGroups: [],
|
|
106
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
107
|
+
selectors: types.allSelectors,
|
|
108
|
+
modifiers: [],
|
|
110
109
|
options,
|
|
111
110
|
})
|
|
112
111
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
@@ -119,33 +118,33 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
119
118
|
})
|
|
120
119
|
let formattedMembers = node.types.reduce(
|
|
121
120
|
(accumulator, type) => {
|
|
122
|
-
let
|
|
121
|
+
let selectors = []
|
|
123
122
|
switch (type.type) {
|
|
124
123
|
case 'TSTemplateLiteralType':
|
|
125
124
|
case 'TSLiteralType':
|
|
126
|
-
|
|
125
|
+
selectors.push('literal')
|
|
127
126
|
break
|
|
128
127
|
case 'TSIndexedAccessType':
|
|
129
128
|
case 'TSTypeReference':
|
|
130
129
|
case 'TSQualifiedName':
|
|
131
130
|
case 'TSArrayType':
|
|
132
131
|
case 'TSInferType':
|
|
133
|
-
|
|
132
|
+
selectors.push('named')
|
|
134
133
|
break
|
|
135
134
|
case 'TSIntersectionType':
|
|
136
|
-
|
|
135
|
+
selectors.push('intersection')
|
|
137
136
|
break
|
|
138
137
|
case 'TSUndefinedKeyword':
|
|
139
138
|
case 'TSNullKeyword':
|
|
140
139
|
case 'TSVoidKeyword':
|
|
141
|
-
|
|
140
|
+
selectors.push('nullish')
|
|
142
141
|
break
|
|
143
142
|
case 'TSConditionalType':
|
|
144
|
-
|
|
143
|
+
selectors.push('conditional')
|
|
145
144
|
break
|
|
146
145
|
case 'TSConstructorType':
|
|
147
146
|
case 'TSFunctionType':
|
|
148
|
-
|
|
147
|
+
selectors.push('function')
|
|
149
148
|
break
|
|
150
149
|
case 'TSBooleanKeyword':
|
|
151
150
|
case 'TSUnknownKeyword':
|
|
@@ -157,27 +156,40 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
157
156
|
case 'TSNeverKeyword':
|
|
158
157
|
case 'TSAnyKeyword':
|
|
159
158
|
case 'TSThisType':
|
|
160
|
-
|
|
159
|
+
selectors.push('keyword')
|
|
161
160
|
break
|
|
162
161
|
case 'TSTypeOperator':
|
|
163
162
|
case 'TSTypeQuery':
|
|
164
|
-
|
|
163
|
+
selectors.push('operator')
|
|
165
164
|
break
|
|
166
165
|
case 'TSTypeLiteral':
|
|
167
166
|
case 'TSMappedType':
|
|
168
|
-
|
|
167
|
+
selectors.push('object')
|
|
169
168
|
break
|
|
170
169
|
case 'TSImportType':
|
|
171
|
-
|
|
170
|
+
selectors.push('import')
|
|
172
171
|
break
|
|
173
172
|
case 'TSTupleType':
|
|
174
|
-
|
|
173
|
+
selectors.push('tuple')
|
|
175
174
|
break
|
|
176
175
|
case 'TSUnionType':
|
|
177
|
-
|
|
176
|
+
selectors.push('union')
|
|
178
177
|
break
|
|
179
178
|
}
|
|
179
|
+
let name = sourceCode.getText(type)
|
|
180
|
+
let predefinedGroups = generatePredefinedGroups.generatePredefinedGroups({
|
|
181
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
182
|
+
modifiers: [],
|
|
183
|
+
selectors,
|
|
184
|
+
})
|
|
180
185
|
let group = computeGroup.computeGroup({
|
|
186
|
+
customGroupMatcher: customGroup =>
|
|
187
|
+
doesCustomGroupMatch.doesCustomGroupMatch({
|
|
188
|
+
elementName: name,
|
|
189
|
+
modifiers: [],
|
|
190
|
+
customGroup,
|
|
191
|
+
selectors,
|
|
192
|
+
}),
|
|
181
193
|
predefinedGroups,
|
|
182
194
|
options,
|
|
183
195
|
})
|
|
@@ -189,9 +201,9 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
189
201
|
eslintDisabledLines,
|
|
190
202
|
),
|
|
191
203
|
size: rangeToDiff.rangeToDiff(type, sourceCode),
|
|
192
|
-
name: sourceCode.getText(type),
|
|
193
204
|
node: type,
|
|
194
205
|
group,
|
|
206
|
+
name,
|
|
195
207
|
}
|
|
196
208
|
if (
|
|
197
209
|
shouldPartition.shouldPartition({
|
|
@@ -213,7 +225,10 @@ let sortUnionOrIntersectionTypes = ({
|
|
|
213
225
|
for (let nodes of formattedMembers) {
|
|
214
226
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
215
227
|
sortNodesByGroups.sortNodesByGroups({
|
|
216
|
-
getOptionsByGroupNumber:
|
|
228
|
+
getOptionsByGroupNumber:
|
|
229
|
+
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
230
|
+
options,
|
|
231
|
+
),
|
|
217
232
|
ignoreEslintDisabledNodes,
|
|
218
233
|
groups: options.groups,
|
|
219
234
|
nodes,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
4
|
+
let allSelectors = ['initialized', 'uninitialized']
|
|
5
|
+
let singleCustomGroupJsonSchema = {
|
|
6
|
+
selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
7
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
8
|
+
}
|
|
9
|
+
exports.allSelectors = allSelectors
|
|
10
|
+
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
3
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
4
|
+
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
5
|
+
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
3
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
7
|
+
const types = require('./sort-variable-declarations/types.js')
|
|
8
|
+
const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
|
|
4
9
|
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
5
|
-
const reportErrors = require('../utils/report-errors.js')
|
|
6
10
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
7
11
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
12
|
+
const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
|
|
13
|
+
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
8
14
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
9
15
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
10
16
|
const shouldPartition = require('../utils/should-partition.js')
|
|
17
|
+
const computeGroup = require('../utils/compute-group.js')
|
|
11
18
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
12
19
|
const getSettings = require('../utils/get-settings.js')
|
|
13
20
|
const isSortable = require('../utils/is-sortable.js')
|
|
14
|
-
const sortNodes = require('../utils/sort-nodes.js')
|
|
15
21
|
const complete = require('../utils/complete.js')
|
|
22
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
16
23
|
let defaultOptions = {
|
|
17
24
|
fallbackSort: { type: 'unsorted' },
|
|
18
25
|
specialCharacters: 'keep',
|
|
19
26
|
partitionByNewLine: false,
|
|
20
27
|
partitionByComment: false,
|
|
28
|
+
newlinesBetween: 'ignore',
|
|
21
29
|
type: 'alphabetical',
|
|
30
|
+
customGroups: [],
|
|
22
31
|
ignoreCase: true,
|
|
23
32
|
locales: 'en-US',
|
|
24
33
|
alphabet: '',
|
|
25
34
|
order: 'asc',
|
|
35
|
+
groups: [],
|
|
26
36
|
}
|
|
27
37
|
const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
28
38
|
create: context => ({
|
|
@@ -37,83 +47,14 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
37
47
|
defaultOptions,
|
|
38
48
|
)
|
|
39
49
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
50
|
+
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
51
|
+
options,
|
|
52
|
+
)
|
|
40
53
|
let { sourceCode, id } = context
|
|
41
54
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
42
55
|
ruleName: id,
|
|
43
56
|
sourceCode,
|
|
44
57
|
})
|
|
45
|
-
let extractDependencies = init => {
|
|
46
|
-
let dependencies = []
|
|
47
|
-
let checkNode = nodeValue => {
|
|
48
|
-
if (
|
|
49
|
-
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
50
|
-
nodeValue.type === 'FunctionExpression'
|
|
51
|
-
) {
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
if (nodeValue.type === 'Identifier') {
|
|
55
|
-
dependencies.push(nodeValue.name)
|
|
56
|
-
}
|
|
57
|
-
if (nodeValue.type === 'Property') {
|
|
58
|
-
traverseNode(nodeValue.key)
|
|
59
|
-
traverseNode(nodeValue.value)
|
|
60
|
-
}
|
|
61
|
-
if (nodeValue.type === 'ConditionalExpression') {
|
|
62
|
-
traverseNode(nodeValue.test)
|
|
63
|
-
traverseNode(nodeValue.consequent)
|
|
64
|
-
traverseNode(nodeValue.alternate)
|
|
65
|
-
}
|
|
66
|
-
if (
|
|
67
|
-
'expression' in nodeValue &&
|
|
68
|
-
typeof nodeValue.expression !== 'boolean'
|
|
69
|
-
) {
|
|
70
|
-
traverseNode(nodeValue.expression)
|
|
71
|
-
}
|
|
72
|
-
if ('object' in nodeValue) {
|
|
73
|
-
traverseNode(nodeValue.object)
|
|
74
|
-
}
|
|
75
|
-
if ('callee' in nodeValue) {
|
|
76
|
-
traverseNode(nodeValue.callee)
|
|
77
|
-
}
|
|
78
|
-
if ('left' in nodeValue) {
|
|
79
|
-
traverseNode(nodeValue.left)
|
|
80
|
-
}
|
|
81
|
-
if ('right' in nodeValue) {
|
|
82
|
-
traverseNode(nodeValue.right)
|
|
83
|
-
}
|
|
84
|
-
if ('elements' in nodeValue) {
|
|
85
|
-
let elements = nodeValue.elements.filter(
|
|
86
|
-
currentNode => currentNode !== null,
|
|
87
|
-
)
|
|
88
|
-
for (let element of elements) {
|
|
89
|
-
traverseNode(element)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if ('argument' in nodeValue && nodeValue.argument) {
|
|
93
|
-
traverseNode(nodeValue.argument)
|
|
94
|
-
}
|
|
95
|
-
if ('arguments' in nodeValue) {
|
|
96
|
-
for (let argument of nodeValue.arguments) {
|
|
97
|
-
traverseNode(argument)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if ('properties' in nodeValue) {
|
|
101
|
-
for (let property of nodeValue.properties) {
|
|
102
|
-
traverseNode(property)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if ('expressions' in nodeValue) {
|
|
106
|
-
for (let nodeExpression of nodeValue.expressions) {
|
|
107
|
-
traverseNode(nodeExpression)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
let traverseNode = nodeValue => {
|
|
112
|
-
checkNode(nodeValue)
|
|
113
|
-
}
|
|
114
|
-
traverseNode(init)
|
|
115
|
-
return dependencies
|
|
116
|
-
}
|
|
117
58
|
let formattedMembers = node.declarations.reduce(
|
|
118
59
|
(accumulator, declaration) => {
|
|
119
60
|
var _a, _b
|
|
@@ -126,13 +67,34 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
126
67
|
} else {
|
|
127
68
|
;({ name } = declaration.id)
|
|
128
69
|
}
|
|
70
|
+
let selector
|
|
129
71
|
let dependencies = []
|
|
130
72
|
if (declaration.init) {
|
|
131
73
|
dependencies = extractDependencies(declaration.init)
|
|
74
|
+
selector = 'initialized'
|
|
75
|
+
} else {
|
|
76
|
+
selector = 'uninitialized'
|
|
132
77
|
}
|
|
78
|
+
let predefinedGroups =
|
|
79
|
+
generatePredefinedGroups.generatePredefinedGroups({
|
|
80
|
+
cache: cachedGroupsByModifiersAndSelectors,
|
|
81
|
+
selectors: [selector],
|
|
82
|
+
modifiers: [],
|
|
83
|
+
})
|
|
133
84
|
let lastSortingNode =
|
|
134
85
|
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
135
86
|
let sortingNode = {
|
|
87
|
+
group: computeGroup.computeGroup({
|
|
88
|
+
customGroupMatcher: customGroup =>
|
|
89
|
+
doesCustomGroupMatch.doesCustomGroupMatch({
|
|
90
|
+
selectors: [selector],
|
|
91
|
+
elementName: name,
|
|
92
|
+
modifiers: [],
|
|
93
|
+
customGroup,
|
|
94
|
+
}),
|
|
95
|
+
predefinedGroups,
|
|
96
|
+
options,
|
|
97
|
+
}),
|
|
136
98
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
137
99
|
declaration,
|
|
138
100
|
eslintDisabledLines,
|
|
@@ -158,24 +120,35 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
158
120
|
},
|
|
159
121
|
[[]],
|
|
160
122
|
)
|
|
161
|
-
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
123
|
+
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes => {
|
|
124
|
+
let nodesSortedByGroups = formattedMembers.flatMap(nodes2 =>
|
|
125
|
+
sortNodesByGroups.sortNodesByGroups({
|
|
126
|
+
getOptionsByGroupNumber:
|
|
127
|
+
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
128
|
+
options,
|
|
129
|
+
),
|
|
130
|
+
ignoreEslintDisabledNodes,
|
|
131
|
+
groups: options.groups,
|
|
132
|
+
nodes: nodes2,
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
return sortNodesByDependencies.sortNodesByDependencies(
|
|
136
|
+
nodesSortedByGroups,
|
|
170
137
|
{
|
|
171
138
|
ignoreEslintDisabledNodes,
|
|
172
139
|
},
|
|
173
140
|
)
|
|
141
|
+
}
|
|
174
142
|
let nodes = formattedMembers.flat()
|
|
175
143
|
reportAllErrors.reportAllErrors({
|
|
176
144
|
availableMessageIds: {
|
|
145
|
+
missedSpacingBetweenMembers:
|
|
146
|
+
'missedSpacingBetweenVariableDeclarationsMembers',
|
|
147
|
+
extraSpacingBetweenMembers:
|
|
148
|
+
'extraSpacingBetweenVariableDeclarationsMembers',
|
|
177
149
|
unexpectedDependencyOrder:
|
|
178
150
|
'unexpectedVariableDeclarationsDependencyOrder',
|
|
151
|
+
unexpectedGroupOrder: 'unexpectedVariableDeclarationsGroupOrder',
|
|
179
152
|
unexpectedOrder: 'unexpectedVariableDeclarationsOrder',
|
|
180
153
|
},
|
|
181
154
|
sortNodesExcludingEslintDisabled,
|
|
@@ -191,27 +164,109 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
191
164
|
{
|
|
192
165
|
properties: {
|
|
193
166
|
...commonJsonSchemas.commonJsonSchemas,
|
|
167
|
+
customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
168
|
+
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
169
|
+
}),
|
|
194
170
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
195
171
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
172
|
+
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
173
|
+
groups: commonJsonSchemas.groupsJsonSchema,
|
|
196
174
|
},
|
|
197
175
|
additionalProperties: false,
|
|
198
176
|
type: 'object',
|
|
199
177
|
},
|
|
200
178
|
],
|
|
201
|
-
docs: {
|
|
202
|
-
url: 'https://perfectionist.dev/rules/sort-variable-declarations',
|
|
203
|
-
description: 'Enforce sorted variable declarations.',
|
|
204
|
-
recommended: true,
|
|
205
|
-
},
|
|
206
179
|
messages: {
|
|
180
|
+
missedSpacingBetweenVariableDeclarationsMembers:
|
|
181
|
+
reportErrors.MISSED_SPACING_ERROR,
|
|
207
182
|
unexpectedVariableDeclarationsDependencyOrder:
|
|
208
183
|
reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
184
|
+
extraSpacingBetweenVariableDeclarationsMembers:
|
|
185
|
+
reportErrors.EXTRA_SPACING_ERROR,
|
|
186
|
+
unexpectedVariableDeclarationsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
209
187
|
unexpectedVariableDeclarationsOrder: reportErrors.ORDER_ERROR,
|
|
210
188
|
},
|
|
189
|
+
docs: {
|
|
190
|
+
url: 'https://perfectionist.dev/rules/sort-variable-declarations',
|
|
191
|
+
description: 'Enforce sorted variable declarations.',
|
|
192
|
+
recommended: true,
|
|
193
|
+
},
|
|
211
194
|
type: 'suggestion',
|
|
212
195
|
fixable: 'code',
|
|
213
196
|
},
|
|
214
197
|
name: 'sort-variable-declarations',
|
|
215
198
|
defaultOptions: [defaultOptions],
|
|
216
199
|
})
|
|
200
|
+
let extractDependencies = init => {
|
|
201
|
+
let dependencies = []
|
|
202
|
+
let checkNode = nodeValue => {
|
|
203
|
+
if (
|
|
204
|
+
nodeValue.type === 'ArrowFunctionExpression' ||
|
|
205
|
+
nodeValue.type === 'FunctionExpression'
|
|
206
|
+
) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
if (nodeValue.type === 'Identifier') {
|
|
210
|
+
dependencies.push(nodeValue.name)
|
|
211
|
+
}
|
|
212
|
+
if (nodeValue.type === 'Property') {
|
|
213
|
+
traverseNode(nodeValue.key)
|
|
214
|
+
traverseNode(nodeValue.value)
|
|
215
|
+
}
|
|
216
|
+
if (nodeValue.type === 'ConditionalExpression') {
|
|
217
|
+
traverseNode(nodeValue.test)
|
|
218
|
+
traverseNode(nodeValue.consequent)
|
|
219
|
+
traverseNode(nodeValue.alternate)
|
|
220
|
+
}
|
|
221
|
+
if (
|
|
222
|
+
'expression' in nodeValue &&
|
|
223
|
+
typeof nodeValue.expression !== 'boolean'
|
|
224
|
+
) {
|
|
225
|
+
traverseNode(nodeValue.expression)
|
|
226
|
+
}
|
|
227
|
+
if ('object' in nodeValue) {
|
|
228
|
+
traverseNode(nodeValue.object)
|
|
229
|
+
}
|
|
230
|
+
if ('callee' in nodeValue) {
|
|
231
|
+
traverseNode(nodeValue.callee)
|
|
232
|
+
}
|
|
233
|
+
if ('left' in nodeValue) {
|
|
234
|
+
traverseNode(nodeValue.left)
|
|
235
|
+
}
|
|
236
|
+
if ('right' in nodeValue) {
|
|
237
|
+
traverseNode(nodeValue.right)
|
|
238
|
+
}
|
|
239
|
+
if ('elements' in nodeValue) {
|
|
240
|
+
let elements = nodeValue.elements.filter(
|
|
241
|
+
currentNode => currentNode !== null,
|
|
242
|
+
)
|
|
243
|
+
for (let element of elements) {
|
|
244
|
+
traverseNode(element)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if ('argument' in nodeValue && nodeValue.argument) {
|
|
248
|
+
traverseNode(nodeValue.argument)
|
|
249
|
+
}
|
|
250
|
+
if ('arguments' in nodeValue) {
|
|
251
|
+
for (let argument of nodeValue.arguments) {
|
|
252
|
+
traverseNode(argument)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if ('properties' in nodeValue) {
|
|
256
|
+
for (let property of nodeValue.properties) {
|
|
257
|
+
traverseNode(property)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if ('expressions' in nodeValue) {
|
|
261
|
+
for (let nodeExpression of nodeValue.expressions) {
|
|
262
|
+
traverseNode(nodeExpression)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
let traverseNode = nodeValue => {
|
|
267
|
+
checkNode(nodeValue)
|
|
268
|
+
}
|
|
269
|
+
traverseNode(init)
|
|
270
|
+
return dependencies
|
|
271
|
+
}
|
|
217
272
|
module.exports = sortVariableDeclarations
|
|
@@ -7,12 +7,13 @@ let typeJsonSchema = {
|
|
|
7
7
|
}
|
|
8
8
|
let orderJsonSchema = {
|
|
9
9
|
description:
|
|
10
|
-
'
|
|
10
|
+
'Specifies whether to sort items in ascending or descending order.',
|
|
11
11
|
enum: ['asc', 'desc'],
|
|
12
12
|
type: 'string',
|
|
13
13
|
}
|
|
14
14
|
let alphabetJsonSchema = {
|
|
15
|
-
description:
|
|
15
|
+
description:
|
|
16
|
+
"Used only when the `type` option is set to `'custom'`. Specifies the custom alphabet for sorting.",
|
|
16
17
|
type: 'string',
|
|
17
18
|
}
|
|
18
19
|
let localesJsonSchema = {
|
|
@@ -35,7 +36,7 @@ let ignoreCaseJsonSchema = {
|
|
|
35
36
|
}
|
|
36
37
|
let specialCharactersJsonSchema = {
|
|
37
38
|
description:
|
|
38
|
-
'
|
|
39
|
+
'Specifies whether to trim, remove, or keep special characters before sorting.',
|
|
39
40
|
enum: ['remove', 'trim', 'keep'],
|
|
40
41
|
type: 'string',
|
|
41
42
|
}
|
|
@@ -46,10 +47,14 @@ let buildFallbackSortJsonSchema = ({ additionalProperties } = {}) => ({
|
|
|
46
47
|
...additionalProperties,
|
|
47
48
|
},
|
|
48
49
|
description: 'Fallback sort order.',
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
minProperties: 1,
|
|
49
52
|
type: 'object',
|
|
50
53
|
})
|
|
51
54
|
let buildCommonJsonSchemas = ({ additionalFallbackSortProperties } = {}) => ({
|
|
52
|
-
fallbackSort: buildFallbackSortJsonSchema(
|
|
55
|
+
fallbackSort: buildFallbackSortJsonSchema({
|
|
56
|
+
additionalProperties: additionalFallbackSortProperties,
|
|
57
|
+
}),
|
|
53
58
|
specialCharacters: specialCharactersJsonSchema,
|
|
54
59
|
ignoreCase: ignoreCaseJsonSchema,
|
|
55
60
|
alphabet: alphabetJsonSchema,
|
|
@@ -59,7 +64,7 @@ let buildCommonJsonSchemas = ({ additionalFallbackSortProperties } = {}) => ({
|
|
|
59
64
|
})
|
|
60
65
|
let commonJsonSchemas = buildCommonJsonSchemas()
|
|
61
66
|
let newlinesBetweenJsonSchema = {
|
|
62
|
-
description: 'Specifies how new lines
|
|
67
|
+
description: 'Specifies how to handle new lines between groups.',
|
|
63
68
|
enum: ['ignore', 'always', 'never'],
|
|
64
69
|
type: 'string',
|
|
65
70
|
}
|
|
@@ -79,15 +84,16 @@ let groupsJsonSchema = {
|
|
|
79
84
|
properties: {
|
|
80
85
|
newlinesBetween: newlinesBetweenJsonSchema,
|
|
81
86
|
},
|
|
87
|
+
required: ['newlinesBetween'],
|
|
82
88
|
additionalProperties: false,
|
|
83
89
|
type: 'object',
|
|
84
90
|
},
|
|
85
91
|
],
|
|
86
92
|
},
|
|
87
|
-
description: 'Specifies
|
|
93
|
+
description: 'Specifies a list of groups for sorting.',
|
|
88
94
|
type: 'array',
|
|
89
95
|
}
|
|
90
|
-
let
|
|
96
|
+
let deprecatedCustomGroupsJsonSchema = {
|
|
91
97
|
additionalProperties: {
|
|
92
98
|
oneOf: [
|
|
93
99
|
{
|
|
@@ -109,13 +115,16 @@ let singleRegexJsonSchema = {
|
|
|
109
115
|
{
|
|
110
116
|
properties: {
|
|
111
117
|
pattern: {
|
|
118
|
+
description: 'Regular expression pattern.',
|
|
112
119
|
type: 'string',
|
|
113
120
|
},
|
|
114
121
|
flags: {
|
|
122
|
+
description: 'Regular expression flags.',
|
|
115
123
|
type: 'string',
|
|
116
124
|
},
|
|
117
125
|
},
|
|
118
126
|
additionalProperties: false,
|
|
127
|
+
required: ['pattern'],
|
|
119
128
|
// https://github.com/azat-io/eslint-plugin-perfectionist/pull/490#issuecomment-2720969705
|
|
120
129
|
// Uncomment the code below in the next major version (v5)
|
|
121
130
|
// To uncomment: required: ['pattern'],
|
|
@@ -149,25 +158,30 @@ let partitionByCommentJsonSchema = {
|
|
|
149
158
|
{
|
|
150
159
|
properties: {
|
|
151
160
|
block: {
|
|
161
|
+
description: 'Enables specific block comments to separate the nodes.',
|
|
152
162
|
oneOf: allowedPartitionByCommentJsonSchemas,
|
|
153
163
|
},
|
|
154
164
|
line: {
|
|
165
|
+
description: 'Enables specific line comments to separate the nodes.',
|
|
155
166
|
oneOf: allowedPartitionByCommentJsonSchemas,
|
|
156
167
|
},
|
|
157
168
|
},
|
|
158
169
|
additionalProperties: false,
|
|
170
|
+
minProperties: 1,
|
|
159
171
|
type: 'object',
|
|
160
172
|
},
|
|
161
173
|
],
|
|
162
174
|
description:
|
|
163
|
-
'
|
|
175
|
+
'Enables the use of comments to separate the nodes into logical groups.',
|
|
164
176
|
}
|
|
165
177
|
let partitionByNewLineJsonSchema = {
|
|
166
178
|
description:
|
|
167
|
-
'
|
|
179
|
+
'Enables the use of newlines to separate the nodes into logical groups.',
|
|
168
180
|
type: 'boolean',
|
|
169
181
|
}
|
|
170
182
|
let buildUseConfigurationIfJsonSchema = ({ additionalProperties } = {}) => ({
|
|
183
|
+
description:
|
|
184
|
+
'Specifies filters to match a particular options configuration for a given element to sort.',
|
|
171
185
|
properties: {
|
|
172
186
|
allNamesMatchPattern: regexJsonSchema,
|
|
173
187
|
...additionalProperties,
|
|
@@ -180,7 +194,7 @@ let buildCommonCustomGroupJsonSchemas = ({
|
|
|
180
194
|
} = {}) => ({
|
|
181
195
|
newlinesInside: {
|
|
182
196
|
description:
|
|
183
|
-
'Specifies how new lines
|
|
197
|
+
'Specifies how to handle new lines between members of the custom group.',
|
|
184
198
|
enum: ['always', 'never'],
|
|
185
199
|
type: 'string',
|
|
186
200
|
},
|
|
@@ -219,6 +233,7 @@ let buildCustomGroupsArrayJsonSchema = ({
|
|
|
219
233
|
},
|
|
220
234
|
description: 'Custom group block.',
|
|
221
235
|
additionalProperties: false,
|
|
236
|
+
required: ['groupName'],
|
|
222
237
|
type: 'object',
|
|
223
238
|
},
|
|
224
239
|
{
|
|
@@ -230,11 +245,12 @@ let buildCustomGroupsArrayJsonSchema = ({
|
|
|
230
245
|
},
|
|
231
246
|
description: 'Custom group.',
|
|
232
247
|
additionalProperties: false,
|
|
248
|
+
required: ['groupName'],
|
|
233
249
|
type: 'object',
|
|
234
250
|
},
|
|
235
251
|
],
|
|
236
252
|
},
|
|
237
|
-
description: '
|
|
253
|
+
description: 'Defines custom groups to match specific members.',
|
|
238
254
|
type: 'array',
|
|
239
255
|
})
|
|
240
256
|
let buildCustomGroupModifiersJsonSchema = modifiers => ({
|
|
@@ -257,7 +273,7 @@ exports.buildCustomGroupSelectorJsonSchema = buildCustomGroupSelectorJsonSchema
|
|
|
257
273
|
exports.buildCustomGroupsArrayJsonSchema = buildCustomGroupsArrayJsonSchema
|
|
258
274
|
exports.buildUseConfigurationIfJsonSchema = buildUseConfigurationIfJsonSchema
|
|
259
275
|
exports.commonJsonSchemas = commonJsonSchemas
|
|
260
|
-
exports.
|
|
276
|
+
exports.deprecatedCustomGroupsJsonSchema = deprecatedCustomGroupsJsonSchema
|
|
261
277
|
exports.groupsJsonSchema = groupsJsonSchema
|
|
262
278
|
exports.newlinesBetweenJsonSchema = newlinesBetweenJsonSchema
|
|
263
279
|
exports.partitionByCommentJsonSchema = partitionByCommentJsonSchema
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
let getCommentsBefore = ({ tokenValueToIgnoreBefore, sourceCode, node }) => {
|
|
4
|
-
let commentsBefore =
|
|
4
|
+
let commentsBefore = getRelevantCommentsBeforeNodeOrToken(sourceCode, node)
|
|
5
5
|
let tokenBeforeNode = sourceCode.getTokenBefore(node)
|
|
6
6
|
if (
|
|
7
7
|
commentsBefore.length > 0 ||
|
|
@@ -11,15 +11,20 @@ let getCommentsBefore = ({ tokenValueToIgnoreBefore, sourceCode, node }) => {
|
|
|
11
11
|
) {
|
|
12
12
|
return commentsBefore
|
|
13
13
|
}
|
|
14
|
-
return
|
|
14
|
+
return getRelevantCommentsBeforeNodeOrToken(sourceCode, tokenBeforeNode)
|
|
15
15
|
}
|
|
16
|
-
let
|
|
17
|
-
source
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
let getRelevantCommentsBeforeNodeOrToken = (source, node) =>
|
|
17
|
+
source
|
|
18
|
+
.getCommentsBefore(node)
|
|
19
|
+
.filter(comment => !isShebangComment(comment))
|
|
20
|
+
.filter(comment => {
|
|
21
|
+
let tokenBeforeComment = source.getTokenBefore(comment)
|
|
22
|
+
return (
|
|
23
|
+
(tokenBeforeComment == null
|
|
24
|
+
? void 0
|
|
25
|
+
: tokenBeforeComment.loc.end.line) !== comment.loc.end.line
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
let isShebangComment = comment =>
|
|
29
|
+
comment.type === 'Shebang' || comment.type === 'Hashbang'
|
|
25
30
|
exports.getCommentsBefore = getCommentsBefore
|
|
@@ -28,12 +28,8 @@ let reportAllErrors = ({
|
|
|
28
28
|
)
|
|
29
29
|
: /* @__PURE__ */ new Set()
|
|
30
30
|
pairwise.pairwise(nodes, (left, right) => {
|
|
31
|
-
let leftNumber = options.groups
|
|
32
|
-
|
|
33
|
-
: 0
|
|
34
|
-
let rightNumber = options.groups
|
|
35
|
-
? getGroupNumber.getGroupNumber(options.groups, right)
|
|
36
|
-
: 0
|
|
31
|
+
let leftNumber = getGroupNumber.getGroupNumber(options.groups, left)
|
|
32
|
+
let rightNumber = getGroupNumber.getGroupNumber(options.groups, right)
|
|
37
33
|
let leftIndex = nodeIndexMap.get(left)
|
|
38
34
|
let rightIndex = nodeIndexMap.get(right)
|
|
39
35
|
let indexOfRightExcludingEslintDisabled =
|
|
@@ -66,7 +62,6 @@ let reportAllErrors = ({
|
|
|
66
62
|
}
|
|
67
63
|
if (
|
|
68
64
|
options.newlinesBetween &&
|
|
69
|
-
options.groups &&
|
|
70
65
|
availableMessageIds.missedSpacingBetweenMembers &&
|
|
71
66
|
availableMessageIds.extraSpacingBetweenMembers
|
|
72
67
|
) {
|
|
@@ -76,7 +71,6 @@ let reportAllErrors = ({
|
|
|
76
71
|
options: {
|
|
77
72
|
...options,
|
|
78
73
|
newlinesBetween: options.newlinesBetween,
|
|
79
|
-
groups: options.groups,
|
|
80
74
|
},
|
|
81
75
|
missedSpacingError: availableMessageIds.missedSpacingBetweenMembers,
|
|
82
76
|
extraSpacingError: availableMessageIds.extraSpacingBetweenMembers,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.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",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"./dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@typescript-eslint/types": "^8.
|
|
31
|
-
"@typescript-eslint/utils": "^8.
|
|
30
|
+
"@typescript-eslint/types": "^8.32.1",
|
|
31
|
+
"@typescript-eslint/utils": "^8.32.1",
|
|
32
32
|
"natural-orderby": "^5.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
-
const validateNewlinesBetweenInsideGroups = require('./validate-newlines-between-inside-groups.js')
|
|
4
|
-
const validateNoDuplicatedGroups = require('./validate-no-duplicated-groups.js')
|
|
5
|
-
const isNewlinesBetweenOption = require('./is-newlines-between-option.js')
|
|
6
|
-
let validateGroupsConfiguration = ({
|
|
7
|
-
allowedPredefinedGroups,
|
|
8
|
-
allowedCustomGroups,
|
|
9
|
-
options,
|
|
10
|
-
}) => {
|
|
11
|
-
let allowedGroupsSet = /* @__PURE__ */ new Set([
|
|
12
|
-
...allowedPredefinedGroups,
|
|
13
|
-
...allowedCustomGroups,
|
|
14
|
-
])
|
|
15
|
-
let invalidGroups = []
|
|
16
|
-
for (let groupElement of options.groups) {
|
|
17
|
-
if (isNewlinesBetweenOption.isNewlinesBetweenOption(groupElement)) {
|
|
18
|
-
continue
|
|
19
|
-
}
|
|
20
|
-
let groupElements = Array.isArray(groupElement)
|
|
21
|
-
? groupElement
|
|
22
|
-
: [groupElement]
|
|
23
|
-
for (let group of groupElements) {
|
|
24
|
-
if (!allowedGroupsSet.has(group)) {
|
|
25
|
-
invalidGroups.push(group)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (invalidGroups.length > 0) {
|
|
30
|
-
throw new Error(`Invalid group(s): ${invalidGroups.join(', ')}`)
|
|
31
|
-
}
|
|
32
|
-
validateNoDuplicatedGroups.validateNoDuplicatedGroups(options)
|
|
33
|
-
validateNewlinesBetweenInsideGroups.validateNewlinesBetweenInsideGroups(
|
|
34
|
-
options,
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
exports.validateGroupsConfiguration = validateGroupsConfiguration
|