fallow icon indicating copy to clipboard operation
fallow copied to clipboard

constant-parameter: follow a loader helper that returns an unknown-source load

Open BartWaardenburg opened this issue 3 weeks ago • 0 comments

Problem

The opt-in constant-parameter rule skips each exported function of the project when the value of an import() or require call with an unknown source escapes (reason opaque-module-load, from #4565). The most common escape is a loader helper that returns the loaded value:

// src/load.ts
export const load = async (path: string) => await import(path);

// src/run.ts
const mod = await load(name);
mod.migrate();

The rule cannot see that mod holds the loaded value, so the return counts as an escape, and the rule reports no exported function. On a corpus of 29 public projects, this fallback removes 45% of the correct findings in the default mode and 50% with --production. Loader helpers that return the value give a large part of this loss, for example in payload (utilities/dynamicImport.ts) and novu (esm-import.ts).

Proposal

  • Record a function whose return value is a value loaded from an unknown source.
  • At each call of that function, read the names on the result with the rules for a direct load (members, destructuring, in, .then).
  • Keep the escape when the function itself escapes, or when a call result escapes.

The same flow rule can cover mod.default ?? mod, a ternary, and a later assignment such as let mod; mod = await import(x).

Acceptance

  • The example above blocks only exported functions named migrate.
  • A measurement on the corpus reports the change in the fallback rate and in the correct findings that the rule keeps. No new false finding appears.

BartWaardenburg avatar Nov 13 '26 06:11 BartWaardenburg