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
[no-unused-vars] flagged though it is used inside an object #13327
Comments
Are you sure you want to redeclare Seems this would make more sense: let placedAt = 0;
placedAt = myFunction({
previous: placedAt
}); Also, no-unused-vars is expecting another use of let placedAt = 0;
myFunction({
previous: placedAt
});
// Since nothing else is reading placedAt, this is equivalent behavior If you do intend to reassign to |
@platinumazure thanks for the quick feedback! I see that I removed too much to simplify the example, the code looks like this: let placedAt = 0;
placedAt = myFunction({
previous: placedAt
});
placedAt = myFunction({
previous: placedAt
});
placedAt = myFunction({
previous: placedAt
}); So the |
Hi @gforcada, The logic is the same as before: On the last reassignment, you could just call the function for its side effects, without reassigning the variable. let placedAt = 0;
placedAt = myFunction({
previous: placedAt
});
placedAt = myFunction({
previous: placedAt
});
/* placedAt = */ myFunction({
previous: placedAt
}); Or you can add another usage: let placedAt = 0;
placedAt = myFunction({
previous: placedAt
});
placedAt = myFunction({
previous: placedAt
});
placedAt = myFunction({
previous: placedAt
});
doSomethingWith(placedAt); Basically, the last assignment is what is unused here. Either drop that reassignment, or use the variable again, and the rule will be satisfied. |
Oh I see know 🤦 sorry for the noise and thanks for the (very quick 👍 ) explanations!! 🙇 |
Final minor disclaimer that might be worthy: I did report it as |
There's an enhancement proposal for this: #13181 |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
eslint finishing without an error.
What actually happened? Please include the actual, raw output from ESLint.
eslint complains with
error 'placedAt' is assigned a value but never used no-unused-vars
.While the
placedAt
variable is used inside the object given tomyFunction
functionAre you willing to submit a pull request to fix this bug?
I could try, though my time and JS-foo is not so good, but given some guidance I can give it a try.
The text was updated successfully, but these errors were encountered: