@tsslint/typescript-plugin 2.0.7 → 3.0.0-alpha.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.
- package/index.js +35 -130
- package/package.json +6 -7
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const core = require("@tsslint/core");
|
|
3
3
|
const path = require("path");
|
|
4
|
-
const url = require("url");
|
|
5
|
-
const fs = require("fs");
|
|
6
4
|
const ErrorStackParser = require("error-stack-parser");
|
|
7
5
|
const languageServiceDecorators = new WeakMap();
|
|
8
6
|
const plugin = modules => {
|
|
@@ -31,7 +29,6 @@ function decorateLanguageService(ts, projectRoot, info) {
|
|
|
31
29
|
const { getSemanticDiagnostics, getCodeFixesAtPosition, getCombinedCodeFix, getApplicableRefactors, getEditsForRefactor, } = info.languageService;
|
|
32
30
|
const projectFileNameKeys = new Set();
|
|
33
31
|
let configFile;
|
|
34
|
-
let configFileBuildContext;
|
|
35
32
|
let configFileDiagnostics = [];
|
|
36
33
|
let config;
|
|
37
34
|
let linter;
|
|
@@ -117,147 +114,55 @@ function decorateLanguageService(ts, projectRoot, info) {
|
|
|
117
114
|
configFile = newConfigFile;
|
|
118
115
|
config = undefined;
|
|
119
116
|
linter = undefined;
|
|
120
|
-
configFileBuildContext?.dispose();
|
|
121
117
|
configFileDiagnostics = [];
|
|
122
118
|
if (!configFile) {
|
|
123
119
|
return;
|
|
124
120
|
}
|
|
125
121
|
const projectContext = {
|
|
126
|
-
|
|
127
|
-
languageService: info.languageService,
|
|
122
|
+
...info,
|
|
128
123
|
typescript: ts,
|
|
129
124
|
};
|
|
130
125
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
messageText: error.text,
|
|
137
|
-
};
|
|
138
|
-
if (error.location) {
|
|
139
|
-
const fileName = path.resolve(error.location.file).replace('http-url:', '');
|
|
140
|
-
let relatedFile = info.languageService.getCurrentProgram()?.getSourceFile(fileName);
|
|
141
|
-
if (!relatedFile) {
|
|
142
|
-
const fileText = ts.sys.readFile(error.location.file);
|
|
143
|
-
if (fileText !== undefined) {
|
|
144
|
-
relatedFile = ts.createSourceFile(fileName, fileText, ts.ScriptTarget.Latest, true);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (relatedFile) {
|
|
148
|
-
diag.messageText = `Error building config file.`;
|
|
149
|
-
diag.relatedInformation = [{
|
|
150
|
-
category: ts.DiagnosticCategory.Message,
|
|
151
|
-
code: error.id,
|
|
152
|
-
messageText: error.text,
|
|
153
|
-
file: relatedFile,
|
|
154
|
-
start: relatedFile.getPositionOfLineAndCharacter(error.location.line - 1, error.location.column),
|
|
155
|
-
length: error.location.lineText.length,
|
|
156
|
-
}];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return diag;
|
|
160
|
-
});
|
|
161
|
-
if (builtConfig) {
|
|
162
|
-
try {
|
|
163
|
-
initSourceMapSupport();
|
|
164
|
-
const mtime = ts.sys.getModifiedTime?.(builtConfig)?.getTime() ?? Date.now();
|
|
165
|
-
config = (await import(url.pathToFileURL(builtConfig).toString() + '?tsslint_time=' + mtime)).default;
|
|
166
|
-
linter = core.createLinter(projectContext, path.dirname(configFile), config, (diag, err, stackOffset) => {
|
|
167
|
-
const relatedInfo = createRelatedInformation(ts, err, stackOffset);
|
|
168
|
-
if (relatedInfo) {
|
|
169
|
-
diag.relatedInformation.push(relatedInfo);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
catch (err) {
|
|
174
|
-
config = undefined;
|
|
175
|
-
linter = undefined;
|
|
176
|
-
const prevLength = configFileDiagnostics.length;
|
|
177
|
-
if (err instanceof Error) {
|
|
178
|
-
const relatedInfo = createRelatedInformation(ts, err, 0);
|
|
179
|
-
if (relatedInfo) {
|
|
180
|
-
configFileDiagnostics.push({
|
|
181
|
-
category: ts.DiagnosticCategory.Message,
|
|
182
|
-
code: 0,
|
|
183
|
-
messageText: err.message,
|
|
184
|
-
relatedInformation: [relatedInfo],
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (prevLength === configFileDiagnostics.length) {
|
|
189
|
-
configFileDiagnostics.push({
|
|
190
|
-
category: ts.DiagnosticCategory.Message,
|
|
191
|
-
code: 0,
|
|
192
|
-
messageText: String(err),
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
126
|
+
config = (await import(configFile)).default;
|
|
127
|
+
linter = core.createLinter(projectContext, path.dirname(configFile), config, (err, stackIndex) => {
|
|
128
|
+
const stacks = ErrorStackParser.parse(err);
|
|
129
|
+
if (stacks.length <= stackIndex) {
|
|
130
|
+
return [];
|
|
196
131
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
category: ts.DiagnosticCategory.Message,
|
|
203
|
-
code: 'config-build-error',
|
|
204
|
-
messageText: String(err),
|
|
132
|
+
const relatedInfo = createRelatedInformation(ts, stacks[stackIndex]);
|
|
133
|
+
if (relatedInfo) {
|
|
134
|
+
return [relatedInfo];
|
|
135
|
+
}
|
|
136
|
+
return [];
|
|
205
137
|
});
|
|
206
138
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
require('source-map-support').install({
|
|
224
|
-
retrieveFile(pathOrUrl) {
|
|
225
|
-
if (pathOrUrl.endsWith('.map')) {
|
|
226
|
-
try {
|
|
227
|
-
if (pathOrUrl.includes('://')) {
|
|
228
|
-
pathOrUrl = url.fileURLToPath(pathOrUrl);
|
|
229
|
-
}
|
|
230
|
-
const contents = fs.readFileSync(pathOrUrl, 'utf8');
|
|
231
|
-
const map = JSON.parse(contents);
|
|
232
|
-
for (let source of map.sources) {
|
|
233
|
-
if (!source.startsWith('./') && !source.startsWith('../')) {
|
|
234
|
-
source = './' + source;
|
|
235
|
-
}
|
|
236
|
-
source = path.resolve(path.dirname(pathOrUrl), source);
|
|
237
|
-
if (!fs.existsSync(source)) {
|
|
238
|
-
// Fixes https://github.com/typescript-eslint/typescript-eslint/issues/9352
|
|
239
|
-
return JSON.stringify({
|
|
240
|
-
version: 3,
|
|
241
|
-
sources: [],
|
|
242
|
-
sourcesContent: [],
|
|
243
|
-
mappings: '',
|
|
244
|
-
names: [],
|
|
245
|
-
});
|
|
246
|
-
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
config = undefined;
|
|
141
|
+
linter = undefined;
|
|
142
|
+
const prevLength = configFileDiagnostics.length;
|
|
143
|
+
if (err instanceof Error) {
|
|
144
|
+
const relatedInfo = createRelatedInformation(ts, ErrorStackParser.parse(err)[0]);
|
|
145
|
+
if (relatedInfo) {
|
|
146
|
+
configFileDiagnostics.push({
|
|
147
|
+
category: ts.DiagnosticCategory.Message,
|
|
148
|
+
code: 0,
|
|
149
|
+
messageText: err.message,
|
|
150
|
+
relatedInformation: [relatedInfo],
|
|
151
|
+
});
|
|
247
152
|
}
|
|
248
|
-
return contents;
|
|
249
153
|
}
|
|
250
|
-
|
|
154
|
+
if (prevLength === configFileDiagnostics.length) {
|
|
155
|
+
configFileDiagnostics.push({
|
|
156
|
+
category: ts.DiagnosticCategory.Message,
|
|
157
|
+
code: 0,
|
|
158
|
+
messageText: String(err),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
251
161
|
}
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
function createRelatedInformation(ts, err, stackOffset) {
|
|
256
|
-
const stacks = ErrorStackParser.parse(err);
|
|
257
|
-
if (stacks.length <= stackOffset) {
|
|
258
|
-
return;
|
|
162
|
+
}
|
|
259
163
|
}
|
|
260
|
-
|
|
164
|
+
}
|
|
165
|
+
function createRelatedInformation(ts, stack) {
|
|
261
166
|
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
262
167
|
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
263
168
|
if (fileName.startsWith('file://')) {
|
|
@@ -273,7 +178,7 @@ function createRelatedInformation(ts, err, stackOffset) {
|
|
|
273
178
|
fsFiles.set(fileName, [
|
|
274
179
|
text !== undefined,
|
|
275
180
|
mtime,
|
|
276
|
-
ts.createSourceFile(fileName, text ?? '', ts.ScriptTarget.Latest, true)
|
|
181
|
+
ts.createSourceFile(fileName, text ?? '', ts.ScriptTarget.Latest, true),
|
|
277
182
|
]);
|
|
278
183
|
}
|
|
279
184
|
const [exist, _mtime, relatedFile] = fsFiles.get(fileName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,12 +12,11 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/core": "
|
|
16
|
-
"error-stack-parser": "^2.1.4"
|
|
17
|
-
"source-map-support": "^0.5.21"
|
|
15
|
+
"@tsslint/core": "3.0.0-alpha.1",
|
|
16
|
+
"error-stack-parser": "^2.1.4"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
|
-
"@tsslint/config": "
|
|
19
|
+
"@tsslint/config": "3.0.0-alpha.1"
|
|
21
20
|
},
|
|
22
|
-
"gitHead": "
|
|
23
|
-
}
|
|
21
|
+
"gitHead": "eacd205927cda18d084e78cc21115578792f3955"
|
|
22
|
+
}
|