@tsslint/core 2.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/index.js +35 -20
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -41,36 +41,43 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
41
41
  lint(fileName, cache) {
42
42
  let currentRuleId;
43
43
  let shouldRetry = false;
44
+ let rulesContext;
44
45
  const rules = getRulesForFile(fileName, cache?.[2]);
45
46
  const typeAwareMode = !getNonBoundSourceFile
46
47
  || shouldEnableTypeAware && !Object.keys(rules).some(ruleId => !rule2Mode.has(ruleId));
47
- const rulesContext = typeAwareMode
48
- ? {
48
+ const token = ctx.languageServiceHost.getCancellationToken?.();
49
+ const configs = getConfigsForFile(fileName, cache?.[2]);
50
+ if (typeAwareMode) {
51
+ const program = ctx.languageService.getProgram();
52
+ const file = ctx.languageService.getProgram().getSourceFile(fileName);
53
+ rulesContext = {
49
54
  ...ctx,
50
- sourceFile: ctx.languageService.getProgram().getSourceFile(fileName),
51
- get program() {
52
- return ctx.languageService.getProgram();
53
- },
55
+ file,
56
+ sourceFile: file,
57
+ program,
54
58
  report,
55
59
  reportError: report,
56
60
  reportWarning: report,
57
61
  reportSuggestion: report,
58
- }
59
- : {
62
+ };
63
+ }
64
+ else {
65
+ const file = getNonBoundSourceFile(fileName);
66
+ rulesContext = {
60
67
  ...ctx,
61
68
  languageService: syntaxOnlyLanguageService,
62
69
  get program() {
63
70
  throw new Error('Not supported');
64
71
  },
65
- sourceFile: getNonBoundSourceFile(fileName),
72
+ file,
73
+ sourceFile: file,
66
74
  report,
67
75
  reportError: report,
68
76
  reportWarning: report,
69
77
  reportSuggestion: report,
70
78
  };
71
- const token = ctx.languageServiceHost.getCancellationToken?.();
72
- const configs = getConfigsForFile(fileName, cache?.[2]);
73
- lintResults.set(fileName, [rulesContext.sourceFile, new Map(), []]);
79
+ }
80
+ lintResults.set(fileName, [rulesContext.file, new Map(), []]);
74
81
  const lintResult = lintResults.get(fileName);
75
82
  for (const [ruleId, rule] of Object.entries(rules)) {
76
83
  if (token?.isCancellationRequested()) {
@@ -81,15 +88,15 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
81
88
  if (ruleCache) {
82
89
  let lintResult = lintResults.get(fileName);
83
90
  if (!lintResult) {
84
- lintResults.set(fileName, lintResult = [rulesContext.sourceFile, new Map(), []]);
91
+ lintResults.set(fileName, lintResult = [rulesContext.file, new Map(), []]);
85
92
  }
86
93
  for (const cacheDiagnostic of ruleCache[1]) {
87
94
  lintResult[1].set({
88
95
  ...cacheDiagnostic,
89
- file: rulesContext.sourceFile,
96
+ file: rulesContext.file,
90
97
  relatedInformation: cacheDiagnostic.relatedInformation?.map(info => ({
91
98
  ...info,
92
- file: info.file ? syntaxOnlyLanguageService.getNonBoundSourceFile(info.file.fileName) : undefined,
99
+ file: info.file ? getNonBoundSourceFile?.(info.file.fileName) : undefined,
93
100
  })),
94
101
  }, []);
95
102
  }
@@ -130,6 +137,10 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
130
137
  if (shouldRetry) {
131
138
  // Retry
132
139
  shouldEnableTypeAware = true;
140
+ if (cache && Object.values(cache[1]).some(([hasFix]) => hasFix)) {
141
+ cache[1] = {};
142
+ cache[2] = {};
143
+ }
133
144
  return this.lint(fileName, cache);
134
145
  }
135
146
  let diagnostics = [...lintResult[1].keys()];
@@ -137,7 +148,7 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
137
148
  for (const { plugins } of configs) {
138
149
  for (const { resolveDiagnostics } of plugins) {
139
150
  if (resolveDiagnostics) {
140
- diagnostics = resolveDiagnostics(rulesContext.sourceFile, diagnostics);
151
+ diagnostics = resolveDiagnostics(rulesContext.file, diagnostics);
141
152
  }
142
153
  }
143
154
  }
@@ -146,6 +157,10 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
146
157
  if (!typeAwareMode) {
147
158
  // Retry
148
159
  shouldEnableTypeAware = true;
160
+ if (cache && Object.values(cache[1]).some(([hasFix]) => hasFix)) {
161
+ cache[1] = {};
162
+ cache[2] = {};
163
+ }
149
164
  return this.lint(fileName, cache);
150
165
  }
151
166
  throw error;
@@ -164,7 +179,7 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
164
179
  category: ts.DiagnosticCategory.Message,
165
180
  code: currentRuleId,
166
181
  messageText: message,
167
- file: rulesContext.sourceFile,
182
+ file: rulesContext.file,
168
183
  start,
169
184
  length: end - start,
170
185
  source: 'tsslint',
@@ -184,7 +199,7 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
184
199
  handleError(error, err ?? new Error(), stackOffset);
185
200
  let lintResult = lintResults.get(fileName);
186
201
  if (!lintResult) {
187
- lintResults.set(fileName, lintResult = [rulesContext.sourceFile, new Map(), []]);
202
+ lintResults.set(fileName, lintResult = [rulesContext.file, new Map(), []]);
188
203
  }
189
204
  const diagnostic2Fixes = lintResult[1];
190
205
  const refactors = lintResult[2];
@@ -231,7 +246,7 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
231
246
  if (!lintResult) {
232
247
  return [];
233
248
  }
234
- const sourceFile = lintResult[0];
249
+ const file = lintResult[0];
235
250
  const configs = getConfigsForFile(fileName, minimatchCache);
236
251
  const result = [];
237
252
  for (const [diagnostic, actions] of lintResult[1]) {
@@ -257,7 +272,7 @@ function createLinter(ctx, rootDir, config, handleError, syntaxOnlyLanguageServi
257
272
  for (const { plugins } of configs) {
258
273
  for (const { resolveCodeFixes } of plugins) {
259
274
  if (resolveCodeFixes) {
260
- codeFixes = resolveCodeFixes(sourceFile, diagnostic, codeFixes);
275
+ codeFixes = resolveCodeFixes(file, diagnostic, codeFixes);
261
276
  }
262
277
  }
263
278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "dependencies": {
15
- "@tsslint/types": "2.0.0",
15
+ "@tsslint/types": "2.0.1",
16
16
  "esbuild": ">=0.17.0",
17
17
  "minimatch": "^10.0.1"
18
18
  },
@@ -22,5 +22,5 @@
22
22
  "scripts": {
23
23
  "postinstall": "node scripts/cleanCache.js"
24
24
  },
25
- "gitHead": "ae93f5a423f55be0af23e4b088bf589dbc215ef6"
25
+ "gitHead": "175c1f2840d38e50f8042542feb317acc7049f91"
26
26
  }