@tsslint/core 1.2.0 → 1.2.2

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.
Files changed (3) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +31 -54
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare function createLinter(ctx: ProjectContext, config: Config | Confi
8
8
  hasCodeFixes(fileName: string): boolean;
9
9
  getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]): ts.CodeFixAction[];
10
10
  getRefactors(fileName: string, start: number, end: number): ts.RefactorActionInfo[];
11
- getRefactorEdits(fileName: string, name: string): ts.FileTextChanges[] | undefined;
11
+ getRefactorEdits(fileName: string, actionName: string): ts.FileTextChanges[] | undefined;
12
12
  };
13
13
  export declare function combineCodeFixes(fileName: string, fixes: ts.CodeFixAction[]): ts.TextChange[];
14
14
  export declare function applyTextChanges(baseSnapshot: ts.IScriptSnapshot, textChanges: ts.TextChange[]): ts.IScriptSnapshot;
package/index.js CHANGED
@@ -105,7 +105,7 @@ function createLinter(ctx, config, withStack) {
105
105
  let currentFixes = 0;
106
106
  let currentRefactors = 0;
107
107
  fixes.clear();
108
- refactors.clear();
108
+ refactors.length = 0;
109
109
  if (debugInfo) {
110
110
  debugInfo.messageText += '- Rules:\n';
111
111
  }
@@ -162,22 +162,12 @@ function createLinter(ctx, config, withStack) {
162
162
  }
163
163
  }
164
164
  const diagnosticSet = new Set(diagnostics);
