eslint-plugin-ts-type-forge 0.8.15 → 0.8.16
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 +4 -2
- package/dist/rule-types.d.mts +4 -4
- package/dist/rules/ast-utils.mjs +71 -71
- package/dist/rules/ast-utils.mjs.map +1 -1
- package/dist/rules/import-style.d.mts +2 -1
- package/dist/rules/import-style.d.mts.map +1 -1
- package/dist/rules/import-style.mjs +4 -3
- package/dist/rules/import-style.mjs.map +1 -1
- package/dist/rules/import-utils.d.mts +17 -2
- package/dist/rules/import-utils.d.mts.map +1 -1
- package/dist/rules/import-utils.mjs +72 -3
- package/dist/rules/import-utils.mjs.map +1 -1
- package/dist/rules/rewrite-rule-utils.d.mts +8 -7
- package/dist/rules/rewrite-rule-utils.d.mts.map +1 -1
- package/dist/rules/rewrite-rule-utils.mjs +9 -7
- package/dist/rules/rewrite-rule-utils.mjs.map +1 -1
- package/dist/rules/std-type-rule-utils.d.mts.map +1 -1
- package/dist/rules/std-type-rule-utils.mjs +3 -5
- package/dist/rules/std-type-rule-utils.mjs.map +1 -1
- package/package.json +4 -4
- package/src/rule-types.mts +4 -4
- package/src/rules/ast-utils.mts +108 -108
- package/src/rules/import-style.mts +5 -4
- package/src/rules/import-utils.mts +124 -5
- package/src/rules/prefer-canonical-length-constrained-tuple.test.mts +49 -12
- package/src/rules/prefer-canonical-mutable-record.test.mts +120 -5
- package/src/rules/prefer-readonly-or-mutable-record.test.mts +29 -2
- package/src/rules/prefer-strict-or-relaxed-utility-type.test.mts +1 -2
- package/src/rules/rewrite-rule-utils.mts +21 -16
- package/src/rules/std-type-rule-utils.mts +3 -5
package/README.md
CHANGED
|
@@ -249,8 +249,10 @@ options.
|
|
|
249
249
|
- `'global'` — the ambient globals of `ts-type-forge/global` are in use
|
|
250
250
|
(`/// <reference types="ts-type-forge/global" />`), so the fix only rewrites
|
|
251
251
|
the type and never touches imports.
|
|
252
|
-
- `'named'` — the fix additionally
|
|
253
|
-
`import {
|
|
252
|
+
- `'named'` — the fix additionally imports the name when the file does not
|
|
253
|
+
import it yet: added to an existing `import type { … }` from `ts-type-forge`,
|
|
254
|
+
else to an `import { … }` from it (as `type X`), else after a lone default
|
|
255
|
+
import, and otherwise as a new `import { type … } from 'ts-type-forge';`.
|
|
254
256
|
|
|
255
257
|
Either way, if the file already imports the target type from `ts-type-forge`
|
|
256
258
|
(possibly under an alias), the fix reuses that binding.
|
package/dist/rule-types.d.mts
CHANGED
|
@@ -48,7 +48,7 @@ declare namespace PreferCanonicalLengthConstrainedTuple {
|
|
|
48
48
|
* "global",
|
|
49
49
|
* "named"
|
|
50
50
|
* ],
|
|
51
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
51
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
52
52
|
* },
|
|
53
53
|
* "maxLength": {
|
|
54
54
|
* "type": "integer",
|
|
@@ -90,7 +90,7 @@ declare namespace PreferCanonicalMutableRecord {
|
|
|
90
90
|
* "global",
|
|
91
91
|
* "named"
|
|
92
92
|
* ],
|
|
93
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
93
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
94
94
|
* }
|
|
95
95
|
* },
|
|
96
96
|
* "additionalProperties": false
|
|
@@ -127,7 +127,7 @@ declare namespace PreferReadonlyOrMutableRecord {
|
|
|
127
127
|
* "global",
|
|
128
128
|
* "named"
|
|
129
129
|
* ],
|
|
130
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
130
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
131
131
|
* }
|
|
132
132
|
* },
|
|
133
133
|
* "additionalProperties": false
|
|
@@ -164,7 +164,7 @@ declare namespace PreferStrictOrRelaxedUtilityType {
|
|
|
164
164
|
* "global",
|
|
165
165
|
* "named"
|
|
166
166
|
* ],
|
|
167
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
167
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
168
168
|
* }
|
|
169
169
|
* },
|
|
170
170
|
* "additionalProperties": false
|
package/dist/rules/ast-utils.mjs
CHANGED
|
@@ -88,6 +88,77 @@ const isInConditionalTypeExtendsClause = (node) => {
|
|
|
88
88
|
isInConditionalTypeExtendsClause(parent));
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
const enclosingTypeAlias = (node) => node.type === AST_NODE_TYPES.TSTypeAliasDeclaration
|
|
92
|
+
? node
|
|
93
|
+
: node.type === AST_NODE_TYPES.Program
|
|
94
|
+
? undefined
|
|
95
|
+
: enclosingTypeAlias(node.parent);
|
|
96
|
+
const isNode = (value) => isNonNullObject(value) &&
|
|
97
|
+
typeof value.type === 'string';
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const walk = (node, sourceCode, visit) => {
|
|
108
|
+
visit(node);
|
|
109
|
+
if (!isRecord(node)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const keys = sourceCode.visitorKeys[node.type] ??
|
|
113
|
+
Object.keys(node).filter((key) => key !== 'parent');
|
|
114
|
+
for (const key of keys) {
|
|
115
|
+
const value = hasKey(node, key) ? node[key] : undefined;
|
|
116
|
+
if (Arr.isArray(value)) {
|
|
117
|
+
for (const element of value) {
|
|
118
|
+
if (isNode(element)) {
|
|
119
|
+
walk(element, sourceCode, visit);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (isNode(value)) {
|
|
124
|
+
walk(value, sourceCode, visit);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const referencedTypeNames = (node, sourceCode) => {
|
|
130
|
+
const mut_names = new Set();
|
|
131
|
+
walk(node, sourceCode, (visited) => {
|
|
132
|
+
if (visited.type === AST_NODE_TYPES.TSTypeReference &&
|
|
133
|
+
visited.typeName.type === AST_NODE_TYPES.Identifier) {
|
|
134
|
+
mut_names.add(visited.typeName.name);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return mut_names;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
const aliasReferenceGraph = (program, sourceCode) => {
|
|
147
|
+
const cached = aliasReferenceGraphCache.get(program);
|
|
148
|
+
if (cached !== undefined) {
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
151
|
+
const mut_graph = new Map();
|
|
152
|
+
walk(program, sourceCode, (visited) => {
|
|
153
|
+
if (visited.type === AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
154
|
+
mut_graph.set(visited.id.name, referencedTypeNames(visited.typeAnnotation, sourceCode));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
aliasReferenceGraphCache.set(program, mut_graph);
|
|
158
|
+
return mut_graph;
|
|
159
|
+
};
|
|
160
|
+
const programOf = (node) => node.type === AST_NODE_TYPES.Program ? node : programOf(node.parent);
|
|
161
|
+
|
|
91
162
|
|
|
92
163
|
|
|
93
164
|
|
|
@@ -152,78 +223,7 @@ const definesRecursiveTypeAlias = (tuple, sourceCode) => {
|
|
|
152
223
|
}
|
|
153
224
|
}
|
|
154
225
|
};
|
|
155
|
-
|
|
156
|
-
const enclosingTypeAlias = (node) => node.type === AST_NODE_TYPES.TSTypeAliasDeclaration
|
|
157
|
-
? node
|
|
158
|
-
: node.type === AST_NODE_TYPES.Program
|
|
159
|
-
? undefined
|
|
160
|
-
: enclosingTypeAlias(node.parent);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const aliasReferenceGraph = (program, sourceCode) => {
|
|
169
|
-
const cached = aliasReferenceGraphCache.get(program);
|
|
170
|
-
if (cached !== undefined) {
|
|
171
|
-
return cached;
|
|
172
|
-
}
|
|
173
|
-
const mut_graph = new Map();
|
|
174
|
-
walk(program, sourceCode, (visited) => {
|
|
175
|
-
if (visited.type === AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
176
|
-
mut_graph.set(visited.id.name, referencedTypeNames(visited.typeAnnotation, sourceCode));
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
aliasReferenceGraphCache.set(program, mut_graph);
|
|
180
|
-
return mut_graph;
|
|
181
|
-
};
|
|
182
226
|
const aliasReferenceGraphCache = new WeakMap();
|
|
183
|
-
const programOf = (node) => node.type === AST_NODE_TYPES.Program ? node : programOf(node.parent);
|
|
184
|
-
|
|
185
|
-
const referencedTypeNames = (node, sourceCode) => {
|
|
186
|
-
const mut_names = new Set();
|
|
187
|
-
walk(node, sourceCode, (visited) => {
|
|
188
|
-
if (visited.type === AST_NODE_TYPES.TSTypeReference &&
|
|
189
|
-
visited.typeName.type === AST_NODE_TYPES.Identifier) {
|
|
190
|
-
mut_names.add(visited.typeName.name);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
return mut_names;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const walk = (node, sourceCode, visit) => {
|
|
205
|
-
visit(node);
|
|
206
|
-
if (!isRecord(node)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
const keys = sourceCode.visitorKeys[node.type] ??
|
|
210
|
-
Object.keys(node).filter((key) => key !== 'parent');
|
|
211
|
-
for (const key of keys) {
|
|
212
|
-
const value = hasKey(node, key) ? node[key] : undefined;
|
|
213
|
-
if (Arr.isArray(value)) {
|
|
214
|
-
for (const element of value) {
|
|
215
|
-
if (isNode(element)) {
|
|
216
|
-
walk(element, sourceCode, visit);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else if (isNode(value)) {
|
|
221
|
-
walk(value, sourceCode, visit);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const isNode = (value) => isNonNullObject(value) &&
|
|
226
|
-
typeof value.type === 'string';
|
|
227
227
|
|
|
228
228
|
const getArrayElementType = (node) => {
|
|
229
229
|
if (node.type === AST_NODE_TYPES.TSArrayType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.mjs","sourceRoot":"","sources":["../../src/rules/ast-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBvE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAA2B,EAC3B,UAA+B,EACA,EAAE;IACjC,IAAI,gCAAgC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAEzB,MAAM,UAAU,GACd,MAAM,CAAC,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CAAC,IAAI,CAAC,CAAC;QAEnB,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAExC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAGzC,CAAC;AAEJ,+CAA+C;AAC/C,MAAM,mBAAmB,GAAG,CAC1B,IAAuB,EACQ,EAAE;IACjC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,cAAc;QAChD,IAAI,CAAC,QAAQ,KAAK,UAAU;QAC5B,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,cAAc,CAAC,WAAW;QACxD,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW;QACjC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAU,EAAE,CACnD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -9,7 +9,8 @@ export declare const IMPORT_STYLE_SCHEMA_PROPERTY: JsonSchema;
|
|
|
9
9
|
* whether the fix has to add an import for it.
|
|
10
10
|
*
|
|
11
11
|
* Returns `undefined` when the name is already bound to something else (a local
|
|
12
|
-
* alias,
|
|
12
|
+
* alias, an import from another module, or another ts-type-forge export
|
|
13
|
+
* imported under the name) — rewriting to it would then silently
|
|
13
14
|
* resolve to the wrong declaration, which is exactly what happens inside
|
|
14
15
|
* ts-type-forge's own sources.
|
|
15
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-style.d.mts","sourceRoot":"","sources":["../../src/rules/import-style.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOnE,mEAAmE;AACnE,KAAK,UAAU,GAAG,OAAO,CACvB,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACjE,SAAS,OAAO,EAAE,CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE7C,eAAO,MAAM,oBAAoB,EAAE,WAAqB,CAAC;AAEzD,eAAO,MAAM,4BAA4B,EAAE,UAW1C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"import-style.d.mts","sourceRoot":"","sources":["../../src/rules/import-style.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOnE,mEAAmE;AACnE,KAAK,UAAU,GAAG,OAAO,CACvB,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACjE,SAAS,OAAO,EAAE,CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE7C,eAAO,MAAM,oBAAoB,EAAE,WAAqB,CAAC;AAEzD,eAAO,MAAM,4BAA4B,EAAE,UAW1C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,YACjB,QAAQ,CAAC,OAAO,iBACV,MAAM,eACR,WAAW,KACvB,QAAQ,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,SAW1D,CAAC"}
|
|
@@ -7,9 +7,9 @@ export const IMPORT_STYLE_SCHEMA_PROPERTY = {
|
|
|
7
7
|
enum: ['global', 'named'],
|
|
8
8
|
description: [
|
|
9
9
|
'How the ts-type-forge type is brought into scope.',
|
|
10
|
-
"'named' (default) makes the autofix
|
|
11
|
-
|
|
12
|
-
"
|
|
10
|
+
"'named' (default) makes the autofix import the type from",
|
|
11
|
+
`\`${TS_TYPE_FORGE_MODULE}\` when the name is not imported yet,`,
|
|
12
|
+
"adding it to an existing import of the module where there is one; 'global' assumes the",
|
|
13
13
|
'ambient globals of `ts-type-forge/global` and never touches',
|
|
14
14
|
'imports.',
|
|
15
15
|
].join(' '),
|
|
@@ -23,6 +23,7 @@ export const IMPORT_STYLE_SCHEMA_PROPERTY = {
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
export const resolveTypeName = (program, canonicalName, importStyle) => {
|
|
27
28
|
const importedLocalName = getImportedLocalName(getImportDeclarations(program, TS_TYPE_FORGE_MODULE), canonicalName);
|
|
28
29
|
return importedLocalName !== undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-style.mjs","sourceRoot":"","sources":["../../src/rules/import-style.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAY/D,MAAM,CAAC,MAAM,oBAAoB,GAAgB,OAAO,CAAC;AAEzD,MAAM,CAAC,MAAM,4BAA4B,GAAe;IACtD,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE;QACX,mDAAmD;QACnD,
|
|
1
|
+
{"version":3,"file":"import-style.mjs","sourceRoot":"","sources":["../../src/rules/import-style.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAY/D,MAAM,CAAC,MAAM,oBAAoB,GAAgB,OAAO,CAAC;AAEzD,MAAM,CAAC,MAAM,4BAA4B,GAAe;IACtD,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE;QACX,mDAAmD;QACnD,0DAA0D;QAC1D,KAAK,oBAAoB,uCAAuC;QAChE,wFAAwF;QACxF,6DAA6D;QAC7D,UAAU;KACX,CAAC,IAAI,CAAC,GAAG,CAAC;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAyB,EACzB,aAAqB,EACrB,WAAwB,EAC2C,EAAE;IACrE,MAAM,iBAAiB,GAAG,oBAAoB,CAC5C,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,CAAC,EACpD,aAAa,CACd,CAAC;IAEF,OAAO,iBAAiB,KAAK,SAAS;QACpC,CAAC,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,KAAK,EAAE;QACtD,CAAC,CAAC,yBAAyB,CAAC,OAAO,EAAE,aAAa,CAAC;YACjD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,KAAK,OAAO,EAAE,CAAC;AAC3E,CAAC,CAAC"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { type TSESTree } from '@typescript-eslint/utils';
|
|
1
|
+
import { type TSESLint, type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* The edits that import the ts-type-forge types `names` the file does not
|
|
4
|
+
* import yet, as types: added to an existing `import type { … }` from the
|
|
5
|
+
* module (`, X`), else to a named import from it (`, type X`), else after a
|
|
6
|
+
* lone default import (`, { type X }`), and only failing all of those as a
|
|
7
|
+
* new `import { type X } from 'ts-type-forge'` after the directive prologue.
|
|
8
|
+
* Empty braces count as a host. Adding to an existing declaration keeps
|
|
9
|
+
* `import-x/no-duplicates` satisfied.
|
|
10
|
+
*
|
|
11
|
+
* Fixes that add an import overlap, so `--fix` applies one per pass, and the
|
|
12
|
+
* rest in later passes, by when the file imports their names (see
|
|
13
|
+
* `resolveTypeName`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const buildTypeImportFix: (fixer: TSESLint.RuleFixer, sourceCode: Readonly<TSESLint.SourceCode>, names: readonly string[]) => readonly TSESLint.RuleFix[];
|
|
2
16
|
/**
|
|
3
17
|
* Whether the file already binds `name` to something that is not the
|
|
4
18
|
* ts-type-forge export of the same name — a local type alias / interface /
|
|
5
|
-
* class / enum,
|
|
19
|
+
* class / enum, an import from another module, or another ts-type-forge
|
|
20
|
+
* export imported under that name. Autofixes that introduce
|
|
6
21
|
* `name` must bail out in that case, because the rewritten type would resolve
|
|
7
22
|
* to the wrong declaration. (ts-type-forge's own sources, which declare
|
|
8
23
|
* `NonEmptyArray` themselves, are the motivating example.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-utils.d.mts","sourceRoot":"","sources":["../../src/rules/import-utils.mts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"import-utils.d.mts","sourceRoot":"","sources":["../../src/rules/import-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;AAOlC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,UACtB,QAAQ,CAAC,SAAS,cACb,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,SAClC,SAAS,MAAM,EAAE,KACvB,SAAS,QAAQ,CAAC,OAAO,EAqD3B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,YAC3B,QAAQ,CAAC,OAAO,QACnB,MAAM,KACX,OAuBC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
1
|
+
import { AST_NODE_TYPES, } from '@typescript-eslint/utils';
|
|
2
|
+
import { buildNamedImportFix, getImportDeclarations } from 'eslint-rule-forge';
|
|
3
|
+
import { Arr } from 'ts-data-forge';
|
|
2
4
|
import { TS_TYPE_FORGE_MODULE } from './constants.mjs';
|
|
3
5
|
|
|
4
6
|
|
|
@@ -12,16 +14,83 @@ import { TS_TYPE_FORGE_MODULE } from './constants.mjs';
|
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const buildTypeImportFix = (fixer, sourceCode, names) => {
|
|
20
|
+
if (!Arr.isNonEmpty(names)) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const declarations = getImportDeclarations(sourceCode.ast, TS_TYPE_FORGE_MODULE);
|
|
24
|
+
const typeOnlyFix = declarations
|
|
25
|
+
.filter((declaration) => declaration.importKind === 'type')
|
|
26
|
+
.map((declaration) => addToBraces(fixer, sourceCode, declaration, names))
|
|
27
|
+
.find((fix) => fix !== undefined);
|
|
28
|
+
if (typeOnlyFix !== undefined) {
|
|
29
|
+
return [typeOnlyFix];
|
|
30
|
+
}
|
|
31
|
+
const typeSpecifiers = names.map((name) => `type ${name}`);
|
|
32
|
+
const valueDeclarations = declarations.filter((declaration) => declaration.importKind !== 'type');
|
|
33
|
+
const valueFix = valueDeclarations
|
|
34
|
+
.map((declaration) => addToBraces(fixer, sourceCode, declaration, typeSpecifiers))
|
|
35
|
+
.find((fix) => fix !== undefined);
|
|
36
|
+
if (valueFix !== undefined) {
|
|
37
|
+
return [valueFix];
|
|
38
|
+
}
|
|
39
|
+
const defaultHost = valueDeclarations.find((declaration) => Arr.isFixedLengthArray(1, declaration.specifiers) &&
|
|
40
|
+
declaration.specifiers[0].type === AST_NODE_TYPES.ImportDefaultSpecifier)?.specifiers[0];
|
|
41
|
+
if (defaultHost !== undefined) {
|
|
42
|
+
return [
|
|
43
|
+
fixer.insertTextAfter(defaultHost, `, { ${typeSpecifiers.join(', ')} }`),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
return buildNamedImportFix(fixer, sourceCode.ast, TS_TYPE_FORGE_MODULE, typeSpecifiers);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
15
60
|
export const hasConflictingDeclaration = (program, name) => program.body.some((node) => {
|
|
16
61
|
if (node.type === AST_NODE_TYPES.ImportDeclaration) {
|
|
17
|
-
return
|
|
18
|
-
node.
|
|
62
|
+
return node.specifiers.some((specifier) => specifier.local.name === name &&
|
|
63
|
+
!(node.source.value === TS_TYPE_FORGE_MODULE &&
|
|
64
|
+
specifier.type === AST_NODE_TYPES.ImportSpecifier &&
|
|
65
|
+
(specifier.imported.type === AST_NODE_TYPES.Identifier
|
|
66
|
+
? specifier.imported.name
|
|
67
|
+
: specifier.imported.value) === name));
|
|
19
68
|
}
|
|
20
69
|
return declaresName(node.type === AST_NODE_TYPES.ExportNamedDeclaration ||
|
|
21
70
|
node.type === AST_NODE_TYPES.ExportDefaultDeclaration
|
|
22
71
|
? node.declaration
|
|
23
72
|
: node, name);
|
|
24
73
|
});
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const addToBraces = (fixer, sourceCode, declaration, specifiers) => {
|
|
80
|
+
const lastNamed = declaration.specifiers
|
|
81
|
+
.filter((specifier) => specifier.type === AST_NODE_TYPES.ImportSpecifier)
|
|
82
|
+
.at(-1);
|
|
83
|
+
if (lastNamed !== undefined) {
|
|
84
|
+
return fixer.insertTextAfter(lastNamed, `, ${specifiers.join(', ')}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const openingBrace = sourceCode.getFirstToken(declaration, {
|
|
88
|
+
filter: (token) => token.value === '{' && token.range[1] <= declaration.source.range[0],
|
|
89
|
+
});
|
|
90
|
+
return openingBrace === null
|
|
91
|
+
? undefined
|
|
92
|
+
: fixer.insertTextAfter(openingBrace, ` ${specifiers.join(', ')} `);
|
|
93
|
+
};
|
|
25
94
|
const declaresName = (node, name) => {
|
|
26
95
|
if (node === null || node === undefined) {
|
|
27
96
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-utils.mjs","sourceRoot":"","sources":["../../src/rules/import-utils.mts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"import-utils.mjs","sourceRoot":"","sources":["../../src/rules/import-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,uEAAuE;AAEvE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAyB,EACzB,UAAyC,EACzC,KAAwB,EACK,EAAE;IAC/B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,qBAAqB,CACxC,UAAU,CAAC,GAAG,EACd,oBAAoB,CACrB,CAAC;IAEF,MAAM,WAAW,GAAG,YAAY;SAC7B,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,KAAK,MAAM,CAAC;SAC1D,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,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@ export type TypeRewrite = Readonly<{
|
|
|
8
8
|
typeArgs: string;
|
|
9
9
|
}>;
|
|
10
10
|
/**
|
|
11
|
-
* Emits one report per rewrite, resolving each target name
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* Emits one report per rewrite, resolving each target name. Every fix imports
|
|
12
|
+
* the name it writes when the file does not import it yet
|
|
13
|
+
* ({@link buildTypeImportFix}), so that one applied alone is complete, and the
|
|
14
|
+
* first of those imports every name the reports need: the import edits
|
|
15
|
+
* overlap, so `--fix` applies one fix per pass, and when that is the batching
|
|
16
|
+
* fix the second pass applies the rest. (With nested rewrites an inner fix,
|
|
17
|
+
* whose range ends first, can win the pass instead; that costs a pass, not a
|
|
18
|
+
* fix.) A report that needs no import has no import edit.
|
|
18
19
|
*/
|
|
19
20
|
export declare const reportTypeRewrites: <MessageIds extends string>(context: TSESLint.RuleContext<MessageIds, readonly unknown[]>, rewrites: readonly TypeRewrite[], messageId: MessageIds, importStyle: ImportStyle) => void;
|
|
20
21
|
//# sourceMappingURL=rewrite-rule-utils.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite-rule-utils.d.mts","sourceRoot":"","sources":["../../src/rules/rewrite-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"rewrite-rule-utils.d.mts","sourceRoot":"","sources":["../../src/rules/rewrite-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKvE,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IACjC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,SAAS,MAAM,WACjD,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,SAAS,OAAO,EAAE,CAAC,YACnD,SAAS,WAAW,EAAE,aACrB,UAAU,eACR,WAAW,KACvB,IAoDF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { buildNamedImportFix } from 'eslint-rule-forge';
|
|
2
1
|
import { Arr } from 'ts-data-forge';
|
|
3
|
-
import { TS_TYPE_FORGE_MODULE } from './constants.mjs';
|
|
4
2
|
import { resolveTypeName } from './import-style.mjs';
|
|
3
|
+
import { buildTypeImportFix } from './import-utils.mjs';
|
|
4
|
+
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -27,17 +27,19 @@ export const reportTypeRewrites = (context, rewrites, messageId, importStyle) =>
|
|
|
27
27
|
const importNames = Arr.uniq(resolved
|
|
28
28
|
.filter(({ target }) => target.needsImport)
|
|
29
29
|
.map(({ rewrite }) => rewrite.canonicalName));
|
|
30
|
+
|
|
31
|
+
const batchIndex = resolved.findIndex(({ target }) => target.needsImport);
|
|
30
32
|
for (const [index, { rewrite, target }] of resolved.entries()) {
|
|
31
33
|
const replacement = `${target.localName}<${rewrite.typeArgs}>`;
|
|
32
34
|
context.report({
|
|
33
35
|
node: rewrite.node,
|
|
34
36
|
messageId,
|
|
35
37
|
data: { original: sourceCode.getText(rewrite.node), replacement },
|
|
36
|
-
fix: (fixer) => Arr.toPushed(index ===
|
|
37
|
-
? importNames
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
fix: (fixer) => Arr.toPushed(buildTypeImportFix(fixer, sourceCode, index === batchIndex
|
|
39
|
+
? importNames
|
|
40
|
+
: target.needsImport
|
|
41
|
+
? [rewrite.canonicalName]
|
|
42
|
+
: []), fixer.replaceText(rewrite.node, replacement)),
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite-rule-utils.mjs","sourceRoot":"","sources":["../../src/rules/rewrite-rule-utils.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
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;;;;;;;;;GASG;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,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACrC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,eAAe,CAC5B,OAAO,EACP,OAAO,CAAC,aAAa,EACrB,WAAW,CACZ,CAAC;YAEF,2EAA2E;YAC3E,0CAA0C;YAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAC1B,QAAQ;SACL,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;SAC1C,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAC/C,CAAC;IAEF,wEAAwE;IACxE,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE1E,KAAK,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAC9D,MAAM,WAAW,GAAG,GAAG,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,GAAG,CAAC;QAE/D,OAAO,CAAC,MAAM,CAAC;YACb,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS;YACT,IAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE;YACjE,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CACb,GAAG,CAAC,QAAQ,CACV,kBAAkB,CAChB,KAAK,EACL,UAAU,EACV,KAAK,KAAK,UAAU;gBAClB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,MAAM,CAAC,WAAW;oBAClB,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;oBACzB,CAAC,CAAC,EAAE,CACT,EACD,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAC7C;SACJ,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"std-type-rule-utils.d.mts","sourceRoot":"","sources":["../../src/rules/std-type-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"std-type-rule-utils.d.mts","sourceRoot":"","sources":["../../src/rules/std-type-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKvE;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAEzE;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,SAAS,MAAM,WACrD,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,SAAS,OAAO,EAAE,CAAC,QACvD,QAAQ,CAAC,eAAe,gBAChB,mBAAmB,cACrB,QAAQ,CAAC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,eACvD,WAAW,KACvB,IAkDF,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, } from '@typescript-eslint/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { isLocallyBound } from 'eslint-rule-forge';
|
|
3
3
|
import { Arr } from 'ts-data-forge';
|
|
4
|
-
import { TS_TYPE_FORGE_MODULE } from './constants.mjs';
|
|
5
4
|
import { resolveTypeName } from './import-style.mjs';
|
|
5
|
+
import { buildTypeImportFix } from './import-utils.mjs';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -44,9 +44,7 @@ export const reportStdTypeReference = (context, node, alternatives, messageIds,
|
|
|
44
44
|
messageId: messageIds.suggestion,
|
|
45
45
|
data: { name: stdName, replacement: target.localName },
|
|
46
46
|
fix: (fixer) => Arr.toPushed(target.needsImport
|
|
47
|
-
?
|
|
48
|
-
`type ${candidate}`,
|
|
49
|
-
])
|
|
47
|
+
? buildTypeImportFix(fixer, context.sourceCode, [candidate])
|
|
50
48
|
: [], fixer.replaceText(typeName, target.localName)),
|
|
51
49
|
};
|
|
52
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"std-type-rule-utils.mjs","sourceRoot":"","sources":["../../src/rules/std-type-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"std-type-rule-utils.mjs","sourceRoot":"","sources":["../../src/rules/std-type-rule-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAoB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAUxD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAA6D,EAC7D,IAA8B,EAC9B,YAAiC,EACjC,UAAoE,EACpE,WAAwB,EAClB,EAAE;IACR,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAE/B,yEAAyE;IACzE,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;QAChD,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC;IAE9B,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,uEAAuE;IACvE,sDAAsD;IACtD,IAAI,cAAc,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;QACtD,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;IAEvC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ge",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ESLint rules that steer type declarations toward ts-type-forge idioms.",
|
|
6
6
|
"keywords": [
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"@typescript-eslint/parser": "8.72.0",
|
|
45
45
|
"@typescript-eslint/rule-tester": "8.72.0",
|
|
46
46
|
"dedent": "1.7.2",
|
|
47
|
-
"eslint-config-typed": "7.1
|
|
48
|
-
"eslint-plugin-ts-data-forge": "0.10.
|
|
49
|
-
"eslint-plugin-ts-fortress": "1.3.
|
|
47
|
+
"eslint-config-typed": "7.2.1",
|
|
48
|
+
"eslint-plugin-ts-data-forge": "0.10.6",
|
|
49
|
+
"eslint-plugin-ts-fortress": "1.3.11",
|
|
50
50
|
"prettier": "3.9.10",
|
|
51
51
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
52
52
|
"prettier-plugin-packagejson": "3.0.2",
|
package/src/rule-types.mts
CHANGED
|
@@ -68,7 +68,7 @@ namespace PreferCanonicalLengthConstrainedTuple {
|
|
|
68
68
|
* "global",
|
|
69
69
|
* "named"
|
|
70
70
|
* ],
|
|
71
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
71
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
72
72
|
* },
|
|
73
73
|
* "maxLength": {
|
|
74
74
|
* "type": "integer",
|
|
@@ -117,7 +117,7 @@ namespace PreferCanonicalMutableRecord {
|
|
|
117
117
|
* "global",
|
|
118
118
|
* "named"
|
|
119
119
|
* ],
|
|
120
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
120
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
121
121
|
* }
|
|
122
122
|
* },
|
|
123
123
|
* "additionalProperties": false
|
|
@@ -161,7 +161,7 @@ namespace PreferReadonlyOrMutableRecord {
|
|
|
161
161
|
* "global",
|
|
162
162
|
* "named"
|
|
163
163
|
* ],
|
|
164
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
164
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
165
165
|
* }
|
|
166
166
|
* },
|
|
167
167
|
* "additionalProperties": false
|
|
@@ -205,7 +205,7 @@ namespace PreferStrictOrRelaxedUtilityType {
|
|
|
205
205
|
* "global",
|
|
206
206
|
* "named"
|
|
207
207
|
* ],
|
|
208
|
-
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix
|
|
208
|
+
* "description": "How the ts-type-forge type is brought into scope. 'named' (default) makes the autofix import the type from `ts-type-forge` when the name is not imported yet, adding it to an existing import of the module where there is one; 'global' assumes the ambient globals of `ts-type-forge/global` and never touches imports."
|
|
209
209
|
* }
|
|
210
210
|
* },
|
|
211
211
|
* "additionalProperties": false
|