@tsslint/typescript-plugin 2.0.6 → 3.0.0-alpha.0
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 +26 -109
- package/package.json +5 -6
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,7 +114,6 @@ 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;
|
|
@@ -128,74 +124,40 @@ function decorateLanguageService(ts, projectRoot, info) {
|
|
|
128
124
|
typescript: ts,
|
|
129
125
|
};
|
|
130
126
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
}
|
|
127
|
+
config = require(configFile).default ?? [];
|
|
128
|
+
if (config) {
|
|
129
|
+
try {
|
|
130
|
+
linter = core.createLinter(projectContext, path.dirname(configFile), config, (diag, err, stackOffset) => {
|
|
131
|
+
const relatedInfo = createRelatedInformation(ts, err, stackOffset);
|
|
132
|
+
if (relatedInfo) {
|
|
133
|
+
diag.relatedInformation.push(relatedInfo);
|
|
146
134
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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) {
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
config = undefined;
|
|
139
|
+
linter = undefined;
|
|
140
|
+
const prevLength = configFileDiagnostics.length;
|
|
141
|
+
if (err instanceof Error) {
|
|
142
|
+
const relatedInfo = createRelatedInformation(ts, err, 0);
|
|
143
|
+
if (relatedInfo) {
|
|
189
144
|
configFileDiagnostics.push({
|
|
190
145
|
category: ts.DiagnosticCategory.Message,
|
|
191
146
|
code: 0,
|
|
192
|
-
messageText:
|
|
147
|
+
messageText: err.message,
|
|
148
|
+
relatedInformation: [relatedInfo],
|
|
193
149
|
});
|
|
194
150
|
}
|
|
195
151
|
}
|
|
152
|
+
if (prevLength === configFileDiagnostics.length) {
|
|
153
|
+
configFileDiagnostics.push({
|
|
154
|
+
category: ts.DiagnosticCategory.Message,
|
|
155
|
+
code: 0,
|
|
156
|
+
messageText: String(err),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
196
159
|
}
|
|
197
|
-
|
|
198
|
-
}, true, ts.sys.createHash);
|
|
160
|
+
}
|
|
199
161
|
}
|
|
200
162
|
catch (err) {
|
|
201
163
|
configFileDiagnostics.push({
|
|
@@ -207,51 +169,6 @@ function decorateLanguageService(ts, projectRoot, info) {
|
|
|
207
169
|
}
|
|
208
170
|
}
|
|
209
171
|
}
|
|
210
|
-
function initSourceMapSupport() {
|
|
211
|
-
delete require.cache[require.resolve('source-map-support')];
|
|
212
|
-
require('source-map-support').install({
|
|
213
|
-
retrieveFile(pathOrUrl) {
|
|
214
|
-
if (pathOrUrl.includes('?tsslint_time=')) {
|
|
215
|
-
pathOrUrl = pathOrUrl.replace(/\?tsslint_time=\d*/, '');
|
|
216
|
-
if (pathOrUrl.includes('://')) {
|
|
217
|
-
pathOrUrl = url.fileURLToPath(pathOrUrl);
|
|
218
|
-
}
|
|
219
|
-
return fs.readFileSync(pathOrUrl, 'utf8');
|
|
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
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return contents;
|
|
249
|
-
}
|
|
250
|
-
catch { }
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
172
|
function createRelatedInformation(ts, err, stackOffset) {
|
|
256
173
|
const stacks = ErrorStackParser.parse(err);
|
|
257
174
|
if (stacks.length <= stackOffset) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
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.0",
|
|
16
|
+
"error-stack-parser": "^2.1.4"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
|
-
"@tsslint/config": "
|
|
19
|
+
"@tsslint/config": "3.0.0-alpha.0"
|
|
21
20
|
},
|
|
22
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "ec683ca05f4360fac720bd8c567f4d9460d255e1"
|
|
23
22
|
}
|