@tsslint/typescript-plugin 0.0.5 → 0.0.6
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.d.ts +0 -1
- package/index.js +30 -84
- package/package.json +4 -4
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
const core_1 = require("@tsslint/core");
|
|
26
|
-
const path =
|
|
3
|
+
const path = require("path");
|
|
27
4
|
const languageServiceDecorators = new WeakMap();
|
|
28
5
|
const init = (modules) => {
|
|
29
6
|
const { typescript: ts } = modules;
|
|
@@ -51,32 +28,15 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
51
28
|
let configFileBuildContext;
|
|
52
29
|
let configFileDiagnostics = [];
|
|
53
30
|
let config;
|
|
54
|
-
let
|
|
31
|
+
let linter;
|
|
55
32
|
info.languageService.getCompilerOptionsDiagnostics = () => {
|
|
56
33
|
return getCompilerOptionsDiagnostics().concat(configFileDiagnostics);
|
|
57
34
|
};
|
|
58
35
|
info.languageService.getSyntacticDiagnostics = fileName => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return errors;
|
|
64
|
-
}
|
|
65
|
-
const token = info.languageServiceHost.getCancellationToken?.();
|
|
66
|
-
for (const plugin of plugins) {
|
|
67
|
-
if (token?.isCancellationRequested()) {
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
if (plugin.lint) {
|
|
71
|
-
let pluginResult = plugin.lint?.(sourceFile, config?.rules ?? {});
|
|
72
|
-
for (const plugin of plugins) {
|
|
73
|
-
if (plugin.resolveDiagnostics) {
|
|
74
|
-
pluginResult = plugin.resolveDiagnostics(pluginResult);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
errors = errors.concat(pluginResult);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
36
|
+
const errors = [
|
|
37
|
+
...getSyntacticDiagnostics(fileName),
|
|
38
|
+
...linter?.lint(fileName) ?? [],
|
|
39
|
+
];
|
|
80
40
|
if (config?.debug) {
|
|
81
41
|
errors.push({
|
|
82
42
|
category: ts.DiagnosticCategory.Warning,
|
|
@@ -84,11 +44,11 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
84
44
|
code: 'debug-info',
|
|
85
45
|
messageText: JSON.stringify({
|
|
86
46
|
rules: Object.keys(config?.rules ?? {}),
|
|
87
|
-
plugins: plugins
|
|
47
|
+
plugins: config.plugins?.length,
|
|
88
48
|
configFile,
|
|
89
49
|
tsconfig,
|
|
90
50
|
}, null, 2),
|
|
91
|
-
file:
|
|
51
|
+
file: info.languageService.getProgram()?.getSourceFile(fileName),
|
|
92
52
|
start: 0,
|
|
93
53
|
length: 0,
|
|
94
54
|
});
|
|
@@ -96,39 +56,17 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
96
56
|
return errors;
|
|
97
57
|
};
|
|
98
58
|
info.languageService.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
fixes = fixes.concat(plugin.getFixes?.(fileName, start, end) ?? []);
|
|
106
|
-
}
|
|
107
|
-
return fixes;
|
|
59
|
+
return [
|
|
60
|
+
...getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences),
|
|
61
|
+
...linter?.getCodeFixes(fileName, start, end) ?? [],
|
|
62
|
+
];
|
|
108
63
|
};
|
|
109
64
|
return { update };
|
|
110
65
|
async function update(pluginConfig) {
|
|
111
66
|
let configOptionSpan = { start: 0, length: 0 };
|
|
112
67
|
let newConfigFile;
|
|
113
|
-
let configImportPath;
|
|
114
68
|
let configResolveError;
|
|
115
69
|
const jsonConfigFile = ts.readJsonConfigFile(tsconfig, ts.sys.readFile);
|
|
116
|
-
try {
|
|
117
|
-
configImportPath = require.resolve('@tsslint/config', { paths: [path.dirname(tsconfig)] });
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
configResolveError = err;
|
|
121
|
-
configFileDiagnostics = [{
|
|
122
|
-
category: ts.DiagnosticCategory.Error,
|
|
123
|
-
code: 0,
|
|
124
|
-
messageText: String(err),
|
|
125
|
-
file: jsonConfigFile,
|
|
126
|
-
start: 0,
|
|
127
|
-
length: 0,
|
|
128
|
-
}];
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const { watchConfigFile } = require(configImportPath);
|
|
132
70
|
if (pluginConfig?.configFile) {
|
|
133
71
|
configOptionSpan = {
|
|
134
72
|
start: jsonConfigFile.text.indexOf(pluginConfig.configFile) - 1,
|
|
@@ -147,7 +85,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
147
85
|
if (newConfigFile !== configFile) {
|
|
148
86
|
configFile = newConfigFile;
|
|
149
87
|
config = undefined;
|
|
150
|
-
|
|
88
|
+
linter = undefined;
|
|
151
89
|
configFileBuildContext?.dispose();
|
|
152
90
|
configFileDiagnostics = [];
|
|
153
91
|
if (configResolveError) {
|
|
@@ -163,6 +101,22 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
163
101
|
if (!configFile) {
|
|
164
102
|
return;
|
|
165
103
|
}
|
|
104
|
+
let configImportPath;
|
|
105
|
+
try {
|
|
106
|
+
configImportPath = require.resolve('@tsslint/config', { paths: [configFile] });
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
configFileDiagnostics = [{
|
|
110
|
+
category: ts.DiagnosticCategory.Error,
|
|
111
|
+
code: 0,
|
|
112
|
+
messageText: String(err),
|
|
113
|
+
file: jsonConfigFile,
|
|
114
|
+
start: 0,
|
|
115
|
+
length: 0,
|
|
116
|
+
}];
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { watchConfigFile } = require(configImportPath);
|
|
166
120
|
const projectContext = {
|
|
167
121
|
configFile,
|
|
168
122
|
tsconfig,
|
|
@@ -201,15 +155,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
201
155
|
return diag;
|
|
202
156
|
});
|
|
203
157
|
if (config) {
|
|
204
|
-
|
|
205
|
-
...(0, core_1.getBuiltInPlugins)(true),
|
|
206
|
-
...config.plugins ?? []
|
|
207
|
-
].map(plugin => plugin(projectContext)));
|
|
208
|
-
for (const plugin of plugins) {
|
|
209
|
-
if (plugin.resolveRules) {
|
|
210
|
-
config.rules = plugin.resolveRules(config.rules ?? {});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
158
|
+
linter = (0, core_1.createLinter)(projectContext, config, true);
|
|
213
159
|
}
|
|
214
160
|
info.project.refreshDiagnostics();
|
|
215
161
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/core": "0.0.
|
|
15
|
+
"@tsslint/core": "0.0.6"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@tsslint/config": "0.0.
|
|
18
|
+
"@tsslint/config": "0.0.6"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "a9a381f7c5e84819c99b70f6b429150ce766739c"
|
|
21
21
|
}
|