eslint-plugin-ts-type-forge 0.7.3 → 0.8.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/README.md +31 -8
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.d.mts +2 -0
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +34 -30
- package/dist/plugin.mjs.map +1 -1
- package/dist/rule-types.d.mts +15 -0
- package/dist/rule-types.d.mts.map +1 -1
- package/dist/rule-types.mjs +2 -1
- package/dist/rule-types.mjs.map +1 -1
- package/dist/rules/ast-utils.mjs +224 -103
- package/dist/rules/ast-utils.mjs.map +1 -1
- package/dist/rules/constants.mjs +14 -11
- package/dist/rules/constants.mjs.map +1 -1
- package/dist/rules/import-style.mjs +31 -26
- package/dist/rules/import-style.mjs.map +1 -1
- package/dist/rules/import-utils.mjs +49 -29
- package/dist/rules/import-utils.mjs.map +1 -1
- package/dist/rules/index.mjs +2 -2
- package/dist/rules/index.mjs.map +1 -1
- package/dist/rules/no-side-effect-import.d.mts +19 -0
- package/dist/rules/no-side-effect-import.d.mts.map +1 -0
- package/dist/rules/no-side-effect-import.mjs +55 -0
- package/dist/rules/no-side-effect-import.mjs.map +1 -0
- package/dist/rules/prefer-canonical-length-constrained-tuple.mjs +93 -73
- package/dist/rules/prefer-canonical-length-constrained-tuple.mjs.map +1 -1
- package/dist/rules/prefer-canonical-mutable-record.mjs +88 -75
- package/dist/rules/prefer-canonical-mutable-record.mjs.map +1 -1
- package/dist/rules/prefer-readonly-or-mutable-record.mjs +41 -45
- package/dist/rules/prefer-readonly-or-mutable-record.mjs.map +1 -1
- package/dist/rules/prefer-strict-or-relaxed-utility-type.mjs +48 -46
- package/dist/rules/prefer-strict-or-relaxed-utility-type.mjs.map +1 -1
- package/dist/rules/rewrite-rule-utils.mjs +31 -28
- package/dist/rules/rewrite-rule-utils.mjs.map +1 -1
- package/dist/rules/rules.d.mts +1 -0
- package/dist/rules/rules.d.mts.map +1 -1
- package/dist/rules/rules.mjs +8 -9
- package/dist/rules/rules.mjs.map +1 -1
- package/dist/rules/std-type-rule-utils.mjs +47 -30
- package/dist/rules/std-type-rule-utils.mjs.map +1 -1
- package/dist/types.mjs +2 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -7
- package/src/plugin.mts +1 -0
- package/src/rule-types.mts +16 -0
- package/src/rules/no-side-effect-import.mts +73 -0
- package/src/rules/no-side-effect-import.test.mts +83 -0
- package/src/rules/rules.mts +2 -0
|
@@ -1,83 +1,96 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
1
|
+
import { AST_NODE_TYPES, } from '@typescript-eslint/utils';
|
|
2
2
|
import { Arr } from 'ts-data-forge';
|
|
3
3
|
import { isLocallyBound } from './ast-utils.mjs';
|
|
4
|
-
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY } from './import-style.mjs';
|
|
5
|
-
import { getTsTypeForgeImports,
|
|
4
|
+
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY, } from './import-style.mjs';
|
|
5
|
+
import { getImportedLocalName, getTsTypeForgeImports, } from './import-utils.mjs';
|
|
6
6
|
import { reportTypeRewrites } from './rewrite-rule-utils.mjs';
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
8
12
|
const WRAPPED_RECORD_NAMES = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
'Record',
|
|
14
|
+
'ReadonlyRecord',
|
|
15
|
+
'MutableRecord',
|
|
12
16
|
];
|
|
13
|
-
const MUTABLE_TYPE_NAME =
|
|
14
|
-
const MUTABLE_RECORD_TYPE_NAME =
|
|
15
|
-
const preferCanonicalMutableRecord = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
fixable: "code",
|
|
22
|
-
schema: [
|
|
23
|
-
{
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: {
|
|
26
|
-
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY
|
|
17
|
+
const MUTABLE_TYPE_NAME = 'Mutable';
|
|
18
|
+
const MUTABLE_RECORD_TYPE_NAME = 'MutableRecord';
|
|
19
|
+
export const preferCanonicalMutableRecord = {
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'suggestion',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Replace `Mutable<Record<K, V>>` (and `Mutable` applied to `ReadonlyRecord` / `MutableRecord`) with the canonical ts-type-forge `MutableRecord<K, V>`.',
|
|
27
24
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const wrapped = node.typeArguments?.params;
|
|
49
|
-
if (wrapped === void 0 || !Arr.isFixedLengthArray(1, wrapped)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const record = wrapped[0];
|
|
53
|
-
if (record.type !== AST_NODE_TYPES.TSTypeReference || WRAPPED_RECORD_NAMES.every(
|
|
54
|
-
(name) => !referencesTsTypeForgeType(record, name)
|
|
55
|
-
)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const recordTypeArgs = record.typeArguments?.params;
|
|
59
|
-
if (recordTypeArgs === void 0 || !Arr.isFixedLengthArray(2, recordTypeArgs)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const [K, V] = recordTypeArgs;
|
|
63
|
-
mut_rewrites.push({
|
|
64
|
-
node,
|
|
65
|
-
canonicalName: MUTABLE_RECORD_TYPE_NAME,
|
|
66
|
-
typeArgs: `${sourceCode.getText(K)}, ${sourceCode.getText(V)}`
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
"Program:exit": () => {
|
|
70
|
-
reportTypeRewrites(
|
|
71
|
-
context,
|
|
72
|
-
mut_rewrites,
|
|
73
|
-
"useMutableRecord",
|
|
74
|
-
importStyle
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
defaultOptions: [{ importStyle: DEFAULT_IMPORT_STYLE }]
|
|
80
|
-
};
|
|
25
|
+
fixable: 'code',
|
|
26
|
+
schema: [
|
|
27
|
+
{
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY,
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
messages: {
|
|
36
|
+
useMutableRecord: 'Replace `{{original}}` with `{{replacement}}` from ts-type-forge.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
create: (context) => {
|
|
40
|
+
const importStyle = context.options[0]?.importStyle ?? DEFAULT_IMPORT_STYLE;
|
|
41
|
+
const sourceCode = context.sourceCode;
|
|
42
|
+
const tsTypeForgeImports = getTsTypeForgeImports(sourceCode.ast);
|
|
43
|
+
|
|
44
|
+
|
|
81
45
|
|
|
82
|
-
|
|
83
|
-
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const referencesTsTypeForgeType = (
|
|
52
|
+
|
|
53
|
+
node, canonicalName) => {
|
|
54
|
+
const typeName = node.typeName;
|
|
55
|
+
|
|
56
|
+
if (typeName.type !== AST_NODE_TYPES.Identifier)
|
|
57
|
+
return false;
|
|
58
|
+
return (typeName.name ===
|
|
59
|
+
getImportedLocalName(tsTypeForgeImports, canonicalName) ||
|
|
60
|
+
(typeName.name === canonicalName &&
|
|
61
|
+
!isLocallyBound(sourceCode, node, canonicalName)));
|
|
62
|
+
};
|
|
63
|
+
const mut_rewrites = [];
|
|
64
|
+
return {
|
|
65
|
+
TSTypeReference: (node) => {
|
|
66
|
+
if (!referencesTsTypeForgeType(node, MUTABLE_TYPE_NAME))
|
|
67
|
+
return;
|
|
68
|
+
const wrapped = node.typeArguments?.params;
|
|
69
|
+
if (wrapped === undefined || !Arr.isFixedLengthArray(1, wrapped)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const record = wrapped[0];
|
|
73
|
+
if (record.type !== AST_NODE_TYPES.TSTypeReference ||
|
|
74
|
+
WRAPPED_RECORD_NAMES.every((name) => !referencesTsTypeForgeType(record, name))) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const recordTypeArgs = record.typeArguments?.params;
|
|
78
|
+
if (recordTypeArgs === undefined ||
|
|
79
|
+
!Arr.isFixedLengthArray(2, recordTypeArgs)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const [K, V] = recordTypeArgs;
|
|
83
|
+
mut_rewrites.push({
|
|
84
|
+
node,
|
|
85
|
+
canonicalName: MUTABLE_RECORD_TYPE_NAME,
|
|
86
|
+
typeArgs: `${sourceCode.getText(K)}, ${sourceCode.getText(V)}`,
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
'Program:exit': () => {
|
|
90
|
+
reportTypeRewrites(context, mut_rewrites, 'useMutableRecord', importStyle);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
defaultOptions: [{ importStyle: DEFAULT_IMPORT_STYLE }],
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=prefer-canonical-mutable-record.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-canonical-mutable-record.mjs","sources":["../../src/rules/prefer-canonical-mutable-record.mts"],"
|
|
1
|
+
{"version":3,"file":"prefer-canonical-mutable-record.mjs","sourceRoot":"","sources":["../../src/rules/pref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,CAAC,CAAC,GAAG,cAAc,CAAC;gBAE9B,YAAY,CAAC,IAAI,CAAC;oBAChB,IAAI;oBACJ,aAAa,EAAE,wBAAwB;oBACvC,QAAQ,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;iBAC/D,CAAC,CAAC;YACL,CAAC;YACD,cAAc,EAAE,GAAG,EAAE;gBACnB,kBAAkB,CAChB,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,WAAW,CACZ,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;CAC/C,CAAC"}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY } from './import-style.mjs';
|
|
2
|
-
import { reportStdTypeReference } from './std-type-rule-utils.mjs';
|
|
1
|
+
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY, } from './import-style.mjs';
|
|
2
|
+
import { reportStdTypeReference, } from './std-type-rule-utils.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const ALTERNATIVES = new Map([
|
|
9
|
+
['Record', ['ReadonlyRecord', 'MutableRecord']],
|
|
6
10
|
]);
|
|
7
|
-
const preferReadonlyOrMutableRecord = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
hasSuggestions: true,
|
|
14
|
-
schema: [
|
|
15
|
-
{
|
|
16
|
-
type: "object",
|
|
17
|
-
properties: {
|
|
18
|
-
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY
|
|
11
|
+
export const preferReadonlyOrMutableRecord = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'suggestion',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Replace the built-in `Record` with the ts-type-forge `ReadonlyRecord` or `MutableRecord`, so that the mutability of the record is stated rather than implied.',
|
|
19
16
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
17
|
+
hasSuggestions: true,
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY,
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
messages: {
|
|
28
|
+
useReadonlyOrMutableRecord: 'Use {{alternatives}} from ts-type-forge instead of the built-in `{{name}}`.',
|
|
29
|
+
replaceWith: 'Replace `{{name}}` with `{{replacement}}`.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
create: (context) => {
|
|
33
|
+
const importStyle = context.options[0]?.importStyle ?? DEFAULT_IMPORT_STYLE;
|
|
34
|
+
return {
|
|
35
|
+
TSTypeReference: (node) => {
|
|
36
|
+
reportStdTypeReference(context, node, ALTERNATIVES, {
|
|
37
|
+
report: 'useReadonlyOrMutableRecord',
|
|
38
|
+
suggestion: 'replaceWith',
|
|
39
|
+
}, importStyle);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
defaultOptions: [{ importStyle: DEFAULT_IMPORT_STYLE }],
|
|
46
44
|
};
|
|
47
|
-
|
|
48
|
-
export { preferReadonlyOrMutableRecord };
|
|
49
|
-
//# sourceMappingURL=prefer-readonly-or-mutable-record.mjs.map
|
|
45
|
+
//# sourceMappingURL=prefer-readonly-or-mutable-record.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-readonly-or-mutable-record.mjs","sources":["../../src/rules/prefer-readonly-or-mutable-record.mts"],"
|
|
1
|
+
{"version":3,"file":"prefer-readonly-or-mutable-record.mjs","sourceRoot":"","sources":["../../src/rules/prefer-readonly-or-mutable-record.mts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAUnC;;;;GAIG;AACH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,CAAC,QAAQ,EAAE,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;CAChD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,6BAA6B,GAGtC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,+JAA+J;SAClK;QACD,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,WAAW,EAAE,4BAA4B;iBAC1C;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,0BAA0B,EACxB,6EAA6E;YAC/E,WAAW,EAAE,4CAA4C;SAC1D;KACF;IAED,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,oBAAoB,CAAC;QAE5E,OAAO;YACL,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxB,sBAAsB,CACpB,OAAO,EACP,IAAI,EACJ,YAAY,EACZ;oBACE,MAAM,EAAE,4BAA4B;oBACpC,UAAU,EAAE,aAAa;iBAC1B,EACD,WAAW,CACZ,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;CAC/C,CAAC"}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY } from './import-style.mjs';
|
|
2
|
-
import { reportStdTypeReference } from './std-type-rule-utils.mjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { DEFAULT_IMPORT_STYLE, IMPORT_STYLE_SCHEMA_PROPERTY, } from './import-style.mjs';
|
|
2
|
+
import { reportStdTypeReference, } from './std-type-rule-utils.mjs';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const ALTERNATIVES = new Map([
|
|
15
|
+
['Exclude', ['StrictExclude', 'RelaxedExclude']],
|
|
16
|
+
['Extract', ['StrictExtract', 'RelaxedExtract']],
|
|
17
|
+
['Omit', ['StrictOmit', 'RelaxedOmit']],
|
|
18
|
+
['Pick', ['StrictPick', 'RelaxedPick']],
|
|
9
19
|
]);
|
|
10
|
-
const preferStrictOrRelaxedUtilityType = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
hasSuggestions: true,
|
|
17
|
-
schema: [
|
|
18
|
-
{
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY
|
|
20
|
+
export const preferStrictOrRelaxedUtilityType = {
|
|
21
|
+
meta: {
|
|
22
|
+
type: 'suggestion',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Replace the built-in `Exclude` / `Extract` / `Omit` / `Pick` with the ts-type-forge `Strict*` or `Relaxed*` counterpart, so that the unchecked second argument becomes an explicit choice.',
|
|
22
25
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
hasSuggestions: true,
|
|
27
|
+
schema: [
|
|
28
|
+
{
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
importStyle: IMPORT_STYLE_SCHEMA_PROPERTY,
|
|
32
|
+
},
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
messages: {
|
|
37
|
+
useStrictOrRelaxed: 'Use {{alternatives}} from ts-type-forge instead of the built-in `{{name}}`.',
|
|
38
|
+
replaceWith: 'Replace `{{name}}` with `{{replacement}}`.',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
create: (context) => {
|
|
42
|
+
const importStyle = context.options[0]?.importStyle ?? DEFAULT_IMPORT_STYLE;
|
|
43
|
+
return {
|
|
44
|
+
TSTypeReference: (node) => {
|
|
45
|
+
reportStdTypeReference(context, node, ALTERNATIVES, { report: 'useStrictOrRelaxed', suggestion: 'replaceWith' }, importStyle);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
defaultOptions: [{ importStyle: DEFAULT_IMPORT_STYLE }],
|
|
46
50
|
};
|
|
47
|
-
|
|
48
|
-
export { preferStrictOrRelaxedUtilityType };
|
|
49
|
-
//# sourceMappingURL=prefer-strict-or-relaxed-utility-type.mjs.map
|
|
51
|
+
//# sourceMappingURL=prefer-strict-or-relaxed-utility-type.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-strict-or-relaxed-utility-type.mjs","sources":["../../src/rules/prefer-strict-or-relaxed-utility-type.mts"],"
|
|
1
|
+
{"version":3,"file":"prefer-strict-or-relaxed-utility-type.mjs","sourceRoot":"","sources":["../../src/rules/prefer-strict-or-relaxed-utility-type.mts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAUnC;;;;;;;;;;GAUG;AACH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,CAAC,SAAS,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC,SAAS,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IACvC,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAGzC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,4LAA4L;SAC/L;QACD,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,WAAW,EAAE,4BAA4B;iBAC1C;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,kBAAkB,EAChB,6EAA6E;YAC/E,WAAW,EAAE,4CAA4C;SAC1D;KACF;IAED,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,oBAAoB,CAAC;QAE5E,OAAO;YACL,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxB,sBAAsB,CACpB,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,aAAa,EAAE,EAC3D,WAAW,CACZ,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;CAC/C,CAAC"}
|
|
@@ -2,33 +2,36 @@ import { Arr } from 'ts-data-forge';
|
|
|
2
2
|
import { resolveTypeName } from './import-style.mjs';
|
|
3
3
|
import { buildTypeImportFix } from './import-utils.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
messageId,
|
|
22
|
-
data: { original: sourceCode.getText(rewrite.node), replacement },
|
|
23
|
-
fix: (fixer) => Arr.toPushed(
|
|
24
|
-
index === 0 ? importNames.flatMap(
|
|
25
|
-
(name) => buildTypeImportFix(fixer, program, name)
|
|
26
|
-
) : [],
|
|
27
|
-
fixer.replaceText(rewrite.node, replacement)
|
|
28
|
-
)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export const reportTypeRewrites = (context, rewrites, messageId, importStyle) => {
|
|
14
|
+
const sourceCode = context.sourceCode;
|
|
15
|
+
const program = sourceCode.ast;
|
|
16
|
+
const resolved = rewrites.flatMap((rewrite) => {
|
|
17
|
+
const target = resolveTypeName(program, rewrite.canonicalName, importStyle);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
return target === undefined ? [] : [{ rewrite, target }];
|
|
29
21
|
});
|
|
30
|
-
|
|
22
|
+
const importNames = Array.from(new Set(resolved
|
|
23
|
+
.filter(({ target }) => target.needsImport)
|
|
24
|
+
.map(({ rewrite }) => rewrite.canonicalName)));
|
|
25
|
+
for (const [index, { rewrite, target }] of resolved.entries()) {
|
|
26
|
+
const replacement = `${target.localName}<${rewrite.typeArgs}>`;
|
|
27
|
+
context.report({
|
|
28
|
+
node: rewrite.node,
|
|
29
|
+
messageId,
|
|
30
|
+
data: { original: sourceCode.getText(rewrite.node), replacement },
|
|
31
|
+
fix: (fixer) => Arr.toPushed(index === 0
|
|
32
|
+
? importNames.flatMap((name) => buildTypeImportFix(fixer, program, name))
|
|
33
|
+
: [], fixer.replaceText(rewrite.node, replacement)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
31
36
|
};
|
|
32
|
-
|
|
33
|
-
export { reportTypeRewrites };
|
|
34
|
-
//# sourceMappingURL=rewrite-rule-utils.mjs.map
|
|
37
|
+
//# sourceMappingURL=rewrite-rule-utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite-rule-utils.mjs","sources":["../../src/rules/rewrite-rule-utils.mts"],"
|
|
1
|
+
{"version":3,"file":"rewrite-rule-utils.mjs","sourceRoot":"","sources":["../../src/rules/rewrite-rule-utils.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAoB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAYxD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA6D,EAC7D,QAAgC,EAChC,SAAqB,EACrB,WAAwB,EAClB,EAAE;IACR,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAEtC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC;IAE/B,MAAM,QAAQ,GAAG,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,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAC7C;SACJ,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
package/dist/rules/rules.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const tsTypeForgeRules: {
|
|
2
|
+
readonly 'no-side-effect-import': import("@typescript-eslint/utils/ts-eslint").RuleModule<"removeSideEffectImport", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
2
3
|
readonly 'prefer-canonical-length-constrained-tuple': import("@typescript-eslint/utils/ts-eslint").RuleModule<"useCanonicalTuple", readonly [(Readonly<{
|
|
3
4
|
importStyle?: 'global' | 'named';
|
|
4
5
|
maxLength?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.mts","sourceRoot":"","sources":["../../src/rules/rules.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.d.mts","sourceRoot":"","sources":["../../src/rules/rules.mts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;CAOa,CAAC"}
|
package/dist/rules/rules.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { noSideEffectImport } from './no-side-effect-import.mjs';
|
|
1
2
|
import { preferCanonicalLengthConstrainedTuple } from './prefer-canonical-length-constrained-tuple.mjs';
|
|
2
3
|
import { preferCanonicalMutableRecord } from './prefer-canonical-mutable-record.mjs';
|
|
3
4
|
import { preferReadonlyOrMutableRecord } from './prefer-readonly-or-mutable-record.mjs';
|
|
4
5
|
import { preferStrictOrRelaxedUtilityType } from './prefer-strict-or-relaxed-utility-type.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export const tsTypeForgeRules = {
|
|
7
|
+
'no-side-effect-import': noSideEffectImport,
|
|
8
|
+
'prefer-canonical-length-constrained-tuple': preferCanonicalLengthConstrainedTuple,
|
|
9
|
+
'prefer-canonical-mutable-record': preferCanonicalMutableRecord,
|
|
10
|
+
'prefer-readonly-or-mutable-record': preferReadonlyOrMutableRecord,
|
|
11
|
+
'prefer-strict-or-relaxed-utility-type': preferStrictOrRelaxedUtilityType,
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
export { tsTypeForgeRules };
|
|
14
|
-
//# sourceMappingURL=rules.mjs.map
|
|
13
|
+
//# sourceMappingURL=rules.mjs.map
|
package/dist/rules/rules.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.mjs","sources":["../../src/rules/rules.mts"],"
|
|
1
|
+
{"version":3,"file":"rules.mjs","sourceRoot":"","sources":["../../src/rules/rules.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,qCAAqC,EAAE,MAAM,iDAAiD,CAAC;AACxG,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAE/F,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,uBAAuB,EAAE,kBAAkB;IAC3C,2CAA2C,EACzC,qCAAqC;IACvC,iCAAiC,EAAE,4BAA4B;IAC/D,mCAAmC,EAAE,6BAA6B;IAClE,uCAAuC,EAAE,gCAAgC;CACjC,CAAC"}
|