eslint-plugin-perfectionist 5.10.1 → 5.11.1
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/index.js +5 -5
- package/dist/package.json.js +2 -2
- package/dist/rules/sort-array-includes.js +7 -7
- package/dist/rules/sort-arrays/types.js +2 -2
- package/dist/rules/sort-arrays.js +7 -7
- package/dist/rules/sort-classes/compute-dependencies-by-sorting-node.js +27 -42
- package/dist/rules/sort-classes/sort-class.js +4 -4
- package/dist/rules/sort-classes/types.d.ts +1 -1
- package/dist/rules/sort-classes/types.js +8 -8
- package/dist/rules/sort-decorators.js +5 -5
- package/dist/rules/sort-enums/build-comparator-by-options-computer.js +2 -2
- package/dist/rules/sort-enums/sort-enum.js +1 -1
- package/dist/rules/sort-enums/types.d.ts +1 -1
- package/dist/rules/sort-enums/types.js +6 -6
- package/dist/rules/sort-export-attributes.js +5 -5
- package/dist/rules/sort-exports/types.js +3 -3
- package/dist/rules/sort-exports.js +8 -8
- package/dist/rules/sort-heritage-clauses/sort-heritage-clause.js +1 -1
- package/dist/rules/sort-heritage-clauses/types.js +4 -4
- package/dist/rules/sort-import-attributes.js +6 -6
- package/dist/rules/sort-imports/comparator-by-options-computer.js +2 -2
- package/dist/rules/sort-imports/compute-common-selectors.d.ts +1 -1
- package/dist/rules/sort-imports/compute-common-selectors.js +4 -4
- package/dist/rules/sort-imports/matches-tsconfig-paths.d.ts +1 -1
- package/dist/rules/sort-imports/matches-tsconfig-paths.js +1 -1
- package/dist/rules/sort-imports/types.d.ts +7 -16
- package/dist/rules/sort-imports/types.js +5 -5
- package/dist/rules/sort-imports.js +12 -25
- package/dist/rules/sort-interfaces.js +4 -4
- package/dist/rules/sort-intersection-types.js +6 -6
- package/dist/rules/sort-jsx-props/sort-jsx-object.js +2 -2
- package/dist/rules/sort-jsx-props/types.js +7 -7
- package/dist/rules/sort-maps/sort-potential-map.js +1 -1
- package/dist/rules/sort-maps/types.js +4 -4
- package/dist/rules/sort-modules/build-usage-comparator.js +1 -1
- package/dist/rules/sort-modules/compute-additional-module-statements.d.ts +19 -0
- package/dist/rules/sort-modules/compute-additional-module-statements.js +32 -0
- package/dist/rules/sort-modules/dependencies/compute-dependencies-by-sorting-node.d.ts +26 -0
- package/dist/rules/sort-modules/{compute-dependencies-by-sorting-node.js → dependencies/compute-dependencies-by-sorting-node.js} +33 -9
- package/dist/rules/sort-modules/dependencies/is-identifier-in-decorator-metadata-type-position.d.ts +13 -0
- package/dist/rules/sort-modules/dependencies/is-identifier-in-decorator-metadata-type-position.js +100 -0
- package/dist/rules/sort-modules/types.d.ts +13 -1
- package/dist/rules/sort-modules/types.js +4 -4
- package/dist/rules/sort-modules.js +49 -9
- package/dist/rules/sort-named-exports/sort-named-export.js +2 -2
- package/dist/rules/sort-named-exports/types.js +7 -7
- package/dist/rules/sort-named-imports/sort-named-import.js +2 -2
- package/dist/rules/sort-named-imports/types.js +7 -7
- package/dist/rules/sort-object-types/comparator-by-options-computer.js +2 -2
- package/dist/rules/sort-object-types/sort-object-type-elements.js +1 -1
- package/dist/rules/sort-object-types/types.js +5 -5
- package/dist/rules/sort-object-types.js +6 -6
- package/dist/rules/sort-objects/comparator-by-options-computer.js +2 -2
- package/dist/rules/sort-objects/compute-matched-context-options.js +1 -1
- package/dist/rules/sort-objects/passes-declaration-matches-pattern-filter.js +1 -1
- package/dist/rules/sort-objects/sort-object.js +7 -4
- package/dist/rules/sort-objects/types.d.ts +6 -1
- package/dist/rules/sort-objects/types.js +10 -10
- package/dist/rules/sort-objects.js +2 -0
- package/dist/rules/sort-sets.js +5 -5
- package/dist/rules/sort-switch-case.js +16 -11
- package/dist/rules/sort-union-types/types.js +2 -2
- package/dist/rules/sort-union-types.js +6 -6
- package/dist/rules/sort-variable-declarations/sort-variable-declaration.js +7 -4
- package/dist/rules/sort-variable-declarations/types.d.ts +6 -1
- package/dist/rules/sort-variable-declarations/types.js +9 -7
- package/dist/rules/sort-variable-declarations.js +2 -0
- package/dist/types/scoped-regex-option.js +1 -1
- package/dist/types/ts-config-option.d.ts +10 -0
- package/dist/utils/compare/compare-by-custom-sort.js +1 -1
- package/dist/utils/compare/default-comparator-by-options-computer.js +1 -1
- package/dist/utils/compare/unsorted-comparator.js +1 -1
- package/dist/utils/{compute-dependencies-outside-functions-by-sorting-node.d.ts → compute-dependencies-outside-deferred-functions-by-sorting-node.d.ts} +4 -1
- package/dist/utils/compute-dependencies-outside-deferred-functions-by-sorting-node.js +22 -0
- package/dist/utils/create-eslint-rule.js +1 -1
- package/dist/utils/create-fix-provider.d.ts +83 -0
- package/dist/utils/create-fix-provider.js +72 -0
- package/dist/utils/does-node-end-with-expression.d.ts +29 -0
- package/dist/utils/does-node-end-with-expression.js +40 -0
- package/dist/utils/get-eslint-disabled-rules.js +1 -1
- package/dist/utils/get-node-range.js +1 -1
- package/dist/utils/get-settings.d.ts +4 -2
- package/dist/utils/get-settings.js +1 -0
- package/dist/utils/is-expression-continuation-token.d.ts +15 -0
- package/dist/utils/is-expression-continuation-token.js +29 -0
- package/dist/utils/is-node-immediately-called.d.ts +4 -1
- package/dist/utils/is-node-inside-deferred-function.d.ts +26 -0
- package/dist/utils/is-node-inside-deferred-function.js +70 -0
- package/dist/utils/is-partition-comment.js +1 -1
- package/dist/utils/json-schemas/common-groups-json-schemas.js +2 -2
- package/dist/utils/json-schemas/common-json-schemas.js +7 -7
- package/dist/utils/json-schemas/common-partition-json-schemas.js +3 -3
- package/dist/utils/json-schemas/scoped-regex-json-schema.js +1 -1
- package/dist/utils/json-schemas/tsconfig-json-schema.d.ts +2 -0
- package/dist/utils/json-schemas/tsconfig-json-schema.js +16 -0
- package/dist/utils/make-fixes.d.ts +1 -2
- package/dist/utils/make-newlines-between-fixes.js +1 -1
- package/dist/utils/make-order-fixes.js +12 -2
- package/dist/utils/merge-fixes.d.ts +75 -0
- package/dist/utils/merge-fixes.js +80 -0
- package/dist/utils/report-all-errors.js +12 -8
- package/dist/utils/report-errors.d.ts +3 -16
- package/dist/utils/report-errors.js +14 -26
- package/dist/utils/should-partition.js +1 -1
- package/dist/{rules/sort-imports → utils/tsconfig}/get-typescript-import.js +3 -3
- package/dist/{rules/sort-imports → utils/tsconfig}/read-closest-ts-config-by-path.js +13 -4
- package/dist/utils/validate-newlines-and-partition-config.js +2 -2
- package/package.json +2 -2
- package/readme.md +2 -2
- package/dist/rules/sort-modules/compute-dependencies-by-sorting-node.d.ts +0 -16
- package/dist/utils/compute-dependencies-outside-functions-by-sorting-node.js +0 -30
- /package/dist/{rules/sort-imports → utils/tsconfig}/get-typescript-import.d.ts +0 -0
- /package/dist/{rules/sort-imports → utils/tsconfig}/read-closest-ts-config-by-path.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -22,8 +22,8 @@ import sort_arrays_default from './rules/sort-arrays.js'
|
|
|
22
22
|
import sort_enums_default from './rules/sort-enums.js'
|
|
23
23
|
import sort_maps_default from './rules/sort-maps.js'
|
|
24
24
|
import sort_sets_default from './rules/sort-sets.js'
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let pluginName = 'perfectionist'
|
|
26
|
+
let recommendedRules = {
|
|
27
27
|
'sort-variable-declarations': sort_variable_declarations_default,
|
|
28
28
|
'sort-intersection-types': sort_intersection_types_default,
|
|
29
29
|
'sort-import-attributes': sort_import_attributes_default,
|
|
@@ -47,11 +47,11 @@ var recommendedRules = {
|
|
|
47
47
|
'sort-sets': sort_sets_default,
|
|
48
48
|
'sort-maps': sort_maps_default,
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
let rules = {
|
|
51
51
|
...recommendedRules,
|
|
52
52
|
'sort-arrays': sort_arrays_default,
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
let plugin = {
|
|
55
55
|
meta: {
|
|
56
56
|
version,
|
|
57
57
|
name,
|
|
@@ -78,7 +78,7 @@ function createLegacyConfig(options) {
|
|
|
78
78
|
plugins: [pluginName],
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
let configs = {
|
|
82
82
|
'recommended-alphabetical-legacy': createLegacyConfig({
|
|
83
83
|
type: 'alphabetical',
|
|
84
84
|
order: 'asc',
|
package/dist/package.json.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const name = 'eslint-plugin-perfectionist'
|
|
2
|
+
const version = '5.11.1'
|
|
3
3
|
export { name, version }
|
|
@@ -22,12 +22,12 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
|
22
22
|
/**
|
|
23
23
|
* Cache computed groups by modifiers and selectors for performance.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
26
|
+
const ORDER_ERROR_ID = 'unexpectedArrayIncludesOrder'
|
|
27
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedArrayIncludesGroupOrder'
|
|
28
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenArrayIncludesMembers'
|
|
29
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenArrayIncludesMembers'
|
|
30
|
+
let defaultOptions = {
|
|
31
31
|
fallbackSort: { type: 'unsorted' },
|
|
32
32
|
newlinesInside: 'newlinesBetween',
|
|
33
33
|
specialCharacters: 'keep',
|
|
@@ -43,7 +43,7 @@ var defaultOptions = {
|
|
|
43
43
|
alphabet: '',
|
|
44
44
|
order: 'asc',
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
let jsonSchema = {
|
|
47
47
|
items: {
|
|
48
48
|
properties: {
|
|
49
49
|
...buildCommonJsonSchemas(),
|
|
@@ -3,12 +3,12 @@ import { buildCustomGroupSelectorJsonSchema } from '../../utils/json-schemas/com
|
|
|
3
3
|
* Complete list of available selectors for array elements. Used for validation
|
|
4
4
|
* and JSON schema generation.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
let allSelectors = ['literal']
|
|
7
7
|
/**
|
|
8
8
|
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
9
9
|
* rule options at configuration time.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
12
12
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
13
13
|
}
|
|
14
14
|
export { additionalCustomGroupMatchOptionsJsonSchema, allSelectors }
|
|
@@ -22,12 +22,12 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
|
22
22
|
/**
|
|
23
23
|
* Cache computed groups by modifiers and selectors for performance.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
26
|
+
const ORDER_ERROR_ID = 'unexpectedArraysOrder'
|
|
27
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedArraysGroupOrder'
|
|
28
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenArraysMembers'
|
|
29
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenArraysMembers'
|
|
30
|
+
let defaultOptions = {
|
|
31
31
|
fallbackSort: { type: 'unsorted' },
|
|
32
32
|
newlinesInside: 'newlinesBetween',
|
|
33
33
|
specialCharacters: 'keep',
|
|
@@ -43,7 +43,7 @@ var defaultOptions = {
|
|
|
43
43
|
alphabet: '',
|
|
44
44
|
order: 'asc',
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
let jsonSchema = {
|
|
47
47
|
items: {
|
|
48
48
|
properties: {
|
|
49
49
|
...buildCommonJsonSchemas(),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
2
|
-
import { matches } from '../../utils/matches.js'
|
|
3
1
|
import { computeDependenciesBySortingNode as computeDependenciesBySortingNode$1 } from '../../utils/compute-dependencies-by-sorting-node.js'
|
|
4
|
-
import {
|
|
2
|
+
import { isNodeInsideDeferredFunction } from '../../utils/is-node-inside-deferred-function.js'
|
|
3
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
5
4
|
import { computeIdentifierNameDetails } from './compute-identifier-name-details.js'
|
|
6
5
|
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils'
|
|
7
6
|
function computeDependenciesBySortingNode({
|
|
@@ -44,7 +43,14 @@ function computeIdentifierOrThisExpressionDependency({
|
|
|
44
43
|
classElement,
|
|
45
44
|
node,
|
|
46
45
|
}) {
|
|
47
|
-
if (
|
|
46
|
+
if (
|
|
47
|
+
classElement.type !== AST_NODE_TYPES.StaticBlock &&
|
|
48
|
+
isNodeInsideDeferredFunction({
|
|
49
|
+
ignoreCallbackDependenciesPatterns,
|
|
50
|
+
maxParent: classElement,
|
|
51
|
+
node,
|
|
52
|
+
})
|
|
53
|
+
) {
|
|
48
54
|
return null
|
|
49
55
|
}
|
|
50
56
|
let { parent } = node
|
|
@@ -73,23 +79,6 @@ function computeIdentifierOrThisExpressionDependency({
|
|
|
73
79
|
return null
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
|
-
function shouldIgnoreCallbackDependency() {
|
|
77
|
-
return computeParentNodesWithTypes({
|
|
78
|
-
allowedTypes: [AST_NODE_TYPES.CallExpression],
|
|
79
|
-
maxParent: classElement,
|
|
80
|
-
consecutiveOnly: false,
|
|
81
|
-
node,
|
|
82
|
-
}).some(shouldIgnoreCallExpression)
|
|
83
|
-
function shouldIgnoreCallExpression(callExpressionParent) {
|
|
84
|
-
return (
|
|
85
|
-
'name' in callExpressionParent.callee &&
|
|
86
|
-
matches(
|
|
87
|
-
callExpressionParent.callee.name,
|
|
88
|
-
ignoreCallbackDependenciesPatterns,
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
82
|
}
|
|
94
83
|
function computeThisExpressionDependenciesBySortingNode({
|
|
95
84
|
ignoreCallbackDependenciesPatterns,
|
|
@@ -146,27 +135,6 @@ function buildAdditionalIdentifierDependenciesComputer({
|
|
|
146
135
|
return dependency ? [dependency] : []
|
|
147
136
|
}
|
|
148
137
|
}
|
|
149
|
-
function shouldIgnoreDependencyComputation(node) {
|
|
150
|
-
switch (node.type) {
|
|
151
|
-
case AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
152
|
-
case AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
153
|
-
case AST_NODE_TYPES.StaticBlock:
|
|
154
|
-
return false
|
|
155
|
-
case AST_NODE_TYPES.TSAbstractAccessorProperty:
|
|
156
|
-
case AST_NODE_TYPES.PropertyDefinition:
|
|
157
|
-
case AST_NODE_TYPES.AccessorProperty:
|
|
158
|
-
return (
|
|
159
|
-
node.value?.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
160
|
-
node.value?.type === AST_NODE_TYPES.FunctionExpression
|
|
161
|
-
)
|
|
162
|
-
case AST_NODE_TYPES.MethodDefinition:
|
|
163
|
-
case AST_NODE_TYPES.TSIndexSignature:
|
|
164
|
-
return true
|
|
165
|
-
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
166
|
-
default:
|
|
167
|
-
throw new UnreachableCaseError(node)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
138
|
function computeThisExpressionsInsideClassElement({
|
|
171
139
|
classElement,
|
|
172
140
|
sourceCode,
|
|
@@ -183,4 +151,21 @@ function computeThisExpressionsInsideClassElement({
|
|
|
183
151
|
return token.type === AST_TOKEN_TYPES.Keyword && token.value === 'this'
|
|
184
152
|
}
|
|
185
153
|
}
|
|
154
|
+
function shouldIgnoreDependencyComputation(node) {
|
|
155
|
+
switch (node.type) {
|
|
156
|
+
case AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
157
|
+
case AST_NODE_TYPES.TSAbstractAccessorProperty:
|
|
158
|
+
case AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
159
|
+
case AST_NODE_TYPES.PropertyDefinition:
|
|
160
|
+
case AST_NODE_TYPES.AccessorProperty:
|
|
161
|
+
case AST_NODE_TYPES.StaticBlock:
|
|
162
|
+
return false
|
|
163
|
+
case AST_NODE_TYPES.MethodDefinition:
|
|
164
|
+
case AST_NODE_TYPES.TSIndexSignature:
|
|
165
|
+
return true
|
|
166
|
+
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
|
|
167
|
+
default:
|
|
168
|
+
throw new UnreachableCaseError(node)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
186
171
|
export { computeDependenciesBySortingNode }
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
2
|
-
import { getGroupIndex } from '../../utils/get-group-index.js'
|
|
3
1
|
import { populateSortingNodeGroupsWithDependencies } from '../../utils/populate-sorting-node-groups-with-dependencies.js'
|
|
2
|
+
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
|
|
4
3
|
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
5
4
|
import { validateNewlinesAndPartitionConfig } from '../../utils/validate-newlines-and-partition-config.js'
|
|
6
5
|
import { buildOptionsByGroupIndexComputer } from '../../utils/build-options-by-group-index-computer.js'
|
|
@@ -11,6 +10,7 @@ import { getEslintDisabledLines } from '../../utils/get-eslint-disabled-lines.js
|
|
|
11
10
|
import { doesCustomGroupMatch } from '../../utils/does-custom-group-match.js'
|
|
12
11
|
import { isNodeEslintDisabled } from '../../utils/is-node-eslint-disabled.js'
|
|
13
12
|
import { validateGroupsConfig } from '../../utils/validate-groups-config.js'
|
|
13
|
+
import { getGroupIndex } from '../../utils/get-group-index.js'
|
|
14
14
|
import { sortNodesByGroups } from '../../utils/sort-nodes-by-groups.js'
|
|
15
15
|
import { reportAllErrors } from '../../utils/report-all-errors.js'
|
|
16
16
|
import { shouldPartition } from '../../utils/should-partition.js'
|
|
@@ -45,8 +45,8 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
|
45
45
|
/**
|
|
46
46
|
* Cache computed groups by modifiers and selectors for performance.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
49
|
+
let defaultOptions = {
|
|
50
50
|
groups: [
|
|
51
51
|
'index-signature',
|
|
52
52
|
['static-property', 'static-accessor-property'],
|
|
@@ -50,7 +50,7 @@ export type Options = Partial<
|
|
|
50
50
|
*/
|
|
51
51
|
ignoreCallbackDependenciesPatterns: RegexOption
|
|
52
52
|
/**
|
|
53
|
-
* Enables experimental dependency detection.
|
|
53
|
+
* @deprecated Enables experimental dependency detection.
|
|
54
54
|
*/
|
|
55
55
|
useExperimentalDependencyDetection: boolean
|
|
56
56
|
} & AllCommonOptions<
|
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
buildCustomGroupModifiersJsonSchema,
|
|
4
4
|
buildCustomGroupSelectorJsonSchema,
|
|
5
5
|
} from '../../utils/json-schemas/common-groups-json-schemas.js'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const ORDER_ERROR_ID = 'unexpectedClassesOrder'
|
|
7
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedClassesGroupOrder'
|
|
8
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenClassMembers'
|
|
9
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenClassMembers'
|
|
10
|
+
const DEPENDENCY_ORDER_ERROR_ID = 'unexpectedClassesDependencyOrder'
|
|
11
11
|
/**
|
|
12
12
|
* Complete list of available class member selectors. Used for validation and
|
|
13
13
|
* JSON schema generation.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
let allSelectors = [
|
|
16
16
|
'accessor-property',
|
|
17
17
|
'index-signature',
|
|
18
18
|
'constructor',
|
|
@@ -27,7 +27,7 @@ var allSelectors = [
|
|
|
27
27
|
* Complete list of available class member modifiers. Used for validation and
|
|
28
28
|
* JSON schema generation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
let allModifiers = [
|
|
31
31
|
'async',
|
|
32
32
|
'protected',
|
|
33
33
|
'private',
|
|
@@ -47,7 +47,7 @@ var allModifiers = [
|
|
|
47
47
|
* Note: Ideally, we should generate as many schemas as there are selectors, and
|
|
48
48
|
* ensure that users do not enter invalid modifiers for a given selector.
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
51
51
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
52
52
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
53
53
|
decoratorNamePattern: buildRegexJsonSchema(),
|
|
@@ -30,11 +30,11 @@ import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
|
30
30
|
import { getNodeDecorators } from '../utils/get-node-decorators.js'
|
|
31
31
|
import { getDecoratorName } from '../utils/get-decorator-name.js'
|
|
32
32
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const ORDER_ERROR_ID = 'unexpectedDecoratorsOrder'
|
|
34
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedDecoratorsGroupOrder'
|
|
35
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenDecorators'
|
|
36
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenDecorators'
|
|
37
|
+
let defaultOptions = {
|
|
38
38
|
fallbackSort: { type: 'unsorted' },
|
|
39
39
|
newlinesInside: 'newlinesBetween',
|
|
40
40
|
specialCharacters: 'keep',
|
|
@@ -37,7 +37,7 @@ function buildComparatorByOptionsComputer(isNumericEnum) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
let byNonNumericValueComparatorComputer = options => {
|
|
41
41
|
switch (options.type) {
|
|
42
42
|
/* v8 ignore next 2 -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
43
43
|
case 'subgroup-order':
|
|
@@ -59,7 +59,7 @@ var byNonNumericValueComparatorComputer = options => {
|
|
|
59
59
|
throw new UnreachableCaseError(options.type)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
let byNumericValueComparatorComputer = options => {
|
|
63
63
|
switch (options.type) {
|
|
64
64
|
/* v8 ignore next 2 -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
65
65
|
case 'subgroup-order':
|
|
@@ -30,7 +30,7 @@ import { computeNodeName } from './compute-node-name.js'
|
|
|
30
30
|
import { computeMatchedContextOptions } from './compute-matched-context-options.js'
|
|
31
31
|
import { computeDependencies } from './compute-dependencies.js'
|
|
32
32
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
33
|
-
|
|
33
|
+
let defaultOptions = {
|
|
34
34
|
useExperimentalDependencyDetection: true,
|
|
35
35
|
fallbackSort: { type: 'unsorted' },
|
|
36
36
|
newlinesInside: 'newlinesBetween',
|
|
@@ -47,7 +47,7 @@ export type Options = Partial<
|
|
|
47
47
|
*/
|
|
48
48
|
sortByValue: 'ifNumericEnum' | 'always' | 'never'
|
|
49
49
|
/**
|
|
50
|
-
* Enables experimental dependency detection.
|
|
50
|
+
* @deprecated Enables experimental dependency detection.
|
|
51
51
|
*/
|
|
52
52
|
useExperimentalDependencyDetection: boolean
|
|
53
53
|
} & AllCommonOptions<
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { buildRegexJsonSchema } from '../../utils/json-schemas/common-json-schemas.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const ORDER_ERROR_ID = 'unexpectedEnumsOrder'
|
|
3
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedEnumsGroupOrder'
|
|
4
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenEnumsMembers'
|
|
5
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenEnumsMembers'
|
|
6
|
+
const DEPENDENCY_ORDER_ERROR_ID = 'unexpectedEnumsDependencyOrder'
|
|
7
7
|
/**
|
|
8
8
|
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
9
9
|
* rule options at configuration time.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
12
12
|
elementValuePattern: buildRegexJsonSchema(),
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
@@ -9,11 +9,11 @@ import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
|
9
9
|
import { sortImportOrExportAttributes } from './sort-import-attributes/sort-import-or-export-attributes.js'
|
|
10
10
|
import { jsonSchema } from './sort-import-attributes.js'
|
|
11
11
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const ORDER_ERROR_ID = 'unexpectedExportAttributesOrder'
|
|
13
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedExportAttributesGroupOrder'
|
|
14
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenExportAttributes'
|
|
15
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenExportAttributes'
|
|
16
|
+
let defaultOptions = {
|
|
17
17
|
fallbackSort: { type: 'unsorted' },
|
|
18
18
|
newlinesInside: 'newlinesBetween',
|
|
19
19
|
specialCharacters: 'keep',
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
* Complete list of available export selectors. Used for validation and JSON
|
|
7
7
|
* schema generation.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
let allSelectors = ['export']
|
|
10
10
|
/**
|
|
11
11
|
* Complete list of available export modifiers. Used for validation and JSON
|
|
12
12
|
* schema generation.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
let allModifiers = [
|
|
15
15
|
'value',
|
|
16
16
|
'type',
|
|
17
17
|
'named',
|
|
@@ -23,7 +23,7 @@ var allModifiers = [
|
|
|
23
23
|
* Additional custom group match options JSON schema. Used by ESLint to validate
|
|
24
24
|
* rule options at configuration time.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
let additionalCustomGroupMatchOptionsJsonSchema = {
|
|
27
27
|
modifiers: buildCustomGroupModifiersJsonSchema(allModifiers),
|
|
28
28
|
selector: buildCustomGroupSelectorJsonSchema(allSelectors),
|
|
29
29
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas.js'
|
|
2
2
|
import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
|
|
3
|
-
import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
|
|
4
3
|
import {
|
|
5
4
|
EXTRA_SPACING_ERROR,
|
|
6
5
|
GROUP_ORDER_ERROR,
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
partitionByCommentJsonSchema,
|
|
13
12
|
partitionByNewlineJsonSchema,
|
|
14
13
|
} from '../utils/json-schemas/common-partition-json-schemas.js'
|
|
14
|
+
import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
|
|
15
15
|
import { defaultComparatorByOptionsComputer } from '../utils/compare/default-comparator-by-options-computer.js'
|
|
16
16
|
import { validateNewlinesAndPartitionConfig } from '../utils/validate-newlines-and-partition-config.js'
|
|
17
17
|
import { buildOptionsByGroupIndexComputer } from '../utils/build-options-by-group-index-computer.js'
|
|
@@ -39,13 +39,13 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
|
39
39
|
/**
|
|
40
40
|
* Cache computed groups by modifiers and selectors for performance.
|
|
41
41
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
|
|
43
|
+
const ORDER_ERROR_ID = 'unexpectedExportsOrder'
|
|
44
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedExportsGroupOrder'
|
|
45
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenExports'
|
|
46
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenExports'
|
|
47
|
+
const MISSED_COMMENT_ABOVE_ERROR_ID = 'missedCommentAboveExport'
|
|
48
|
+
let defaultOptions = {
|
|
49
49
|
fallbackSort: { type: 'unsorted' },
|
|
50
50
|
newlinesInside: 'newlinesBetween',
|
|
51
51
|
specialCharacters: 'keep',
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { computeNodeName } from './compute-node-name.js'
|
|
24
24
|
import { computeMatchedContextOptions } from './compute-matched-context-options.js'
|
|
25
25
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
26
|
-
|
|
26
|
+
let defaultOptions = {
|
|
27
27
|
fallbackSort: { type: 'unsorted' },
|
|
28
28
|
newlinesInside: 'newlinesBetween',
|
|
29
29
|
specialCharacters: 'keep',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const ORDER_ERROR_ID = 'unexpectedHeritageClausesOrder'
|
|
2
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedHeritageClausesGroupOrder'
|
|
3
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenHeritageClauses'
|
|
4
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenHeritageClauses'
|
|
5
5
|
export {
|
|
6
6
|
EXTRA_SPACING_ERROR_ID,
|
|
7
7
|
GROUP_ORDER_ERROR_ID,
|
|
@@ -18,11 +18,11 @@ import { buildAstListeners } from '../utils/build-ast-listeners.js'
|
|
|
18
18
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
19
19
|
import { sortImportOrExportAttributes } from './sort-import-attributes/sort-import-or-export-attributes.js'
|
|
20
20
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const ORDER_ERROR_ID = 'unexpectedImportAttributesOrder'
|
|
22
|
+
const GROUP_ORDER_ERROR_ID = 'unexpectedImportAttributesGroupOrder'
|
|
23
|
+
const EXTRA_SPACING_ERROR_ID = 'extraSpacingBetweenImportAttributes'
|
|
24
|
+
const MISSED_SPACING_ERROR_ID = 'missedSpacingBetweenImportAttributes'
|
|
25
|
+
let defaultOptions = {
|
|
26
26
|
fallbackSort: { type: 'unsorted' },
|
|
27
27
|
newlinesInside: 'newlinesBetween',
|
|
28
28
|
specialCharacters: 'keep',
|
|
@@ -38,7 +38,7 @@ var defaultOptions = {
|
|
|
38
38
|
order: 'asc',
|
|
39
39
|
groups: [],
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
let jsonSchema = {
|
|
42
42
|
items: {
|
|
43
43
|
properties: {
|
|
44
44
|
...buildCommonJsonSchemas(),
|
|
@@ -6,7 +6,7 @@ import { compareByCustomSort } from '../../utils/compare/compare-by-custom-sort.
|
|
|
6
6
|
import { unsortedComparator } from '../../utils/compare/unsorted-comparator.js'
|
|
7
7
|
import { compareNaturally } from '../../utils/compare/compare-naturally.js'
|
|
8
8
|
import { defaultComparatorByOptionsComputer } from '../../utils/compare/default-comparator-by-options-computer.js'
|
|
9
|
-
|
|
9
|
+
let comparatorByOptionsComputer = options => {
|
|
10
10
|
switch (options.type) {
|
|
11
11
|
case 'type-import-first':
|
|
12
12
|
return (a, b) => compareTypeImportFirst(a, b, options)
|
|
@@ -56,7 +56,7 @@ function compareTypeImportFirst(a, b, options) {
|
|
|
56
56
|
}
|
|
57
57
|
return computeOrderedValue(a.isTypeImport ? -1 : 1, options.order)
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
let bySpecifierComparatorByOptionsComputer = options => {
|
|
60
60
|
switch (options.type) {
|
|
61
61
|
/* v8 ignore next 2 -- @preserve Untested for now as not a relevant sort for this rule. */
|
|
62
62
|
case 'subgroup-order':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadClosestTsConfigByPathValue } from '
|
|
1
|
+
import { ReadClosestTsConfigByPathValue } from '../../utils/tsconfig/read-closest-ts-config-by-path.js'
|
|
2
2
|
import { RegexOption } from '../../types/common-options.js'
|
|
3
3
|
import { Selector } from './types.js'
|
|
4
4
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { matches } from '../../utils/matches.js'
|
|
2
|
-
import { getTypescriptImport } from '
|
|
2
|
+
import { getTypescriptImport } from '../../utils/tsconfig/get-typescript-import.js'
|
|
3
3
|
import { matchesTsconfigPaths } from './matches-tsconfig-paths.js'
|
|
4
4
|
import { builtinModules } from 'node:module'
|
|
5
5
|
/**
|
|
@@ -63,7 +63,7 @@ function computeCommonSelectors({ tsConfigOutput, filename, options, name }) {
|
|
|
63
63
|
}
|
|
64
64
|
return commonSelectors
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
let bunModules = /* @__PURE__ */ new Set([
|
|
67
67
|
'detect-libc',
|
|
68
68
|
'bun:sqlite',
|
|
69
69
|
'bun:test',
|
|
@@ -74,8 +74,8 @@ var bunModules = /* @__PURE__ */ new Set([
|
|
|
74
74
|
'bun',
|
|
75
75
|
'ws',
|
|
76
76
|
])
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
let nodeBuiltinModules = new Set(builtinModules)
|
|
78
|
+
let builtinPrefixOnlyModules = /* @__PURE__ */ new Set([
|
|
79
79
|
'node:sqlite',
|
|
80
80
|
'node:test',
|
|
81
81
|
'node:sea',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadClosestTsConfigByPathValue } from '
|
|
1
|
+
import { ReadClosestTsConfigByPathValue } from '../../utils/tsconfig/read-closest-ts-config-by-path.js'
|
|
2
2
|
/**
|
|
3
3
|
* Checks if an import matches any of the path mappings in tsconfig.json.
|
|
4
4
|
*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Cache for compiled regex patterns from tsconfig paths. Avoids recompiling the
|
|
3
3
|
* same path patterns repeatedly.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
let regexByTsconfigPathCache = /* @__PURE__ */ new Map()
|
|
6
6
|
/**
|
|
7
7
|
* Checks if an import matches any of the path mappings in tsconfig.json.
|
|
8
8
|
*
|
|
@@ -3,6 +3,7 @@ import { TSESTree } from '@typescript-eslint/types'
|
|
|
3
3
|
import { SortingNodeWithDependencies } from '../../utils/sort-nodes-by-dependencies.js'
|
|
4
4
|
import { RegexOption, TypeOption } from '../../types/common-options.js'
|
|
5
5
|
import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
6
|
+
import { TsConfigOption } from '../../types/ts-config-option.js'
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for the sort-imports rule.
|
|
8
9
|
*
|
|
@@ -12,22 +13,7 @@ import { AllCommonOptions } from '../../types/all-common-options.js'
|
|
|
12
13
|
export type Options = Partial<
|
|
13
14
|
{
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* resolution based on tsconfig.json paths configuration.
|
|
17
|
-
*/
|
|
18
|
-
tsconfig: {
|
|
19
|
-
/**
|
|
20
|
-
* Optional filename of the TypeScript config file. `@default`
|
|
21
|
-
* tsconfig.json'.
|
|
22
|
-
*/
|
|
23
|
-
filename?: string
|
|
24
|
-
/**
|
|
25
|
-
* Root directory where to search for the TypeScript config file.
|
|
26
|
-
*/
|
|
27
|
-
rootDir: string
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Enables experimental dependency detection.
|
|
16
|
+
* @deprecated Enables experimental dependency detection.
|
|
31
17
|
*/
|
|
32
18
|
useExperimentalDependencyDetection: boolean
|
|
33
19
|
/**
|
|
@@ -42,6 +28,11 @@ export type Options = Partial<
|
|
|
42
28
|
* @default 'node'
|
|
43
29
|
*/
|
|
44
30
|
environment: 'node' | 'bun'
|
|
31
|
+
/**
|
|
32
|
+
* TypeScript configuration for resolving module paths. Enables path alias
|
|
33
|
+
* resolution based on tsconfig.json paths configuration.
|
|
34
|
+
*/
|
|
35
|
+
tsconfig: TsConfigOption
|
|
45
36
|
/**
|
|
46
37
|
* Controls whether side-effect imports should be sorted. When false,
|
|
47
38
|
* side-effect imports remain in their original positions.
|