Skip to content

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

Merged
4 commits merged into from
Aug 28, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 10, 2018

Fixes #26345

@@ -3,11 +3,15 @@ function f(x = 0) {
x = 1;
x++;
x /= 2;
([x] = [1]);
({ x } = { x: 1 });
({ x: x } = { x: 1 });
Copy link
Member

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)

Copy link
Member

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?

Copy link
Author

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.

}
case SyntaxKind.ShorthandPropertyAssignment:
// Assume it's the local variable being accessed, since we don't check public properties for --noUnusedLocals.
return accessKind(parent.parent);
Copy link
Contributor

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.

@ghost ghost force-pushed the unusedLocals_destructureAssignment branch from a73413d to f5cffb5 Compare August 10, 2018 23:35
@ghost
Copy link
Author

ghost commented Aug 27, 2018

@sheetalkamat Please re-review

@ghost ghost merged commit 3931b72 into master Aug 28, 2018
@ghost ghost deleted the unusedLocals_destructureAssignment branch August 28, 2018 18:43
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants