-
Notifications
You must be signed in to change notification settings - Fork 1
New Rule: no-unsafe-array-access #65
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requesthigh-valueCatches real bugs or enforces critical patternsCatches real bugs or enforces critical patternsneeds-analysisRequires overlap/scope analysis before implementationRequires overlap/scope analysis before implementationruleRelated to an ESLint rule (new or existing)Related to an ESLint rule (new or existing)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthigh-valueCatches real bugs or enforces critical patternsCatches real bugs or enforces critical patternsneeds-analysisRequires overlap/scope analysis before implementationRequires overlap/scope analysis before implementationruleRelated to an ESLint rule (new or existing)Related to an ESLint rule (new or existing)
Research Evidence
From empirical LLM bug studies: Missing edge cases account for ~15% of LLM bugs. The "Understanding Code Generation Errors" study (557 bugs) lists "missing condition" as a top semantic error. LLMs frequently access array elements without checking if the array is empty.
Description
Prevent accessing
arr[0],arr[arr.length - 1], or destructuringconst [first] = arrwithout first checking that the array is non-empty.Examples
Bad
Good
Detection Approach
arr[0]andarr[arr.length - 1]when not preceded by a length/emptiness check in the same scopeconst [x] = arrwithout a guardundefinedin its element type (to avoid flagging whennoUncheckedIndexedAccessis enabled)Scope Considerations
noUncheckedIndexedAccesshandles the type-level concern, but many projects don't enable itif (arr.length),arr?.length > 0,arr.length !== 0, etc.Priority
High — one of the most specific, detectable edge-case patterns from the research. Directly derived from splitting the overly broad
require-edge-case-handlingproposal.