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).
Guard fixed array index access or map instead
Reading arr[0]/arr[1]/arr[2] from a variable-length array can render undefined or break; provide a fallback per access (?? '') or render by mapping over the array.
Bad example
| 1 | <tr> |
| 2 | <th>{columns[0]}</th> |
| 3 | <th>{columns[1]}</th> |
| 4 | <th>{columns[2]}</th> |
| 5 | </tr> |
Explanation (EN)
If fewer than three columns are passed, the missing cells render undefined with no safeguard.
Objašnjenje (HR)
Ako se proslijedi manje od tri stupca, nedostajuce celije renderiraju undefined bez ikakve zastite.
Good example
| 1 | <tr> |
| 2 | {columns.map((col, i) => ( |
| 3 | <th key={i}>{col}</th> |
| 4 | ))} |
| 5 | </tr> |
Explanation (EN)
Mapping over the actual array tolerates any length; alternatively use {columns[0] ?? ''} per cell for a fixed header layout.
Objašnjenje (HR)
Mapiranje preko stvarnog niza podnosi bilo koju duljinu; alternativno koristi {columns[0] ?? ''} po celiji za fiksni raspored zaglavlja.
Exceptions / Tradeoffs (EN)
If the array length is guaranteed by a tuple type or contract, direct indexing is acceptable.
Iznimke / Tradeoffi (HR)
Ako je duljina niza zajamcena tuple tipom ili ugovorom, izravno indeksiranje je prihvatljivo.