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.

no-undef: ignorePattern option

See original GitHub issue

With no-undef: [2] and this code:

var x;
[_, x] = [1, 2];
console.log(x);

one gets

2:2  error  '_' is not defined  no-undef

There are two possible ways for the author to solve this:

  1. var [_, x] = [1, 2];. Not an option if one wants to re-use existing variables in scope.
  2. [, x] = [1, 2];. Arguably ugly.

I think it would be great if no-undef would gain a ignorePattern option for cases like this, similar to the options available in no-unused-vars.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ilyavolodincommented, Mar 25, 2017

I’m not sure why [ , x] = [1, 2] is considered ugly? That seems like a significantly better and much more readable solution then proposed [_, x] with a throw-away variable.

3reactions
silverwindcommented, Mar 25, 2017

Sure:


What rule do you want to change?

Add a ignorePattern option to no-undef, which takes a RegExp pattern for variable names that are ignored by the rule. This is useful for unavoidable “trash” variables like _ during array destructuring, where a pattern ^_ can match them.

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings based on the user’s preference.

How will the change be implemented? (New option, new default behavior, etc.)?

New option.

Please provide some example code that this change will affect:

var x;
[_, x] = [1, 2];
console.log(x);

What does the rule currently do for this code?

2:2  error  '_' is not defined  no-undef

What will the rule do after it’s changed?

With ignorePattern: ^_, the code would pass.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No-undef ignore pattern - eslint
I understand that you want eslint to ignore the app global variable. Did you try /*global app */ ? More info here.
Read more >
Command Line Interface
--ignore-pattern. This option allows you to specify patterns of files to ignore (in addition to those in .eslintignore ). Argument Type ...
Read more >
vue/no-undef-components
ignorePatterns Suppresses all errors if component name matches one or more patterns. ignorePatterns: ['custom(\\-\\w+)+'] ...
Read more >
The first variable in the options of ESLint's max-len setting – iTecNote
Javascript – ESLint's “no-undef” rule is calling the use of Underscore an undefined variable · Javascript – Issues with ESLint “max-len” ignore pattern....
Read more >
Command Line Interface - ESLint - Pluggable ... - GitHub Pages
eslint [options] file.js [file.js] [dir] Basic configuration: -c, ... Disable use of ignore files and patterns --ignore-pattern [String] Pattern of files to ...
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