Skip to content

Rule proposal: no-array-delete #4432

Closed
@davidmaxwaterman

Description

@davidmaxwaterman

Description

Deleting an array element can lead to unexpected (for some) behaviour since it leaves 'length' unchanged. Some might say that using delete on array elements should best be avoided and there are alternatives - splice() seems to be preferred.

Having a rule to prevent delete being used on arrays would be beneficial.

Fail

> var myArray = [ 1, 2, 3 ];
undefined
> delete myArray[1];
true
> myArray
(3) [1, empty, 3]
> myArray[1]
undefined
> myArray.length
3

Pass

> var myArray = [ 1, 2, 3 ];
(3) [1, 2, 3]
> myArray.splice(1,1)
[2]
> myArray
(2) [1, 3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions