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).
Derive a canonical value one way across all code paths
Avoid building the same logical value with divergent logic in different paths; share one derivation.
Bad example
| 1 | // Path A (from DB): deterministic slug |
| 2 | entry.loc = `${prefix}${buildPath(article)}`; |
| 3 |
|
| 4 | // Path B (from webhook): trusts caller verbatim |
| 5 | entry.loc = article.url ?? ''; |
| 6 | // Same article, two different URLs -> flip-flop on every handoff |
Explanation (EN)
Two paths cover the same entity but compute the canonical URL differently, so each handoff overwrites the other with a slightly different value, confusing downstream consumers.
Objašnjenje (HR)
Dvije putanje pokrivaju isti entitet, ali kanonski URL računaju različito, pa svaka primopredaja prepiše drugu malo drugačijom vrijednošću, što zbunjuje potrošače nizvodno.
Good example
| 1 | function canonicalUrl(article: Article): string { |
| 2 | return `${prefix}${buildPath(article)}`; |
| 3 | } |
| 4 |
|
| 5 | // Both paths call the same function |
| 6 | entry.loc = canonicalUrl(article); |
Explanation (EN)
A shared derivation guarantees both paths emit the identical canonical value for the same entity, eliminating drift.
Objašnjenje (HR)
Zajednička derivacija jamči da obje putanje emitiraju identičnu kanonsku vrijednost za isti entitet, čime se uklanja odstupanje.