lightsoutAlpha

file-placement

Where a file belongs, from who uses it.

Deterministic checkAgent checkAdvises by default

The rule

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

Put a file where its users are.

  • Used by one file: beside that file, in its module folder.
  • Used by two or more files: in the common/ of the lowest folder that holds them all.
  • Used from outside its subject folder: at the top level of that subject folder.

When a file gains a user, move it, update the imports, and check the move made no circular imports.

Then where a file sits shows who uses it.

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

srcbillingcommoninvoices
src/billing/common/formatMoney.ts
// Incorrect: sendInvoice.ts uses this too, so it sits too low. It belongs in
// src/common/, the lowest folder that holds both users.
export const formatMoney = ({ cents }: { cents: number }): string => `$${(cents / 100).toFixed(2)}`;

Correct

srcbillingchargeCustomercommoncommoninvoices
src/common/formatMoney.ts
// Correct: billing and invoices both use this, and src/ is the lowest folder
// that holds both.
export const formatMoney = ({ cents }: { cents: number }): string => `$${(cents / 100).toFixed(2)}`;

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": {
"file-placement": "advisory"
}
}

Packs that select it