165
- for (const [ruleId, { diagnostic, actions }] of [...fixes]) {
166
- if (actions.length && diagnosticSet.has(diagnostic)) {
167
- fixes.set(ruleId, { diagnostic, actions });
168
- }
169
- else {
170
- fixes.delete(ruleId);
171
- }
172
- }
173
- for (const [ruleId, { diagnostic, actions }] of [...refactors]) {
174
- if (actions.length && diagnosticSet.has(diagnostic)) {
175
- fixes.set(ruleId, { diagnostic, actions });
176
- }
177
- else {
178
- refactors.delete(ruleId);
165
+ for (const diagnostic of [...fixes.keys()]) {
166
+ if (!diagnosticSet.has(diagnostic)) {
167
+ fixes.delete(diagnostic);
179
168
  }
180
169
  }
170
+ fileRefactors.set(fileName, refactors.filter(refactor => diagnosticSet.has(refactor.diagnostic)));
181
171
  return diagnostics;
182
172
  function reportError(message, start, end, traceOffset = 0) {
183
173
  return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
@@ -223,27 +213,16 @@ function createLinter(ctx, config, withStack) {
223
213
  },
224
214
  withFix(title, getEdits) {
225
215
  currentFixes++;
226
- if (!fixes.has(currentRuleId)) {
227
- fixes.set(currentRuleId, {
228
- diagnostic: error,
229
- actions: [],
230
- });
216
+ if (!fixes.has(error)) {
217
+ fixes.set(error, []);
231
218
  }
232
- fixes.get(currentRuleId).actions.push(({
233
- title,
234
- getEdits,
235
- }));
219
+ fixes.get(error).push(({ title, getEdits }));
236
220
  return this;
237
221
  },
238
222
  withRefactor(title, getEdits) {
239
223
  currentRefactors++;
240
- if (!refactors.has(currentRuleId)) {
241
- refactors.set(currentRuleId, {
242
- diagnostic: error,
243
- actions: [],
244
- });
245
- }
246
- refactors.get(currentRuleId).actions.push(({
224
+ refactors.push(({
225
+ diagnostic: error,
247
226
  title,
248
227
  getEdits,
249
228
  }));
@@ -291,7 +270,7 @@ function createLinter(ctx, config, withStack) {
291
270
  },
292
271
  hasCodeFixes(fileName) {
293
272
  const fixesMap = getFileFixes(fileName);
294
- for (const [_ruleId, { actions }] of fixesMap) {
273
+ for (const [_diagnostic, actions] of fixesMap) {
295
274
  if (actions.length) {
296
275
  return true;
297
276
  }
@@ -301,7 +280,7 @@ function createLinter(ctx, config, withStack) {
301
280
  getCodeFixes(fileName, start, end, diagnostics) {
302
281
  const fixesMap = getFileFixes(fileName);
303
282
  const result = [];
304
- for (const [ruleId, { diagnostic, actions }] of fixesMap) {
283
+ for (const [diagnostic, actions] of fixesMap) {
305
284
  if (diagnostics?.length && !diagnostics.includes(diagnostic)) {
306
285
  continue;
307
286
  }
@@ -314,7 +293,7 @@ function createLinter(ctx, config, withStack) {
314
293
  let codeFixes = [];
315
294
  for (const action of actions) {
316
295
  codeFixes.push({
317
- fixName: `tsslint:${ruleId}`,
296
+ fixName: `tsslint:${diagnostic.code}`,
318
297
  description: action.title,
319
298
  changes: action.getEdits(),
320
299
  fixId: 'tsslint',
@@ -323,7 +302,7 @@ function createLinter(ctx, config, withStack) {
323
302
  }
324
303
  for (const plugin of plugins) {
325
304
  if (plugin.resolveCodeFixes) {
326
- codeFixes = plugin.resolveCodeFixes(fileName, diagnostic, result);
305
+ codeFixes = plugin.resolveCodeFixes(fileName, diagnostic, codeFixes);
327
306
  }
328
307
  }
329
308
  result.push(...codeFixes);
@@ -332,32 +311,30 @@ function createLinter(ctx, config, withStack) {
332
311
  return result;
333
312
  },
334
313
  getRefactors(fileName, start, end) {
335
- const refactorsMap = getFileRefactors(fileName);
336
- let result = [];
337
- for (const [ruleId, { diagnostic, actions }] of refactorsMap) {
338
- const diagStart = diagnostic.start;
339
- const diagEnd = diagStart + diagnostic.length;
314
+ const refactors = getFileRefactors(fileName);
315
+ const result = [];
316
+ for (let i = 0; i < refactors.length; i++) {
317
+ const refactor = refactors[i];
318
+ const diagStart = refactor.diagnostic.start;
319
+ const diagEnd = diagStart + refactor.diagnostic.length;
340
320
  if ((diagStart >= start && diagStart <= end) ||
341
321
  (diagEnd >= start && diagEnd <= end) ||
342
322
  (start >= diagStart && start <= diagEnd) ||
343
323
  (end >= diagStart && end <= diagEnd)) {
344
- for (let i = 0; i < actions.length; i++) {
345
- const action = actions[i];
346
- result.push({
347
- name: `tsslint:${ruleId}:${i}`,
348
- description: action.title + ' (' + ruleId + ')',
349
- kind: 'quickfix',
350
- });
351
- }
324
+ result.push({
325
+ name: `tsslint:${i}`,
326
+ description: refactor.title,
327
+ kind: 'quickfix',
328
+ });
352
329
  }
353
330
  }
354
331
  return result;
355
332
  },
356
- getRefactorEdits(fileName, name) {
357
- if (name.startsWith('tsslint:')) {
358
- const [ruleId, index] = name.slice('tsslint:'.length).split(':');
359
- const refactorsMap = getFileRefactors(fileName);
360
- const refactor = refactorsMap.get(ruleId)?.actions[Number(index)];
333
+ getRefactorEdits(fileName, actionName) {
334
+ if (actionName.startsWith('tsslint:')) {
335
+ const index = actionName.slice('tsslint:'.length);
336
+ const actions = getFileRefactors(fileName);
337
+ const refactor = actions[Number(index)];
361
338
  if (refactor) {
362
339
  return refactor.getEdits();
363
340
  }
@@ -397,7 +374,7 @@ function createLinter(ctx, config, withStack) {
397
374
  }
398
375
  function getFileRefactors(fileName) {
399
376
  if (!fileRefactors.has(fileName)) {
400
- fileRefactors.set(fileName, new Map());
377
+ fileRefactors.set(fileName, []);
401
378
  }
402
379
  return fileRefactors.get(fileName);
403
380
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,11 +12,11 @@
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "dependencies": {
15
- "@tsslint/types": "1.2.0",
15
+ "@tsslint/types": "1.2.2",
16
16
  "error-stack-parser": "^2.1.4",
17
17
  "esbuild": ">=0.17.0",
18
18
  "minimatch": "^10.0.1",
19
19
  "source-map-support": "^0.5.21"
20
20
  },
21
- "gitHead": "3752318ba6ca2eb953a566b1d0c1b80f2125befd"
21
+ "gitHead": "1cc6be27db1a1532fee17dea34a5f169c0e82329"
22
22
  }