fallow icon indicating copy to clipboard operation
fallow copied to clipboard

constant-parameter: a dynamic import with a variable source blocks no function

Open BartWaardenburg opened this issue 3 weeks ago • 0 comments

Problem

The opt-in constant-parameter rule skips a function when a caller can be invisible. A dynamic import with a literal or a pattern source blocks the target module (gate reason dynamic-import). A dynamic import whose source is a plain variable blocks nothing, so the rule can report a parameter that a hidden caller passes in another way.

Reproduction

// src/pad.ts
export function pad(s: string, n: number): string { return s + n; }

// src/a.ts
import { pad } from "./pad";
export const a = pad("x", 1);
export const b = pad("y", 1);

// src/main.ts
import { a, b } from "./a";
console.log(a, b);
const name = process.argv[2];
const mod = await import(name);
mod.pad("z", 2);

fallow dead-code --constant-parameters --format json --quiet reports n of pad as identical-argument with the value 1. The call through mod passes 2.

Expected

One of these:

  1. The rule skips each exported function of a project when a reachable file has a dynamic import or a require with a source that Fallow cannot resolve to a pattern. A new gate reason names the cause.
  2. The rule keeps the finding, and the user documentation lists the case as a known limit.

Option 1 needs a measurement first: how many findings of the public corpus it removes. A project with a plugin loader would lose each finding on an exported function.

Notes

  • The rule is off by default, and a finding has no fix action.
  • The same question applies to require(variable).
  • The extractor does not record such an import today, so option 1 changes the cached facts.

BartWaardenburg avatar Nov 12 '26 14:11 BartWaardenburg