eslint-plugin-perfectionist 4.7.0 → 4.9.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/rules/sort-array-includes/types.js +1 -1
- package/dist/rules/sort-array-includes.js +8 -19
- package/dist/rules/sort-classes/types.js +3 -6
- package/dist/rules/sort-classes.js +103 -104
- package/dist/rules/sort-decorators.js +62 -60
- package/dist/rules/sort-enums/does-custom-group-match.js +36 -0
- package/dist/rules/sort-enums/types.js +8 -0
- package/dist/rules/sort-enums.js +68 -15
- package/dist/rules/sort-exports.js +3 -2
- package/dist/rules/sort-heritage-clauses.js +11 -12
- package/dist/rules/sort-imports.js +14 -21
- package/dist/rules/sort-interfaces.js +18 -20
- package/dist/rules/sort-intersection-types.js +6 -8
- package/dist/rules/sort-jsx-props.js +65 -39
- package/dist/rules/sort-maps/types.js +1 -1
- package/dist/rules/sort-maps.js +10 -17
- package/dist/rules/sort-modules/types.js +2 -5
- package/dist/rules/sort-modules.js +17 -24
- package/dist/rules/sort-named-exports.js +20 -8
- package/dist/rules/sort-named-imports.js +3 -3
- package/dist/rules/sort-object-types/types.js +1 -1
- package/dist/rules/sort-object-types.js +28 -50
- package/dist/rules/sort-objects/types.js +2 -2
- package/dist/rules/sort-objects.js +19 -39
- package/dist/rules/sort-sets.js +5 -7
- package/dist/rules/sort-switch-case.js +8 -9
- package/dist/rules/sort-union-types.js +23 -26
- package/dist/rules/sort-variable-declarations.js +7 -7
- package/dist/utils/common-json-schemas.js +48 -32
- package/dist/utils/compare.js +16 -4
- package/dist/utils/get-comment-after.js +1 -1
- package/dist/utils/get-custom-groups-compare-options.js +2 -11
- package/dist/utils/get-decorator-name.js +10 -0
- package/dist/utils/get-newlines-between-option.js +20 -4
- package/dist/utils/get-newlines-errors.js +9 -0
- package/dist/utils/is-newlines-between-option.js +5 -0
- package/dist/utils/is-partition-comment.js +14 -10
- package/dist/utils/make-fixes.js +2 -0
- package/dist/utils/make-newlines-fixes.js +9 -0
- package/dist/utils/matches.js +9 -1
- package/dist/utils/report-all-errors.js +6 -3
- package/dist/utils/report-errors.js +29 -10
- package/dist/utils/sort-nodes-by-dependencies.js +1 -3
- package/dist/utils/validate-generated-groups-configuration.js +11 -8
- package/dist/utils/validate-groups-configuration.js +20 -39
- package/dist/utils/validate-newlines-and-partition-configuration.js +3 -2
- package/dist/utils/validate-newlines-between-inside-groups.js +18 -0
- package/dist/utils/validate-no-duplicated-groups.js +22 -0
- package/package.json +3 -3
- package/readme.md +3 -3
- package/dist/rules/sort-decorators/get-decorator-name.js +0 -23
package/dist/rules/sort-enums.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
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 validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
|
|
3
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
7
|
+
const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
|
|
4
8
|
const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
|
|
5
9
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
10
|
+
const doesCustomGroupMatch = require('./sort-enums/does-custom-group-match.js')
|
|
6
11
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
12
|
+
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
13
|
+
const types = require('./sort-enums/types.js')
|
|
7
14
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
8
15
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
9
16
|
const shouldPartition = require('../utils/should-partition.js')
|
|
@@ -12,19 +19,23 @@ const getSourceCode = require('../utils/get-source-code.js')
|
|
|
12
19
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
13
20
|
const getSettings = require('../utils/get-settings.js')
|
|
14
21
|
const isSortable = require('../utils/is-sortable.js')
|
|
15
|
-
const
|
|
22
|
+
const useGroups = require('../utils/use-groups.js')
|
|
16
23
|
const complete = require('../utils/complete.js')
|
|
17
24
|
let defaultOptions = {
|
|
25
|
+
fallbackSort: { type: 'unsorted' },
|
|
18
26
|
partitionByComment: false,
|
|
19
27
|
partitionByNewLine: false,
|
|
20
28
|
specialCharacters: 'keep',
|
|
29
|
+
newlinesBetween: 'ignore',
|
|
21
30
|
forceNumericSort: false,
|
|
22
31
|
type: 'alphabetical',
|
|
23
32
|
sortByValue: false,
|
|
24
33
|
ignoreCase: true,
|
|
25
34
|
locales: 'en-US',
|
|
35
|
+
customGroups: [],
|
|
26
36
|
alphabet: '',
|
|
27
37
|
order: 'asc',
|
|
38
|
+
groups: [],
|
|
28
39
|
}
|
|
29
40
|
const sortEnums = createEslintRule.createEslintRule({
|
|
30
41
|
create: context => ({
|
|
@@ -43,6 +54,16 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
43
54
|
defaultOptions,
|
|
44
55
|
)
|
|
45
56
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
57
|
+
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
|
|
58
|
+
{
|
|
59
|
+
selectors: [],
|
|
60
|
+
modifiers: [],
|
|
61
|
+
options,
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
65
|
+
options,
|
|
66
|
+
)
|
|
46
67
|
let sourceCode = getSourceCode.getSourceCode(context)
|
|
47
68
|
let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
|
|
48
69
|
ruleName: context.id,
|
|
@@ -85,23 +106,40 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
85
106
|
enumDeclaration.id.name,
|
|
86
107
|
)
|
|
87
108
|
}
|
|
109
|
+
let name =
|
|
110
|
+
member.id.type === 'Literal'
|
|
111
|
+
? `${member.id.value}`
|
|
112
|
+
: sourceCode.getText(member.id)
|
|
113
|
+
let { defineGroup, getGroup } = useGroups.useGroups(options)
|
|
114
|
+
for (let customGroup of options.customGroups) {
|
|
115
|
+
if (
|
|
116
|
+
doesCustomGroupMatch.doesCustomGroupMatch({
|
|
117
|
+
elementValue: sourceCode.getText(member.initializer),
|
|
118
|
+
elementName: name,
|
|
119
|
+
customGroup,
|
|
120
|
+
})
|
|
121
|
+
) {
|
|
122
|
+
defineGroup(customGroup.groupName, true)
|
|
123
|
+
if (getGroup() === customGroup.groupName) {
|
|
124
|
+
break
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
88
128
|
let lastSortingNode =
|
|
89
129
|
(_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
|
|
90
130
|
let sortingNode = {
|
|
91
131
|
numericValue: member.initializer
|
|
92
132
|
? getExpressionNumberValue(member.initializer)
|
|
93
133
|
: null,
|
|
94
|
-
name:
|
|
95
|
-
member.id.type === 'Literal'
|
|
96
|
-
? `${member.id.value}`
|
|
97
|
-
: sourceCode.getText(member.id),
|
|
98
134
|
isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
|
|
99
135
|
member,
|
|
100
136
|
eslintDisabledLines,
|
|
101
137
|
),
|
|
102
138
|
size: rangeToDiff.rangeToDiff(member, sourceCode),
|
|
139
|
+
group: getGroup(),
|
|
103
140
|
node: member,
|
|
104
141
|
dependencies,
|
|
142
|
+
name,
|
|
105
143
|
}
|
|
106
144
|
if (
|
|
107
145
|
shouldPartition.shouldPartition({
|
|
@@ -125,6 +163,7 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
125
163
|
!Number.isNaN(sortingNode.numericValue),
|
|
126
164
|
)
|
|
127
165
|
let compareOptions = {
|
|
166
|
+
...options,
|
|
128
167
|
// Get the enum value rather than the name if needed.
|
|
129
168
|
nodeValueGetter:
|
|
130
169
|
options.sortByValue || (isNumericEnum && options.forceNumericSort)
|
|
@@ -155,16 +194,16 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
155
194
|
isNumericEnum && (options.forceNumericSort || options.sortByValue)
|
|
156
195
|
? 'natural'
|
|
157
196
|
: options.type,
|
|
158
|
-
specialCharacters: options.specialCharacters,
|
|
159
|
-
ignoreCase: options.ignoreCase,
|
|
160
|
-
alphabet: options.alphabet,
|
|
161
|
-
locales: options.locales,
|
|
162
|
-
order: options.order,
|
|
163
197
|
}
|
|
164
198
|
let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
|
|
165
199
|
sortNodesByDependencies.sortNodesByDependencies(
|
|
166
200
|
formattedMembers.flatMap(sortingNodes =>
|
|
167
|
-
|
|
201
|
+
sortNodesByGroups.sortNodesByGroups(sortingNodes, compareOptions, {
|
|
202
|
+
getGroupCompareOptions: groupNumber =>
|
|
203
|
+
getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
|
|
204
|
+
compareOptions,
|
|
205
|
+
groupNumber,
|
|
206
|
+
),
|
|
168
207
|
ignoreEslintDisabledNodes,
|
|
169
208
|
}),
|
|
170
209
|
),
|
|
@@ -174,7 +213,10 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
174
213
|
)
|
|
175
214
|
reportAllErrors.reportAllErrors({
|
|
176
215
|
availableMessageIds: {
|
|
216
|
+
missedSpacingBetweenMembers: 'missedSpacingBetweenEnumsMembers',
|
|
217
|
+
extraSpacingBetweenMembers: 'extraSpacingBetweenEnumsMembers',
|
|
177
218
|
unexpectedDependencyOrder: 'unexpectedEnumsDependencyOrder',
|
|
219
|
+
unexpectedGroupOrder: 'unexpectedEnumsGroupOrder',
|
|
178
220
|
unexpectedOrder: 'unexpectedEnumsOrder',
|
|
179
221
|
},
|
|
180
222
|
sortNodesExcludingEslintDisabled,
|
|
@@ -195,22 +237,33 @@ const sortEnums = createEslintRule.createEslintRule({
|
|
|
195
237
|
'Will always sort numeric enums by their value regardless of the sort type specified.',
|
|
196
238
|
type: 'boolean',
|
|
197
239
|
},
|
|
240
|
+
customGroups: {
|
|
241
|
+
oneOf: [
|
|
242
|
+
commonJsonSchemas.customGroupsJsonSchema,
|
|
243
|
+
commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
|
|
244
|
+
singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
|
|
245
|
+
}),
|
|
246
|
+
],
|
|
247
|
+
},
|
|
198
248
|
sortByValue: {
|
|
199
249
|
description: 'Compare enum values instead of names.',
|
|
200
250
|
type: 'boolean',
|
|
201
251
|
},
|
|
202
252
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
203
253
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
204
|
-
|
|
254
|
+
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
255
|
+
groups: commonJsonSchemas.groupsJsonSchema,
|
|
205
256
|
},
|
|
206
257
|
additionalProperties: false,
|
|
207
258
|
type: 'object',
|
|
208
259
|
},
|
|
209
260
|
],
|
|
210
261
|
messages: {
|
|
211
|
-
unexpectedEnumsDependencyOrder:
|
|
212
|
-
|
|
213
|
-
|
|
262
|
+
unexpectedEnumsDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
263
|
+
missedSpacingBetweenEnumsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
264
|
+
extraSpacingBetweenEnumsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
265
|
+
unexpectedEnumsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
266
|
+
unexpectedEnumsOrder: reportErrors.ORDER_ERROR,
|
|
214
267
|
},
|
|
215
268
|
docs: {
|
|
216
269
|
url: 'https://perfectionist.dev/rules/sort-enums',
|
|
@@ -8,10 +8,12 @@ const reportAllErrors = require('../utils/report-all-errors.js')
|
|
|
8
8
|
const shouldPartition = require('../utils/should-partition.js')
|
|
9
9
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
10
10
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
11
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
11
12
|
const getSettings = require('../utils/get-settings.js')
|
|
12
13
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
13
14
|
const complete = require('../utils/complete.js')
|
|
14
15
|
let defaultOptions = {
|
|
16
|
+
fallbackSort: { type: 'unsorted' },
|
|
15
17
|
specialCharacters: 'keep',
|
|
16
18
|
partitionByComment: false,
|
|
17
19
|
partitionByNewLine: false,
|
|
@@ -118,7 +120,6 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
118
120
|
},
|
|
119
121
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
120
122
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
121
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
122
123
|
},
|
|
123
124
|
additionalProperties: false,
|
|
124
125
|
type: 'object',
|
|
@@ -130,7 +131,7 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
130
131
|
recommended: true,
|
|
131
132
|
},
|
|
132
133
|
messages: {
|
|
133
|
-
unexpectedExportsOrder:
|
|
134
|
+
unexpectedExportsOrder: reportErrors.ORDER_ERROR,
|
|
134
135
|
},
|
|
135
136
|
type: 'suggestion',
|
|
136
137
|
fixable: 'code',
|
|
@@ -4,6 +4,7 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
|
|
|
4
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
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
7
8
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
8
9
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
9
10
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
@@ -14,6 +15,7 @@ const isSortable = require('../utils/is-sortable.js')
|
|
|
14
15
|
const useGroups = require('../utils/use-groups.js')
|
|
15
16
|
const complete = require('../utils/complete.js')
|
|
16
17
|
let defaultOptions = {
|
|
18
|
+
fallbackSort: { type: 'unsorted' },
|
|
17
19
|
specialCharacters: 'keep',
|
|
18
20
|
type: 'alphabetical',
|
|
19
21
|
ignoreCase: true,
|
|
@@ -30,24 +32,21 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
30
32
|
properties: {
|
|
31
33
|
...commonJsonSchemas.commonJsonSchemas,
|
|
32
34
|
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
33
|
-
type: commonJsonSchemas.buildTypeJsonSchema(),
|
|
34
35
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
35
36
|
},
|
|
36
37
|
additionalProperties: false,
|
|
37
38
|
type: 'object',
|
|
38
39
|
},
|
|
39
40
|
],
|
|
40
|
-
messages: {
|
|
41
|
-
unexpectedHeritageClausesGroupOrder:
|
|
42
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
43
|
-
unexpectedHeritageClausesOrder:
|
|
44
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
45
|
-
},
|
|
46
41
|
docs: {
|
|
47
42
|
url: 'https://perfectionist.dev/rules/sort-heritage-clauses',
|
|
48
43
|
description: 'Enforce sorted heritage clauses.',
|
|
49
44
|
recommended: true,
|
|
50
45
|
},
|
|
46
|
+
messages: {
|
|
47
|
+
unexpectedHeritageClausesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
48
|
+
unexpectedHeritageClausesOrder: reportErrors.ORDER_ERROR,
|
|
49
|
+
},
|
|
51
50
|
type: 'suggestion',
|
|
52
51
|
fixable: 'code',
|
|
53
52
|
},
|
|
@@ -59,11 +58,11 @@ const sortHeritageClauses = createEslintRule.createEslintRule({
|
|
|
59
58
|
defaultOptions,
|
|
60
59
|
)
|
|
61
60
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
62
|
-
validateGroupsConfiguration.validateGroupsConfiguration(
|
|
63
|
-
options.
|
|
64
|
-
['unknown'],
|
|
65
|
-
|
|
66
|
-
)
|
|
61
|
+
validateGroupsConfiguration.validateGroupsConfiguration({
|
|
62
|
+
allowedCustomGroups: Object.keys(options.customGroups),
|
|
63
|
+
allowedPredefinedGroups: ['unknown'],
|
|
64
|
+
options,
|
|
65
|
+
})
|
|
67
66
|
return {
|
|
68
67
|
TSInterfaceDeclaration: declaration =>
|
|
69
68
|
sortHeritageClauses$1(context, options, declaration.extends),
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const node_module = require('node:module')
|
|
3
3
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
4
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
4
5
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
5
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
6
7
|
const readClosestTsConfigByPath = require('./sort-imports/read-closest-ts-config-by-path.js')
|
|
7
8
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
8
9
|
const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
|
|
10
|
+
const isNewlinesBetweenOption = require('../utils/is-newlines-between-option.js')
|
|
9
11
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
10
12
|
const getTypescriptImport = require('./sort-imports/get-typescript-import.js')
|
|
11
13
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
@@ -37,6 +39,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
37
39
|
'unknown',
|
|
38
40
|
],
|
|
39
41
|
customGroups: { value: {}, type: {} },
|
|
42
|
+
fallbackSort: { type: 'unsorted' },
|
|
40
43
|
internalPattern: ['^~/.+'],
|
|
41
44
|
partitionByComment: false,
|
|
42
45
|
partitionByNewLine: false,
|
|
@@ -51,9 +54,8 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
51
54
|
order: 'asc',
|
|
52
55
|
}),
|
|
53
56
|
)
|
|
54
|
-
validateGroupsConfiguration.validateGroupsConfiguration(
|
|
55
|
-
|
|
56
|
-
[
|
|
57
|
+
validateGroupsConfiguration.validateGroupsConfiguration({
|
|
58
|
+
allowedPredefinedGroups: [
|
|
57
59
|
'side-effect-style',
|
|
58
60
|
'external-type',
|
|
59
61
|
'internal-type',
|
|
@@ -73,11 +75,12 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
73
75
|
'style',
|
|
74
76
|
'type',
|
|
75
77
|
],
|
|
76
|
-
[
|
|
78
|
+
allowedCustomGroups: [
|
|
77
79
|
...Object.keys(options.customGroups.type ?? {}),
|
|
78
80
|
...Object.keys(options.customGroups.value ?? {}),
|
|
79
81
|
],
|
|
80
|
-
|
|
82
|
+
options,
|
|
83
|
+
})
|
|
81
84
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
82
85
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
83
86
|
options,
|
|
@@ -90,7 +93,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
90
93
|
})
|
|
91
94
|
: null
|
|
92
95
|
let isSideEffectOnlyGroup = group => {
|
|
93
|
-
if (!group || (
|
|
96
|
+
if (!group || isNewlinesBetweenOption.isNewlinesBetweenOption(group)) {
|
|
94
97
|
return false
|
|
95
98
|
}
|
|
96
99
|
if (typeof group === 'string') {
|
|
@@ -426,13 +429,6 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
426
429
|
additionalProperties: false,
|
|
427
430
|
type: 'object',
|
|
428
431
|
},
|
|
429
|
-
internalPattern: {
|
|
430
|
-
description: 'Specifies the pattern for internal modules.',
|
|
431
|
-
items: {
|
|
432
|
-
type: 'string',
|
|
433
|
-
},
|
|
434
|
-
type: 'array',
|
|
435
|
-
},
|
|
436
432
|
maxLineLength: {
|
|
437
433
|
description: 'Specifies the maximum line length.',
|
|
438
434
|
exclusiveMinimum: true,
|
|
@@ -456,7 +452,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
456
452
|
partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
|
|
457
453
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
458
454
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
459
|
-
|
|
455
|
+
internalPattern: commonJsonSchemas.regexJsonSchema,
|
|
460
456
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
461
457
|
},
|
|
462
458
|
definitions: {
|
|
@@ -496,13 +492,10 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
496
492
|
},
|
|
497
493
|
],
|
|
498
494
|
messages: {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
extraSpacingBetweenImports:
|
|
504
|
-
'Extra spacing between "{{left}}" and "{{right}}" imports.',
|
|
505
|
-
unexpectedImportsOrder: 'Expected "{{right}}" to come before "{{left}}".',
|
|
495
|
+
missedSpacingBetweenImports: reportErrors.MISSED_SPACING_ERROR,
|
|
496
|
+
extraSpacingBetweenImports: reportErrors.EXTRA_SPACING_ERROR,
|
|
497
|
+
unexpectedImportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
498
|
+
unexpectedImportsOrder: reportErrors.ORDER_ERROR,
|
|
506
499
|
},
|
|
507
500
|
docs: {
|
|
508
501
|
url: 'https://perfectionist.dev/rules/sort-imports',
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
2
3
|
const sortObjectTypes = require('./sort-object-types.js')
|
|
3
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
4
5
|
let defaultOptions = {
|
|
6
|
+
fallbackSort: { type: 'unsorted' },
|
|
5
7
|
partitionByComment: false,
|
|
6
8
|
partitionByNewLine: false,
|
|
7
9
|
newlinesBetween: 'ignore',
|
|
@@ -18,26 +20,6 @@ let defaultOptions = {
|
|
|
18
20
|
groups: [],
|
|
19
21
|
}
|
|
20
22
|
const sortInterfaces = createEslintRule.createEslintRule({
|
|
21
|
-
meta: {
|
|
22
|
-
messages: {
|
|
23
|
-
unexpectedInterfacePropertiesGroupOrder:
|
|
24
|
-
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
|
|
25
|
-
missedSpacingBetweenInterfaceMembers:
|
|
26
|
-
'Missed spacing between "{{left}}" and "{{right}}" properties.',
|
|
27
|
-
extraSpacingBetweenInterfaceMembers:
|
|
28
|
-
'Extra spacing between "{{left}}" and "{{right}}" properties.',
|
|
29
|
-
unexpectedInterfacePropertiesOrder:
|
|
30
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
31
|
-
},
|
|
32
|
-
docs: {
|
|
33
|
-
url: 'https://perfectionist.dev/rules/sort-interfaces',
|
|
34
|
-
description: 'Enforce sorted interface properties.',
|
|
35
|
-
recommended: true,
|
|
36
|
-
},
|
|
37
|
-
schema: sortObjectTypes.jsonSchema,
|
|
38
|
-
type: 'suggestion',
|
|
39
|
-
fixable: 'code',
|
|
40
|
-
},
|
|
41
23
|
create: context => ({
|
|
42
24
|
TSInterfaceDeclaration: node =>
|
|
43
25
|
sortObjectTypes.sortObjectTypeElements({
|
|
@@ -52,6 +34,22 @@ const sortInterfaces = createEslintRule.createEslintRule({
|
|
|
52
34
|
context,
|
|
53
35
|
}),
|
|
54
36
|
}),
|
|
37
|
+
meta: {
|
|
38
|
+
messages: {
|
|
39
|
+
unexpectedInterfacePropertiesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
40
|
+
missedSpacingBetweenInterfaceMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
41
|
+
extraSpacingBetweenInterfaceMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
42
|
+
unexpectedInterfacePropertiesOrder: reportErrors.ORDER_ERROR,
|
|
43
|
+
},
|
|
44
|
+
docs: {
|
|
45
|
+
url: 'https://perfectionist.dev/rules/sort-interfaces',
|
|
46
|
+
description: 'Enforce sorted interface properties.',
|
|
47
|
+
recommended: true,
|
|
48
|
+
},
|
|
49
|
+
schema: sortObjectTypes.jsonSchema,
|
|
50
|
+
type: 'suggestion',
|
|
51
|
+
fixable: 'code',
|
|
52
|
+
},
|
|
55
53
|
defaultOptions: [defaultOptions],
|
|
56
54
|
name: 'sort-interfaces',
|
|
57
55
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
2
3
|
const sortUnionTypes = require('./sort-union-types.js')
|
|
3
4
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
4
5
|
let defaultOptions = {
|
|
6
|
+
fallbackSort: { type: 'unsorted' },
|
|
5
7
|
specialCharacters: 'keep',
|
|
6
8
|
newlinesBetween: 'ignore',
|
|
7
9
|
partitionByComment: false,
|
|
@@ -16,14 +18,10 @@ let defaultOptions = {
|
|
|
16
18
|
const sortIntersectionTypes = createEslintRule.createEslintRule({
|
|
17
19
|
meta: {
|
|
18
20
|
messages: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
extraSpacingBetweenIntersectionTypes:
|
|
24
|
-
'Extra spacing between "{{left}}" and "{{right}}" types.',
|
|
25
|
-
unexpectedIntersectionTypesOrder:
|
|
26
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
21
|
+
missedSpacingBetweenIntersectionTypes: reportErrors.MISSED_SPACING_ERROR,
|
|
22
|
+
extraSpacingBetweenIntersectionTypes: reportErrors.EXTRA_SPACING_ERROR,
|
|
23
|
+
unexpectedIntersectionTypesGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
24
|
+
unexpectedIntersectionTypesOrder: reportErrors.ORDER_ERROR,
|
|
27
25
|
},
|
|
28
26
|
docs: {
|
|
29
27
|
url: 'https://perfectionist.dev/rules/sort-intersection-types',
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const types = require('@typescript-eslint/types')
|
|
2
3
|
const commonJsonSchemas = require('../utils/common-json-schemas.js')
|
|
4
|
+
const reportErrors = require('../utils/report-errors.js')
|
|
3
5
|
const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
|
|
4
6
|
const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
|
|
5
7
|
const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
|
|
8
|
+
const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
|
|
6
9
|
const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
|
|
7
10
|
const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
|
|
8
11
|
const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
|
|
@@ -17,9 +20,11 @@ const useGroups = require('../utils/use-groups.js')
|
|
|
17
20
|
const complete = require('../utils/complete.js')
|
|
18
21
|
const matches = require('../utils/matches.js')
|
|
19
22
|
let defaultOptions = {
|
|
23
|
+
fallbackSort: { type: 'unsorted' },
|
|
20
24
|
specialCharacters: 'keep',
|
|
21
25
|
newlinesBetween: 'ignore',
|
|
22
26
|
partitionByNewLine: false,
|
|
27
|
+
useConfigurationIf: {},
|
|
23
28
|
type: 'alphabetical',
|
|
24
29
|
ignorePattern: [],
|
|
25
30
|
ignoreCase: true,
|
|
@@ -36,28 +41,50 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
36
41
|
return
|
|
37
42
|
}
|
|
38
43
|
let settings = getSettings.getSettings(context.settings)
|
|
44
|
+
let sourceCode = getSourceCode.getSourceCode(context)
|
|
45
|
+
let matchedContextOptions = getMatchingContextOptions
|
|
46
|
+
.getMatchingContextOptions({
|
|
47
|
+
nodeNames: node.openingElement.attributes
|
|
48
|
+
.filter(
|
|
49
|
+
attribute =>
|
|
50
|
+
attribute.type !==
|
|
51
|
+
types.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute,
|
|
52
|
+
)
|
|
53
|
+
.map(attribute => getNodeName({ attribute })),
|
|
54
|
+
contextOptions: context.options,
|
|
55
|
+
})
|
|
56
|
+
.find(options2 => {
|
|
57
|
+
var _a
|
|
58
|
+
if (
|
|
59
|
+
!((_a = options2.useConfigurationIf) == null
|
|
60
|
+
? void 0
|
|
61
|
+
: _a.tagMatchesPattern)
|
|
62
|
+
) {
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
return matches.matches(
|
|
66
|
+
sourceCode.getText(node.openingElement.name),
|
|
67
|
+
options2.useConfigurationIf.tagMatchesPattern,
|
|
68
|
+
)
|
|
69
|
+
})
|
|
39
70
|
let options = complete.complete(
|
|
40
|
-
|
|
71
|
+
matchedContextOptions,
|
|
41
72
|
settings,
|
|
42
73
|
defaultOptions,
|
|
43
74
|
)
|
|
44
75
|
validateCustomSortConfiguration.validateCustomSortConfiguration(options)
|
|
45
|
-
validateGroupsConfiguration.validateGroupsConfiguration(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
76
|
+
validateGroupsConfiguration.validateGroupsConfiguration({
|
|
77
|
+
allowedPredefinedGroups: ['multiline', 'shorthand', 'unknown'],
|
|
78
|
+
allowedCustomGroups: Object.keys(options.customGroups),
|
|
79
|
+
options,
|
|
80
|
+
})
|
|
50
81
|
validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
|
|
51
82
|
options,
|
|
52
83
|
)
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
shouldIgnore = options.ignorePattern.some(pattern =>
|
|
58
|
-
matches.matches(tagName, pattern),
|
|
59
|
-
)
|
|
60
|
-
}
|
|
84
|
+
let shouldIgnore = matches.matches(
|
|
85
|
+
sourceCode.getText(node.openingElement.name),
|
|
86
|
+
options.ignorePattern,
|
|
87
|
+
)
|
|
61
88
|
if (
|
|
62
89
|
shouldIgnore ||
|
|
63
90
|
!isSortable.isSortable(node.openingElement.attributes)
|
|
@@ -71,14 +98,13 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
71
98
|
let formattedMembers = node.openingElement.attributes.reduce(
|
|
72
99
|
(accumulator, attribute) => {
|
|
73
100
|
var _a
|
|
74
|
-
if (
|
|
101
|
+
if (
|
|
102
|
+
attribute.type === types.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute
|
|
103
|
+
) {
|
|
75
104
|
accumulator.push([])
|
|
76
105
|
return accumulator
|
|
77
106
|
}
|
|
78
|
-
let name =
|
|
79
|
-
attribute.name.type === 'JSXNamespacedName'
|
|
80
|
-
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
81
|
-
: attribute.name.name
|
|
107
|
+
let name = getNodeName({ attribute })
|
|
82
108
|
let { setCustomGroups, defineGroup, getGroup } =
|
|
83
109
|
useGroups.useGroups(options)
|
|
84
110
|
setCustomGroups(options.customGroups, name)
|
|
@@ -136,37 +162,33 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
136
162
|
},
|
|
137
163
|
}),
|
|
138
164
|
meta: {
|
|
139
|
-
schema:
|
|
140
|
-
{
|
|
165
|
+
schema: {
|
|
166
|
+
items: {
|
|
141
167
|
properties: {
|
|
142
168
|
...commonJsonSchemas.commonJsonSchemas,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
type: 'array',
|
|
150
|
-
},
|
|
169
|
+
useConfigurationIf:
|
|
170
|
+
commonJsonSchemas.buildUseConfigurationIfJsonSchema({
|
|
171
|
+
additionalProperties: {
|
|
172
|
+
tagMatchesPattern: commonJsonSchemas.regexJsonSchema,
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
151
175
|
partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
|
|
152
176
|
newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
|
|
153
177
|
customGroups: commonJsonSchemas.customGroupsJsonSchema,
|
|
154
|
-
|
|
178
|
+
ignorePattern: commonJsonSchemas.regexJsonSchema,
|
|
155
179
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
156
180
|
},
|
|
157
181
|
additionalProperties: false,
|
|
158
182
|
type: 'object',
|
|
159
183
|
},
|
|
160
|
-
|
|
184
|
+
uniqueItems: true,
|
|
185
|
+
type: 'array',
|
|
186
|
+
},
|
|
161
187
|
messages: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
extraSpacingBetweenJSXPropsMembers:
|
|
167
|
-
'Extra spacing between "{{left}}" and "{{right}}" props.',
|
|
168
|
-
unexpectedJSXPropsOrder:
|
|
169
|
-
'Expected "{{right}}" to come before "{{left}}".',
|
|
188
|
+
missedSpacingBetweenJSXPropsMembers: reportErrors.MISSED_SPACING_ERROR,
|
|
189
|
+
extraSpacingBetweenJSXPropsMembers: reportErrors.EXTRA_SPACING_ERROR,
|
|
190
|
+
unexpectedJSXPropsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
191
|
+
unexpectedJSXPropsOrder: reportErrors.ORDER_ERROR,
|
|
170
192
|
},
|
|
171
193
|
docs: {
|
|
172
194
|
url: 'https://perfectionist.dev/rules/sort-jsx-props',
|
|
@@ -179,4 +201,8 @@ const sortJsxProps = createEslintRule.createEslintRule({
|
|
|
179
201
|
defaultOptions: [defaultOptions],
|
|
180
202
|
name: 'sort-jsx-props',
|
|
181
203
|
})
|
|
204
|
+
let getNodeName = ({ attribute }) =>
|
|
205
|
+
attribute.name.type === types.TSESTree.AST_NODE_TYPES.JSXNamespacedName
|
|
206
|
+
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
207
|
+
: attribute.name.name
|
|
182
208
|
module.exports = sortJsxProps
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const commonJsonSchemas = require('../../utils/common-json-schemas.js')
|
|
4
4
|
let singleCustomGroupJsonSchema = {
|
|
5
|
-
elementNamePattern: commonJsonSchemas.
|
|
5
|
+
elementNamePattern: commonJsonSchemas.regexJsonSchema,
|
|
6
6
|
}
|
|
7
7
|
exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
|