no-undef: ignorePattern option
See original GitHub issueWith 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:
var [_, x] = [1, 2];
. Not an option if one wants to re-use existing variables in scope.[, 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:
- Created 7 years ago
- Reactions:3
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Sure:
What rule do you want to change?
Add a
ignorePattern
option tono-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:
What does the rule currently do for this code?
What will the rule do after it’s changed?
With
ignorePattern: ^_
, the code would pass.