Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Put pure logic next to its related helpers, not in a UI or page folder
A pure function with no JSX should live alongside the other non-UI helpers it's conceptually paired with, not in the UI folder of the page that happens to call it.
Bad example
| 1 | // app/(articlePage)/(modules)/insert-image-into-body.ts |
| 2 | export function insertImageIntoEditorBody(editor: Editor, image: Asset) { |
| 3 | // pure editor logic, no JSX |
| 4 | } |
Explanation (EN)
This function has nothing to do with page UI, but living in the page's modules folder separates it from its natural sibling, the matching removeImageNode helper, which already lives in the editor's utils package.
Objašnjenje (HR)
Ova funkcija nema veze s UI-jem stranice, ali time sto se nalazi u modules folderu stranice, odvojena je od svog prirodnog para, odgovarajuce removeImageNode funkcije, koja se vec nalazi u utils paketu editora.
Good example
| 1 | // components/RichTextEditor/utils/image-node-utils.ts |
| 2 | export function insertImageIntoEditorBody(editor: Editor, image: Asset) { |
| 3 | // pure editor logic, no JSX |
| 4 | } |
| 5 |
|
| 6 | // same folder already has removeImageNode and stripEmptyParagraphs |
Explanation (EN)
Moving it next to removeImageNode and the other editor utilities keeps insert and remove logic together and makes the module discoverable by anyone working on editor internals, regardless of which page calls it.
Objašnjenje (HR)
Premjestanjem uz removeImageNode i ostale utility funkcije editora, insert i remove logika ostaje na jednom mjestu i modul je lako pronaci svakome tko radi na internoj logici editora, bez obzira koja ga stranica poziva.