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).
Enforce a must-stay-identical claim with a test, not a comment
When you deliberately fork a type or a payload and the whole point is that the copy stays field-for-field identical to the original, a docblock saying so enforces nothing. Assert the parity directly, or the copy silently diverges the first time someone edits the original.
Bad example
| 1 | /** |
| 2 | * Field-for-field identical to WidgetDto - do not let these diverge. |
| 3 | */ |
| 4 | export class FrozenDto { /* ... */ } |
Explanation (EN)
Adding a field to the original, or changing one transform, silently diverges the copy and no test goes red.
Objašnjenje (HR)
Dodavanje polja izvorniku ili promjena jedne transformacije tiho razdvaja kopiju, a nijedan test ne pada.
Good example
| 1 | it("serves the same field set as the widget DTO", () => { |
| 2 | expect(Object.keys(plainToInstance(FrozenDto, row, options))).toEqual( |
| 3 | Object.keys(plainToInstance(WidgetDto, row, options)), |
| 4 | ); |
| 5 | }); |
Explanation (EN)
The claim in the docblock is now checked on every run, so divergence has to be a deliberate edit to the test.
Objašnjenje (HR)
Tvrdnja iz komentara sada se provjerava pri svakom pokretanju, pa razdvajanje mora biti namjerna izmjena testa.
Notes (EN)
This is the same failure class the fork was created to fix, just relocated from one field to the rest of them.
Bilješke (HR)
To je ista vrsta kvara zbog koje je kopija i nastala, samo premjestena s jednog polja na sva ostala.