lightsoutAlpha

shared-layer

Where code that several features use lives.

Deterministic checkAgent checkAdvises by default

The rule

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

Put what two or more features use at the top of src/, in a folder named for its kind:

  • components/ — shared components, grouped by subject once there are enough to group: components/ui/ for the design system's primitives, components/icons/, components/markdown/.
  • layouts/ — the frames routes share, each named with a Layout suffix, the parts only they use, and the root document.
  • providers/ — the context providers wrapped around the app, each with the context it provides.
  • hooks/, utils/, types/, constants/ — as in a feature.
  • styles/ and assets/ — stylesheets, fonts and images.
  • The folders the framework's rules add.

Code one feature uses stays in that feature. When a second feature needs it, move it here and update the imports; when a shared file is down to one user, move it back into that feature.

Then features/ is the product, the top of src/ is what holds it up, and shared code is found by kind without opening a feature.

Examples

The check flags the incorrect code and passes the correct code; the agent judges what the check cannot see. 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

srcfeaturesbillingcomponentsissuescomponentsshared
src/shared/StatusBadge.tsx
interface Params {
label: string;
}
// Incorrect: shared/ says only that something is shared, not what kind of code
// it is, so every shared thing of every kind ends up here.
export const StatusBadge = ({ label }: Params) => <span className="badge">{label}</span>;

Correct

srccomponentsuifeaturesbillingcomponentsissuescomponents
src/components/ui/StatusBadge.tsx
interface Params {
label: string;
}
// Correct: two features use it, so it sits in the shared components, in the
// group for the design system's primitives.
export const StatusBadge = ({ label }: Params) => <span className="badge">{label}</span>;

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": {
"shared-layer": "advisory"
}
}

Packs that select it