@tsslint/typescript-plugin 0.0.2 → 0.0.4
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 +13 -31
- package/package.json +4 -5
- package/lib/builtInPlugins.d.ts +0 -3
- package/lib/builtInPlugins.js +0 -178
- package/lib/watchConfig.d.ts +0 -4
- package/lib/watchConfig.js +0 -88
package/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
const
|
|
25
|
+
const core_1 = require("@tsslint/core");
|
|
26
26
|
const path = __importStar(require("path"));
|
|
27
27
|
const languageServiceDecorators = new WeakMap();
|
|
28
28
|
const init = (modules) => {
|
|
@@ -46,8 +46,7 @@ const init = (modules) => {
|
|
|
46
46
|
function decorateLanguageService(ts, tsconfig, info) {
|
|
47
47
|
const getCompilerOptionsDiagnostics = info.languageService.getCompilerOptionsDiagnostics;
|
|
48
48
|
const getSyntacticDiagnostics = info.languageService.getSyntacticDiagnostics;
|
|
49
|
-
const
|
|
50
|
-
const getEditsForRefactor = info.languageService.getEditsForRefactor;
|
|
49
|
+
const getCodeFixesAtPosition = info.languageService.getCodeFixesAtPosition;
|
|
51
50
|
let configFile;
|
|
52
51
|
let configFileBuildContext;
|
|
53
52
|
let configFileDiagnostics = [];
|
|
@@ -60,7 +59,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
60
59
|
let errors = getSyntacticDiagnostics(fileName);
|
|
61
60
|
errors = errors.concat(configFileDiagnostics);
|
|
62
61
|
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
63
|
-
if (!sourceFile) {
|
|
62
|
+
if (!sourceFile || sourceFile.text.length > 20000) {
|
|
64
63
|
return errors;
|
|
65
64
|
}
|
|
66
65
|
const token = info.languageServiceHost.getCancellationToken?.();
|
|
@@ -71,8 +70,8 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
71
70
|
if (plugin.lint) {
|
|
72
71
|
let pluginResult = plugin.lint?.(sourceFile, config?.rules ?? {});
|
|
73
72
|
for (const plugin of plugins) {
|
|
74
|
-
if (plugin.
|
|
75
|
-
pluginResult = plugin.
|
|
73
|
+
if (plugin.resolveDiagnostics) {
|
|
74
|
+
pluginResult = plugin.resolveDiagnostics(pluginResult);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
errors = errors.concat(pluginResult);
|
|
@@ -80,7 +79,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
80
79
|
}
|
|
81
80
|
if (config?.debug) {
|
|
82
81
|
errors.push({
|
|
83
|
-
category: ts.DiagnosticCategory.
|
|
82
|
+
category: ts.DiagnosticCategory.Warning,
|
|
84
83
|
source: 'tsslint',
|
|
85
84
|
code: 'debug-info',
|
|
86
85
|
messageText: JSON.stringify({
|
|
@@ -96,33 +95,16 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
96
95
|
}
|
|
97
96
|
return errors;
|
|
98
97
|
};
|
|
99
|
-
info.languageService.
|
|
100
|
-
let
|
|
101
|
-
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
102
|
-
if (!sourceFile) {
|
|
103
|
-
return refactors;
|
|
104
|
-
}
|
|
98
|
+
info.languageService.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
|
|
99
|
+
let fixes = getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences);
|
|
105
100
|
const token = info.languageServiceHost.getCancellationToken?.();
|
|
106
101
|
for (const plugin of plugins) {
|
|
107
102
|
if (token?.isCancellationRequested()) {
|
|
108
103
|
break;
|
|
109
104
|
}
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
return refactors;
|
|
113
|
-
};
|
|
114
|
-
info.languageService.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest) => {
|
|
115
|
-
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
116
|
-
if (!sourceFile) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
for (const plugin of plugins) {
|
|
120
|
-
const edits = plugin.fix?.(sourceFile, refactorName, actionName);
|
|
121
|
-
if (edits) {
|
|
122
|
-
return { edits };
|
|
123
|
-
}
|
|
105
|
+
fixes = fixes.concat(plugin.getFixes?.(fileName, start, end) ?? []);
|
|
124
106
|
}
|
|
125
|
-
return
|
|
107
|
+
return fixes;
|
|
126
108
|
};
|
|
127
109
|
return { update };
|
|
128
110
|
async function update(pluginConfig) {
|
|
@@ -146,7 +128,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
146
128
|
}];
|
|
147
129
|
return;
|
|
148
130
|
}
|
|
149
|
-
const {
|
|
131
|
+
const { watchConfigFile } = require(configImportPath);
|
|
150
132
|
if (pluginConfig?.configFile) {
|
|
151
133
|
configOptionSpan = {
|
|
152
134
|
start: jsonConfigFile.text.indexOf(pluginConfig.configFile) - 1,
|
|
@@ -160,7 +142,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
160
142
|
}
|
|
161
143
|
}
|
|
162
144
|
else {
|
|
163
|
-
newConfigFile = findConfigFile(tsconfig);
|
|
145
|
+
newConfigFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
|
|
164
146
|
}
|
|
165
147
|
if (newConfigFile !== configFile) {
|
|
166
148
|
configFile = newConfigFile;
|
|
@@ -220,7 +202,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
220
202
|
});
|
|
221
203
|
if (config) {
|
|
222
204
|
plugins = await Promise.all([
|
|
223
|
-
...
|
|
205
|
+
...(0, core_1.getBuiltInPlugins)(true),
|
|
224
206
|
...config.plugins ?? []
|
|
225
207
|
].map(plugin => plugin(projectContext)));
|
|
226
208
|
for (const plugin of plugins) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,11 +12,10 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"source-map-support": "^0.5.19"
|
|
15
|
+
"@tsslint/core": "0.0.4"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@tsslint/config": "0.0.
|
|
18
|
+
"@tsslint/config": "0.0.4"
|
|
20
19
|
},
|
|
21
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "7012413ccd5eb949f8bcc599daddc16b4c316b57"
|
|
22
21
|
}
|
package/lib/builtInPlugins.d.ts
DELETED
package/lib/builtInPlugins.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.builtInPlugins = void 0;
|
|
27
|
-
const ErrorStackParser = __importStar(require("error-stack-parser"));
|
|
28
|
-
require('source-map-support').install();
|
|
29
|
-
exports.builtInPlugins = [
|
|
30
|
-
ctx => {
|
|
31
|
-
const ts = ctx.typescript;
|
|
32
|
-
const fileFixes = new Map();
|
|
33
|
-
const sourceFiles = new Map();
|
|
34
|
-
const configSourceFile = ts.createSourceFile(ctx.configFile, ts.sys.readFile(ctx.configFile) ?? '', ts.ScriptTarget.Latest, true);
|
|
35
|
-
return {
|
|
36
|
-
lint(sourceFile, rules) {
|
|
37
|
-
const rulesContext = {
|
|
38
|
-
...ctx,
|
|
39
|
-
sourceFile,
|
|
40
|
-
reportError,
|
|
41
|
-
reportWarning,
|
|
42
|
-
reportSuggestion,
|
|
43
|
-
};
|
|
44
|
-
const token = ctx.languageServiceHost.getCancellationToken?.();
|
|
45
|
-
const result = [];
|
|
46
|
-
const fixes = getFileFixes(sourceFile.fileName);
|
|
47
|
-
fixes.clear();
|
|
48
|
-
let currentRuleId;
|
|
49
|
-
for (const [id, rule] of Object.entries(rules)) {
|
|
50
|
-
if (token?.isCancellationRequested()) {
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
currentRuleId = id;
|
|
54
|
-
rule(rulesContext);
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
function reportError(message, start, end, trace = true) {
|
|
58
|
-
return report(ts.DiagnosticCategory.Error, message, start, end, trace);
|
|
59
|
-
}
|
|
60
|
-
function reportWarning(message, start, end, trace = true) {
|
|
61
|
-
return report(ts.DiagnosticCategory.Warning, message, start, end, trace);
|
|
62
|
-
}
|
|
63
|
-
function reportSuggestion(message, start, end, trace = true) {
|
|
64
|
-
return report(ts.DiagnosticCategory.Suggestion, message, start, end, trace);
|
|
65
|
-
}
|
|
66
|
-
function report(category, message, start, end, trace) {
|
|
67
|
-
const error = {
|
|
68
|
-
category,
|
|
69
|
-
code: currentRuleId,
|
|
70
|
-
messageText: message,
|
|
71
|
-
file: sourceFile,
|
|
72
|
-
start,
|
|
73
|
-
length: end - start,
|
|
74
|
-
source: 'tsslint',
|
|
75
|
-
relatedInformation: [],
|
|
76
|
-
};
|
|
77
|
-
const stacks = trace ? ErrorStackParser.parse(new Error()) : [];
|
|
78
|
-
if (stacks.length >= 3) {
|
|
79
|
-
const stack = stacks[2];
|
|
80
|
-
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
81
|
-
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
82
|
-
if (fileName.startsWith('file://')) {
|
|
83
|
-
fileName = fileName.substring('file://'.length);
|
|
84
|
-
}
|
|
85
|
-
if (!sourceFiles.has(fileName)) {
|
|
86
|
-
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
87
|
-
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
88
|
-
}
|
|
89
|
-
const stackFile = sourceFiles.get(fileName);
|
|
90
|
-
const pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1);
|
|
91
|
-
error.relatedInformation?.push({
|
|
92
|
-
category: ts.DiagnosticCategory.Message,
|
|
93
|
-
code: 0,
|
|
94
|
-
file: stackFile,
|
|
95
|
-
start: pos,
|
|
96
|
-
length: 0,
|
|
97
|
-
messageText: 'Related rule file',
|
|
98
|
-
});
|
|
99
|
-
error.relatedInformation?.push({
|
|
100
|
-
category: ts.DiagnosticCategory.Message,
|
|
101
|
-
code: 0,
|
|
102
|
-
file: configSourceFile,
|
|
103
|
-
start: 0,
|
|
104
|
-
length: 0,
|
|
105
|
-
messageText: 'Related config file',
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
result.push(error);
|
|
110
|
-
return {
|
|
111
|
-
withDeprecated() {
|
|
112
|
-
error.reportsDeprecated = true;
|
|
113
|
-
return this;
|
|
114
|
-
},
|
|
115
|
-
withUnnecessary() {
|
|
116
|
-
error.reportsUnnecessary = true;
|
|
117
|
-
return this;
|
|
118
|
-
},
|
|
119
|
-
withFix(title, getEdits) {
|
|
120
|
-
if (!fixes.has(currentRuleId)) {
|
|
121
|
-
fixes.set(currentRuleId, []);
|
|
122
|
-
}
|
|
123
|
-
fixes.get(currentRuleId).push(({
|
|
124
|
-
title,
|
|
125
|
-
start,
|
|
126
|
-
end,
|
|
127
|
-
getEdits,
|
|
128
|
-
}));
|
|
129
|
-
return this;
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
getFixes(sourceFile, positionOrRange) {
|
|
135
|
-
const start = typeof positionOrRange === 'number' ? positionOrRange : positionOrRange.pos;
|
|
136
|
-
const end = typeof positionOrRange === 'number' ? positionOrRange : positionOrRange.end;
|
|
137
|
-
const fixes = getFileFixes(sourceFile.fileName);
|
|
138
|
-
const refactors = [];
|
|
139
|
-
for (const [errorCode, _fixes] of fixes) {
|
|
140
|
-
for (let i = 0; i < _fixes.length; i++) {
|
|
141
|
-
const fix = _fixes[i];
|
|
142
|
-
if ((start <= fix.start && end >= fix.end) ||
|
|
143
|
-
(start >= fix.start && start <= fix.end) ||
|
|
144
|
-
(end >= fix.start && end <= fix.end)) {
|
|
145
|
-
if (refactors[refactors.length - 1]?.name !== 'tsslint/fix') {
|
|
146
|
-
refactors.push({
|
|
147
|
-
name: 'tsslint/fix',
|
|
148
|
-
description: 'Fix ' + errorCode,
|
|
149
|
-
actions: [],
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
refactors[refactors.length - 1].actions.push({
|
|
153
|
-
name: errorCode + '-' + i,
|
|
154
|
-
description: fix.title,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return refactors;
|
|
160
|
-
},
|
|
161
|
-
fix(sourceFile, refactorName, actionName) {
|
|
162
|
-
if (refactorName === 'tsslint/fix') {
|
|
163
|
-
const errorCode = actionName.substring(0, actionName.lastIndexOf('-'));
|
|
164
|
-
const fixIndex = actionName.substring(actionName.lastIndexOf('-') + 1);
|
|
165
|
-
const fix = getFileFixes(sourceFile.fileName).get(errorCode)[Number(fixIndex)];
|
|
166
|
-
return fix.getEdits();
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
function getFileFixes(fileName) {
|
|
171
|
-
if (!fileFixes.has(fileName)) {
|
|
172
|
-
fileFixes.set(fileName, new Map());
|
|
173
|
-
}
|
|
174
|
-
return fileFixes.get(fileName);
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
];
|
|
178
|
-
//# sourceMappingURL=builtInPlugins.js.map
|
package/lib/watchConfig.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@tsslint/config';
|
|
2
|
-
import rollup = require('rollup');
|
|
3
|
-
export declare function watchConfig(tsConfigPath: string, onBuild: (config: Config | undefined, result: Error | undefined) => void): Promise<rollup.RollupBuild>;
|
|
4
|
-
//# sourceMappingURL=watchConfig.d.ts.map
|
package/lib/watchConfig.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.watchConfig = void 0;
|
|
4
|
-
const rollup = require("rollup");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
async function watchConfig(tsConfigPath, onBuild) {
|
|
7
|
-
const outDir = path.resolve(__dirname, '..', '..', '.tsslint');
|
|
8
|
-
const outFileName = btoa(path.relative(outDir, tsConfigPath)) + '.cjs';
|
|
9
|
-
const outFile = path.join(outDir, outFileName);
|
|
10
|
-
// const ctx = await esbuild.context({
|
|
11
|
-
// entryPoints: [tsConfigPath],
|
|
12
|
-
// bundle: true,
|
|
13
|
-
// sourcemap: true,
|
|
14
|
-
// outfile: outFile,
|
|
15
|
-
// format: 'cjs',
|
|
16
|
-
// platform: 'node',
|
|
17
|
-
// plugins: [{
|
|
18
|
-
// name: 'tsslint',
|
|
19
|
-
// setup(build) {
|
|
20
|
-
// build.onResolve({ filter: /.*/ }, args => {
|
|
21
|
-
// if (!args.path.endsWith('.ts')) {
|
|
22
|
-
// try {
|
|
23
|
-
// const jsPath = require.resolve(args.path, { paths: [args.resolveDir] });
|
|
24
|
-
// return {
|
|
25
|
-
// path: jsPath,
|
|
26
|
-
// external: true,
|
|
27
|
-
// };
|
|
28
|
-
// } catch { }
|
|
29
|
-
// }
|
|
30
|
-
// return {};
|
|
31
|
-
// });
|
|
32
|
-
// build.onEnd(result => {
|
|
33
|
-
// let config: Config | undefined;
|
|
34
|
-
// if (!result.errors.length) {
|
|
35
|
-
// try {
|
|
36
|
-
// config = require(outFile).default;
|
|
37
|
-
// delete require.cache[outFile!];
|
|
38
|
-
// } catch (e) {
|
|
39
|
-
// result.errors.push({ text: String(e) } as any);
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
// onBuild(config, result);
|
|
43
|
-
// });
|
|
44
|
-
// },
|
|
45
|
-
// }],
|
|
46
|
-
// });
|
|
47
|
-
const bundle = await rollup.rollup({
|
|
48
|
-
input: tsConfigPath,
|
|
49
|
-
output: {
|
|
50
|
-
file: outFile,
|
|
51
|
-
format: 'cjs',
|
|
52
|
-
sourcemap: true,
|
|
53
|
-
},
|
|
54
|
-
watch: {},
|
|
55
|
-
external: ['typescript'],
|
|
56
|
-
plugins: [{
|
|
57
|
-
name: 'tsslint',
|
|
58
|
-
resolveId(id, importer) {
|
|
59
|
-
if (!id.endsWith('.ts') && importer) {
|
|
60
|
-
try {
|
|
61
|
-
const jsPath = require.resolve(id, { paths: [path.dirname(importer)] });
|
|
62
|
-
return {
|
|
63
|
-
id: jsPath,
|
|
64
|
-
external: true,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
catch { }
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
buildEnd(error) {
|
|
71
|
-
let config;
|
|
72
|
-
if (!error) {
|
|
73
|
-
try {
|
|
74
|
-
config = require(outFile).default;
|
|
75
|
-
delete require.cache[outFile];
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
error = { message: String(e) };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
onBuild(config, error);
|
|
82
|
-
},
|
|
83
|
-
}],
|
|
84
|
-
});
|
|
85
|
-
return bundle;
|
|
86
|
-
}
|
|
87
|
-
exports.watchConfig = watchConfig;
|
|
88
|
-
//# sourceMappingURL=watchConfig.js.map
|