@tsslint/typescript-plugin 0.0.2 → 0.0.3
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 -25
- package/lib/builtInPlugins.js +12 -27
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -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?.();
|
|
@@ -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, errorCodes) ?? []);
|
|
124
106
|
}
|
|
125
|
-
return
|
|
107
|
+
return fixes;
|
|
126
108
|
};
|
|
127
109
|
return { update };
|
|
128
110
|
async function update(pluginConfig) {
|
package/lib/builtInPlugins.js
CHANGED
|
@@ -131,40 +131,25 @@ exports.builtInPlugins = [
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
|
-
getFixes(
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const fixes
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if ((start <= fix.start && end >= fix.end) ||
|
|
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) ||
|
|
143
142
|
(start >= fix.start && start <= fix.end) ||
|
|
144
143
|
(end >= fix.start && end <= fix.end)) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
name: 'tsslint/fix',
|
|
148
|
-
description: 'Fix ' + errorCode,
|
|
149
|
-
actions: [],
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
refactors[refactors.length - 1].actions.push({
|
|
153
|
-
name: errorCode + '-' + i,
|
|
144
|
+
result.push({
|
|
145
|
+
fixName: `tsslint: ${fix.title}`,
|
|
154
146
|
description: fix.title,
|
|
147
|
+
changes: fix.getEdits(),
|
|
155
148
|
});
|
|
156
149
|
}
|
|
157
150
|
}
|
|
158
151
|
}
|
|
159
|
-
return
|
|
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
|
-
}
|
|
152
|
+
return result;
|
|
168
153
|
},
|
|
169
154
|
};
|
|
170
155
|
function getFileFixes(fileName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"source-map-support": "^0.5.19"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@tsslint/config": "0.0.
|
|
19
|
+
"@tsslint/config": "0.0.3"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "13557d614907865f38ad32fd3582c9f198fb9ffa"
|
|
22
22
|
}
|