Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't re-check the first element after verifying length
Use established array and element guarantees; a length check alone does not prove a present non-null first item.
Bad example
| 1 | if (shouldShowEmptyState) return <Empty />; // already ensures length > 0 |
| 2 | const first = reports?.[0]; // '?' redundant here |
Explanation (EN)
Optional access to the array is redundant only when the preceding guard has actually narrowed that array.
Objašnjenje (HR)
Good example
| 1 | if (shouldShowEmptyState) return <Empty />; |
| 2 | const first = reports[0]; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Remove optional access only when the guard establishes the array object exists; separately prove the accessed element exists if it will be dereferenced.
Exceptions / Tradeoffs (EN)
Positive length does not guarantee a dense array or non-null element. Sparse arrays and noUncheckedIndexedAccess can still require a check; a guard name alone is not proof.