@tsslint/typescript-plugin 0.0.3 → 0.0.5
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 +7 -7
- package/package.json +4 -5
- package/lib/builtInPlugins.d.ts +0 -3
- package/lib/builtInPlugins.js +0 -163
- 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) => {
|
|
@@ -70,8 +70,8 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
70
70
|
if (plugin.lint) {
|
|
71
71
|
let pluginResult = plugin.lint?.(sourceFile, config?.rules ?? {});
|
|
72
72
|
for (const plugin of plugins) {
|
|
73
|
-
if (plugin.
|
|
74
|
-
pluginResult = plugin.
|
|
73
|
+
if (plugin.resolveDiagnostics) {
|
|
74
|
+
pluginResult = plugin.resolveDiagnostics(pluginResult);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
errors = errors.concat(pluginResult);
|
|
@@ -102,7 +102,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
102
102
|
if (token?.isCancellationRequested()) {
|
|
103
103
|
break;
|
|
104
104
|
}
|
|
105
|
-
fixes = fixes.concat(plugin.getFixes?.(fileName, start, end
|
|
105
|
+
fixes = fixes.concat(plugin.getFixes?.(fileName, start, end) ?? []);
|
|
106
106
|
}
|
|
107
107
|
return fixes;
|
|
108
108
|
};
|
|
@@ -128,7 +128,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
128
128
|
}];
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
|
-
const {
|
|
131
|
+
const { watchConfigFile } = require(configImportPath);
|
|
132
132
|
if (pluginConfig?.configFile) {
|
|
133
133
|
configOptionSpan = {
|
|
134
134
|
start: jsonConfigFile.text.indexOf(pluginConfig.configFile) - 1,
|
|
@@ -142,7 +142,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
newConfigFile = findConfigFile(tsconfig);
|
|
145
|
+
newConfigFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
|
|
146
146
|
}
|
|
147
147
|
if (newConfigFile !== configFile) {
|
|
148
148
|
configFile = newConfigFile;
|
|
@@ -202,7 +202,7 @@ function decorateLanguageService(ts, tsconfig, info) {
|
|
|
202
202
|
});
|
|
203
203
|
if (config) {
|
|
204
204
|
plugins = await Promise.all([
|
|
205
|
-
...
|
|
205
|
+
...(0, core_1.getBuiltInPlugins)(true),
|
|
206
206
|
...config.plugins ?? []
|
|
207
207
|
].map(plugin => plugin(projectContext)));
|
|
208
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.5",
|
|
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.5"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@tsslint/config": "0.0.
|
|
18
|
+
"@tsslint/config": "0.0.5"
|
|
20
19
|
},
|
|
21
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "0522e03f552e0ac5bb27124ef923ff093ff02cdc"
|
|
22
21
|
}
|
package/lib/builtInPlugins.d.ts
DELETED
package/lib/builtInPlugins.js
DELETED
|
@@ -1,163 +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(fileName, start, end) {
|
|
135
|
-
const fixesMap = getFileFixes(fileName);
|
|
136
|
-
const result = [];
|
|
137
|
-
for (const [_errorCode, fixes] of fixesMap) {
|
|
138
|
-
for (let i = 0; i < fixes.length; i++) {
|
|
139
|
-
const fix = fixes[i];
|
|
140
|
-
if ((fix.start >= start && fix.start <= end) ||
|
|
141
|
-
(fix.end >= start && fix.end <= end) ||
|
|
142
|
-
(start >= fix.start && start <= fix.end) ||
|
|
143
|
-
(end >= fix.start && end <= fix.end)) {
|
|
144
|
-
result.push({
|
|
145
|
-
fixName: `tsslint: ${fix.title}`,
|
|
146
|
-
description: fix.title,
|
|
147
|
-
changes: fix.getEdits(),
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
function getFileFixes(fileName) {
|
|
156
|
-
if (!fileFixes.has(fileName)) {
|
|
157
|
-
fileFixes.set(fileName, new Map());
|
|
158
|
-
}
|
|
159
|
-
return fileFixes.get(fileName);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
];
|
|
163
|
-
//# 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
|