@tsslint/core 1.1.6 → 1.2.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/index.d.ts +1 -1
- package/index.js +74 -83
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function createLinter(ctx: ProjectContext, config: Config | Confi
|
|
|
8
8
|
hasCodeFixes(fileName: string): boolean;
|
|
9
9
|
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]): ts.CodeFixAction[];
|
|
10
10
|
getRefactors(fileName: string, start: number, end: number): ts.RefactorActionInfo[];
|
|
11
|
-
getRefactorEdits(fileName: string,
|
|
11
|
+
getRefactorEdits(fileName: string, actionName: string): ts.FileTextChanges[] | undefined;
|
|
12
12
|
};
|
|
13
13
|
export declare function combineCodeFixes(fileName: string, fixes: ts.CodeFixAction[]): ts.TextChange[];
|
|
14
14
|
export declare function applyTextChanges(baseSnapshot: ts.IScriptSnapshot, textChanges: ts.TextChange[]): ts.IScriptSnapshot;
|
package/index.js
CHANGED
|
@@ -26,8 +26,13 @@ function createLinter(ctx, config, withStack) {
|
|
|
26
26
|
if (withStack) {
|
|
27
27
|
require('source-map-support').install({
|
|
28
28
|
retrieveFile(path) {
|
|
29
|
+
if (!path.endsWith('.js.map')) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
path = path.replace(/\\/g, '/');
|
|
29
33
|
// monkey-fix, refs: https://github.com/typescript-eslint/typescript-eslint/issues/9352
|
|
30
|
-
if (path.
|
|
34
|
+
if (path.includes('/@typescript-eslint/eslint-plugin/dist/rules/')
|
|
35
|
+
|| path.includes('/eslint-plugin-expect-type/lib/rules/')) {
|
|
31
36
|
return JSON.stringify({
|
|
32
37
|
version: 3,
|
|
33
38
|
sources: [],
|
|
@@ -100,7 +105,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
100
105
|
let currentFixes = 0;
|
|
101
106
|
let currentRefactors = 0;
|
|
102
107
|
fixes.clear();
|
|
103
|
-
refactors.
|
|
108
|
+
refactors.length = 0;
|
|
104
109
|
if (debugInfo) {
|
|
105
110
|
debugInfo.messageText += '- Rules:\n';
|
|
106
111
|
}
|
|
@@ -157,24 +162,12 @@ function createLinter(ctx, config, withStack) {
|
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
const diagnosticSet = new Set(diagnostics);
|
|
160
|
-
for (const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fixes.set(ruleId, final);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
fixes.delete(ruleId);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
for (const [ruleId, refactor] of [...refactors]) {
|
|
170
|
-
const final = refactor.filter(fix => diagnosticSet.has(fix.diagnostic));
|
|
171
|
-
if (final.length) {
|
|
172
|
-
refactors.set(ruleId, final);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
refactors.delete(ruleId);
|
|
165
|
+
for (const diagnostic of [...fixes.keys()]) {
|
|
166
|
+
if (!diagnosticSet.has(diagnostic)) {
|
|
167
|
+
fixes.delete(diagnostic);
|
|
176
168
|
}
|
|
177
169
|
}
|
|
170
|
+
fileRefactors.set(fileName, refactors.filter(refactor => diagnosticSet.has(refactor.diagnostic)));
|
|
178
171
|
return diagnostics;
|
|
179
172
|
function reportError(message, start, end, traceOffset = 0) {
|
|
180
173
|
return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
|
|
@@ -220,28 +213,17 @@ function createLinter(ctx, config, withStack) {
|
|
|
220
213
|
},
|
|
221
214
|
withFix(title, getEdits) {
|
|
222
215
|
currentFixes++;
|
|
223
|
-
if (!fixes.has(
|
|
224
|
-
fixes.set(
|
|
216
|
+
if (!fixes.has(error)) {
|
|
217
|
+
fixes.set(error, []);
|
|
225
218
|
}
|
|
226
|
-
fixes.get(
|
|
227
|
-
diagnostic: error,
|
|
228
|
-
title,
|
|
229
|
-
start,
|
|
230
|
-
end,
|
|
231
|
-
getEdits,
|
|
232
|
-
}));
|
|
219
|
+
fixes.get(error).push(({ title, getEdits }));
|
|
233
220
|
return this;
|
|
234
221
|
},
|
|
235
222
|
withRefactor(title, getEdits) {
|
|
236
223
|
currentRefactors++;
|
|
237
|
-
|
|
238
|
-
refactors.set(currentRuleId, []);
|
|
239
|
-
}
|
|
240
|
-
refactors.get(currentRuleId).push(({
|
|
224
|
+
refactors.push(({
|
|
241
225
|
diagnostic: error,
|
|
242
226
|
title,
|
|
243
|
-
start,
|
|
244
|
-
end,
|
|
245
227
|
getEdits,
|
|
246
228
|
}));
|
|
247
229
|
return this;
|
|
@@ -260,16 +242,22 @@ function createLinter(ctx, config, withStack) {
|
|
|
260
242
|
fileName = fileName.split('http-url:')[1];
|
|
261
243
|
}
|
|
262
244
|
if (!sourceFiles.has(fileName)) {
|
|
263
|
-
const text = ctx.languageServiceHost.readFile(fileName)
|
|
264
|
-
sourceFiles.set(fileName,
|
|
245
|
+
const text = ctx.languageServiceHost.readFile(fileName);
|
|
246
|
+
sourceFiles.set(fileName, [
|
|
247
|
+
text !== undefined,
|
|
248
|
+
ts.createSourceFile(fileName, text ?? '', ts.ScriptTarget.Latest, true)
|
|
249
|
+
]);
|
|
265
250
|
}
|
|
266
|
-
const stackFile = sourceFiles.get(fileName);
|
|
251
|
+
const [exist, stackFile] = sourceFiles.get(fileName);
|
|
267
252
|
let pos = 0;
|
|
268
|
-
|
|
269
|
-
|
|
253
|
+
if (exist) {
|
|
254
|
+
try {
|
|
255
|
+
pos = stackFile.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1) ?? 0;
|
|
256
|
+
}
|
|
257
|
+
catch { }
|
|
270
258
|
}
|
|
271
|
-
|
|
272
|
-
error.relatedInformation
|
|
259
|
+
error.relatedInformation ??= [];
|
|
260
|
+
error.relatedInformation.push({
|
|
273
261
|
category: ts.DiagnosticCategory.Message,
|
|
274
262
|
code: 0,
|
|
275
263
|
file: stackFile,
|
|
@@ -282,8 +270,8 @@ function createLinter(ctx, config, withStack) {
|
|
|
282
270
|
},
|
|
283
271
|
hasCodeFixes(fileName) {
|
|
284
272
|
const fixesMap = getFileFixes(fileName);
|
|
285
|
-
for (const [
|
|
286
|
-
if (
|
|
273
|
+
for (const [_diagnostic, actions] of fixesMap) {
|
|
274
|
+
if (actions.length) {
|
|
287
275
|
return true;
|
|
288
276
|
}
|
|
289
277
|
}
|
|
@@ -291,59 +279,62 @@ function createLinter(ctx, config, withStack) {
|
|
|
291
279
|
},
|
|
292
280
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
293
281
|
const fixesMap = getFileFixes(fileName);
|
|
294
|
-
|
|
295
|
-
for (const [
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
282
|
+
const result = [];
|
|
283
|
+
for (const [diagnostic, actions] of fixesMap) {
|
|
284
|
+
if (diagnostics?.length && !diagnostics.includes(diagnostic)) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const diagStart = diagnostic.start;
|
|
288
|
+
const diagEnd = diagStart + diagnostic.length;
|
|
289
|
+
if ((diagStart >= start && diagStart <= end) ||
|
|
290
|
+
(diagEnd >= start && diagEnd <= end) ||
|
|
291
|
+
(start >= diagStart && start <= diagEnd) ||
|
|
292
|
+
(end >= diagStart && end <= diagEnd)) {
|
|
293
|
+
let codeFixes = [];
|
|
294
|
+
for (const action of actions) {
|
|
295
|
+
codeFixes.push({
|
|
296
|
+
fixName: `tsslint:${diagnostic.code}`,
|
|
297
|
+
description: action.title,
|
|
298
|
+
changes: action.getEdits(),
|
|
309
299
|
fixId: 'tsslint',
|
|
310
300
|
fixAllDescription: 'Fix all TSSLint errors'
|
|
311
301
|
});
|
|
312
302
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
303
|
+
for (const plugin of plugins) {
|
|
304
|
+
if (plugin.resolveCodeFixes) {
|
|
305
|
+
codeFixes = plugin.resolveCodeFixes(fileName, diagnostic, codeFixes);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
result.push(...codeFixes);
|
|
318
309
|
}
|
|
319
310
|
}
|
|
320
311
|
return result;
|
|
321
312
|
},
|
|
322
313
|
getRefactors(fileName, start, end) {
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
for (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
314
|
+
const refactors = getFileRefactors(fileName);
|
|
315
|
+
const result = [];
|
|
316
|
+
for (let i = 0; i < refactors.length; i++) {
|
|
317
|
+
const refactor = refactors[i];
|
|
318
|
+
const diagStart = refactor.diagnostic.start;
|
|
319
|
+
const diagEnd = diagStart + refactor.diagnostic.length;
|
|
320
|
+
if ((diagStart >= start && diagStart <= end) ||
|
|
321
|
+
(diagEnd >= start && diagEnd <= end) ||
|
|
322
|
+
(start >= diagStart && start <= diagEnd) ||
|
|
323
|
+
(end >= diagStart && end <= diagEnd)) {
|
|
324
|
+
result.push({
|
|
325
|
+
name: `tsslint:${i}`,
|
|
326
|
+
description: refactor.title,
|
|
327
|
+
kind: 'quickfix',
|
|
328
|
+
});
|
|
338
329
|
}
|
|
339
330
|
}
|
|
340
331
|
return result;
|
|
341
332
|
},
|
|
342
|
-
getRefactorEdits(fileName,
|
|
343
|
-
if (
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
const refactor =
|
|
333
|
+
getRefactorEdits(fileName, actionName) {
|
|
334
|
+
if (actionName.startsWith('tsslint:')) {
|
|
335
|
+
const index = actionName.slice('tsslint:'.length);
|
|
336
|
+
const actions = getFileRefactors(fileName);
|
|
337
|
+
const refactor = actions[Number(index)];
|
|
347
338
|
if (refactor) {
|
|
348
339
|
return refactor.getEdits();
|
|
349
340
|
}
|
|
@@ -383,7 +374,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
383
374
|
}
|
|
384
375
|
function getFileRefactors(fileName) {
|
|
385
376
|
if (!fileRefactors.has(fileName)) {
|
|
386
|
-
fileRefactors.set(fileName,
|
|
377
|
+
fileRefactors.set(fileName, []);
|
|
387
378
|
}
|
|
388
379
|
return fileRefactors.get(fileName);
|
|
389
380
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"directory": "packages/core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/types": "1.1
|
|
15
|
+
"@tsslint/types": "1.2.1",
|
|
16
16
|
"error-stack-parser": "^2.1.4",
|
|
17
17
|
"esbuild": ">=0.17.0",
|
|
18
18
|
"minimatch": "^10.0.1",
|
|
19
19
|
"source-map-support": "^0.5.21"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "404b3fc30589e6a217de6953a5e5f582854b5189"
|
|
22
22
|
}
|