@tsslint/core 1.4.3 → 1.4.4

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 +4 -5
  2. package/index.js +29 -63
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -5,19 +5,18 @@ import type * as ts from 'typescript';
5
5
  export type FileLintCache = [
6
6
  mtime: number,
7
7
  ruleFixes: Record<string, number>,
8
- result: ts.DiagnosticWithLocation[],
9
- resolvedResult: ts.DiagnosticWithLocation[],
8
+ result: Record<string, ts.DiagnosticWithLocation[]>,
10
9
  minimatchResult: Record<string, boolean>
11
10
  ];
12
11
  export type Linter = ReturnType<typeof createLinter>;
13
12
  export declare function createLinter(ctx: ProjectContext, config: Config | Config[], mode: 'cli' | 'typescript-plugin'): {
14
13
  lint(fileName: string, cache?: FileLintCache): ts.DiagnosticWithLocation[];
15
14
  hasCodeFixes(fileName: string): boolean;
16
- getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[], minimatchCache?: FileLintCache[4]): ts.CodeFixAction[];
15
+ getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[], minimatchCache?: FileLintCache[3]): ts.CodeFixAction[];
17
16
  getRefactors(fileName: string, start: number, end: number): ts.RefactorActionInfo[];
18
17
  getRefactorEdits(fileName: string, actionName: string): ts.FileTextChanges[] | undefined;
