Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep entry and barrel files only when they provide a useful boundary
Import a module directly when a barrel or entry wrapper adds no needed public contract, initialization or build behavior. Prefer a directly supported build entry over a file that only imports it.
Bad example
| 1 | // feature/dto/index.ts |
| 2 | export * from './create-order.dto'; |
| 3 | export * from './order-response.dto'; |
| 4 |
|
| 5 | // ...but every consumer still imports directly: |
| 6 | import { CreateOrderDto } from 'feature/dto/create-order.dto'; |
Explanation (EN)
The barrel re-exports DTOs nobody imports through it. It adds an unused indirection layer and can defeat tree-shaking.
Objašnjenje (HR)
Barrel re-exporta DTO-ove kroz koje nitko ne uvozi. Dodaje neiskoristen sloj posredovanja i moze unistiti tree-shaking.
Good example
| 1 | // no index.ts; consumers import the module they need directly |
| 2 | import { CreateOrderDto } from 'feature/dto/create-order.dto'; |
| 3 | import { OrderResponseDto } from 'feature/dto/order-response.dto'; |
Explanation (EN)
Direct imports keep the dependency graph explicit and avoid maintaining a file that earns nothing.
Objašnjenje (HR)
Izravni uvozi cuvaju graf ovisnosti eksplicitnim i izbjegavaju odrzavanje datoteke koja nista ne donosi.
Notes (EN)
A barrel is justified for a published public API or genuinely shared facade. For a build entry that merely imports one already supported virtual module, reference that module directly if the installed tool supports it. Verify emitted assets and required side effects before removing the wrapper. Extra documentation does not justify a file that adds no behavior or boundary.
Bilješke (HR)
Barrel je opravdan za objavljen javni API ili stvarno zajedničku fasadu. Ako ulazna datoteka za build samo uvozi jedan već podržani virtualni modul, navedi ga izravno ako to instalirani alat podržava. Prije uklanjanja omotača provjeri izlazne resurse i potrebne nuspojave. Dodatna dokumentacija ne opravdava datoteku koja ne dodaje ponašanje ni granicu odgovornosti.
Exceptions / Tradeoffs (EN)
Keep intentional package entry points, compatibility facades, initialization modules and wrappers required by the build tool or asset graph. A used public boundary may legitimately be thin. Do not remove a wrapper solely because it has one line.
Iznimke / Tradeoffi (HR)
Zadrži namjerne ulazne točke paketa, kompatibilne fasade, inicijalizacijske module i omotače koje zahtijeva alat ili graf resursa. Korištena javna granica smije biti tanka. Nemoj ukloniti omotač samo zato što ima jednu liniju.