Shallow directory
What a shallow-directory finding of fallow health means, why it matters and how to fix it.
What it reports
Directory shows as many interface items as it hides.
Health explains how fallow finds it.
Why it matters
Files outside the directory use at least as many of its interface items as it keeps inside, and it shows at least health.shallowDirectories.minInterface items (default 8). An interface item is a module-scope function or an exported class with a method; types, constants, enums, UI components and exports that a package entry publishes are no items.
Only runtime imports from files that are not tests or stories count. A catalog (about one item per file), a family of functions with one parameter list, and items with about one outside user are not reported. The section is opt-in with fallow health --shallow-directories, advisory, and has no health score weight.
Example
src/utils holds 10 functions in 2 files. src/main.ts and src/report.ts use 8 of them through the barrel, and src/utils keeps 2 helpers inside.
import { slugify, truncate, capitalize, wordCount, formatDate, parseDate, addDays, isWeekend } from './utils';
import { report } from './report';
console.log(report('x'), slugify('x'), truncate('x'), capitalize('x'), wordCount('x'), formatDate('x'), parseDate('x'), addDays('x'), isWeekend('x'));
import { slugify, truncate, capitalize, wordCount, formatDate, parseDate, addDays, isWeekend } from './utils';
export function report(input: string): string[] {
return [slugify(input), truncate(input), capitalize(input), wordCount(input), formatDate(input), parseDate(input), addDays(input), isWeekend(input)];
}
export * from './text';
export * from './time';
function normalize(value: string): string {
return value.trim();
}
export function slugify(slugifyInput: string): string {
return normalize(slugifyInput);
}
export function truncate(truncateInput: string): string {
return normalize(truncateInput);
}
export function capitalize(capitalizeInput: string): string {
return normalize(capitalizeInput);
}
export function wordCount(wordCountInput: string): string {
return normalize(wordCountInput);
}
function pad(value: string): string {
return value.padStart(2, '0');
}
export function formatDate(formatDateInput: string): string {
return pad(formatDateInput);
}
export function parseDate(parseDateInput: string): string {
return pad(parseDateInput);
}
export function addDays(addDaysInput: string): string {
return pad(addDaysInput);
}
export function isWeekend(isWeekendInput: string): string {
return pad(isWeekendInput);
}
Fix
Group the items by the concern of their callers, and move each group into a module with a small interface, or next to its only caller. When the width is on purpose, for example a published helper set, add the directory to health.shallowDirectories.ignore.
Facts
| Fact | Value |
|---|---|
| Issue type | shallow-directory |
| Rule id in SARIF output | fallow/shallow-directory |
| Command | fallow health |
Fixable with fallow fix | No |