Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unused: option to add matcher to ignore #32

Open
nathanmarks opened this issue Sep 7, 2017 · 3 comments
Open

no-unused: option to add matcher to ignore #32

nathanmarks opened this issue Sep 7, 2017 · 3 comments

Comments

@nathanmarks
Copy link

Just a suggestion... similar to no-unused-variable:

"no-unused": [true, {"ignore-pattern": "^_"}]

This allows you to use things like _ for array destructuring in parameters to skip no-unused for them.

@ajafff
Copy link
Owner

ajafff commented Sep 7, 2017

I thought about allowing underscore prefixed variables in array destructuring (similar to object destructuring).
But in array destructuring you can simply omit the variable completely. That's why I decided not to allow them:

const [_one, two, _three, _four, five] = arr;
console.log(two, five);
// can be simplified to
const [, two, , five] = arr;
console.log(two, five);

I'd like to hear your opinion why this is not the way to go for you.

@whatisaphone
Copy link

I'm interested in this. When I destructure an array I like to name all the values even if I don't use them, for clarity. Example:

function findByKey(haystack: Array<[string, string]>, needle: string) {
  const [_key, value] = haystack.find(([k, _v]) => k === needle);
  return value;
}

A version where you just omit the unused bindings is not as clear:

function findByKey(haystack: Array<[string, string]>, needle: string) {
  const [, value] = haystack.find(([k]) => k === needle);
  return value;
}

Funnily enough, naming-convention can already do this indirectly by setting an unused regex with an underscore, but that feels too rube-goldberg for me to feel okay introducing it at work.

@ajafff
Copy link
Owner

ajafff commented Feb 19, 2019

So the proposal here is to add an option to ignore all underscore-prefixed variables, parameters and destructuring bindings?

IMO that sounds reasonable. If someone wants to contribute, please send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants