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).
Keep entry-point files lean; extract helpers into modules
Move non-trivial helpers out of busy bootstrap files (server.ts, index.ts) into focused utility modules where they can also reach shared config directly.
Bad example
| 1 | // server.ts — already wiring env, navigation, robots, locals... |
| 2 | function resolveComponentsUrl(isLocal: boolean): string | undefined { |
| 3 | if (!isLocal) return deployConfig.url; |
| 4 | // ...more branching... |
| 5 | } |
| 6 | app.locals.componentsUrl = resolveComponentsUrl(config.isLocal); |
Explanation (EN)
The bootstrap file already does a lot; inlining a branchy resolver here grows it further and forces shared config (isLocal) to be threaded in as an argument. The helper has no natural home in the entry point.
Objašnjenje (HR)
Ulazna datoteka već radi puno; ubacivanje razgranatog resolvera ovdje je dodatno povećava i prisiljava da se zajednička konfiguracija (isLocal) provlači kao argument. Pomoćna funkcija nema prirodno mjesto u entry pointu.
Good example
| 1 | // utils/components.ts |
| 2 | import { config } from './config'; |
| 3 | export const resolveComponentsUrl = (): string | undefined => { |
| 4 | if (!config.isLocal) return deployConfig.url; |
| 5 | // ... |
| 6 | }; |
| 7 |
|
| 8 | // server.ts |
| 9 | import { resolveComponentsUrl } from './utils/components'; |
| 10 | app.locals.componentsUrl = resolveComponentsUrl(); |
Explanation (EN)
The helper lives in a focused module, so server.ts stays a thin wiring layer. Co-located with config, the function reads config.isLocal itself instead of accepting it as a parameter.
Objašnjenje (HR)
Pomoćna funkcija živi u fokusiranom modulu pa server.ts ostaje tanak sloj povezivanja. Smještena uz konfiguraciju, funkcija sama čita config.isLocal umjesto da ga prima kao parametar.
Notes (EN)
A function that needs config the surrounding module already owns is a signal it belongs in that module, not in the entry point.
Bilješke (HR)
Funkcija kojoj treba konfiguracija koju okolni modul već posjeduje znak je da pripada tom modulu, a ne ulaznoj datoteci.