19
- getRules: (fileName: string, minimatchCache: undefined | FileLintCache[4]) => Rules;
20
- getConfigs: (fileName: string, minimatchCache: undefined | FileLintCache[4]) => {
18
+ getRules: (fileName: string, minimatchCache: undefined | FileLintCache[3]) => Rules;
19
+ getConfigs: (fileName: string, minimatchCache: undefined | FileLintCache[3]) => {
21
20
  include: string[];
22
21
  exclude: string[];
23
22
  rules: Rules;
package/index.js CHANGED
@@ -53,16 +53,14 @@ function createLinter(ctx, config, mode) {
53
53
  const normalizedPath = new Map();
54
54
  return {
55
55
  lint(fileName, cache) {
56
- let cacheableDiagnostics = [];
57
- let uncacheableDiagnostics = [];
56
+ let diagnostics = [];
58
57
  let currentRuleId;
59
58
  let currentIssues = 0;
60
59
  let currentFixes = 0;
61
60
  let currentRefactors = 0;
62
61
  let currentRuleLanguageServiceUsage = 0;
63
62
  let sourceFile;
64
- let hasUncacheResult = false;
65
- const rules = getFileRules(fileName, cache?.[4]);
63
+ const rules = getFileRules(fileName, cache?.[3]);
66
64
  const rulesContext = {
67
65
  ...ctx,
68
66
  languageService,
@@ -76,66 +74,20 @@ function createLinter(ctx, config, mode) {
76
74
  const token = ctx.languageServiceHost.getCancellationToken?.();
77
75
  const fixes = getFileFixes(fileName);
78
76
  const refactors = getFileRefactors(fileName);
79
- const cachedRules = new Map();
80
- if (cache) {
81
- for (const ruleId in cache[1]) {
82
- cachedRules.set(ruleId, cache[1][ruleId]);
83
- }
84
- }
77
+ const configs = getFileConfigs(fileName, cache?.[3]);
85
78
  fixes.clear();
86
79
  refactors.length = 0;
87
80
  if (!runRules(rules)) {
88
81
  return this.lint(fileName, cache);
89
82
  }
90
- const configs = getFileConfigs(fileName, cache?.[4]);
91
- if (cache) {
92
- for (const [ruleId, fixes] of cachedRules) {
93
- cache[1][ruleId] = fixes;
94
- }
95
- }
96
- let diagnostics;
97
- if (hasUncacheResult) {
98
- diagnostics = [
99
- ...(cacheableDiagnostics.length
100
- ? cacheableDiagnostics
101
- : (cache?.[2] ?? []).map(data => ({
102
- ...data,
103
- file: rulesContext.sourceFile,
104
- relatedInformation: data.relatedInformation?.map(info => ({
105
- ...info,
106
- file: info.file ? getSourceFile(info.file.fileName) : undefined,
107
- })),
108
- }))),
109
- ...uncacheableDiagnostics,
110
- ];
111
- for (const { plugins } of configs) {
112
- for (const { resolveDiagnostics } of plugins) {
113
- if (resolveDiagnostics) {
114
- diagnostics = resolveDiagnostics(rulesContext.sourceFile, diagnostics);
115
- }
83
+ for (const { plugins } of configs) {
84
+ for (const { resolveDiagnostics } of plugins) {
85
+ if (resolveDiagnostics) {
86
+ diagnostics = resolveDiagnostics(rulesContext.sourceFile, diagnostics);
116
87
  }
117
88
  }
118
- if (cache) {
119
- cache[3] = diagnostics.map(data => ({
120
- ...data,
121
- file: undefined,
122
- relatedInformation: data.relatedInformation?.map(info => ({
123
- ...info,
124
- file: info.file ? { fileName: info.file.fileName } : undefined,
125
- })),
126
- }));
127
- }
128
- }
129
- else {
130
- diagnostics = (cache?.[3] ?? []).map(data => ({
131
- ...data,
132
- file: rulesContext.sourceFile,
133
- relatedInformation: data.relatedInformation?.map(info => ({
134
- ...info,
135
- file: info.file ? getSourceFile(info.file.fileName) : undefined,
136
- })),
137
- }));
138
89
  }
90
+ // Remove fixes and refactors that removed by resolveDiagnostics
139
91
  const diagnosticSet = new Set(diagnostics);
140
92
  for (const diagnostic of [...fixes.keys()]) {
141
93
  if (!diagnosticSet.has(diagnostic)) {
@@ -160,10 +112,20 @@ function createLinter(ctx, config, mode) {
160
112
  currentIssues = 0;
161
113
  currentFixes = 0;
162
114
  currentRefactors = 0;
163
- if (cachedRules.has(currentRuleId)) {
164
- continue;
115
+ if (cache) {
116
+ const ruleCache = cache[2][currentRuleId];
117
+ if (ruleCache) {
118
+ diagnostics.push(...ruleCache.map(data => ({
119
+ ...data,
120
+ file: rulesContext.sourceFile,
121
+ relatedInformation: data.relatedInformation?.map(info => ({
122
+ ...info,
123
+ file: info.file ? getSourceFile(info.file.fileName) : undefined,
124
+ })),
125
+ })));
126
+ continue;
127
+ }
165
128
  }
166
- hasUncacheResult = true;
167
129
  try {
168
130
  rule(rulesContext);
169
131
  }
@@ -179,8 +141,11 @@ function createLinter(ctx, config, mode) {
179
141
  report(ts.DiagnosticCategory.Error, String(err), 0, 0, false);
180
142
  }
181
143
  }
182
- if (cache && currentRuleLanguageServiceUsage === languageServiceUsage) {
183
- cachedRules.set(currentRuleId, currentFixes);
144
+ if (cache) {
145
+ if (currentRuleLanguageServiceUsage === languageServiceUsage) {
146
+ cache[1][currentRuleId] = currentFixes;
147
+ cache[2][currentRuleId] ??= [];
148
+ }
184
149
  }
185
150
  }
186
151
  return true;
@@ -208,7 +173,8 @@ function createLinter(ctx, config, mode) {
208
173
  };
209
174
  const cacheable = currentRuleLanguageServiceUsage === languageServiceUsage;
210
175
  if (cache && cacheable) {
211
- cache[2].push({
176
+ cache[2][currentRuleId] ??= [];
177
+ cache[2][currentRuleId].push({
212
178
  ...error,
213
179
  file: undefined,
214
180
  relatedInformation: error.relatedInformation?.map(info => ({
@@ -225,7 +191,7 @@ function createLinter(ctx, config, mode) {
225
191
  }
226
192
  }
227
193
  fixes.set(error, []);
228
- (cacheable ? cacheableDiagnostics : uncacheableDiagnostics).push(error);
194
+ diagnostics.push(error);
229
195
  currentIssues++;
230
196
  return {
231
197
  withDeprecated() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/core",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "dependencies": {
15
- "@tsslint/types": "1.4.3",
15
+ "@tsslint/types": "1.4.4",
16
16
  "error-stack-parser": "^2.1.4",
17
17
  "esbuild": ">=0.17.0",
18
18
  "minimatch": "^10.0.1"
@@ -23,5 +23,5 @@
23
23
  "scripts": {
24
24
  "postinstall": "node scripts/cleanCache.js"
25
25
  },
26
- "gitHead": "7cdb4a39c0af8ee4cebd430bb546c6b6e2ddc28b"
26
+ "gitHead": "7e4401c6734fd2b8d09d9aa45584e83e3ecf9e48"
27
27
  }