Skip to content

Commit

Permalink
Clear expect rule program cache when heap is almost exhausted (#1024)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
andrewbranch and jakebailey committed Jun 28, 2024
1 parent 8e449ea commit 3fec9fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-vans-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@definitelytyped/eslint-plugin": patch
---

Clear expect rule program cache when heap is almost exhausted
16 changes: 12 additions & 4 deletions packages/eslint-plugin/src/rules/expect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createRule, findTypesPackage, findUp } from "../util";
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
import type * as ts from "typescript";
import path from "path";
import fs from "fs";
import { ReportDescriptorMessageData } from "@typescript-eslint/utils/ts-eslint";
import fs from "fs";
import v8 from "node:v8";
import path from "path";
import * as semver from "semver";
import type * as ts from "typescript";
import { createRule, findTypesPackage, findUp } from "../util";

type TSModule = typeof ts;

Expand Down Expand Up @@ -198,6 +199,13 @@ function getProgram(
newProgram = createProgram(path.resolve(dirPath, configFile), ts);
versionToProgram.set(cacheKey, newProgram);
}

const heapStats = v8.getHeapStatistics();
const heapUsage = heapStats.used_heap_size / heapStats.heap_size_limit;
if (heapUsage > 0.9) {
versionToProgram.clear();
}

return newProgram;
}

Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fec9fe

Please sign in to comment.