Rule Change: (Add destructuredArrayIgnorePattern option to no-unused-vars)
See original GitHub issueWhat rule do you want to change?
no-unused-vars
What change to do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new option
Example code
// With the following option set within eslintrc rules
// "no-unused-vars": ["error", { "destructuredArrayIgnorePattern": "^_" }],
const array = ['a', 'b', 'c'];
const [a, _b, c] = array;
const newArray = [a, c];
// No "no-unused-vars" error on _b
What does the rule currently do for this code?
Currently _b
would be seen as an unused variable.
What will the rule do after it’s changed?
The proposed rule would allow a pattern to be set to ignore certain deconstructed array variables from triggering no-unused-vars
.
It would essentially work in the same way as the existing argsIgnorePattern
option for no-unused-vars
.
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
Currently it is possible to avoid the no-unused-vars
error by changing the example code to the following:
const [a, , c] = array;
However in my opinion this doesn’t read as well as either
const [a, _b, c] = array;
or
const [a, _, c] = array;
And so it would be great to have this option.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Top Results From Across the Web
no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, ... The destructuredArrayIgnorePattern option specifies exceptions not to check for usage: ...
Read more >The 3 Best ESLint No-Unused-Vars Option Settings (Make it ...
Allowing unused values when destructuring arrays; Requiring caught errors to be used. All three of these options change the default behavior.
Read more >ESLint - Configuring "no-unused-vars" for TypeScript
VS Code, using eslint, was giving me warnings about unused variables in my type declarations for function callbacks. These options, added to my ......
Read more >no-unused-vars - TypeScript ESLint
Disallow unused variables. ... Examples. This rule extends the base eslint/no-unused-vars rule. It adds support for TypeScript features, such as types.
Read more >7 Recommended ESLint Rules for React TypeScript Project
This is originally from no-unused-vars rule of ESLint. ... option destructuredArrayIgnorePattern are bit case specific rules.
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 Free
Top 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
Okay @snitin315 you’re up.
@snitin315 lets see if @JJPell wants to first.