@tsslint/core 0.0.6 → 0.0.8
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 +3 -1
- package/index.js +45 -1
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Config, ProjectContext } from '@tsslint/config';
|
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary.js';
|
|
3
3
|
export type Linter = ReturnType<typeof createLinter>;
|
|
4
4
|
export declare function createLinter(ctx: ProjectContext, config: Config, withStack: boolean): {
|
|
5
|
-
lint(fileName: string): ts.
|
|
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) {
|
|
@@ -145,6 +145,8 @@ function createLinter(ctx, config, withStack) {
|
|
|
145
145
|
fixName: `tsslint: ${fix.title}`,
|
|
146
146
|
description: fix.title,
|
|
147
147
|
changes: fix.getEdits(),
|
|
148
|
+
fixId: 'tsslint',
|
|
149
|
+
fixAllDescription: 'Fix all TSSLint 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.8",
|
|
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.8"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "6fc30164bf7d50722f3fdb565f178b13821be692"
|
|
22
22
|
}
|