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).
Never ship the same code in three places: extract it before the PR
If an expression, guard, block or template include appears in three or more files (or three times in one), it must become one helper, hook, wrapper component or partial imported at each site before the PR opens. A reviewer finding it is a junior-level miss; the pre-PR gate scans for it mechanically.
Bad example
| 1 | // five components, same line each time |
| 2 | if (useRequestResponseOrNull()?.res.locals.adFree) return null; |
| 3 |
|
| 4 | {# five head templates, same block each time #} |
| 5 | {% include 'common/livewrapped.njk' %} |
| 6 | {% include 'common/gpt.njk' %} |
| 7 | {% include 'common/adnami.njk' %} |
Explanation (EN)
Objašnjenje (HR)
Good example
| 1 | // one wrapper, imported five times |
| 2 | <AdSurface>...</AdSurface> |
| 3 |
|
| 4 | {# one partial with the gate inside, included five times #} |
| 5 | {% include 'common/ad-tech.njk' %} |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Run `node ~/Code/pro-code/scripts/find-repetition.mjs --base <base>` on the WHOLE PR diff (base...HEAD plus the working tree, never only the latest layer). Every hit is a P1 finding unless the repetition is a deliberate, written-down exception (avoid-premature-abstraction covers two tiny copies, not three).