no-array-size-assignment
Reports append-by-size assignments and points you to push.
Rule details Problem
Section titled “Rule details ”ProblemThe 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.
Configuration
Section titled “Configuration”import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense, }, rules: { "cease-nonsense/no-array-size-assignment": ["error", { "allowAutofix": true }], }, },];Option
Section titled “Option”| Option | Default | What it does |
|---|---|---|
allowAutofix | false | Rewrites 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].
Examples
Section titled “Examples” Incorrect
inventory[inventory.size()] = item;state.items[state.items.size()] = nextItem; Correct
inventory.push(item);state.items.push(nextItem);Related rules
Section titled “Related rules” no-array-constructor-elements Cleans up other array initialization patterns