Skip to content
Fallow home
All docs pages

Docs home

Test-only exports

What a test-only-export finding of fallow dead-code means, why it matters and how to fix it.

What it reports

Export is used only by test-side files.

Dead code explains how fallow finds it.

Why it matters

An exported value that production code does not use, while a test-side file does. Test-side files are the files that --production leaves out: test, story, fixture and bench files and the production.ignore globs, plus the files that only tests reach, such as a test helper.

A file that a runtime or support entry reaches, such as a source file that a bundler config names, is production code. In the default mode the tests keep such an export alive, so unused-export does not report it. In --production mode the same export is an unused-export finding, and this rule does not run.

One export is never in both kinds in one run. Only values are checked in this version, not types. Entry exports, keepExportTags, ignoreExports and plugin rules keep an export, as for unused-export.

The colocated_only field is true when each test-side importer is next to the module, which can mean a deliberate internal seam. A test-only use does not make an @expected-unused tag stale. Defaults to off.

Example

src/price.ts exports legacyFormat. Only src/price.test.ts imports it, and no production file calls it.

{
  "rules": {
    "test-only-exports": "warn"
  }
}
import { formatPrice } from "./price";

export const label = (cents: number): string => `Total: ${formatPrice(cents)}`;
import { expect, it } from "vitest";
import { formatPrice, legacyFormat } from "./price";

it("formats", () => {
  expect(formatPrice(150)).toBe("1.5 EUR");
  expect(legacyFormat(150)).toBe("EUR 1.5");
});
export const formatPrice = (cents: number): string => `${roundCents(cents) / 100} EUR`;

export const roundCents = (cents: number): number => Math.round(cents);

export const legacyFormat = (cents: number): string => `EUR ${cents / 100}`;

Fix

When the export is dead code that its tests keep alive, remove the export and those tests. When it is a seam for tests only, test the behavior through the public functions of the module and make the item internal. When the export is deliberate, add // fallow-ignore-next-line test-only-export above it. See also unused-export.

Facts

FactValue
Issue typetest-only-export
Rule id in SARIF outputfallow/test-only-export
Commandfallow dead-code
Default severityoff
Config key in rulestest-only-exports
Filter option--test-only-exports
Suppression comment// fallow-ignore-next-line test-only-export
Fixable with fallow fixNo
Opt-inYes

Note. Opt-in check for default-scope runs; the rule defaults to off. No automatic fix, because a removal breaks the test-side importers.