question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support "varsIgnorePattern" on no-redeclare rule

See original GitHub issue

ESLint 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sleepycatcommented, Oct 2, 2017

@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.

1reaction
ghengeveldcommented, Aug 25, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint - Configuring "no-unused-vars" for TypeScript
Is there any way to configure the no-unused-vars rule to take these two cases into account? I'm not a fan of disabling the...
Read more >
no-redeclare - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint-plugin v6.0.0 - hapi.dev
An ESLint configuration containing hapi style guide rules and config. To use in your project, ... The object supports the following keys.
Read more >
eslint - Slides
rules 1/3 ... { "exceptions": { "VariableDeclarator": true } }], "no-redeclare": 2, ... {"varsIgnorePattern": "waitForFinalEvent"}] */ "use strict"; ...
Read more >
Local Install of ESLint Breaks In-Editor Linting
Removing `parserOptions.project` and the rule that depends on it also made ... this be set as error to help prevent this creeping into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found