Support "varsIgnorePattern" on no-redeclare rule
See original GitHub issueESLint version: 3.2.2
The problem
I’m using no-unused-vars
with "varsIgnorePattern": "_+"
in order to allow this syntax (in React):
render() {
const { children, beforeSubmit: _, onSuccess: __, onFailure: ___, ...props } = this.props
return <form {...props} onSubmit={this.submit} onReset={this.reset}>{children}</form>
}
As you see I’m using the ES6 rest parameters syntax to create a shallow copy of the this.props
object while omitting certain properties, so I can use the JSX spread operator to pass them all in one go. This is necessary because React will throw an error when passing non-standard attributes to an HTML element. However, some of these props are not being used in the scope of this function, so ESLint would complain about that. Right now I use the varsIgnorePattern
option on no-unused-vars
to allow any variable that consists of only underscores and assign each of the unused props to _
, __
, ___
etc. As you see this gets ugly. I would rather just alias them all to _
, but I can’t right now because no-redeclare
would complain about that.
Suggestion
I suggest adding support for "varsIgnorePattern"
to no-redeclare
, so it can be configured like this:
"no-redeclare": [2, { "varsIgnorePattern": "_" }],
Background: I also program in Scala, in which it is common to use _
do denote “something is here but I don’t care what it’s called” (among other uses).
I’d be happy to implement this if I know my PR has a chance of being accepted.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:10 (6 by maintainers)
@kaicataldo This should be reopened IMO. @ghengeveld is making an useful enhancement request and even offering to implement, and @platinumazure seems to support this. I personally would love to see this option added.
I think you’re confusing my code for a regular object literal, while what I’m doing is a destructuring assignment. This really is a variable declaration, so no-redeclare is correct. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Assigning_to_new_variable_names