@tsslint/core 1.2.1 → 1.2.3
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 +46 -26
- 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);
|
|
@@ -278,6 +282,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
278
282
|
return false;
|
|
279
283
|
},
|
|
280
284
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
285
|
+
const configs = getFileConfigs(fileName);
|
|
281
286
|
const fixesMap = getFileFixes(fileName);
|
|
282
287
|
const result = [];
|
|
283
288
|
for (const [diagnostic, actions] of fixesMap) {
|
|
@@ -300,9 +305,11 @@ function createLinter(ctx, config, withStack) {
|
|
|
300
305
|
fixAllDescription: 'Fix all TSSLint errors'
|
|
301
306
|
});
|
|
302
307
|
}
|
|
303
|
-
for (const
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
for (const { plugins } of configs) {
|
|
309
|
+
for (const { resolveCodeFixes } of plugins) {
|
|
310
|
+
if (resolveCodeFixes) {
|
|
311
|
+
codeFixes = resolveCodeFixes(fileName, diagnostic, codeFixes);
|
|
312
|
+
}
|
|
306
313
|
}
|
|
307
314
|
}
|
|
308
315
|
result.push(...codeFixes);
|
|
@@ -342,29 +349,42 @@ function createLinter(ctx, config, withStack) {
|
|
|
342
349
|
},
|
|
343
350
|
};
|
|
344
351
|
function getFileRules(fileName) {
|
|
345
|
-
let
|
|
346
|
-
if (!
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
352
|
+
let result = fileRules.get(fileName);
|
|
353
|
+
if (!result) {
|
|
354
|
+
result = {};
|
|
355
|
+
const configs = getFileConfigs(fileName);
|
|
356
|
+
for (const { rules } of configs) {
|
|
357
|
+
result = {
|
|
358
|
+
...result,
|
|
359
|
+
...rules,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
for (const { plugins } of configs) {
|
|
363
|
+
for (const { resolveRules } of plugins) {
|
|
364
|
+
if (resolveRules) {
|
|
365
|
+
result = resolveRules(fileName, result);
|
|
366
|
+
}
|
|
351
367
|
}
|
|
368
|
+
}
|
|
369
|
+
fileRules.set(fileName, result);
|
|
370
|
+
}
|
|
371
|
+
return result;
|
|
372
|
+
}
|
|
373
|
+
function getFileConfigs(fileName) {
|
|
374
|
+
let result = fileConfigs.get(fileName);
|
|
375
|
+
if (!result) {
|
|
376
|
+
result = configs.filter(({ includes, excludes }) => {
|
|
352
377
|
if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
|
|
353
|
-
|
|
378
|
+
return false;
|
|
354
379
|
}
|
|
355
380
|
if (includes.length && !includes.some(pattern => minimatch.minimatch(fileName, pattern))) {
|
|
356
|
-
|
|
381
|
+
return false;
|
|
357
382
|
}
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (plugin.resolveRules) {
|
|
362
|
-
rules = plugin.resolveRules(fileName, rules);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
fileRules.set(fileName, rules);
|
|
383
|
+
return true;
|
|
384
|
+
});
|
|
385
|
+
fileConfigs.set(fileName, result);
|
|
366
386
|
}
|
|
367
|
-
return
|
|
387
|
+
return result;
|
|
368
388
|
}
|
|
369
389
|
function getFileFixes(fileName) {
|
|
370
390
|
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.3",
|
|
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.3",
|
|
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": "a7b3f988607c37d3e029ec17ff3cec0da5015ea8"
|
|
22
22
|
}
|