Skip to content

no-array-size-assignment

Reports append-by-size assignments and points you to push.

The rule matches this exact append pattern:

array[array.size()] = value;

It also works with member chains such as state.items[state.items.size()] = item;.

It does not match lookalikes like array[array.size() - 1] = value, array[other.size()] = value, or array[array.size()] += value.

eslint.config.ts
import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [
{
plugins: {
"cease-nonsense": ceaseNonsense,
},
rules: {
"cease-nonsense/no-array-size-assignment": ["error", {
"allowAutofix": true
}],
},
},
];
OptionDefaultWhat it does
allowAutofixfalseRewrites the assignment to .push(...) when the target is safe to evaluate once

The automatic fix only runs when the assignment is a standalone expression statement and the array target is a simple, non-optional reference chain such as array, this.items, store["items"], or registry[keyRef.value].

Incorrect
inventory[inventory.size()] = item;
state.items[state.items.size()] = nextItem;
Correct
inventory.push(item);
state.items.push(nextItem);