@tsslint/core 1.4.2 → 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.
- package/index.d.ts +5 -6
- package/index.js +30 -66
- 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
|
-
export declare function createLinter(ctx: ProjectContext, config: Config | Config[], mode: 'cli' | 'typescript-plugin'
|
|
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[
|
|
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[
|
|
20
|
-
getConfigs: (fileName: string, minimatchCache: undefined | FileLintCache[
|
|
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
|
@@ -24,9 +24,7 @@ const ErrorStackParser = require("error-stack-parser");
|
|
|
24
24
|
const path = require("path");
|
|
25
25
|
const minimatch = require("minimatch");
|
|
26
26
|
const typeAwareModeChange = new Error('enable type-aware mode');
|
|
27
|
-
function createLinter(ctx, config, mode
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
logger) {
|
|
27
|
+
function createLinter(ctx, config, mode) {
|
|
30
28
|
let languageServiceUsage = 0;
|
|
31
29
|
const ts = ctx.typescript;
|
|
32
30
|
const languageService = new Proxy(ctx.languageService, {
|
|
@@ -55,16 +53,14 @@ logger) {
|
|
|
55
53
|
const normalizedPath = new Map();
|
|
56
54
|
return {
|
|
57
55
|
lint(fileName, cache) {
|
|
58
|
-
let
|
|
59
|
-
let uncacheableDiagnostics = [];
|
|
56
|
+
let diagnostics = [];
|
|
60
57
|
let currentRuleId;
|
|
61
58
|
let currentIssues = 0;
|
|
62
59
|
let currentFixes = 0;
|
|
63
60
|
let currentRefactors = 0;
|
|
64
61
|
let currentRuleLanguageServiceUsage = 0;
|
|
65
62
|
let sourceFile;
|
|
66
|
-
|
|
67
|
-
const rules = getFileRules(fileName, cache?.[4]);
|
|
63
|
+
const rules = getFileRules(fileName, cache?.[3]);
|
|
68
64
|
const rulesContext = {
|
|
69
65
|
...ctx,
|
|
70
66
|
languageService,
|
|
@@ -78,66 +74,20 @@ logger) {
|
|
|
78
74
|
const token = ctx.languageServiceHost.getCancellationToken?.();
|
|
79
75
|
const fixes = getFileFixes(fileName);
|
|
80
76
|
const refactors = getFileRefactors(fileName);
|
|
81
|
-
const
|
|
82
|
-
if (cache) {
|
|
83
|
-
for (const ruleId in cache[1]) {
|
|
84
|
-
cachedRules.set(ruleId, cache[1][ruleId]);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
77
|
+
const configs = getFileConfigs(fileName, cache?.[3]);
|
|
87
78
|
fixes.clear();
|
|
88
79
|
refactors.length = 0;
|
|
89
80
|
if (!runRules(rules)) {
|
|
90
81
|
return this.lint(fileName, cache);
|
|
91
82
|
}
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
let diagnostics;
|
|
99
|
-
if (hasUncacheResult) {
|
|
100
|
-
diagnostics = [
|
|
101
|
-
...(cacheableDiagnostics.length
|
|
102
|
-
? cacheableDiagnostics
|
|
103
|
-
: (cache?.[2] ?? []).map(data => ({
|
|
104
|
-
...data,
|
|
105
|
-
file: rulesContext.sourceFile,
|
|
106
|
-
relatedInformation: data.relatedInformation?.map(info => ({
|
|
107
|
-
...info,
|
|
108
|
-
file: info.file ? getSourceFile(info.file.fileName) : undefined,
|
|
109
|
-
})),
|
|
110
|
-
}))),
|
|
111
|
-
...uncacheableDiagnostics,
|
|
112
|
-
];
|
|
113
|
-
for (const { plugins } of configs) {
|
|
114
|
-
for (const { resolveDiagnostics } of plugins) {
|
|
115
|
-
if (resolveDiagnostics) {
|
|
116
|
-
diagnostics = resolveDiagnostics(rulesContext.sourceFile, diagnostics);
|
|
117
|
-
}
|
|
83
|
+
for (const { plugins } of configs) {
|
|
84
|
+
for (const { resolveDiagnostics } of plugins) {
|
|
85
|
+
if (resolveDiagnostics) {
|
|
86
|
+
diagnostics = resolveDiagnostics(rulesContext.sourceFile, diagnostics);
|
|
118
87
|
}
|
|
119
88
|
}
|
|
120
|
-
if (cache) {
|
|
121
|
-
cache[3] = diagnostics.map(data => ({
|
|
122
|
-
...data,
|
|
123
|
-
file: undefined,
|
|
124
|
-
relatedInformation: data.relatedInformation?.map(info => ({
|
|
125
|
-
...info,
|
|
126
|
-
file: info.file ? { fileName: info.file.fileName } : undefined,
|
|
127
|
-
})),
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
diagnostics = (cache?.[3] ?? []).map(data => ({
|
|
133
|
-
...data,
|
|
134
|
-
file: rulesContext.sourceFile,
|
|
135
|
-
relatedInformation: data.relatedInformation?.map(info => ({
|
|
136
|
-
...info,
|
|
137
|
-
file: info.file ? getSourceFile(info.file.fileName) : undefined,
|
|
138
|
-
})),
|
|
139
|
-
}));
|
|
140
89
|
}
|
|
90
|
+
// Remove fixes and refactors that removed by resolveDiagnostics
|
|
141
91
|
const diagnosticSet = new Set(diagnostics);
|
|
142
92
|
for (const diagnostic of [...fixes.keys()]) {
|
|
143
93
|
if (!diagnosticSet.has(diagnostic)) {
|
|
@@ -162,10 +112,20 @@ logger) {
|
|
|
162
112
|
currentIssues = 0;
|
|
163
113
|
currentFixes = 0;
|
|
164
114
|
currentRefactors = 0;
|
|
165
|
-
if (
|
|
166
|
-
|
|
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
|
+
}
|
|
167
128
|
}
|
|
168
|
-
hasUncacheResult = true;
|
|
169
129
|
try {
|
|
170
130
|
rule(rulesContext);
|
|
171
131
|
}
|
|
@@ -181,8 +141,11 @@ logger) {
|
|
|
181
141
|
report(ts.DiagnosticCategory.Error, String(err), 0, 0, false);
|
|
182
142
|
}
|
|
183
143
|
}
|
|
184
|
-
if (cache
|
|
185
|
-
|
|
144
|
+
if (cache) {
|
|
145
|
+
if (currentRuleLanguageServiceUsage === languageServiceUsage) {
|
|
146
|
+
cache[1][currentRuleId] = currentFixes;
|
|
147
|
+
cache[2][currentRuleId] ??= [];
|
|
148
|
+
}
|
|
186
149
|
}
|
|
187
150
|
}
|
|
188
151
|
return true;
|
|
@@ -210,7 +173,8 @@ logger) {
|
|
|
210
173
|
};
|
|
211
174
|
const cacheable = currentRuleLanguageServiceUsage === languageServiceUsage;
|
|
212
175
|
if (cache && cacheable) {
|
|
213
|
-
cache[2]
|
|
176
|
+
cache[2][currentRuleId] ??= [];
|
|
177
|
+
cache[2][currentRuleId].push({
|
|
214
178
|
...error,
|
|
215
179
|
file: undefined,
|
|
216
180
|
relatedInformation: error.relatedInformation?.map(info => ({
|
|
@@ -227,7 +191,7 @@ logger) {
|
|
|
227
191
|
}
|
|
228
192
|
}
|
|
229
193
|
fixes.set(error, []);
|
|
230
|
-
|
|
194
|
+
diagnostics.push(error);
|
|
231
195
|
currentIssues++;
|
|
232
196
|
return {
|
|
233
197
|
withDeprecated() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.4.
|
|
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.
|
|
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": "
|
|
26
|
+
"gitHead": "7e4401c6734fd2b8d09d9aa45584e83e3ecf9e48"
|
|
27
27
|
}
|