Rules Hub
Code Ruleset
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)
A variable-length collection cannot guarantee every hardcoded index is populated.
Objašnjenje (HR)
Kolekcija promjenjive duljine ne jamči vrijednost na svakom hardkodiranom indeksu.
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.
Notes (EN)
Render the available collection when the number of columns is dynamic, or validate a fixed-size tuple when the UI requires exactly that shape.
Exceptions / Tradeoffs (EN)
Mapping can change a fixed-column layout. A missing React text child may render nothing rather than crash; choose fallback, omission or validation according to the table contract.
Iznimke / Tradeoffi (HR)
Mapiranje može promijeniti izgled s fiksnim brojem stupaca. Nedostajući React tekst može samo izostati umjesto izazvati kvar; fallback, izostavljanje ili validaciju odredi prema ugovoru tablice.