@tsslint/core 1.0.12 → 1.0.13
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 +64 -3
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare function createLinter(ctx: ProjectContext, config: Config, withSt
|
|
|
5
5
|
lint(fileName: string): ts.DiagnosticWithLocation[];
|
|
6
6
|
hasCodeFixes(fileName: string): boolean;
|
|
7
7
|
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]): ts.CodeFixAction[];
|
|
8
|
+
getRefactors(fileName: string, start: number, end: number): ts.RefactorActionInfo[];
|
|
9
|
+
getRefactorEdits(fileName: string, name: string): ts.FileTextChanges[] | undefined;
|
|
8
10
|
};
|
|
9
11
|
export declare function combineCodeFixes(fileName: string, fixes: ts.CodeFixAction[]): ts.TextChange[];
|
|
10
12
|
export declare function applyTextChanges(baseSnapshot: ts.IScriptSnapshot, textChanges: ts.TextChange[]): ts.IScriptSnapshot;
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
24
24
|
const ts = ctx.typescript;
|
|
25
25
|
const fileRules = new Map();
|
|
26
26
|
const fileFixes = new Map();
|
|
27
|
+
const fileRefactors = new Map();
|
|
27
28
|
const sourceFiles = new Map();
|
|
28
29
|
const plugins = (config.plugins ?? []).map(plugin => plugin(ctx));
|
|
29
30
|
const excludes = [];
|
|
@@ -50,9 +51,11 @@ function createLinter(ctx, config, withStack) {
|
|
|
50
51
|
const token = ctx.languageServiceHost.getCancellationToken?.();
|
|
51
52
|
const rules = getFileRules(sourceFile.fileName);
|
|
52
53
|
const fixes = getFileFixes(sourceFile.fileName);
|
|
54
|
+
const refactors = getFileRefactors(sourceFile.fileName);
|
|
53
55
|
let diagnostics = [];
|
|
54
56
|
let currentRuleId;
|
|
55
57
|
fixes.clear();
|
|
58
|
+
refactors.clear();
|
|
56
59
|
for (const [id, rule] of Object.entries(rules)) {
|
|
57
60
|
if (token?.isCancellationRequested()) {
|
|
58
61
|
break;
|
|
@@ -73,14 +76,23 @@ function createLinter(ctx, config, withStack) {
|
|
|
73
76
|
}
|
|
74
77
|
const diagnosticSet = new Set(diagnostics);
|
|
75
78
|
for (const [ruleId, fix] of [...fixes]) {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
fixes.set(ruleId,
|
|
79
|
+
const final = fix.filter(fix => diagnosticSet.has(fix.diagnostic));
|
|
80
|
+
if (final.length) {
|
|
81
|
+
fixes.set(ruleId, final);
|
|
79
82
|
}
|
|
80
83
|
else {
|
|
81
84
|
fixes.delete(ruleId);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
87
|
+
for (const [ruleId, refactor] of [...refactors]) {
|
|
88
|
+
const final = refactor.filter(fix => diagnosticSet.has(fix.diagnostic));
|
|
89
|
+
if (final.length) {
|
|
90
|
+
refactors.set(ruleId, final);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
refactors.delete(ruleId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
84
96
|
return diagnostics;
|
|
85
97
|
function reportError(message, start, end, traceOffset = 0) {
|
|
86
98
|
return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
|
|
@@ -136,6 +148,19 @@ function createLinter(ctx, config, withStack) {
|
|
|
136
148
|
}));
|
|
137
149
|
return this;
|
|
138
150
|
},
|
|
151
|
+
withRefactor(title, getEdits) {
|
|
152
|
+
if (!refactors.has(currentRuleId)) {
|
|
153
|
+
refactors.set(currentRuleId, []);
|
|
154
|
+
}
|
|
155
|
+
refactors.get(currentRuleId).push(({
|
|
156
|
+
diagnostic: error,
|
|
157
|
+
title,
|
|
158
|
+
start,
|
|
159
|
+
end,
|
|
160
|
+
getEdits,
|
|
161
|
+
}));
|
|
162
|
+
return this;
|
|
163
|
+
},
|
|
139
164
|
};
|
|
140
165
|
}
|
|
141
166
|
function pushRelatedInformation(error, stack) {
|
|
@@ -207,6 +232,36 @@ function createLinter(ctx, config, withStack) {
|
|
|
207
232
|
}
|
|
208
233
|
return result;
|
|
209
234
|
},
|
|
235
|
+
getRefactors(fileName, start, end) {
|
|
236
|
+
const refactorsMap = getFileRefactors(fileName);
|
|
237
|
+
let result = [];
|
|
238
|
+
for (const [ruleId, refactors] of refactorsMap) {
|
|
239
|
+
for (let i = 0; i < refactors.length; i++) {
|
|
240
|
+
const refactor = refactors[i];
|
|
241
|
+
if ((refactor.start >= start && refactor.start <= end) ||
|
|
242
|
+
(refactor.end >= start && refactor.end <= end) ||
|
|
243
|
+
(start >= refactor.start && start <= refactor.end) ||
|
|
244
|
+
(end >= refactor.start && end <= refactor.end)) {
|
|
245
|
+
result.push({
|
|
246
|
+
name: `tsslint:${ruleId}:${i}`,
|
|
247
|
+
description: refactor.title + ' (' + ruleId + ')',
|
|
248
|
+
kind: 'quickfix',
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
},
|
|
255
|
+
getRefactorEdits(fileName, name) {
|
|
256
|
+
if (name.startsWith('tsslint:')) {
|
|
257
|
+
const [ruleId, index] = name.slice('tsslint:'.length).split(':');
|
|
258
|
+
const refactorsMap = getFileRefactors(fileName);
|
|
259
|
+
const refactor = refactorsMap.get(ruleId)?.[Number(index)];
|
|
260
|
+
if (refactor) {
|
|
261
|
+
return refactor.getEdits();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
210
265
|
};
|
|
211
266
|
function getFileRules(fileName) {
|
|
212
267
|
let rules = fileRules.get(fileName);
|
|
@@ -227,6 +282,12 @@ function createLinter(ctx, config, withStack) {
|
|
|
227
282
|
}
|
|
228
283
|
return fileFixes.get(fileName);
|
|
229
284
|
}
|
|
285
|
+
function getFileRefactors(fileName) {
|
|
286
|
+
if (!fileRefactors.has(fileName)) {
|
|
287
|
+
fileRefactors.set(fileName, new Map());
|
|
288
|
+
}
|
|
289
|
+
return fileRefactors.get(fileName);
|
|
290
|
+
}
|
|
230
291
|
}
|
|
231
292
|
exports.createLinter = createLinter;
|
|
232
293
|
function combineCodeFixes(fileName, fixes) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"source-map-support": "^0.5.21"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@tsslint/config": "1.0.
|
|
20
|
+
"@tsslint/config": "1.0.13"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "47f0f4bdbb68d8343c2967d46bd4b7bf9fb00e7e"
|
|
23
23
|
}
|