refactor(analysis): remove fixed result quotas

This commit is contained in:
morluto
2026-09-29 13:57:24 +08:00
parent 0e2738ffb6
commit 20152a9872
105 changed files with 605 additions and 1084 deletions
+3 -25
View File
@@ -6,17 +6,16 @@ import type {
LocatedJavaScriptFindingInput,
} from "./javascriptStaticAnalysisState.js";
/** Add one module-attributable finding under the shared global finding bound. */
/** Add one module-attributable finding once per source location. */
export const addLocatedFinding = <
Value extends { readonly module_key: string | null },
>(
context: JavaScriptFindingContext,
input: LocatedJavaScriptFindingInput<Value>,
): void =>
addBoundedFinding(
addFindingOnce(
context.accumulator,
`${input.key}\0${String(input.node.start)}`,
context.maximum,
() =>
input.collection.push({
offset: input.node.start ?? -1,
@@ -25,17 +24,12 @@ export const addLocatedFinding = <
);
/** Reserve one deterministic finding key before mutating an accumulator. */
export const addBoundedFinding = (
export const addFindingOnce = (
accumulator: JavaScriptAnalysisAccumulator,
key: string,
maximum: number,
add: () => void,
): void => {
if (accumulator.seen.has(key)) return;
if (accumulatedFindingCount(accumulator) >= maximum) {
accumulator.droppedFindings += 1;
return;
}
accumulator.seen.add(key);
add();
};
@@ -60,19 +54,3 @@ export const moduleAtOffset = (
if (offset === null || offset === undefined) return undefined;
return modules.find(({ start, end }) => offset >= start && offset <= end);
};
const accumulatedFindingCount = (
accumulator: JavaScriptAnalysisAccumulator,
): number =>
accumulator.references.length +
accumulator.endpoints.length +
accumulator.storage.length +
accumulator.roles.length +
accumulator.sourceMaps.length +
accumulator.registrations.length +
accumulator.browserWindows.length +
accumulator.contextBridgeApis.length +
accumulator.ipc.length +
accumulator.senderValidations.length +
accumulator.utilityProcesses.length +
accumulator.nativeAddonBindings.length;