@tsslint/core 1.0.10 → 1.0.12

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.
Files changed (2) hide show
  1. package/index.js +29 -10
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -22,6 +22,7 @@ function createLinter(ctx, config, withStack) {
22
22
  });
23
23
  }
24
24
  const ts = ctx.typescript;
25
+ const fileRules = new Map();
25
26
  const fileFixes = new Map();
26
27
  const sourceFiles = new Map();
27
28
  const plugins = (config.plugins ?? []).map(plugin => plugin(ctx));
@@ -30,12 +31,6 @@ function createLinter(ctx, config, withStack) {
30
31
  const basePath = path.dirname(ctx.configFile);
31
32
  excludes.push(path.resolve(basePath, exclude));
32
33
  }
33
- let rules = { ...config.rules };
34
- for (const plugin of plugins) {
35
- if (plugin.resolveRules) {
36
- rules = plugin.resolveRules(rules);
37
- }
38
- }
39
34
  return {
40
35
  lint(fileName) {
41
36
  if (excludes.some(pattern => minimatch.minimatch(fileName, pattern))) {
@@ -53,8 +48,9 @@ function createLinter(ctx, config, withStack) {
53
48
  reportSuggestion,
54
49
  };
55
50
  const token = ctx.languageServiceHost.getCancellationToken?.();
51
+ const rules = getFileRules(sourceFile.fileName);
56
52
  const fixes = getFileFixes(sourceFile.fileName);
57
- let result = [];
53
+ let diagnostics = [];
58
54
  let currentRuleId;
59
55
  fixes.clear();
60
56
  for (const [id, rule] of Object.entries(rules)) {
@@ -72,10 +68,20 @@ function createLinter(ctx, config, withStack) {
72
68
  }
73
69
  for (const plugin of plugins) {
74
70
  if (plugin.resolveDiagnostics) {
75
- result = plugin.resolveDiagnostics(sourceFile.fileName, result);
71
+ diagnostics = plugin.resolveDiagnostics(sourceFile.fileName, diagnostics);
76
72
  }
77
73
  }
78
- return result;
74
+ const diagnosticSet = new Set(diagnostics);
75
+ for (const [ruleId, fix] of [...fixes]) {
76
+ const finalFixes = fix.filter(fix => diagnosticSet.has(fix.diagnostic));
77
+ if (finalFixes.length) {
78
+ fixes.set(ruleId, finalFixes);
79
+ }
80
+ else {
81
+ fixes.delete(ruleId);
82
+ }
83
+ }
84
+ return diagnostics;
79
85
  function reportError(message, start, end, traceOffset = 0) {
80
86
  return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
81
87
  }
@@ -107,7 +113,7 @@ function createLinter(ctx, config, withStack) {
107
113
  }
108
114
  }
109
115
  }
110
- result.push(error);
116
+ diagnostics.push(error);
111
117
  return {
112
118
  withDeprecated() {
113
119
  error.reportsDeprecated = true;
@@ -202,6 +208,19 @@ function createLinter(ctx, config, withStack) {
202
208
  return result;
203
209
  },
204
210
  };
211
+ function getFileRules(fileName) {
212
+ let rules = fileRules.get(fileName);
213
+ if (!rules) {
214
+ rules = { ...config.rules };
215
+ for (const plugin of plugins) {
216
+ if (plugin.resolveRules) {
217
+ rules = plugin.resolveRules(fileName, rules);
218
+ }
219
+ }
220
+ fileRules.set(fileName, rules);
221
+ }
222
+ return rules;
223
+ }
205
224
  function getFileFixes(fileName) {
206
225
  if (!fileFixes.has(fileName)) {
207
226
  fileFixes.set(fileName, new Map());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -17,7 +17,7 @@
17
17
  "source-map-support": "^0.5.21"
18
18
  },
19
19
  "devDependencies": {
20
- "@tsslint/config": "1.0.10"
20
+ "@tsslint/config": "1.0.12"
21
21
  },
22
- "gitHead": "075fc3bf0058d41b4131345ab3634ad059562223"
22
+ "gitHead": "b34fbb2c8408616eb00536f00e525cb4fc8d8913"
23
23
  }