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.

Rule Change: (Add destructuredArrayIgnorePattern option to no-unused-vars)

See original GitHub issue

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

github_iconTop GitHub Comments

2reactions
nzakascommented, Feb 26, 2022

Okay @snitin315 you’re up.

1reaction
nzakascommented, Feb 25, 2022

@snitin315 lets see if @JJPell wants to first.

Read more comments on GitHub >

github_iconTop 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 >

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