lightsoutAlpha

feature-import-direction

Which way imports flow between features and the shared layer.

Deterministic checkAdvises by default

The rule

Agents read this text as written when they write and review code.

Imports flow one way: the shared layer imports nothing from a feature, a feature imports from the shared layer and from itself, and the app above the features, its routes and entry files, imports from any feature.

When two features need the same code, move it to the shared layer, as shared-layer says, and import it from there.

A feature that reaches into no sibling can be read, tested and deleted on its own.

Examples

The check flags the incorrect code and passes the correct code. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.

Incorrect

srcfeaturesbillingcomponentsissuescomponents
src/features/billing/components/InvoiceRow.tsx
import { StatusBadge } from '../../issues/components/StatusBadge.tsx';
interface Params {
number: string;
status: string;
}
// Incorrect: billing imports from issues, so neither feature can change or go
// without the other.
export const InvoiceRow = ({ number, status }: Params) => (
<li>
{number} <StatusBadge label={status} />
</li>
);

Correct

srccomponentsuifeaturesbillingcomponentsissuescomponents
src/features/billing/components/InvoiceRow.tsx
import { StatusBadge } from '../../../components/ui/StatusBadge.tsx';
interface Params {
number: string;
status: string;
}
// Correct: both features import the badge from the shared layer, and neither
// knows the other exists.
export const InvoiceRow = ({ number, status }: Params) => (
<li>
{number} <StatusBadge label={status} />
</li>
);

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"feature-import-direction": "advisory"
}
}

Packs that select it