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).
Reuse existing shared types, enums, and helpers before adding new ones
Before creating a new type, enum, interface, or validator, search the codebase for an existing shared version and reuse it when the semantics already match.
Bad example
| 1 | export type PortfolioTransactionOrder = 'ASC' | 'DESC'; |
| 2 | export interface PortfolioTransactionsResponse { |
| 3 | data: PortfolioTransaction[]; |
| 4 | meta: { |
| 5 | page: number; |
| 6 | take: number; |
| 7 | itemCount: number; |
| 8 | pageCount: number; |
| 9 | hasPreviousPage: boolean; |
| 10 | hasNextPage: boolean; |
| 11 | }; |
| 12 | } |
Explanation (EN)
This redefines concepts that often already exist elsewhere in the codebase, such as shared sort-order enums or paginated response shapes. Repeating them increases drift and review noise.
Objašnjenje (HR)
Ovo ponovno definira koncepte koji cesto vec postoje u codebaseu, poput shared sort-order enumova ili paginated response shapeova. Ponavljanje povecava drift i review noise.
Good example
| 1 | import type { SortOrderUpper } from 'enums/SortOptions'; |
| 2 |
|
| 3 | export interface PaginationMeta { |
| 4 | page: number; |
| 5 | take: number; |
| 6 | itemCount: number; |
| 7 | pageCount: number; |
| 8 | hasPreviousPage: boolean; |
| 9 | hasNextPage: boolean; |
| 10 | } |
| 11 |
|
| 12 | export interface PaginatedResponse<T> { |
| 13 | data: T[]; |
| 14 | meta: PaginationMeta; |
| 15 | } |
| 16 |
|
| 17 | export type PortfolioTransactionOrder = SortOrderUpper; |
| 18 | export type PortfolioTransactionsResponse = PaginatedResponse<PortfolioTransaction>; |
Explanation (EN)
The code reuses shared abstractions where the semantics already match. This keeps the project consistent and makes future changes cheaper.
Objašnjenje (HR)
Kod ponovno koristi shared apstrakcije kada se semantika vec poklapa. Tako projekt ostaje konzistentan, a buduce promjene su jeftinije.
Notes (EN)
Search for an existing project abstraction first. Only add a new one when the semantics are genuinely different.
Bilješke (HR)
Prvo pretrazi postoji li vec projektna apstrakcija. Novi tip dodaj samo kada je semantika stvarno drugacija.
Exceptions / Tradeoffs (EN)
A new local type or helper is acceptable when the existing shared abstraction would hide meaningful domain differences or create awkward coupling.
Iznimke / Tradeoffi (HR)
Novi lokalni tip ili helper je prihvatljiv kada bi postojeca shared apstrakcija sakrila vazne domenske razlike ili stvorila nezgodan coupling.