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).
Don't re-export a symbol from a module that only consumes it
Avoid pass-through re-exports: a consuming module shouldn't re-export another module's symbol, which creates a misleading import path and hides the real owner.
Bad example
| 1 | // auth.guard.ts — consumes userCacheKey, but also re-exports it |
| 2 | import { userCacheKey } from '../user/user.cache-keys'; |
| 3 |
|
| 4 | export { userCacheKey } from '../user/user.cache-keys'; // pass-through re-export |
| 5 |
|
| 6 | export class AuthGuard { /* uses userCacheKey internally */ } |
| 7 |
|
| 8 | // Now two import paths exist for the same symbol; the auth guard |
| 9 | // looks like an owner of a user concern that it merely uses. |
Explanation (EN)
Re-exporting userCacheKey from the auth guard gives the symbol a second, unrelated import path. It obscures the true owning module, encourages others to import from the wrong place, and increases the risk of circular dependencies and confusing refactors.
Objašnjenje (HR)
Re-eksportiranje userCacheKey iz auth guarda daje simbolu drugu, nepovezanu uvoznu putanju. To zamagljuje pravi vlasnicki modul, potice druge da uvoze s krivog mjesta i povecava rizik od kruznih ovisnosti i zbunjujucih refaktoriranja.
Good example
| 1 | // auth.guard.ts — consumes the symbol, does not re-export it |
| 2 | import { userCacheKey } from '../user/user.cache-keys'; |
| 3 |
|
| 4 | export class AuthGuard { /* uses userCacheKey internally */ } |
| 5 |
|
| 6 | // Every consumer imports from the owning module: |
| 7 | // import { userCacheKey } from '../user/user.cache-keys'; |
Explanation (EN)
Each symbol has exactly one canonical import path: its owning module. Consumers import directly from the source, keeping module ownership clear and avoiding accidental coupling through unrelated files.
Objašnjenje (HR)
Svaki simbol ima tocno jednu kanonsku uvoznu putanju: svoj vlasnicki modul. Pozivatelji uvoze izravno iz izvora, sto cuva jasno vlasnistvo modula i izbjegava slucajno povezivanje kroz nepovezane datoteke.
Notes (EN)
Legitimate re-exports belong in deliberate barrel/index modules whose purpose is to aggregate a public API, not in a feature module that happens to consume the symbol.
Bilješke (HR)
Legitimni re-eksporti pripadaju namjernim barrel/index modulima cija je svrha okupiti javni API, a ne u feature modulu koji slucajno koristi simbol.
Exceptions / Tradeoffs (EN)
A dedicated barrel/index file or a module intentionally curating a public surface may re-export symbols from submodules.
Iznimke / Tradeoffi (HR)
Namjenska barrel/index datoteka ili modul koji namjerno kurira javnu povrsinu smiju re-eksportirati simbole iz podmodula.