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).
Keep guard-clause formatting consistent within a file
Match the early-return style already used nearby; do not mix one-liner guards with multi-line block guards for equivalent checks.
Bad example
| 1 | if (!session) return res.status(401).json({ message: 'Unauthorized' }); |
| 2 |
|
| 3 | if (!token) { |
| 4 | return res.status(401).json({ message: 'Unauthorized: Missing auth token.' }); |
| 5 | } |
Explanation (EN)
Two equivalent guard clauses are formatted differently in the same function, which adds visual noise and makes the code look inconsistent.
Objašnjenje (HR)
Dvije ekvivalentne guard provjere formatirane su razlicito u istoj funkciji, sto dodaje vizualni sum i cini kod nekonzistentnim.
Good example
| 1 | if (!session) return res.status(401).json({ message: 'Unauthorized' }); |
| 2 | if (!token) return res.status(401).json({ message: 'Unauthorized: Missing auth token.' }); |
Explanation (EN)
Both guards use the same one-liner form, matching the surrounding style and reading uniformly.
Objašnjenje (HR)
Obje provjere koriste isti jednolinijski oblik, uskladen s okolnim stilom i citljiv ujednaceno.
Notes (EN)
Original code here also missed a return on the 404 branch, so execution fell through; one-lining with an explicit return fixes that too.
Bilješke (HR)
Izvorni kod ovdje je takoder izostavio return na 404 grani, pa je izvrsavanje propalo dalje; prelazak na jednu liniju s eksplicitnim returnom to ujedno popravlja.
Exceptions / Tradeoffs (EN)
Use a multi-line block when the guard body has multiple statements or the line would become too long to read comfortably.
Iznimke / Tradeoffi (HR)
Koristi viselinijski blok kad tijelo provjere ima vise naredbi ili kad bi linija postala predugacka za ugodno citanje.