Skip to content

No Array Size Assignment

ErrorAuto-fixableRoblox
small-rules/no-array-size-assignment

Disallow array append assignments using array[array.size()] = value (roblox-ts) or array[array.length] = value (standard) and prefer push-based appends.

Rationale

array[array.size()] = value works but it’s goofy. Just use array.push(value) – clearer, faster, and it matches what every JS dev expects. Or even better… use array[size++] = value like what was mentioned in the rationale for no-increment-decrement.

This flags any assignment where the index is the array’s own size. Auto-fixes to .push() when the target is simple. If the assignment references the array in a way that would change semantics (like array[array.size()] = array[array.size() - 1]), it won’t touch it. allowAutofix is off by default so you can review each one.

Diagnostic Messages

usePush
Do not append with array[array.size()] = value or array[array.length] = value. Use array.push(value) instead.

Configuration

This rule accepts one options object after the severity.

allowAutofixOptional

Allow the fixer to replace safe append assignments with array.push(value).

environmentOptional

Array environment mode: 'roblox-ts' checks array[array.size()]; 'standard' checks array[array.length].

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-array-size-assignment": [
"error",
{
"allowAutofix": false,
"environment": "roblox-ts"
}
]
}
}

Examples

array size index assignment
array[array.size()] = value;

After auto-fix

array.push(value);
append with push
array.push(value);