Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRelax rule: Only enforce `const` in destructuring when all variables are constant #1325
Comments
feross
added a commit
to standard/eslint-config-standard
that referenced
this issue
Jul 11, 2019
feross
changed the title
Relax rule: Only error in destructuring if all variables should be const (prefer-const)
Relax rule: Only enforce `const` in destructuring when all variables should be const
Jul 11, 2019
feross
changed the title
Relax rule: Only enforce `const` in destructuring when all variables should be const
Relax rule: Only enforce `const` in destructuring when all variables are constant
Jul 11, 2019
This comment has been minimized.
This comment has been minimized.
|
Released as 13.0.1 since I think this rule is likely to cause folks a lot of trouble. Specifically, it wanted me to split up this component's props into a const Loader = props => {
let {
center,
class: className,
label = 'Loading',
style,
...rest
} = props
if (center) {
style = {
blah: 1
}
}This is too much work. I'd rather just keep this whole destructing assignment using |
feross
closed this
Jul 11, 2019
feross
added
the
bug
label
Jul 11, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
feross commentedJul 11, 2019
When we added
prefer-const, we kept the default setting which is quite strict when there's a bunch of variables being assigned at once in destructuring. For example, this is considered an error:This is because
bis never mutated. So it wants us to rewrite the code like this:When there are many variables being assigned at once through destructuring, or when variables are being switched from mutated vs. not mutated, this causes a lot of churn. I'd rather err on the side of leniency here and just allow the whole block to be
letif any of the variables are mutated.Only when we can affirmatively say that all variables are
const, should the whole thing be forced to beconst. So, I'll enable the{"destructing": "all"}option. https://eslint.org/docs/rules/prefer-const#destructuringFeedback welcome.