@tsslint/typescript-plugin 0.0.5 → 0.0.7
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 +44 -96
- 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,84 +28,47 @@ 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
|
-
let
|
|
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;
|
|
36
|
+
let result = getSyntacticDiagnostics(fileName);
|
|
37
|
+
if (info.languageServiceHost.getScriptFileNames().includes(fileName)) {
|
|
38
|
+
if (linter) {
|
|
39
|
+
result = result.concat(linter.lint(fileName));
|
|
69
40
|
}
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
41
|
+
if (config?.debug) {
|
|
42
|
+
result.push({
|
|
43
|
+
category: ts.DiagnosticCategory.Warning,
|
|
44
|
+
source: 'tsslint',
|
|
45
|
+
code: 'debug-info',
|
|
46
|
+
messageText: JSON.stringify({
|
|
47
|
+
rules: Object.keys(config?.rules ?? {}),
|
|
48
|
+
plugins: config.plugins?.length,
|
|
49
|
+
configFile,
|
|
50
|
+
tsconfig,
|
|
51
|
+
}, null, 2),
|
|
52
|
+
file: info.languageService.getProgram().getSourceFile(fileName),
|
|
53
|
+
start: 0,
|
|
54
|
+
length: 0,
|
|
55
|
+
});
|
|
78
56
|
}
|
|
79
57
|
}
|
|
80
|
-
|
|
81
|
-
errors.push({
|
|
82
|
-
category: ts.DiagnosticCategory.Warning,
|
|
83
|
-
source: 'tsslint',
|
|
84
|
-
code: 'debug-info',
|
|
85
|
-
messageText: JSON.stringify({
|
|
86
|
-
rules: Object.keys(config?.rules ?? {}),
|
|
87
|
-
plugins: plugins.length,
|
|
88
|
-
configFile,
|
|
89
|
-
tsconfig,
|
|
90
|
-
}, null, 2),
|
|
91
|
-
file: sourceFile,
|
|
92
|
-
start: 0,
|
|
93
|
-
length: 0,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return errors;
|
|
58
|
+
return result;
|
|
97
59
|
};
|
|
98
60
|
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;
|
|
61
|
+
return [
|
|
62
|
+
...getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences),
|
|
63
|
+
...linter?.getCodeFixes(fileName, start, end) ?? [],
|
|
64
|
+
];
|
|
108
65
|
};
|
|
109
66
|
return { update };
|
|
110
67
|
async function update(pluginConfig) {
|
|
111
68
|
let configOptionSpan = { start: 0, length: 0 };
|
|
112
69
|
let newConfigFile;
|
|
113
|
-
let configImportPath;
|
|
114
70
|
let configResolveError;
|
|
115
71
|
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
72
|
if (pluginConfig?.configFile) {
|
|
133
73
|
configOptionSpan = {
|
|
134
74
|
start: jsonConfigFile.text.indexOf(pluginConfig.configFile) - 1,
|
|
@@ -147,7 +87,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
147
87
|
if (newConfigFile !== configFile) {
|
|
148
88
|
configFile = newConfigFile;
|
|
149
89
|
config = undefined;
|
|
150
|
-
|
|
90
|
+
linter = undefined;
|
|
151
91
|
configFileBuildContext?.dispose();
|
|
152
92
|
configFileDiagnostics = [];
|
|
153
93
|
if (configResolveError) {
|
|
@@ -163,6 +103,22 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
163
103
|
if (!configFile) {
|
|
164
104
|
return;
|
|
165
105
|
}
|
|
106
|
+
let configImportPath;
|
|
107
|
+
try {
|
|
108
|
+
configImportPath = require.resolve('@tsslint/config', { paths: [configFile] });
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
configFileDiagnostics = [{
|
|
112
|
+
category: ts.DiagnosticCategory.Error,
|
|
113
|
+
code: 0,
|
|
114
|
+
messageText: String(err),
|
|
115
|
+
file: jsonConfigFile,
|
|
116
|
+
start: 0,
|
|
117
|
+
length: 0,
|
|
118
|
+
}];
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const { watchConfigFile } = require(configImportPath);
|
|
166
122
|
const projectContext = {
|
|
167
123
|
configFile,
|
|
168
124
|
tsconfig,
|
|
@@ -201,15 +157,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
201
157
|
return diag;
|
|
202
158
|
});
|
|
203
159
|
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
|
-
}
|
|
160
|
+
linter = (0, core_1.createLinter)(projectContext, config, true);
|
|
213
161
|
}
|
|
214
162
|
info.project.refreshDiagnostics();
|
|
215
163
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
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.7"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@tsslint/config": "0.0.
|
|
18
|
+
"@tsslint/config": "0.0.7"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "ed1086b1f11469e0a9d6a14199c7e027eb28b488"
|
|
21
21
|
}
|