Skip to content

Commit 3fec9fe

Browse files
Clear expect rule program cache when heap is almost exhausted (#1024)
* Clear expect rule program cache when heap is almost exhausted * Update packages/eslint-plugin/src/rules/expect.ts Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> * Clear expect rule program cache when heap is almost exhausted --------- Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent 8e449ea commit 3fec9fe

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

.changeset/three-vans-fetch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@definitelytyped/eslint-plugin": patch
3+
---
4+
5+
Clear expect rule program cache when heap is almost exhausted

packages/eslint-plugin/src/rules/expect.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { createRule, findTypesPackage, findUp } from "../util";
21
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
3-
import type * as ts from "typescript";
4-
import path from "path";
5-
import fs from "fs";
62
import { ReportDescriptorMessageData } from "@typescript-eslint/utils/ts-eslint";
3+
import fs from "fs";
4+
import v8 from "node:v8";
5+
import path from "path";
76
import * as semver from "semver";
7+
import type * as ts from "typescript";
8+
import { createRule, findTypesPackage, findUp } from "../util";
89

910
type TSModule = typeof ts;
1011

@@ -198,6 +199,13 @@ function getProgram(
198199
newProgram = createProgram(path.resolve(dirPath, configFile), ts);
199200
versionToProgram.set(cacheKey, newProgram);
200201
}
202+
203+
const heapStats = v8.getHeapStatistics();
204+
const heapUsage = heapStats.used_heap_size / heapStats.heap_size_limit;
205+
if (heapUsage > 0.9) {
206+
versionToProgram.clear();
207+
}
208+
201209
return newProgram;
202210
}
203211

pnpm-lock.yaml

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)