eslint-plugin-perfectionist 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alphabet.d.ts +1 -1
- package/dist/index.d.ts +15 -244
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-array-includes/types.d.ts +3 -3
- package/dist/rules/sort-array-includes.d.ts +5 -3
- package/dist/rules/sort-array-includes.js +1 -1
- package/dist/rules/sort-classes/types.d.ts +3 -3
- package/dist/rules/sort-classes.d.ts +5 -3
- package/dist/rules/sort-classes.js +1 -1
- package/dist/rules/sort-decorators/types.d.ts +4 -4
- package/dist/rules/sort-decorators.d.ts +5 -3
- package/dist/rules/sort-decorators.js +1 -1
- package/dist/rules/sort-enums/build-comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-enums/types.d.ts +4 -4
- package/dist/rules/sort-enums.d.ts +5 -3
- package/dist/rules/sort-enums.js +1 -1
- package/dist/rules/sort-export-attributes/types.d.ts +4 -4
- package/dist/rules/sort-export-attributes.d.ts +5 -3
- package/dist/rules/sort-export-attributes.js +1 -1
- package/dist/rules/sort-exports/types.d.ts +3 -3
- package/dist/rules/sort-exports.d.ts +5 -3
- package/dist/rules/sort-exports.js +14 -12
- package/dist/rules/sort-heritage-clauses/types.d.ts +3 -3
- package/dist/rules/sort-heritage-clauses.d.ts +5 -3
- package/dist/rules/sort-heritage-clauses.js +1 -1
- package/dist/rules/sort-import-attributes/types.d.ts +4 -4
- package/dist/rules/sort-import-attributes.d.ts +5 -3
- package/dist/rules/sort-import-attributes.js +1 -1
- package/dist/rules/sort-imports/comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-imports/comparator-by-options-computer.js +48 -4
- package/dist/rules/sort-imports/compute-common-selectors.d.ts +3 -3
- package/dist/rules/sort-imports/compute-specifier-name.d.ts +12 -0
- package/dist/rules/sort-imports/compute-specifier-name.js +64 -0
- package/dist/rules/sort-imports/is-side-effect-only-group.d.ts +1 -1
- package/dist/rules/sort-imports/matches-tsconfig-paths.d.ts +1 -1
- package/dist/rules/sort-imports/types.d.ts +16 -6
- package/dist/rules/sort-imports/types.js +5 -0
- package/dist/rules/sort-imports/validate-side-effects-configuration.d.ts +1 -1
- package/dist/rules/sort-imports.d.ts +5 -3
- package/dist/rules/sort-imports.js +7 -1
- package/dist/rules/sort-interfaces.d.ts +5 -3
- package/dist/rules/sort-interfaces.js +0 -1
- package/dist/rules/sort-intersection-types.d.ts +5 -3
- package/dist/rules/sort-intersection-types.js +1 -1
- package/dist/rules/sort-jsx-props/types.d.ts +3 -3
- package/dist/rules/sort-jsx-props.d.ts +5 -3
- package/dist/rules/sort-jsx-props.js +1 -1
- package/dist/rules/sort-maps/types.d.ts +3 -3
- package/dist/rules/sort-maps.d.ts +5 -3
- package/dist/rules/sort-maps.js +1 -1
- package/dist/rules/sort-modules/build-comparator-by-options-computer.d.ts +12 -0
- package/dist/rules/sort-modules/build-comparator-by-options-computer.js +66 -0
- package/dist/rules/sort-modules/compute-dependencies.d.ts +27 -0
- package/dist/rules/sort-modules/compute-dependencies.js +195 -0
- package/dist/rules/sort-modules/is-arrow-function-node.d.ts +12 -0
- package/dist/rules/sort-modules/is-arrow-function-node.js +10 -0
- package/dist/rules/sort-modules/is-property-or-accessor-node.d.ts +11 -0
- package/dist/rules/sort-modules/is-property-or-accessor-node.js +8 -0
- package/dist/rules/sort-modules/types.d.ts +16 -5
- package/dist/rules/sort-modules/types.js +7 -1
- package/dist/rules/sort-modules.d.ts +5 -3
- package/dist/rules/sort-modules.js +34 -142
- package/dist/rules/sort-named-exports/compute-node-name.d.ts +12 -0
- package/dist/rules/sort-named-exports/compute-node-name.js +15 -0
- package/dist/rules/sort-named-exports/types.d.ts +4 -4
- package/dist/rules/sort-named-exports.d.ts +5 -3
- package/dist/rules/sort-named-exports.js +18 -21
- package/dist/rules/sort-named-imports/compute-node-name.d.ts +12 -0
- package/dist/rules/sort-named-imports/compute-node-name.js +17 -0
- package/dist/rules/sort-named-imports/types.d.ts +4 -4
- package/dist/rules/sort-named-imports.d.ts +5 -3
- package/dist/rules/sort-named-imports.js +20 -19
- package/dist/rules/sort-object-types/comparator-by-options-computer.d.ts +2 -2
- package/dist/rules/sort-object-types/compute-matched-context-options.d.ts +1 -1
- package/dist/rules/sort-object-types/compute-node-parent-name.d.ts +1 -1
- package/dist/rules/sort-object-types/passes-declaration-comment-matches-filter.d.ts +2 -2
- package/dist/rules/sort-object-types/passes-declaration-matches-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-object-types/types.d.ts +14 -35
- package/dist/rules/sort-object-types/types.js +0 -1
- package/dist/rules/sort-object-types.d.ts +5 -3
- package/dist/rules/sort-object-types.js +24 -26
- package/dist/rules/sort-objects/compute-matched-context-options.d.ts +1 -1
- package/dist/rules/sort-objects/passes-calling-function-name-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-objects/passes-declaration-comment-matches-filter.d.ts +2 -2
- package/dist/rules/sort-objects/passes-declaration-matches-pattern-filter.d.ts +2 -2
- package/dist/rules/sort-objects/types.d.ts +5 -5
- package/dist/rules/sort-objects.d.ts +5 -3
- package/dist/rules/sort-objects.js +1 -1
- package/dist/rules/sort-sets.d.ts +5 -3
- package/dist/rules/sort-sets.js +0 -1
- package/dist/rules/sort-switch-case.d.ts +5 -3
- package/dist/rules/sort-switch-case.js +0 -1
- package/dist/rules/sort-union-types/types.d.ts +3 -3
- package/dist/rules/sort-union-types.d.ts +5 -3
- package/dist/rules/sort-union-types.js +1 -1
- package/dist/rules/sort-variable-declarations/types.d.ts +3 -3
- package/dist/rules/sort-variable-declarations.d.ts +5 -3
- package/dist/rules/sort-variable-declarations.js +1 -1
- package/dist/types/common-groups-options.d.ts +47 -18
- package/dist/types/common-options.d.ts +11 -5
- package/dist/types/common-partition-options.d.ts +1 -1
- package/dist/types/scoped-regex-option.d.ts +1 -1
- package/dist/utils/build-default-options-by-group-index-computer.d.ts +3 -3
- package/dist/utils/compare/build-line-length-comparator.d.ts +3 -3
- package/dist/utils/compare/build-string-formatter.d.ts +1 -1
- package/dist/utils/compare/compare-alphabetically.d.ts +1 -1
- package/dist/utils/compare/compare-by-custom-sort.d.ts +1 -1
- package/dist/utils/compare/compare-naturally.d.ts +1 -1
- package/dist/utils/compare/compute-comparators.d.ts +3 -3
- package/dist/utils/compare/compute-ordered-value.d.ts +1 -1
- package/dist/utils/compare/default-comparator-by-options-computer.d.ts +2 -2
- package/dist/utils/compare/unsorted-comparator.d.ts +2 -2
- package/dist/utils/complete.d.ts +1 -1
- package/dist/utils/complete.js +1 -52
- package/dist/utils/compute-group-name.d.ts +1 -1
- package/dist/utils/compute-group.d.ts +7 -7
- package/dist/utils/compute-group.js +22 -19
- package/dist/utils/compute-groups-names.d.ts +1 -1
- package/dist/utils/compute-nodes-in-circular-dependencies.d.ts +5 -2
- package/dist/utils/compute-overridden-options-by-group-index.d.ts +2 -2
- package/dist/utils/compute-overridden-options-by-group-index.js +38 -19
- package/dist/utils/compute-parent-nodes-with-types.d.ts +1 -1
- package/dist/utils/create-eslint-rule.d.ts +3 -1
- package/dist/utils/create-node-index-map.d.ts +1 -1
- package/dist/utils/does-custom-group-match.d.ts +2 -2
- package/dist/utils/filter-options-by-all-names-match.d.ts +1 -1
- package/dist/utils/get-comment-above-that-should-exist.d.ts +2 -2
- package/dist/utils/get-group-index.d.ts +2 -2
- package/dist/utils/get-lines-between.d.ts +1 -1
- package/dist/utils/get-newlines-between-errors.d.ts +2 -2
- package/dist/utils/get-newlines-between-option.d.ts +8 -2
- package/dist/utils/get-newlines-between-option.js +17 -31
- package/dist/utils/get-node-range.d.ts +1 -1
- package/dist/utils/get-options-with-clean-groups.d.ts +1 -1
- package/dist/utils/get-settings.d.ts +11 -13
- package/dist/utils/get-settings.js +2 -0
- package/dist/utils/is-group-with-overrides-option.d.ts +10 -3
- package/dist/utils/is-newlines-between-option.d.ts +1 -1
- package/dist/utils/is-node-dependent-on-other-node.d.ts +9 -3
- package/dist/utils/is-partition-comment.d.ts +1 -1
- package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +14 -11
- package/dist/utils/json-schemas/common-groups-json-schemas.js +81 -54
- package/dist/utils/json-schemas/common-json-schemas.d.ts +4 -4
- package/dist/utils/json-schemas/common-json-schemas.js +3 -2
- package/dist/utils/make-comment-above-fixes.d.ts +2 -2
- package/dist/utils/make-comment-after-fixes.d.ts +1 -1
- package/dist/utils/make-fixes.d.ts +7 -9
- package/dist/utils/make-newlines-between-fixes.d.ts +3 -3
- package/dist/utils/make-order-fixes.d.ts +2 -2
- package/dist/utils/matches.d.ts +1 -1
- package/dist/utils/report-all-errors.d.ts +21 -23
- package/dist/utils/report-errors.d.ts +4 -4
- package/dist/utils/scoped-regex/matches-scoped-expressions.d.ts +2 -2
- package/dist/utils/scoped-regex/partition-patterns-by-scope.d.ts +1 -1
- package/dist/utils/should-partition.d.ts +4 -4
- package/dist/utils/sort-nodes-by-dependencies.d.ts +5 -2
- package/dist/utils/sort-nodes-by-groups.d.ts +4 -4
- package/dist/utils/sort-nodes.d.ts +3 -3
- package/dist/utils/validate-custom-sort-configuration.d.ts +2 -2
- package/dist/utils/validate-groups-configuration.d.ts +1 -1
- package/dist/utils/validate-newlines-and-partition-configuration.d.ts +5 -3
- package/dist/utils/validate-newlines-and-partition-configuration.js +61 -9
- package/dist/utils/validate-no-duplicated-groups.d.ts +1 -1
- package/dist/utils/validate-objects-inside-groups.d.ts +1 -1
- package/package.json +2 -2
- package/dist/rules/sort-object-types/build-options-by-group-index-computer.d.ts +0 -18
- package/dist/rules/sort-object-types/build-options-by-group-index-computer.js +0 -33
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Options } from './sort-heritage-clauses/types'
|
|
1
|
+
import { Options } from './sort-heritage-clauses/types.js'
|
|
2
2
|
declare const ORDER_ERROR_ID = 'unexpectedHeritageClausesOrder'
|
|
3
3
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedHeritageClausesGroupOrder'
|
|
4
4
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenHeritageClauses'
|
|
@@ -11,7 +11,9 @@ type MessageId =
|
|
|
11
11
|
declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
|
|
12
12
|
MessageId,
|
|
13
13
|
Options,
|
|
14
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
14
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
15
15
|
import('@typescript-eslint/utils/ts-eslint').RuleListener
|
|
16
|
-
>
|
|
16
|
+
> & {
|
|
17
|
+
name: string
|
|
18
|
+
}
|
|
17
19
|
export default _default
|
|
@@ -33,6 +33,7 @@ const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenHeritageClauses'
|
|
|
33
33
|
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenHeritageClauses'
|
|
34
34
|
let defaultOptions = {
|
|
35
35
|
fallbackSort: { type: 'unsorted' },
|
|
36
|
+
newlinesInside: 'newlinesBetween',
|
|
36
37
|
specialCharacters: 'keep',
|
|
37
38
|
newlinesBetween: 'ignore',
|
|
38
39
|
partitionByNewLine: false,
|
|
@@ -72,7 +73,6 @@ const sortHeritageClauses = createEslintRule({
|
|
|
72
73
|
description: 'Enforce sorted heritage clauses.',
|
|
73
74
|
recommended: true,
|
|
74
75
|
},
|
|
75
|
-
defaultOptions: [defaultOptions],
|
|
76
76
|
type: 'suggestion',
|
|
77
77
|
fixable: 'code',
|
|
78
78
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options'
|
|
3
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options'
|
|
4
|
-
import { CommonOptions, TypeOption } from '../../types/common-options'
|
|
5
|
-
import { SortingNode } from '../../types/sorting-node'
|
|
2
|
+
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
3
|
+
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
4
|
+
import { CommonOptions, TypeOption } from '../../types/common-options.js'
|
|
5
|
+
import { SortingNode } from '../../types/sorting-node.js'
|
|
6
6
|
export type Options = Partial<
|
|
7
7
|
CommonGroupsOptions<SingleCustomGroup, Record<string, never>, TypeOption> &
|
|
8
8
|
CommonOptions<TypeOption> &
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
-
import { Options } from './sort-import-attributes/types'
|
|
2
|
+
import { Options } from './sort-import-attributes/types.js'
|
|
3
3
|
declare const ORDER_ERROR_ID = 'unexpectedImportAttributesOrder'
|
|
4
4
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedImportAttributesGroupOrder'
|
|
5
5
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenImportAttributes'
|
|
@@ -12,7 +12,9 @@ type MessageId =
|
|
|
12
12
|
declare const _default: TSESLint.RuleModule<
|
|
13
13
|
MessageId,
|
|
14
14
|
Options,
|
|
15
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
15
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
16
16
|
TSESLint.RuleListener
|
|
17
|
-
>
|
|
17
|
+
> & {
|
|
18
|
+
name: string
|
|
19
|
+
}
|
|
18
20
|
export default _default
|
|
@@ -33,6 +33,7 @@ const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenImportAttributes'
|
|
|
33
33
|
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenImportAttributes'
|
|
34
34
|
let defaultOptions = {
|
|
35
35
|
fallbackSort: { type: 'unsorted' },
|
|
36
|
+
newlinesInside: 'newlinesBetween',
|
|
36
37
|
specialCharacters: 'keep',
|
|
37
38
|
partitionByComment: false,
|
|
38
39
|
partitionByNewLine: false,
|
|
@@ -161,7 +162,6 @@ const sortImportAttributes = createEslintRule({
|
|
|
161
162
|
description: 'Enforce sorted import attributes.',
|
|
162
163
|
recommended: true,
|
|
163
164
|
},
|
|
164
|
-
defaultOptions: [defaultOptions],
|
|
165
165
|
type: 'suggestion',
|
|
166
166
|
fixable: 'code',
|
|
167
167
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer'
|
|
2
|
-
import { SortImportsSortingNode, Options } from './types'
|
|
1
|
+
import { ComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
2
|
+
import { SortImportsSortingNode, Options } from './types.js'
|
|
3
3
|
export declare let comparatorByOptionsComputer: ComparatorByOptionsComputer<
|
|
4
4
|
Required<Options[number]>,
|
|
5
5
|
SortImportsSortingNode
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
2
|
+
import { buildLineLengthComparator } from '../../utils/compare/build-line-length-comparator.js'
|
|
3
|
+
import { compareAlphabetically } from '../../utils/compare/compare-alphabetically.js'
|
|
4
|
+
import { compareByCustomSort } from '../../utils/compare/compare-by-custom-sort.js'
|
|
2
5
|
import { computeOrderedValue } from '../../utils/compare/compute-ordered-value.js'
|
|
6
|
+
import { unsortedComparator } from '../../utils/compare/unsorted-comparator.js'
|
|
3
7
|
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
8
|
+
import { compareNaturally } from '../../utils/compare/compare-naturally.js'
|
|
4
9
|
let comparatorByOptionsComputer = options => {
|
|
5
10
|
switch (options.type) {
|
|
6
11
|
case 'type-import-first':
|
|
@@ -10,10 +15,21 @@ let comparatorByOptionsComputer = options => {
|
|
|
10
15
|
case 'unsorted':
|
|
11
16
|
case 'natural':
|
|
12
17
|
case 'custom':
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
switch (options.sortBy) {
|
|
19
|
+
case 'specifier':
|
|
20
|
+
return bySpecifierComparatorByOptionsComputer({
|
|
21
|
+
...options,
|
|
22
|
+
type: options.type,
|
|
23
|
+
})
|
|
24
|
+
case 'path':
|
|
25
|
+
return defaultComparatorByOptionsComputer({
|
|
26
|
+
...options,
|
|
27
|
+
type: options.type,
|
|
28
|
+
})
|
|
29
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
30
|
+
default:
|
|
31
|
+
throw new UnreachableCaseError(options.sortBy)
|
|
32
|
+
}
|
|
17
33
|
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
18
34
|
default:
|
|
19
35
|
throw new UnreachableCaseError(options.type)
|
|
@@ -28,4 +44,32 @@ function compareTypeImportFirst(a, b, options) {
|
|
|
28
44
|
}
|
|
29
45
|
return computeOrderedValue(a.isTypeImport ? -1 : 1, options.order)
|
|
30
46
|
}
|
|
47
|
+
let bySpecifierComparatorByOptionsComputer = options => {
|
|
48
|
+
switch (options.type) {
|
|
49
|
+
case 'alphabetical':
|
|
50
|
+
return (a, b) =>
|
|
51
|
+
compareAlphabetically(
|
|
52
|
+
a.specifierName ?? '',
|
|
53
|
+
b.specifierName ?? '',
|
|
54
|
+
options,
|
|
55
|
+
)
|
|
56
|
+
case 'line-length':
|
|
57
|
+
return buildLineLengthComparator(options)
|
|
58
|
+
case 'unsorted':
|
|
59
|
+
return unsortedComparator
|
|
60
|
+
case 'natural':
|
|
61
|
+
return (a, b) =>
|
|
62
|
+
compareNaturally(a.specifierName ?? '', b.specifierName ?? '', options)
|
|
63
|
+
case 'custom':
|
|
64
|
+
return (a, b) =>
|
|
65
|
+
compareByCustomSort(
|
|
66
|
+
a.specifierName ?? '',
|
|
67
|
+
b.specifierName ?? '',
|
|
68
|
+
options,
|
|
69
|
+
)
|
|
70
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
71
|
+
default:
|
|
72
|
+
throw new UnreachableCaseError(options.type)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
31
75
|
export { comparatorByOptionsComputer }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ReadClosestTsConfigByPathValue } from './read-closest-ts-config-by-path'
|
|
2
|
-
import { RegexOption } from '../../types/common-options'
|
|
3
|
-
import { Selector } from './types'
|
|
1
|
+
import { ReadClosestTsConfigByPathValue } from './read-closest-ts-config-by-path.js'
|
|
2
|
+
import { RegexOption } from '../../types/common-options.js'
|
|
3
|
+
import { Selector } from './types.js'
|
|
4
4
|
/**
|
|
5
5
|
* Common import selector types that categorize imports by their
|
|
6
6
|
* characteristics.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
3
|
+
export declare function computeSpecifierName({
|
|
4
|
+
sourceCode,
|
|
5
|
+
node,
|
|
6
|
+
}: {
|
|
7
|
+
node:
|
|
8
|
+
| TSESTree.TSImportEqualsDeclaration
|
|
9
|
+
| TSESTree.VariableDeclaration
|
|
10
|
+
| TSESTree.ImportDeclaration
|
|
11
|
+
sourceCode: TSESLint.SourceCode
|
|
12
|
+
}): string | null
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
3
|
+
function computeSpecifierName({ sourceCode, node }) {
|
|
4
|
+
switch (node.type) {
|
|
5
|
+
case AST_NODE_TYPES.TSImportEqualsDeclaration:
|
|
6
|
+
return node.id.name
|
|
7
|
+
case AST_NODE_TYPES.VariableDeclaration:
|
|
8
|
+
return computeVariableDeclarationSpecifierName(node, sourceCode)
|
|
9
|
+
case AST_NODE_TYPES.ImportDeclaration:
|
|
10
|
+
return computeImportDeclarationSpecifierName(node)
|
|
11
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
12
|
+
default:
|
|
13
|
+
throw new UnreachableCaseError(node)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function computeVariableDeclarationSpecifierName(node, sourceCode) {
|
|
17
|
+
let [declaration] = node.declarations
|
|
18
|
+
switch (declaration.id.type) {
|
|
19
|
+
case AST_NODE_TYPES.ObjectPattern:
|
|
20
|
+
return computeObjectPatternPropertyName(declaration.id.properties[0])
|
|
21
|
+
case AST_NODE_TYPES.ArrayPattern:
|
|
22
|
+
if (!declaration.id.elements[0]) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
return sourceCode.getText(declaration.id.elements[0])
|
|
26
|
+
case AST_NODE_TYPES.Identifier:
|
|
27
|
+
return declaration.id.name
|
|
28
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
29
|
+
default:
|
|
30
|
+
throw new UnreachableCaseError(declaration.id)
|
|
31
|
+
}
|
|
32
|
+
function computeObjectPatternPropertyName(property) {
|
|
33
|
+
if (!property) {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
switch (property.type) {
|
|
37
|
+
case AST_NODE_TYPES.RestElement:
|
|
38
|
+
return sourceCode.getText(property.argument)
|
|
39
|
+
case AST_NODE_TYPES.Property:
|
|
40
|
+
return sourceCode.getText(property.value)
|
|
41
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
42
|
+
default:
|
|
43
|
+
throw new UnreachableCaseError(property)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function computeImportDeclarationSpecifierName(node) {
|
|
48
|
+
let [specifier] = node.specifiers
|
|
49
|
+
if (!specifier) {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
switch (specifier.type) {
|
|
53
|
+
case AST_NODE_TYPES.ImportNamespaceSpecifier:
|
|
54
|
+
return specifier.local.name
|
|
55
|
+
case AST_NODE_TYPES.ImportDefaultSpecifier:
|
|
56
|
+
return specifier.local.name
|
|
57
|
+
case AST_NODE_TYPES.ImportSpecifier:
|
|
58
|
+
return specifier.local.name
|
|
59
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
60
|
+
default:
|
|
61
|
+
throw new UnreachableCaseError(specifier)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export { computeSpecifierName }
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
CommonOptions,
|
|
5
5
|
RegexOption,
|
|
6
6
|
TypeOption,
|
|
7
|
-
} from '../../types/common-options'
|
|
8
|
-
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies'
|
|
9
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options'
|
|
10
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options'
|
|
7
|
+
} from '../../types/common-options.js'
|
|
8
|
+
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
9
|
+
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
10
|
+
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
11
11
|
/**
|
|
12
12
|
* Configuration options for the sort-imports rule.
|
|
13
13
|
*
|
|
@@ -55,10 +55,17 @@ export type Options = Partial<
|
|
|
55
55
|
maxLineLength: number
|
|
56
56
|
} & CommonGroupsOptions<
|
|
57
57
|
SingleCustomGroup,
|
|
58
|
-
|
|
58
|
+
{
|
|
59
|
+
sortBy: 'specifier' | 'path'
|
|
60
|
+
},
|
|
59
61
|
CustomTypeOption
|
|
60
62
|
> &
|
|
61
|
-
CommonOptions<
|
|
63
|
+
CommonOptions<
|
|
64
|
+
CustomTypeOption,
|
|
65
|
+
{
|
|
66
|
+
sortBy: 'specifier' | 'path'
|
|
67
|
+
}
|
|
68
|
+
> &
|
|
62
69
|
CommonPartitionOptions
|
|
63
70
|
>[]
|
|
64
71
|
/**
|
|
@@ -70,6 +77,8 @@ export interface SortImportsSortingNode extends SortingNodeWithDependencies<
|
|
|
70
77
|
| TSESTree.VariableDeclaration
|
|
71
78
|
| TSESTree.ImportDeclaration
|
|
72
79
|
> {
|
|
80
|
+
/** The name of the import specifier for sorting purposes. */
|
|
81
|
+
specifierName: string | null
|
|
73
82
|
/** Whether this import is a type-only import. */
|
|
74
83
|
isTypeImport: boolean
|
|
75
84
|
/**
|
|
@@ -144,5 +153,6 @@ export declare let allModifiers: readonly [
|
|
|
144
153
|
* ensure that users do not enter invalid modifiers for a given selector.
|
|
145
154
|
*/
|
|
146
155
|
export declare let singleCustomGroupJsonSchema: Record<string, JSONSchema4>
|
|
156
|
+
export declare let sortByJsonSchema: JSONSchema4
|
|
147
157
|
export declare const TYPE_IMPORT_FIRST_TYPE_OPTION = 'type-import-first'
|
|
148
158
|
export {}
|
|
@@ -33,10 +33,15 @@ let singleCustomGroupJsonSchema = {
|
|
|
33
33
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
34
34
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
35
35
|
}
|
|
36
|
+
let sortByJsonSchema = {
|
|
37
|
+
enum: ['specifier', 'path'],
|
|
38
|
+
type: 'string',
|
|
39
|
+
}
|
|
36
40
|
const TYPE_IMPORT_FIRST_TYPE_OPTION = 'type-import-first'
|
|
37
41
|
export {
|
|
38
42
|
TYPE_IMPORT_FIRST_TYPE_OPTION,
|
|
39
43
|
allModifiers,
|
|
40
44
|
allSelectors,
|
|
41
45
|
singleCustomGroupJsonSchema,
|
|
46
|
+
sortByJsonSchema,
|
|
42
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
-
import { Options } from './sort-imports/types'
|
|
2
|
+
import { Options } from './sort-imports/types.js'
|
|
3
3
|
declare const ORDER_ERROR_ID = 'unexpectedImportsOrder'
|
|
4
4
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedImportsGroupOrder'
|
|
5
5
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenImports'
|
|
@@ -16,7 +16,9 @@ export type MessageId =
|
|
|
16
16
|
declare const _default: TSESLint.RuleModule<
|
|
17
17
|
MessageId,
|
|
18
18
|
Options,
|
|
19
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
19
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
20
20
|
TSESLint.RuleListener
|
|
21
|
-
>
|
|
21
|
+
> & {
|
|
22
|
+
name: string
|
|
23
|
+
}
|
|
22
24
|
export default _default
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
singleCustomGroupJsonSchema,
|
|
11
11
|
TYPE_IMPORT_FIRST_TYPE_OPTION,
|
|
12
|
+
sortByJsonSchema,
|
|
12
13
|
allSelectors,
|
|
13
14
|
allModifiers,
|
|
14
15
|
} from './sort-imports/types.js'
|
|
@@ -36,6 +37,7 @@ import { isSideEffectOnlyGroup } from './sort-imports/is-side-effect-only-group.
|
|
|
36
37
|
import { computeDependencyNames } from './sort-imports/compute-dependency-names.js'
|
|
37
38
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
38
39
|
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.js'
|
|
40
|
+
import { computeSpecifierName } from './sort-imports/compute-specifier-name.js'
|
|
39
41
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
40
42
|
import { computeDependencies } from './sort-imports/compute-dependencies.js'
|
|
41
43
|
import { isSideEffectImport } from './sort-imports/is-side-effect-import.js'
|
|
@@ -81,9 +83,11 @@ let defaultOptions = {
|
|
|
81
83
|
type: 'alphabetical',
|
|
82
84
|
environment: 'node',
|
|
83
85
|
newlinesBetween: 1,
|
|
86
|
+
newlinesInside: 0,
|
|
84
87
|
customGroups: [],
|
|
85
88
|
ignoreCase: true,
|
|
86
89
|
locales: 'en-US',
|
|
90
|
+
sortBy: 'path',
|
|
87
91
|
alphabet: '',
|
|
88
92
|
order: 'asc',
|
|
89
93
|
}
|
|
@@ -192,6 +196,7 @@ const sortImports = createEslintRule({
|
|
|
192
196
|
(!isStyleSideEffect || !shouldRegroupSideEffectStyleNodes),
|
|
193
197
|
isEslintDisabled: isNodeEslintDisabled(node, eslintDisabledLines),
|
|
194
198
|
dependencyNames: computeDependencyNames({ sourceCode, node }),
|
|
199
|
+
specifierName: computeSpecifierName({ sourceCode, node }),
|
|
195
200
|
isTypeImport: modifiers.includes('type'),
|
|
196
201
|
dependencies: computeDependencies(node),
|
|
197
202
|
addSafetySemicolonWhenInline: true,
|
|
@@ -229,9 +234,11 @@ const sortImports = createEslintRule({
|
|
|
229
234
|
properties: {
|
|
230
235
|
...buildCommonJsonSchemas({
|
|
231
236
|
allowedAdditionalTypeValues: [TYPE_IMPORT_FIRST_TYPE_OPTION],
|
|
237
|
+
additionalSortProperties: { sortBy: sortByJsonSchema },
|
|
232
238
|
}),
|
|
233
239
|
...buildCommonGroupsJsonSchemas({
|
|
234
240
|
allowedAdditionalTypeValues: [TYPE_IMPORT_FIRST_TYPE_OPTION],
|
|
241
|
+
additionalSortProperties: { sortBy: sortByJsonSchema },
|
|
235
242
|
singleCustomGroupJsonSchema,
|
|
236
243
|
}),
|
|
237
244
|
tsconfig: {
|
|
@@ -288,7 +295,6 @@ const sortImports = createEslintRule({
|
|
|
288
295
|
description: 'Enforce sorted imports.',
|
|
289
296
|
recommended: true,
|
|
290
297
|
},
|
|
291
|
-
defaultOptions: [defaultOptions],
|
|
292
298
|
type: 'suggestion',
|
|
293
299
|
fixable: 'code',
|
|
294
300
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Options as SortObjectTypesOptions } from './sort-object-types/types'
|
|
1
|
+
import { Options as SortObjectTypesOptions } from './sort-object-types/types.js'
|
|
2
2
|
declare const ORDER_ERROR_ID = 'unexpectedInterfacePropertiesOrder'
|
|
3
3
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedInterfacePropertiesGroupOrder'
|
|
4
4
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenInterfaceMembers'
|
|
@@ -11,7 +11,9 @@ type MessageId =
|
|
|
11
11
|
declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
|
|
12
12
|
MessageId,
|
|
13
13
|
SortObjectTypesOptions,
|
|
14
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
14
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
15
15
|
import('@typescript-eslint/utils/ts-eslint').RuleListener
|
|
16
|
-
>
|
|
16
|
+
> & {
|
|
17
|
+
name: string
|
|
18
|
+
}
|
|
17
19
|
export default _default
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Options as SortUnionTypesOptions } from './sort-union-types/types'
|
|
1
|
+
import { Options as SortUnionTypesOptions } from './sort-union-types/types.js'
|
|
2
2
|
declare const ORDER_ERROR_ID = 'unexpectedIntersectionTypesOrder'
|
|
3
3
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedIntersectionTypesGroupOrder'
|
|
4
4
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenIntersectionTypes'
|
|
@@ -11,7 +11,9 @@ type MessageId =
|
|
|
11
11
|
declare const _default: import('@typescript-eslint/utils/ts-eslint').RuleModule<
|
|
12
12
|
MessageId,
|
|
13
13
|
SortUnionTypesOptions,
|
|
14
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
14
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
15
15
|
import('@typescript-eslint/utils/ts-eslint').RuleListener
|
|
16
|
-
>
|
|
16
|
+
> & {
|
|
17
|
+
name: string
|
|
18
|
+
}
|
|
17
19
|
export default _default
|
|
@@ -12,6 +12,7 @@ const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenIntersectionTypes'
|
|
|
12
12
|
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenIntersectionTypes'
|
|
13
13
|
let defaultOptions = {
|
|
14
14
|
fallbackSort: { type: 'unsorted' },
|
|
15
|
+
newlinesInside: 'newlinesBetween',
|
|
15
16
|
specialCharacters: 'keep',
|
|
16
17
|
newlinesBetween: 'ignore',
|
|
17
18
|
partitionByComment: false,
|
|
@@ -37,7 +38,6 @@ const sortIntersectionTypes = createEslintRule({
|
|
|
37
38
|
description: 'Enforce sorted intersection types.',
|
|
38
39
|
recommended: true,
|
|
39
40
|
},
|
|
40
|
-
defaultOptions: [defaultOptions],
|
|
41
41
|
schema: jsonSchema,
|
|
42
42
|
type: 'suggestion',
|
|
43
43
|
fixable: 'code',
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
CommonOptions,
|
|
4
4
|
RegexOption,
|
|
5
5
|
TypeOption,
|
|
6
|
-
} from '../../types/common-options'
|
|
7
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options'
|
|
8
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options'
|
|
6
|
+
} from '../../types/common-options.js'
|
|
7
|
+
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
8
|
+
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
9
9
|
/**
|
|
10
10
|
* Configuration options for the sort-jsx-props rule.
|
|
11
11
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
-
import { Options } from './sort-jsx-props/types'
|
|
2
|
+
import { Options } from './sort-jsx-props/types.js'
|
|
3
3
|
declare const ORDER_ERROR_ID = 'unexpectedJSXPropsOrder'
|
|
4
4
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedJSXPropsGroupOrder'
|
|
5
5
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenJSXPropsMembers'
|
|
@@ -12,7 +12,9 @@ type MessageId =
|
|
|
12
12
|
declare const _default: TSESLint.RuleModule<
|
|
13
13
|
MessageId,
|
|
14
14
|
Options,
|
|
15
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
15
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
16
16
|
TSESLint.RuleListener
|
|
17
|
-
>
|
|
17
|
+
> & {
|
|
18
|
+
name: string
|
|
19
|
+
}
|
|
18
20
|
export default _default
|
|
@@ -45,6 +45,7 @@ const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenJSXPropsMembers'
|
|
|
45
45
|
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenJSXPropsMembers'
|
|
46
46
|
let defaultOptions = {
|
|
47
47
|
fallbackSort: { type: 'unsorted' },
|
|
48
|
+
newlinesInside: 'newlinesBetween',
|
|
48
49
|
specialCharacters: 'keep',
|
|
49
50
|
newlinesBetween: 'ignore',
|
|
50
51
|
partitionByNewLine: false,
|
|
@@ -207,7 +208,6 @@ const sortJsxProps = createEslintRule({
|
|
|
207
208
|
description: 'Enforce sorted JSX props.',
|
|
208
209
|
recommended: true,
|
|
209
210
|
},
|
|
210
|
-
defaultOptions: [defaultOptions],
|
|
211
211
|
type: 'suggestion',
|
|
212
212
|
fixable: 'code',
|
|
213
213
|
},
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
CommonOptions,
|
|
3
3
|
RegexOption,
|
|
4
4
|
TypeOption,
|
|
5
|
-
} from '../../types/common-options'
|
|
6
|
-
import { CommonPartitionOptions } from '../../types/common-partition-options'
|
|
7
|
-
import { CommonGroupsOptions } from '../../types/common-groups-options'
|
|
5
|
+
} from '../../types/common-options.js'
|
|
6
|
+
import { CommonPartitionOptions } from '../../types/common-partition-options.js'
|
|
7
|
+
import { CommonGroupsOptions } from '../../types/common-groups-options.js'
|
|
8
8
|
/**
|
|
9
9
|
* Configuration options for the sort-maps rule.
|
|
10
10
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESLint } from '@typescript-eslint/utils'
|
|
2
|
-
import { Options } from './sort-maps/types'
|
|
2
|
+
import { Options } from './sort-maps/types.js'
|
|
3
3
|
declare const ORDER_ERROR_ID = 'unexpectedMapElementsOrder'
|
|
4
4
|
declare const GROUP_ORDER_ERROR_ID = 'unexpectedMapElementsGroupOrder'
|
|
5
5
|
declare const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenMapElementsMembers'
|
|
@@ -12,7 +12,9 @@ type MessageId =
|
|
|
12
12
|
declare const _default: TSESLint.RuleModule<
|
|
13
13
|
MessageId,
|
|
14
14
|
Options,
|
|
15
|
-
import('../utils/create-eslint-rule').ESLintPluginDocumentation,
|
|
15
|
+
import('../utils/create-eslint-rule.js').ESLintPluginDocumentation,
|
|
16
16
|
TSESLint.RuleListener
|
|
17
|
-
>
|
|
17
|
+
> & {
|
|
18
|
+
name: string
|
|
19
|
+
}
|
|
18
20
|
export default _default
|
package/dist/rules/sort-maps.js
CHANGED
|
@@ -36,6 +36,7 @@ const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenMapElementsMembers'
|
|
|
36
36
|
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenMapElementsMembers'
|
|
37
37
|
let defaultOptions = {
|
|
38
38
|
fallbackSort: { type: 'unsorted' },
|
|
39
|
+
newlinesInside: 'newlinesBetween',
|
|
39
40
|
specialCharacters: 'keep',
|
|
40
41
|
partitionByComment: false,
|
|
41
42
|
partitionByNewLine: false,
|
|
@@ -197,7 +198,6 @@ const sortMaps = createEslintRule({
|
|
|
197
198
|
description: 'Enforce sorted Map elements.',
|
|
198
199
|
recommended: true,
|
|
199
200
|
},
|
|
200
|
-
defaultOptions: [defaultOptions],
|
|
201
201
|
type: 'suggestion',
|
|
202
202
|
fixable: 'code',
|
|
203
203
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
2
|
+
import { SortModulesSortingNode, SortModulesOptions } from './types.js'
|
|
3
|
+
export declare function buildComparatorByOptionsComputer({
|
|
4
|
+
ignoreEslintDisabledNodes,
|
|
5
|
+
sortingNodes,
|
|
6
|
+
}: {
|
|
7
|
+
sortingNodes: SortModulesSortingNode[]
|
|
8
|
+
ignoreEslintDisabledNodes: boolean
|
|
9
|
+
}): ComparatorByOptionsComputer<
|
|
10
|
+
Required<SortModulesOptions[number]>,
|
|
11
|
+
SortModulesSortingNode
|
|
12
|
+
>
|