fix(prefer-array-at): guard against more assignment cases where .at(-1) would be illegal - #149
Merged
Merged
Conversation
…1) would be illegal
43081j
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes the
prefer-array-atrule more resilient to assignment cases:left-hand assignments
like
items[items.length - 1]! = 42oritems[items.length - 1]! += 42are no longer transformed because they would lead toTS2364. Note that type assertions and non-null assertions no the target side needed explicit checking. This is what was reported in prefer-array-at produces invalid code: #148, normal assignments without!were already properly checked.for-in and for-of assignments
while uncommon, can lead to
Uncaught ReferenceError: Invalid left-hand side in for-loopDestructuring
also uncommon, but can lead to
Uncaught SyntaxError: Invalid destructuring assignment targetdeletetransforming
delete items[items.length - 1]intodelete items.at(-1)yields no runtime error, but doesn’t delete anything and is therefore wrong.fixes #148
Note: This PR was created with the help of AI, but a human (me) was always in the loop and no communication was done using AI. I am not a meat proxy.