eslint-plugin-perfectionist 4.12.3 → 4.14.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-classes.js +2 -2
- package/dist/rules/sort-decorators.js +5 -5
- package/dist/rules/sort-enums.js +6 -6
- package/dist/rules/sort-exports.js +2 -0
- package/dist/rules/sort-heritage-clauses.js +5 -5
- package/dist/rules/sort-imports/compute-common-selectors.js +15 -5
- package/dist/rules/sort-imports/is-side-effect-only-group.js +5 -1
- package/dist/rules/sort-imports/read-closest-ts-config-by-path.js +11 -13
- package/dist/rules/sort-imports.js +59 -84
- package/dist/rules/sort-intersection-types.js +2 -1
- package/dist/rules/sort-jsx-props.js +1 -1
- package/dist/rules/sort-modules.js +2 -2
- package/dist/rules/sort-object-types.js +4 -2
- package/dist/rules/sort-objects.js +1 -1
- package/dist/rules/sort-switch-case.js +7 -0
- 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 +33 -12
- package/dist/utils/get-comment-above-that-should-exist.js +34 -0
- package/dist/utils/get-comments-before.js +16 -11
- package/dist/utils/{get-group-number.js → get-group-index.js} +2 -2
- package/dist/utils/{get-newlines-errors.js → get-newlines-between-errors.js} +5 -5
- package/dist/utils/get-newlines-between-option.js +3 -6
- package/dist/utils/is-comment-above-option.js +5 -0
- package/dist/utils/make-comment-above-fixes.js +109 -0
- package/dist/utils/make-fixes.js +28 -11
- package/dist/utils/{make-newlines-fixes.js → make-newlines-between-fixes.js} +2 -2
- package/dist/utils/make-single-node-comment-after-fixes.js +16 -2
- package/dist/utils/pairwise.js +2 -1
- package/dist/utils/report-all-errors.js +37 -19
- package/dist/utils/report-errors.js +17 -11
- package/dist/utils/should-partition.js +9 -2
- package/dist/utils/sort-nodes-by-groups.js +2 -2
- package/dist/utils/validate-generated-groups-configuration.js +2 -4
- package/dist/utils/validate-no-duplicated-groups.js +5 -1
- package/dist/utils/validate-objects-inside-groups.js +18 -0
- package/package.json +3 -3
- package/dist/utils/get-comment-after.js +0 -18
- package/dist/utils/has-partition-comment.js +0 -11
- package/dist/utils/to-single-line.js +0 -4
- package/dist/utils/validate-groups-configuration.js +0 -37
- package/dist/utils/validate-newlines-between-inside-groups.js +0 -18
package/dist/package.json.js
CHANGED
|
@@ -18,7 +18,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
18
18
|
const getDecoratorName = require('../utils/get-decorator-name.js')
|
|
19
19
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
20
20
|
const shouldPartition = require('../utils/should-partition.js')
|
|
21
|
-
const
|
|
21
|
+
const getGroupIndex = require('../utils/get-group-index.js')
|
|
22
22
|
const computeGroup = require('../utils/compute-group.js')
|
|
23
23
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
24
24
|
const getSettings = require('../utils/get-settings.js')
|
|
@@ -474,7 +474,7 @@ const sortClasses = createEslintRule.createEslintRule({
|
|
|
474
474
|
let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
|
|
475
475
|
sortNodesByGroups.sortNodesByGroups({
|
|
476
476
|
isNodeIgnored: sortingNode =>
|
|
477
|
-
|
|
477
|
+
getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
|
|
478
478
|
options.groups.length,
|
|
479
479
|
getOptionsByGroupNumber:
|
|
480
480
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
@@ -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',
|
|
@@ -142,6 +142,7 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
142
142
|
missedSpacingBetweenMembers: 'missedSpacingBetweenExports',
|
|
143
143
|
extraSpacingBetweenMembers: 'extraSpacingBetweenExports',
|
|
144
144
|
unexpectedGroupOrder: 'unexpectedExportsGroupOrder',
|
|
145
|
+
missedCommentAbove: 'missedCommentAboveExport',
|
|
145
146
|
unexpectedOrder: 'unexpectedExportsOrder',
|
|
146
147
|
},
|
|
147
148
|
sortNodesExcludingEslintDisabled,
|
|
@@ -185,6 +186,7 @@ const sortExports = createEslintRule.createEslintRule({
|
|
|
185
186
|
type: 'array',
|
|
186
187
|
},
|
|
187
188
|
messages: {
|
|
189
|
+
missedCommentAboveExport: reportErrors.MISSED_COMMENT_ABOVE_ERROR,
|
|
188
190
|
missedSpacingBetweenExports: reportErrors.MISSED_SPACING_ERROR,
|
|
189
191
|
extraSpacingBetweenExports: reportErrors.EXTRA_SPACING_ERROR,
|
|
190
192
|
unexpectedExportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
@@ -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 {
|
|
@@ -65,12 +65,22 @@ let builtinPrefixOnlyModules = /* @__PURE__ */ new Set([
|
|
|
65
65
|
'node:sea',
|
|
66
66
|
])
|
|
67
67
|
let isCoreModule = (value, environment) => {
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
let clean = string_ => string_.replace(/^(?:node:){1,2}/u, '')
|
|
69
|
+
let [basePath] = value.split('/')
|
|
70
|
+
let cleanValue = clean(value)
|
|
71
|
+
let cleanBase = clean(basePath)
|
|
72
|
+
if (nodeBuiltinModules.has(cleanValue) || nodeBuiltinModules.has(cleanBase)) {
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
71
76
|
builtinPrefixOnlyModules.has(value) ||
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
builtinPrefixOnlyModules.has(`node:${cleanValue}`) ||
|
|
78
|
+
builtinPrefixOnlyModules.has(basePath) ||
|
|
79
|
+
builtinPrefixOnlyModules.has(`node:${cleanBase}`)
|
|
80
|
+
) {
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
return environment === 'bun' && bunModules.has(value)
|
|
74
84
|
}
|
|
75
85
|
let isParent = value => value.startsWith('..')
|
|
76
86
|
let isSibling = value => value.startsWith('./')
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
3
|
const isNewlinesBetweenOption = require('../../utils/is-newlines-between-option.js')
|
|
4
|
+
const isCommentAboveOption = require('../../utils/is-comment-above-option.js')
|
|
4
5
|
let isSideEffectOnlyGroup = group => {
|
|
5
|
-
if (
|
|
6
|
+
if (
|
|
7
|
+
isNewlinesBetweenOption.isNewlinesBetweenOption(group) ||
|
|
8
|
+
isCommentAboveOption.isCommentAboveOption(group)
|
|
9
|
+
) {
|
|
6
10
|
return false
|
|
7
11
|
}
|
|
8
12
|
if (typeof group === 'string') {
|
|
@@ -29,15 +29,20 @@ const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path)
|
|
|
29
29
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs)
|
|
30
30
|
let directoryCacheByPath = /* @__PURE__ */ new Map()
|
|
31
31
|
let contentCacheByPath = /* @__PURE__ */ new Map()
|
|
32
|
-
let readClosestTsConfigByPath =
|
|
32
|
+
let readClosestTsConfigByPath = ({
|
|
33
|
+
tsconfigFilename,
|
|
34
|
+
tsconfigRootDir,
|
|
35
|
+
contextCwd,
|
|
36
|
+
filePath,
|
|
37
|
+
}) => {
|
|
33
38
|
let typescriptImport = getTypescriptImport.getTypescriptImport()
|
|
34
39
|
if (!typescriptImport) {
|
|
35
40
|
return null
|
|
36
41
|
}
|
|
37
|
-
let directory = path__namespace.dirname(
|
|
42
|
+
let directory = path__namespace.dirname(filePath)
|
|
38
43
|
let checkedDirectories = [directory]
|
|
39
44
|
do {
|
|
40
|
-
let tsconfigPath = path__namespace.join(directory,
|
|
45
|
+
let tsconfigPath = path__namespace.join(directory, tsconfigFilename)
|
|
41
46
|
let cachedDirectory = directoryCacheByPath.get(directory)
|
|
42
47
|
if (!cachedDirectory && fs__namespace.existsSync(tsconfigPath)) {
|
|
43
48
|
cachedDirectory = tsconfigPath
|
|
@@ -46,20 +51,13 @@ let readClosestTsConfigByPath = input => {
|
|
|
46
51
|
for (let checkedDirectory of checkedDirectories) {
|
|
47
52
|
directoryCacheByPath.set(checkedDirectory, cachedDirectory)
|
|
48
53
|
}
|
|
49
|
-
return getCompilerOptions(
|
|
50
|
-
typescriptImport,
|
|
51
|
-
input.contextCwd,
|
|
52
|
-
cachedDirectory,
|
|
53
|
-
)
|
|
54
|
+
return getCompilerOptions(typescriptImport, contextCwd, cachedDirectory)
|
|
54
55
|
}
|
|
55
56
|
directory = path__namespace.dirname(directory)
|
|
56
57
|
checkedDirectories.push(directory)
|
|
57
|
-
} while (
|
|
58
|
-
directory.length > 1 &&
|
|
59
|
-
directory.length >= input.tsconfigRootDir.length
|
|
60
|
-
)
|
|
58
|
+
} while (directory.length > 1 && directory.length >= tsconfigRootDir.length)
|
|
61
59
|
throw new Error(
|
|
62
|
-
`Couldn't find any
|
|
60
|
+
`Couldn't find any ${tsconfigFilename} relative to '${filePath}' within '${tsconfigRootDir}'.`,
|
|
63
61
|
)
|
|
64
62
|
}
|
|
65
63
|
let getCompilerOptions = (typescriptImport, contextCwd, filePath) => {
|
|
@@ -26,38 +26,39 @@ const getSettings = require('../utils/get-settings.js')
|
|
|
26
26
|
const isSortable = require('../utils/is-sortable.js')
|
|
27
27
|
const complete = require('../utils/complete.js')
|
|
28
28
|
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
let defaultOptions = {
|
|
30
|
+
groups: [
|
|
31
|
+
'type-import',
|
|
32
|
+
['value-builtin', 'value-external'],
|
|
33
|
+
'type-internal',
|
|
34
|
+
'value-internal',
|
|
35
|
+
['type-parent', 'type-sibling', 'type-index'],
|
|
36
|
+
['value-parent', 'value-sibling', 'value-index'],
|
|
37
|
+
'ts-equals-import',
|
|
38
|
+
'unknown',
|
|
39
|
+
],
|
|
40
|
+
internalPattern: ['^~/.+', '^@/.+'],
|
|
41
|
+
fallbackSort: { type: 'unsorted' },
|
|
42
|
+
partitionByComment: false,
|
|
43
|
+
partitionByNewLine: false,
|
|
44
|
+
newlinesBetween: 'always',
|
|
45
|
+
specialCharacters: 'keep',
|
|
46
|
+
sortSideEffects: false,
|
|
47
|
+
type: 'alphabetical',
|
|
48
|
+
environment: 'node',
|
|
49
|
+
customGroups: [],
|
|
50
|
+
ignoreCase: true,
|
|
51
|
+
locales: 'en-US',
|
|
52
|
+
alphabet: '',
|
|
53
|
+
order: 'asc',
|
|
54
|
+
}
|
|
39
55
|
const sortImports = createEslintRule.createEslintRule({
|
|
40
56
|
create: context => {
|
|
57
|
+
var _a, _b
|
|
41
58
|
let settings = getSettings.getSettings(context.settings)
|
|
42
59
|
let userOptions = context.options.at(0)
|
|
43
60
|
let options = getOptionsWithCleanGroups.getOptionsWithCleanGroups(
|
|
44
|
-
complete.complete(userOptions, settings,
|
|
45
|
-
fallbackSort: { type: 'unsorted' },
|
|
46
|
-
internalPattern: ['^~/.+'],
|
|
47
|
-
partitionByComment: false,
|
|
48
|
-
partitionByNewLine: false,
|
|
49
|
-
newlinesBetween: 'always',
|
|
50
|
-
specialCharacters: 'keep',
|
|
51
|
-
sortSideEffects: false,
|
|
52
|
-
groups: defaultGroups,
|
|
53
|
-
type: 'alphabetical',
|
|
54
|
-
environment: 'node',
|
|
55
|
-
customGroups: [],
|
|
56
|
-
ignoreCase: true,
|
|
57
|
-
locales: 'en-US',
|
|
58
|
-
alphabet: '',
|
|
59
|
-
order: 'asc',
|
|
60
|
-
}),
|
|
61
|
+
complete.complete(userOptions, settings, defaultOptions),
|
|
61
62
|
)
|
|
62
63
|
validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
|
|
63
64
|
options: {
|
|
@@ -77,9 +78,15 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
77
78
|
options,
|
|
78
79
|
)
|
|
79
80
|
validateSideEffectsConfiguration.validateSideEffectsConfiguration(options)
|
|
80
|
-
let
|
|
81
|
+
let tsconfigRootDirectory =
|
|
82
|
+
((_a = options.tsconfig) == null ? void 0 : _a.rootDir) ??
|
|
83
|
+
options.tsconfigRootDir
|
|
84
|
+
let tsConfigOutput = tsconfigRootDirectory
|
|
81
85
|
? readClosestTsConfigByPath.readClosestTsConfigByPath({
|
|
82
|
-
|
|
86
|
+
tsconfigFilename:
|
|
87
|
+
((_b = options.tsconfig) == null ? void 0 : _b.filename) ??
|
|
88
|
+
'tsconfig.json',
|
|
89
|
+
tsconfigRootDir: tsconfigRootDirectory,
|
|
83
90
|
filePath: context.physicalFilename,
|
|
84
91
|
contextCwd: context.cwd,
|
|
85
92
|
})
|
|
@@ -306,6 +313,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
306
313
|
missedSpacingBetweenMembers: 'missedSpacingBetweenImports',
|
|
307
314
|
extraSpacingBetweenMembers: 'extraSpacingBetweenImports',
|
|
308
315
|
unexpectedGroupOrder: 'unexpectedImportsGroupOrder',
|
|
316
|
+
missedCommentAbove: 'missedCommentAboveImport',
|
|
309
317
|
unexpectedOrder: 'unexpectedImportsOrder',
|
|
310
318
|
},
|
|
311
319
|
options: {
|
|
@@ -322,15 +330,15 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
322
330
|
}
|
|
323
331
|
},
|
|
324
332
|
VariableDeclaration: node => {
|
|
325
|
-
var
|
|
333
|
+
var _a2
|
|
326
334
|
if (
|
|
327
335
|
node.declarations[0].init &&
|
|
328
336
|
node.declarations[0].init.type === 'CallExpression' &&
|
|
329
337
|
node.declarations[0].init.callee.type === 'Identifier' &&
|
|
330
338
|
node.declarations[0].init.callee.name === 'require' &&
|
|
331
|
-
((
|
|
339
|
+
((_a2 = node.declarations[0].init.arguments[0]) == null
|
|
332
340
|
? void 0
|
|
333
|
-
:
|
|
341
|
+
: _a2.type) === 'Literal'
|
|
334
342
|
) {
|
|
335
343
|
registerNode(node)
|
|
336
344
|
}
|
|
@@ -349,12 +357,12 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
349
357
|
{
|
|
350
358
|
properties: {
|
|
351
359
|
value: {
|
|
360
|
+
...commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
352
361
|
description: 'Specifies custom groups for value imports.',
|
|
353
|
-
type: 'object',
|
|
354
362
|
},
|
|
355
363
|
type: {
|
|
364
|
+
...commonJsonSchemas.deprecatedCustomGroupsJsonSchema,
|
|
356
365
|
description: 'Specifies custom groups for type imports.',
|
|
357
|
-
type: 'object',
|
|
358
366
|
},
|
|
359
367
|
},
|
|
360
368
|
description: 'Specifies custom groups.',
|
|
@@ -366,6 +374,21 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
366
374
|
}),
|
|
367
375
|
],
|
|
368
376
|
},
|
|
377
|
+
tsconfig: {
|
|
378
|
+
properties: {
|
|
379
|
+
rootDir: {
|
|
380
|
+
description: 'Specifies the tsConfig root directory.',
|
|
381
|
+
type: 'string',
|
|
382
|
+
},
|
|
383
|
+
filename: {
|
|
384
|
+
description: 'Specifies the tsConfig filename.',
|
|
385
|
+
type: 'string',
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
additionalProperties: false,
|
|
389
|
+
required: ['rootDir'],
|
|
390
|
+
type: 'object',
|
|
391
|
+
},
|
|
369
392
|
maxLineLength: {
|
|
370
393
|
description: 'Specifies the maximum line length.',
|
|
371
394
|
exclusiveMinimum: true,
|
|
@@ -392,46 +415,15 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
392
415
|
internalPattern: commonJsonSchemas.regexJsonSchema,
|
|
393
416
|
groups: commonJsonSchemas.groupsJsonSchema,
|
|
394
417
|
},
|
|
395
|
-
allOf: [
|
|
396
|
-
{
|
|
397
|
-
$ref: '#/definitions/max-line-length-requires-line-length-type',
|
|
398
|
-
},
|
|
399
|
-
],
|
|
400
|
-
dependencies: {
|
|
401
|
-
maxLineLength: ['type'],
|
|
402
|
-
},
|
|
403
418
|
additionalProperties: false,
|
|
404
419
|
type: 'object',
|
|
405
420
|
},
|
|
406
|
-
definitions: {
|
|
407
|
-
'max-line-length-requires-line-length-type': {
|
|
408
|
-
anyOf: [
|
|
409
|
-
{
|
|
410
|
-
not: {
|
|
411
|
-
required: ['maxLineLength'],
|
|
412
|
-
type: 'object',
|
|
413
|
-
},
|
|
414
|
-
type: 'object',
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
$ref: '#/definitions/is-line-length',
|
|
418
|
-
},
|
|
419
|
-
],
|
|
420
|
-
},
|
|
421
|
-
'is-line-length': {
|
|
422
|
-
properties: {
|
|
423
|
-
type: { enum: ['line-length'], type: 'string' },
|
|
424
|
-
},
|
|
425
|
-
required: ['type'],
|
|
426
|
-
type: 'object',
|
|
427
|
-
},
|
|
428
|
-
},
|
|
429
|
-
id: 'sort-imports',
|
|
430
421
|
uniqueItems: true,
|
|
431
422
|
type: 'array',
|
|
432
423
|
},
|
|
433
424
|
messages: {
|
|
434
425
|
unexpectedImportsDependencyOrder: reportErrors.DEPENDENCY_ORDER_ERROR,
|
|
426
|
+
missedCommentAboveImport: reportErrors.MISSED_COMMENT_ABOVE_ERROR,
|
|
435
427
|
missedSpacingBetweenImports: reportErrors.MISSED_SPACING_ERROR,
|
|
436
428
|
extraSpacingBetweenImports: reportErrors.EXTRA_SPACING_ERROR,
|
|
437
429
|
unexpectedImportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
|
|
@@ -445,24 +437,7 @@ const sortImports = createEslintRule.createEslintRule({
|
|
|
445
437
|
type: 'suggestion',
|
|
446
438
|
fixable: 'code',
|
|
447
439
|
},
|
|
448
|
-
defaultOptions: [
|
|
449
|
-
{
|
|
450
|
-
customGroups: { value: {}, type: {} },
|
|
451
|
-
internalPattern: ['^~/.+'],
|
|
452
|
-
partitionByComment: false,
|
|
453
|
-
partitionByNewLine: false,
|
|
454
|
-
specialCharacters: 'keep',
|
|
455
|
-
newlinesBetween: 'always',
|
|
456
|
-
sortSideEffects: false,
|
|
457
|
-
groups: defaultGroups,
|
|
458
|
-
type: 'alphabetical',
|
|
459
|
-
environment: 'node',
|
|
460
|
-
ignoreCase: true,
|
|
461
|
-
locales: 'en-US',
|
|
462
|
-
alphabet: '',
|
|
463
|
-
order: 'asc',
|
|
464
|
-
},
|
|
465
|
-
],
|
|
440
|
+
defaultOptions: [defaultOptions],
|
|
466
441
|
name: 'sort-imports',
|
|
467
442
|
})
|
|
468
443
|
let hasContentBetweenNodes = (sourceCode, left, right) =>
|
|
@@ -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
|
}),
|
|
@@ -18,8 +18,8 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
18
18
|
const getDecoratorName = require('../utils/get-decorator-name.js')
|
|
19
19
|
const reportAllErrors = require('../utils/report-all-errors.js')
|
|
20
20
|
const shouldPartition = require('../utils/should-partition.js')
|
|
21
|
-
const getGroupNumber = require('../utils/get-group-number.js')
|
|
22
21
|
const getEnumMembers = require('../utils/get-enum-members.js')
|
|
22
|
+
const getGroupIndex = require('../utils/get-group-index.js')
|
|
23
23
|
const computeGroup = require('../utils/compute-group.js')
|
|
24
24
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
25
25
|
const getSettings = require('../utils/get-settings.js')
|
|
@@ -284,7 +284,7 @@ let analyzeModule = ({
|
|
|
284
284
|
let nodesSortedByGroups = formattedNodes.flatMap(nodes2 =>
|
|
285
285
|
sortNodesByGroups.sortNodesByGroups({
|
|
286
286
|
isNodeIgnored: sortingNode =>
|
|
287
|
-
|
|
287
|
+
getGroupIndex.getGroupIndex(options.groups, sortingNode) ===
|
|
288
288
|
options.groups.length,
|
|
289
289
|
getOptionsByGroupNumber:
|
|
290
290
|
getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
|
|
@@ -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
|
}),
|
|
@@ -77,6 +77,9 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
77
77
|
sortedCaseNameSortingNodes,
|
|
78
78
|
)
|
|
79
79
|
pairwise.pairwise(caseNodesSortingNodeGroup, (left, right) => {
|
|
80
|
+
if (!left) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
80
83
|
let leftIndex = nodeIndexMap.get(left)
|
|
81
84
|
let rightIndex = nodeIndexMap.get(right)
|
|
82
85
|
if (leftIndex < rightIndex) {
|
|
@@ -198,6 +201,9 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
198
201
|
let sortingNodeGroupsForBlockSortFlat =
|
|
199
202
|
sortingNodeGroupsForBlockSort.flat()
|
|
200
203
|
pairwise.pairwise(sortingNodeGroupsForBlockSortFlat, (left, right) => {
|
|
204
|
+
if (!left) {
|
|
205
|
+
return
|
|
206
|
+
}
|
|
201
207
|
let indexOfLeft = sortedSortingNodeGroupsForBlockSort.indexOf(left)
|
|
202
208
|
let indexOfRight = sortedSortingNodeGroupsForBlockSort.indexOf(right)
|
|
203
209
|
if (indexOfLeft < indexOfRight) {
|
|
@@ -210,6 +216,7 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
210
216
|
: makeFixes.makeFixes({
|
|
211
217
|
sortedNodes: sortedSortingNodeGroupsForBlockSort,
|
|
212
218
|
nodes: sortingNodeGroupsForBlockSortFlat,
|
|
219
|
+
hasCommentAboveMissing: false,
|
|
213
220
|
sourceCode,
|
|
214
221
|
fixer,
|
|
215
222
|
}),
|
|
@@ -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
|