Skip to content

Commit e05416f

Browse files
fix: add withoutCache API to Reporter (#75)
1 parent 4dfdc27 commit e05416f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/core/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,19 @@ export function createLinter(
215215
},
216216
};
217217
let location: [Error, number] = [new Error(), 1];
218+
let cachedObj: ts.DiagnosticWithLocation | undefined;
218219

219220
if (cache && !rule2Mode.get(currentRuleId)) {
220-
cache[1][currentRuleId] ??= [false, []];
221-
cache[1][currentRuleId][1].push({
221+
cachedObj = {
222222
...error,
223223
file: undefined as any,
224224
relatedInformation: error.relatedInformation?.map(info => ({
225225
...info,
226226
file: info.file ? { fileName: info.file.fileName } as any : undefined,
227227
})),
228-
});
228+
};
229+
cache[1][currentRuleId] ??= [false, []];
230+
cache[1][currentRuleId][1].push(cachedObj);
229231
}
230232

231233
let lintResult = lintResults.get(fileName);
@@ -274,6 +276,18 @@ export function createLinter(
274276
}));
275277
return this;
276278
},
279+
withoutCache() {
280+
if (cachedObj) {
281+
const ruleCache = cache?.[1][currentRuleId];
282+
if (ruleCache) {
283+
const index = ruleCache[1].indexOf(cachedObj);
284+
if (index >= 0) {
285+
ruleCache[1].splice(index, 1);
286+
}
287+
}
288+
}
289+
return this;
290+
},
277291
};
278292
}
279293
},

packages/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ export interface Reporter {
5656
withUnnecessary(): Reporter;
5757
withFix(title: string, getChanges: () => FileTextChanges[]): Reporter;
5858
withRefactor(title: string, getChanges: () => FileTextChanges[]): Reporter;
59+
withoutCache(): Reporter;
5960
}

0 commit comments

Comments
 (0)