Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: enable the @typescript-eslint/no-array-delete lint rule #88790

Merged
merged 2 commits into from
Apr 4, 2025

Conversation

TkDodo
Copy link
Contributor

@TkDodo TkDodo commented Apr 4, 2025

When using the delete operator with an array value, the array's length property is not affected, but the element at the specified index is removed and leaves an empty slot in the array. This is likely to lead to unexpected behavior. As mentioned in the MDN documentation, the recommended way to remove an element from an array is by using the Array#splice or the immutable Array#toSpliced method.

see: https://typescript-eslint.io/rules/no-array-delete/

@TkDodo TkDodo marked this pull request as ready for review April 4, 2025 13:23
@TkDodo TkDodo requested review from a team as code owners April 4, 2025 13:23
@TkDodo TkDodo requested a review from a team April 4, 2025 13:23
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 4, 2025
@TkDodo TkDodo enabled auto-merge (squash) April 4, 2025 15:48
@TkDodo TkDodo merged commit d4676b8 into master Apr 4, 2025
42 checks passed
@TkDodo TkDodo deleted the tkdodo/ref/no-array-delete branch April 4, 2025 16:03
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
When using the delete operator with an array value, the array's length
property is not affected, but the element at the specified index is
removed and leaves an empty slot in the array. This is likely to lead to
unexpected behavior. As mentioned in the [MDN
documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#deleting_array_elements),
the recommended way to remove an element from an array is by using the
[Array#splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
or the immutable
[Array#toSpliced](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
method.

see: https://typescript-eslint.io/rules/no-array-delete/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants