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).
Extract duplicated frontend helpers into shared utilities
If two frontend files need the same helper or constants, move them to a shared utility instead of duplicating or mirroring them.
Bad example
| 1 | // File A |
| 2 | export const DISPLAY_DATE_FORMAT = "dd.MM.yyyy"; |
| 3 | export const getPickerDateValue = (value: string) => { |
| 4 | return value ? value : "2026-03-17"; |
| 5 | }; |
| 6 |
|
| 7 | // File B |
| 8 | export const DISPLAY_DATE_FORMAT = "dd.MM.yyyy"; |
| 9 | export const getPickerDateValue = (value: string) => { |
| 10 | return value ? value : "2026-03-17"; |
| 11 | }; |
Explanation (EN)
The same date helpers live in multiple places, so future fixes drift and one consumer eventually behaves differently from the other.
Objašnjenje (HR)
Isti date helperi zive na vise mjesta, pa buduci fixevi odlutaju i jedan potrosac na kraju pocne raditi drukcije od drugog.
Good example
| 1 | // utils/static/portfolio/dates.ts |
| 2 | export const DISPLAY_DATE_FORMAT = "dd.MM.yyyy"; |
| 3 | export const getPickerDateValue = (value: string) => { |
| 4 | return value ? value : "2026-03-17"; |
| 5 | }; |
| 6 |
|
| 7 | // consumer A |
| 8 | import { DISPLAY_DATE_FORMAT, getPickerDateValue } from "utils/static/portfolio/dates"; |
| 9 |
|
| 10 | // consumer B |
| 11 | import { DISPLAY_DATE_FORMAT, getPickerDateValue } from "utils/static/portfolio/dates"; |
Explanation (EN)
One shared utility becomes the single source of truth. Fixes happen once and every consumer stays aligned.
Objašnjenje (HR)
Jedan shared utility postaje single source of truth. Fix se radi jednom i svi potrosaci ostaju uskladeni.