@tsslint/core 1.2.2 → 1.2.4
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 +47 -29
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -46,22 +46,23 @@ function createLinter(ctx, config, withStack) {
|
|
|
46
46
|
}
|
|
47
47
|
const ts = ctx.typescript;
|
|
48
48
|
const fileRules = new Map();
|
|
49
|
+
const fileConfigs = new Map();
|
|
49
50
|
const fileFixes = new Map();
|
|
50
51
|
const fileRefactors = new Map();
|
|
51
52
|
const sourceFiles = new Map();
|
|
52
53
|
const basePath = path.dirname(ctx.configFile);
|
|
53
54
|
const configs = (Array.isArray(config) ? config : [config])
|
|
54
55
|
.map(config => ({
|
|
55
|
-
config,
|
|
56
|
+
rules: config.rules ?? {},
|
|
56
57
|
includes: (config.include ?? []).map(include => {
|
|
57
58
|
return ts.server.toNormalizedPath(path.resolve(basePath, include));
|
|
58
59
|
}),
|
|
59
60
|
excludes: (config.exclude ?? []).map(exclude => {
|
|
60
61
|
return ts.server.toNormalizedPath(path.resolve(basePath, exclude));
|
|
61
62
|
}),
|
|
63
|
+
plugins: (config.plugins ?? []).map(plugin => plugin(ctx)),
|
|
62
64
|
}));
|
|
63
|
-
const
|
|
64
|
-
const debug = configs.some(({ config }) => config.debug);
|
|
65
|
+
const debug = (Array.isArray(config) ? config : [config]).some(config => config.debug);
|
|
65
66
|
return {
|
|
66
67
|
lint(fileName) {
|
|
67
68
|
let diagnostics = [];
|
|
@@ -156,9 +157,12 @@ function createLinter(ctx, config, withStack) {
|
|
|
156
157
|
}
|
|
157
158
|
};
|
|
158
159
|
processRules(rules);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
const configs = getFileConfigs(fileName);
|
|
161
|
+
for (const { plugins } of configs) {
|
|
162
|
+
for (const { resolveDiagnostics } of plugins) {
|
|
163
|
+
if (resolveDiagnostics) {
|
|
164
|
+
diagnostics = resolveDiagnostics(sourceFile.fileName, diagnostics);
|
|
165
|
+
}
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
const diagnosticSet = new Set(diagnostics);
|
|
@@ -200,6 +204,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
}
|
|
207
|
+
fixes.set(error, []);
|
|
203
208
|
diagnostics.push(error);
|
|
204
209
|
currentIssues++;
|
|
205
210
|
return {
|
|
@@ -213,9 +218,6 @@ function createLinter(ctx, config, withStack) {
|
|
|
213
218
|
},
|
|
214
219
|
withFix(title, getEdits) {
|
|
215
220
|
currentFixes++;
|
|
216
|
-
if (!fixes.has(error)) {
|
|
217
|
-
fixes.set(error, []);
|
|
218
|
-
}
|
|
219
221
|
fixes.get(error).push(({ title, getEdits }));
|
|
220
222
|
return this;
|
|
221
223
|
},
|
|
@@ -278,6 +280,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
278
280
|
return false;
|
|
279
281
|
},
|
|
280
282
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
283
|
+
const configs = getFileConfigs(fileName);
|
|
281
284
|
const fixesMap = getFileFixes(fileName);
|
|
282
285
|
const result = [];
|
|
283
286
|
for (const [diagnostic, actions] of fixesMap) {
|
|
@@ -300,9 +303,11 @@ function createLinter(ctx, config, withStack) {
|
|
|
300
303
|
fixAllDescription: 'Fix all TSSLint errors'
|
|
301
304
|
});
|
|
302
305
|
}
|
|
303
|
-
for (const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
+
for (const { plugins } of configs) {
|
|
307
|
+
for (const { resolveCodeFixes } of plugins) {
|
|
308
|
+
if (resolveCodeFixes) {
|
|
309
|
+
codeFixes = resolveCodeFixes(fileName, diagnostic, codeFixes);
|
|
310
|
+
}
|
|
306
311
|
}
|
|
307
312
|
}
|
|
308
313
|
result.push(...codeFixes);
|
|
@@ -342,29 +347,42 @@ function createLinter(ctx, config, withStack) {
|
|
|
342
347
|
},
|
|
343
348
|
};
|
|
344
349
|
function getFileRules(fileName) {
|
|
345
|
-
let
|
|
346
|
-
if (!
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
350
|
+
let result = fileRules.get(fileName);
|
|
351
|
+
if (!result) {
|
|
352
|
+
result = {};
|
|
353
|
+
const configs = getFileConfigs(fileName);
|
|
354
|
+
for (const { rules } of configs) {
|
|
355
|
+
result = {
|
|
356
|
+
...result,
|
|
357
|
+
...rules,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
for (const { plugins } of configs) {
|
|
361
|
+
for (const { resolveRules } of plugins) {
|
|
362
|
+
if (resolveRules) {
|
|
363
|
+
result = resolveRules(fileName, result);
|
|
364
|
+
}
|
|
351
365
|
}
|
|
366
|
+
}
|
|
367
|
+
fileRules.set(fileName, result);
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
function getFileConfigs(fileName) {
|
|
372
|
+
let result = fileConfigs.get(fileName);
|
|
373
|
+
if (!result) {
|
|
374
|
+
result = configs.filter(({ includes, excludes }) => {
|
|
352
375
|
if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
|
|
353
|
-
|
|
376
|
+
return false;
|
|
354
377
|
}
|
|
355
378
|
if (includes.length && !includes.some(pattern => minimatch.minimatch(fileName, pattern))) {
|
|
356
|
-
|
|
379
|
+
return false;
|
|
357
380
|
}
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (plugin.resolveRules) {
|
|
362
|
-
rules = plugin.resolveRules(fileName, rules);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
fileRules.set(fileName, rules);
|
|
381
|
+
return true;
|
|
382
|
+
});
|
|
383
|
+
fileConfigs.set(fileName, result);
|
|
366
384
|
}
|
|
367
|
-
return
|
|
385
|
+
return result;
|
|
368
386
|
}
|
|
369
387
|
function getFileFixes(fileName) {
|
|
370
388
|
if (!fileFixes.has(fileName)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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.2.
|
|
15
|
+
"@tsslint/types": "1.2.4",
|
|
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": "818bc257e90e431ca8988477862238c70a4757ff"
|
|
22
22
|
}
|