Namespace escapes
What a namespace-escape finding of fallow dead-code means, why it matters and how to fix it.
What it reports
Namespace binding is used as a whole value, so its exports are not checked.
Dead code explains how fallow finds it.
Why it matters
A namespace import (import * as Ns) that the code uses as a whole value: a cast, an assignment, a call argument, a spread, a computed member read, a reflective call such as Object.keys(Ns), or a re-export with export { Ns }.
Fallow cannot see which members such a use reads, so it credits every export of the target module and of the modules that the target re-exports from. These exports are then not checked by unused-exports and unused-types. The finding is on the import and gives the count of exports that the credit hides.
A binding that hides no export is not reported. Defaults to off.
Example
src/index.ts has import * as formats from "./formats" and spreads formats into an object, so formatDate and formatPrice are not checked.
{
"rules": {
"namespace-escapes": "warn"
}
}
export const formatDate = (value: Date): string => value.toISOString();
export const formatPrice = (value: number): string => value.toFixed(2);
// The registry reads the formats as one object.
import * as formats from "./formats";
const registry: Record<string, unknown> = { ...formats };
console.log(Object.keys(registry));
Fix
Read the members by name (formats.formatDate) or import them by name, so fallow can check the other exports. When the whole object is the intent, add // fallow-ignore-next-line namespace-escape above the import.
Facts
| Fact | Value |
|---|---|
| Issue type | namespace-escape |
| Rule id in SARIF output | fallow/namespace-escape |
| Command | fallow dead-code |
| Default severity | off |
Config key in rules | namespace-escapes |
| Filter option | --namespace-escapes |
| Suppression comment | // fallow-ignore-next-line namespace-escape |
Fixable with fallow fix | No |
| Opt-in | Yes |
Note. Opt-in coverage check of unused exports; the rule defaults to off.