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
prefer-object-spread invalid autofix with accessors #12086
Comments
The autofix did this, or you manually did? If you want to preserve the behavior of reifying getters and setters, you’d need to do: const foo = {
...{
get a() { return this._a; },
set a(v) { this._a = v + 1; }
}
} |
The autofix did this. I guess it would be best to simply not fix the code at all if there are any getters/setters in source or target object literals? Perhaps not even warn in Example 1. On the other hand, Example 2 is a possible error in user's code. |
Probably best to not autofix there at all, unless it can use the output i suggested. |
In general tho, I’d say if you’re relying on setters being triggered during an Object.assign call, that’s not something I’d let pass code review :-) |
I agree, not my code just noted that the fix shouldn't change behavior, whatever it is. An additional question might be should the rule warn at all in the first example? |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening this since it's an invalid autofix (at least in the second example). |
Marking as accepted since we definitely don't want to change behavior here if possible. Also marking as "needs bikeshedding" since we still need to figure out the desired behavior here. |
After thinking about this again, I believe that Even without the autofix, the rule would suggest using object literal/object spread instead, which is wrong as it isn't equivalent. Maybe there could be another rule to warn about using getters/setters with |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
I think this should be reopened? |
Assigning to myself so it doesn’t get autoclosed again, but please feel free to assign yourself @mdjermanovic. |
🤦♂ Reopened now. |
@mdjermanovic Are you still advocating for this change? |
This seems like it's a bugfix, so i'd hope it can still happen without additional advocacy :-) |
Yes, fixing I'll make a PR to ignore Semi-related, |
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.
Example #1
Example #2
What did you expect to happen?
Not to change behavior.
What actually happened? Please include the actual, raw output from ESLint.
Example #1
Example #2
Are you willing to submit a pull request to fix this bug?
Yes, just to define what should be done (no warning, warning without the fix or something else).
The text was updated successfully, but these errors were encountered: