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).
Always use braces for control flow blocks
Use braced blocks for if/for/while to prevent accidental logic bugs.
Bad example
| 1 | if (isReady) |
| 2 | doWork(); |
| 3 | log('done'); |
Explanation (EN)
Unbraced blocks are easy to misread and can introduce bugs when lines are added or indentation lies.
Objašnjenje (HR)
Blokovi bez vitičastih zagrada lako zavaraju i često nastanu bugovi kad se doda nova linija ili se oslanjaš na indent.
Good example
| 1 | if (isReady) { |
| 2 | doWork(); |
| 3 | log('done'); |
| 4 | } |
Explanation (EN)
Braces make the scope explicit and safer to edit during refactors.
Objašnjenje (HR)
Zagrade čine scope eksplicitnim i sigurnijim za izmjene tijekom refaktora.
Notes (EN)
A single-line if may be allowed if it truly fits on one line, but braces are safer and preferred.
Bilješke (HR)
Jednolinijski if može proći ako baš stane u jednu liniju, ali zagrade su sigurnije i preporučene.