@tsslint/core 0.0.7 → 0.0.9
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 +2 -0
- package/index.js +47 -3
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare function createLinter(ctx: ProjectContext, config: Config, withSt
|
|
|
5
5
|
lint(fileName: string): ts.DiagnosticWithLocation[];
|
|
6
6
|
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[] | undefined): ts.CodeFixAction[];
|
|
7
7
|
};
|
|
8
|
+
export declare function combineCodeFixes(fileName: string, fixes: ts.CodeFixAction[]): ts.TextChange[];
|
|
9
|
+
export declare function applyTextChanges(baseSnapshot: ts.IScriptSnapshot, textChanges: ts.TextChange[]): ts.IScriptSnapshot;
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLinter = void 0;
|
|
3
|
+
exports.applyTextChanges = exports.combineCodeFixes = exports.createLinter = void 0;
|
|
4
4
|
const ErrorStackParser = require("error-stack-parser");
|
|
5
5
|
function createLinter(ctx, config, withStack) {
|
|
6
6
|
if (withStack) {
|
|
@@ -65,7 +65,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
65
65
|
file: sourceFile,
|
|
66
66
|
start,
|
|
67
67
|
length: end - start,
|
|
68
|
-
source: '
|
|
68
|
+
source: 'tsl',
|
|
69
69
|
relatedInformation: [],
|
|
70
70
|
};
|
|
71
71
|
const stacks = trace ? ErrorStackParser.parse(new Error()) : [];
|
|
@@ -142,9 +142,11 @@ function createLinter(ctx, config, withStack) {
|
|
|
142
142
|
(start >= fix.start && start <= fix.end) ||
|
|
143
143
|
(end >= fix.start && end <= fix.end)) {
|
|
144
144
|
result.push({
|
|
145
|
-
fixName: `
|
|
145
|
+
fixName: `tsl: ${fix.title}`,
|
|
146
146
|
description: fix.title,
|
|
147
147
|
changes: fix.getEdits(),
|
|
148
|
+
fixId: 'tsl',
|
|
149
|
+
fixAllDescription: 'Fix all TSL errors'
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
}
|
|
@@ -165,4 +167,46 @@ function createLinter(ctx, config, withStack) {
|
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
exports.createLinter = createLinter;
|
|
170
|
+
function combineCodeFixes(fileName, fixes) {
|
|
171
|
+
const changes = fixes
|
|
172
|
+
.map(fix => fix.changes)
|
|
173
|
+
.flat()
|
|
174
|
+
.filter(change => change.fileName === fileName && change.textChanges.length)
|
|
175
|
+
.sort((a, b) => b.textChanges[0].span.start - a.textChanges[0].span.start);
|
|
176
|
+
let lastChangeAt = Number.MAX_VALUE;
|
|
177
|
+
let finalTextChanges = [];
|
|
178
|
+
for (const change of changes) {
|
|
179
|
+
const textChanges = [...change.textChanges].sort((a, b) => a.span.start - b.span.start);
|
|
180
|
+
const firstChange = textChanges[0];
|
|
181
|
+
const lastChange = textChanges[textChanges.length - 1];
|
|
182
|
+
if (lastChangeAt >= lastChange.span.start + lastChange.span.length) {
|
|
183
|
+
lastChangeAt = firstChange.span.start;
|
|
184
|
+
finalTextChanges = finalTextChanges.concat(textChanges);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return finalTextChanges;
|
|
188
|
+
}
|
|
189
|
+
exports.combineCodeFixes = combineCodeFixes;
|
|
190
|
+
function applyTextChanges(baseSnapshot, textChanges) {
|
|
191
|
+
textChanges = [...textChanges].sort((a, b) => b.span.start - a.span.start);
|
|
192
|
+
let text = baseSnapshot.getText(0, baseSnapshot.getLength());
|
|
193
|
+
for (const change of textChanges) {
|
|
194
|
+
text = text.slice(0, change.span.start) + change.newText + text.slice(change.span.start + change.span.length);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
getText(start, end) {
|
|
198
|
+
return text.substring(start, end);
|
|
199
|
+
},
|
|
200
|
+
getLength() {
|
|
201
|
+
return text.length;
|
|
202
|
+
},
|
|
203
|
+
getChangeRange(oldSnapshot) {
|
|
204
|
+
if (oldSnapshot === baseSnapshot) {
|
|
205
|
+
// TODO
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
exports.applyTextChanges = applyTextChanges;
|
|
168
212
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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.9"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "ee84b80bac5dab5fad732e4265e2164c6a0724a6"
|
|
22
22
|
}
|