component-folder
When a component gets a folder of its own.
Deterministic checkAdvises by default
The rule
Agents read this text as written when they write and review code.
Keep a component in one file until it has parts only it uses: sub-components, a hook, a type. Then give it a folder of its own name inside the components/ it sat in, with the component as the folder's main file and its parts flat beside it.
- A part that gains a second user moves up to the folder for its kind.
- A part with parts of its own is a component in its own right: it moves up to
components/and takes a folder there. - A folder down to its main file turns back into a file.
Then a component's folder reads as the list of its parts, and no path goes deeper than one folder.
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
srcfeaturesissuescomponentsIssueCardHeaderIssueFooter
interface Params {title: string;}// Incorrect: a folder inside the component folder. The card's parts sit flat// beside it; a part with parts of its own becomes a component in components/.export const IssueCardHeader = ({ title }: Params) => <h2>{title}</h2>;
Correct
srcfeaturesissuescomponentsIssueCard
interface Params {title: string;}// Correct: a part of the card, beside the card.export const IssueCardHeader = ({ title }: Params) => <h2>{title}</h2>;
Configure
- Block
"blocking"Stops a run when a file the run changed breaks the rule. - AdviseDefault
"advisory"Reports it and hands it to the refactor agent. Never stops a run. - 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.
{"standards-rule-settings": {"component-folder": "advisory"}}