refactor(analysis): remove fixed result quotas
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user