@tsslint/core 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +70 -56
- package/lib/watch.js +5 -5
- package/package.json +3 -3
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: [],
|
|
@@ -157,19 +162,17 @@ function createLinter(ctx, config, withStack) {
|
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
const diagnosticSet = new Set(diagnostics);
|
|
160
|
-
for (const [ruleId,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fixes.set(ruleId, final);
|
|
165
|
+
for (const [ruleId, { diagnostic, actions }] of [...fixes]) {
|
|
166
|
+
if (actions.length && diagnosticSet.has(diagnostic)) {
|
|
167
|
+
fixes.set(ruleId, { diagnostic, actions });
|
|
164
168
|
}
|
|
165
169
|
else {
|
|
166
170
|
fixes.delete(ruleId);
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
|
-
for (const [ruleId,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
refactors.set(ruleId, final);
|
|
173
|
+
for (const [ruleId, { diagnostic, actions }] of [...refactors]) {
|
|
174
|
+
if (actions.length && diagnosticSet.has(diagnostic)) {
|
|
175
|
+
fixes.set(ruleId, { diagnostic, actions });
|
|
173
176
|
}
|
|
174
177
|
else {
|
|
175
178
|
refactors.delete(ruleId);
|
|
@@ -221,13 +224,13 @@ function createLinter(ctx, config, withStack) {
|
|
|
221
224
|
withFix(title, getEdits) {
|
|
222
225
|
currentFixes++;
|
|
223
226
|
if (!fixes.has(currentRuleId)) {
|
|
224
|
-
fixes.set(currentRuleId,
|
|
227
|
+
fixes.set(currentRuleId, {
|
|
228
|
+
diagnostic: error,
|
|
229
|
+
actions: [],
|
|
230
|
+
});
|
|
225
231
|
}
|
|
226
|
-
fixes.get(currentRuleId).push(({
|
|
227
|
-
diagnostic: error,
|
|
232
|
+
fixes.get(currentRuleId).actions.push(({
|
|
228
233
|
title,
|
|
229
|
-
start,
|
|
230
|
-
end,
|
|
231
234
|
getEdits,
|
|
232
235
|
}));
|
|
233
236
|
return this;
|
|
@@ -235,13 +238,13 @@ function createLinter(ctx, config, withStack) {
|
|
|
235
238
|
withRefactor(title, getEdits) {
|
|
236
239
|
currentRefactors++;
|
|
237
240
|
if (!refactors.has(currentRuleId)) {
|
|
238
|
-
refactors.set(currentRuleId,
|
|
241
|
+
refactors.set(currentRuleId, {
|
|
242
|
+
diagnostic: error,
|
|
243
|
+
actions: [],
|
|
244
|
+
});
|
|
239
245
|
}
|
|
240
|
-
refactors.get(currentRuleId).push(({
|
|
241
|
-
diagnostic: error,
|
|
246
|
+
refactors.get(currentRuleId).actions.push(({
|
|
242
247
|
title,
|
|
243
|
-
start,
|
|
244
|
-
end,
|
|
245
248
|
getEdits,
|
|
246
249
|
}));
|
|
247
250
|
return this;
|
|
@@ -260,16 +263,22 @@ function createLinter(ctx, config, withStack) {
|
|
|
260
263
|
fileName = fileName.split('http-url:')[1];
|
|
261
264
|
}
|
|
262
265
|
if (!sourceFiles.has(fileName)) {
|
|
263
|
-
const text = ctx.languageServiceHost.readFile(fileName)
|
|
264
|
-
sourceFiles.set(fileName,
|
|
266
|
+
const text = ctx.languageServiceHost.readFile(fileName);
|
|
267
|
+
sourceFiles.set(fileName, [
|
|
268
|
+
text !== undefined,
|
|
269
|
+
ts.createSourceFile(fileName, text ?? '', ts.ScriptTarget.Latest, true)
|
|
270
|
+
]);
|
|
265
271
|
}
|
|
266
|
-
const stackFile = sourceFiles.get(fileName);
|
|
272
|
+
const [exist, stackFile] = sourceFiles.get(fileName);
|
|
267
273
|
let pos = 0;
|
|
268
|
-
|
|
269
|
-
|
|
274
|
+
if (exist) {
|
|
275
|
+
try {
|
|
276
|
+
pos = stackFile.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1) ?? 0;
|
|
277
|
+
}
|
|
278
|
+
catch { }
|
|
270
279
|
}
|
|
271
|
-
|
|
272
|
-
error.relatedInformation
|
|
280
|
+
error.relatedInformation ??= [];
|
|
281
|
+
error.relatedInformation.push({
|
|
273
282
|
category: ts.DiagnosticCategory.Message,
|
|
274
283
|
code: 0,
|
|
275
284
|
file: stackFile,
|
|
@@ -282,8 +291,8 @@ function createLinter(ctx, config, withStack) {
|
|
|
282
291
|
},
|
|
283
292
|
hasCodeFixes(fileName) {
|
|
284
293
|
const fixesMap = getFileFixes(fileName);
|
|
285
|
-
for (const [_ruleId,
|
|
286
|
-
if (
|
|
294
|
+
for (const [_ruleId, { actions }] of fixesMap) {
|
|
295
|
+
if (actions.length) {
|
|
287
296
|
return true;
|
|
288
297
|
}
|
|
289
298
|
}
|
|
@@ -291,30 +300,33 @@ function createLinter(ctx, config, withStack) {
|
|
|
291
300
|
},
|
|
292
301
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
293
302
|
const fixesMap = getFileFixes(fileName);
|
|
294
|
-
|
|
295
|
-
for (const [ruleId,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
const result = [];
|
|
304
|
+
for (const [ruleId, { diagnostic, actions }] of fixesMap) {
|
|
305
|
+
if (diagnostics?.length && !diagnostics.includes(diagnostic)) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const diagStart = diagnostic.start;
|
|
309
|
+
const diagEnd = diagStart + diagnostic.length;
|
|
310
|
+
if ((diagStart >= start && diagStart <= end) ||
|
|
311
|
+
(diagEnd >= start && diagEnd <= end) ||
|
|
312
|
+
(start >= diagStart && start <= diagEnd) ||
|
|
313
|
+
(end >= diagStart && end <= diagEnd)) {
|
|
314
|
+
let codeFixes = [];
|
|
315
|
+
for (const action of actions) {
|
|
316
|
+
codeFixes.push({
|
|
306
317
|
fixName: `tsslint:${ruleId}`,
|
|
307
|
-
description:
|
|
308
|
-
changes:
|
|
318
|
+
description: action.title,
|
|
319
|
+
changes: action.getEdits(),
|
|
309
320
|
fixId: 'tsslint',
|
|
310
321
|
fixAllDescription: 'Fix all TSSLint errors'
|
|
311
322
|
});
|
|
312
323
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
324
|
+
for (const plugin of plugins) {
|
|
325
|
+
if (plugin.resolveCodeFixes) {
|
|
326
|
+
codeFixes = plugin.resolveCodeFixes(fileName, diagnostic, result);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
result.push(...codeFixes);
|
|
318
330
|
}
|
|
319
331
|
}
|
|
320
332
|
return result;
|
|
@@ -322,16 +334,18 @@ function createLinter(ctx, config, withStack) {
|
|
|
322
334
|
getRefactors(fileName, start, end) {
|
|
323
335
|
const refactorsMap = getFileRefactors(fileName);
|
|
324
336
|
let result = [];
|
|
325
|
-
for (const [ruleId,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
337
|
+
for (const [ruleId, { diagnostic, actions }] of refactorsMap) {
|
|
338
|
+
const diagStart = diagnostic.start;
|
|
339
|
+
const diagEnd = diagStart + diagnostic.length;
|
|
340
|
+
if ((diagStart >= start && diagStart <= end) ||
|
|
341
|
+
(diagEnd >= start && diagEnd <= end) ||
|
|
342
|
+
(start >= diagStart && start <= diagEnd) ||
|
|
343
|
+
(end >= diagStart && end <= diagEnd)) {
|
|
344
|
+
for (let i = 0; i < actions.length; i++) {
|
|
345
|
+
const action = actions[i];
|
|
332
346
|
result.push({
|
|
333
347
|
name: `tsslint:${ruleId}:${i}`,
|
|
334
|
-
description:
|
|
348
|
+
description: action.title + ' (' + ruleId + ')',
|
|
335
349
|
kind: 'quickfix',
|
|
336
350
|
});
|
|
337
351
|
}
|
|
@@ -343,7 +357,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
343
357
|
if (name.startsWith('tsslint:')) {
|
|
344
358
|
const [ruleId, index] = name.slice('tsslint:'.length).split(':');
|
|
345
359
|
const refactorsMap = getFileRefactors(fileName);
|
|
346
|
-
const refactor = refactorsMap.get(ruleId)?.[Number(index)];
|
|
360
|
+
const refactor = refactorsMap.get(ruleId)?.actions[Number(index)];
|
|
347
361
|
if (refactor) {
|
|
348
362
|
return refactor.getEdits();
|
|
349
363
|
}
|
package/lib/watch.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.watchConfigFile = watchConfigFile;
|
|
|
4
4
|
const esbuild = require("esbuild");
|
|
5
5
|
const _path = require("path");
|
|
6
6
|
const fs = require("fs");
|
|
7
|
-
const
|
|
7
|
+
const url = require("url");
|
|
8
8
|
const ErrorStackParser = require("error-stack-parser");
|
|
9
9
|
async function watchConfigFile(configFilePath, onBuild, watch = true, createHash = btoa, logger = console) {
|
|
10
10
|
let start;
|
|
@@ -28,7 +28,7 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
28
28
|
}
|
|
29
29
|
if (!result.errors.length) {
|
|
30
30
|
try {
|
|
31
|
-
config = (await import(
|
|
31
|
+
config = (await import(url.pathToFileURL(outFile).toString() + '?time=' + Date.now())).default;
|
|
32
32
|
}
|
|
33
33
|
catch (e) {
|
|
34
34
|
if (e.stack) {
|
|
@@ -97,8 +97,8 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
97
97
|
fs.writeFileSync(cachePath, text, 'utf8');
|
|
98
98
|
}
|
|
99
99
|
return {
|
|
100
|
-
path:
|
|
101
|
-
external:
|
|
100
|
+
path: cachePath,
|
|
101
|
+
external: !isTsFile(cachePath),
|
|
102
102
|
};
|
|
103
103
|
});
|
|
104
104
|
build.onResolve({ filter: /.*/ }, ({ path, resolveDir }) => {
|
|
@@ -107,7 +107,7 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
107
107
|
const maybeJsPath = require.resolve(path, { paths: [resolveDir] });
|
|
108
108
|
if (!isTsFile(maybeJsPath) && fs.existsSync(maybeJsPath)) {
|
|
109
109
|
return {
|
|
110
|
-
path:
|
|
110
|
+
path: url.pathToFileURL(maybeJsPath).toString(),
|
|
111
111
|
external: true,
|
|
112
112
|
};
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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.
|
|
15
|
+
"@tsslint/types": "1.2.0",
|
|
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": "3752318ba6ca2eb953a566b1d0c1b80f2125befd"
|
|
22
22
|
}
|