-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Add 'consistent-destructuring' exceptions #1501
Comments
If |
That's safer, and my general preference, but sometimes it makes sense (in my opinion) to destructure it off if you're passing it down to a child component under the same name. |
Exceptions would be welcome! In customElements there are many times we had to disable this rule because of e.g.: classList. Example: const { foo, bar, baz } = this
// ... later in that function
this.classList.toggle(styles.empty) // <--- Use destructured variables over properties.eslintunicorn/consistent-destructuring) |
The rule was recently removed from the "recommended" config and this issue hasn't seen activity in a while. Closing for now |
I've found that destructuring React's
state
andprops
off ofthis
can be a bit unwieldy due to the depth of destructuring. It would be great to be able to exclude select patterns - in our particular case,this.state
andthis.props
.This is pretty trivial as we can just move the state/props destructures above like this, but it would still be great if this was supported.
Maybe it's just me, but I find destructuring directly from
this.state
to be easier to reason about than first destructuringstate
off ofthis
.It's also a bit of a pain when refactoring if you're getting rid of
someMethod
and you have the following:because now you're left with this:
That destructuring assignment seems needless at that point, but to remove it requires updating two lines of code, which can be tedious during refactors. Even if each individual case only adds a couple seconds, it adds up in terms of time and reducing focus on the task at hand.
The text was updated successfully, but these errors were encountered: