-
Notifications
You must be signed in to change notification settings - Fork 12.9k
noUnusedLocals: Destructuring assignment is a write #26365
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
Conversation
@@ -3,11 +3,15 @@ function f(x = 0) { | |||
x = 1; | |||
x++; | |||
x /= 2; | |||
([x] = [1]); | |||
({ x } = { x: 1 }); | |||
({ x: x } = { x: 1 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need tests for more levels in destructuring (nested object literal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt each test be moved to their own function to guarantee used is getting marked correctly for each expression type usage of x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every one of these tests only writes to x
, so we're testing that none of these marks x
as used. If a single test failed the baseline would change since x
was used.
src/compiler/utilities.ts
Outdated
} | ||
case SyntaxKind.ShorthandPropertyAssignment: | ||
// Assume it's the local variable being accessed, since we don't check public properties for --noUnusedLocals. | ||
return accessKind(parent.parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to handle objectAssignmentInitializer
as that is always read.
consider adding a test case for that, too.
a73413d
to
f5cffb5
Compare
@sheetalkamat Please re-review |
Fixes #26345