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

Ignore rest siblings for no-unused-vars #213

Merged
merged 4 commits into from
Apr 25, 2022

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 24, 2021

The ignoreRestSiblings rule has been enabled for the no-unused-vars rule and the @typescript-eslint/no-unused-vars rule. This allows the use of unused variables alongside a rest operator. This pattern can be useful for excluding variables from a group that you don't want to use.

This option is already in use in the @metamask/controllers repository.

The `ignoreRestSiblings` rule has been enabled for the `no-unused-vars`
rule [1] and the `@typescript-eslint/no-unused-vars` rule [2]. This
allows the use of unused variables alongside a rest operator. This
pattern can be useful for excluding variables from a group that you
don't want to use.

This option is already in use in the `@metamask/controllers`
repository [3].

[1]: https://eslint.org/docs/rules/no-unused-vars
[2]: /~https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
[3]: /~https://github.com/MetaMask/controllers/blob/8134da08a03fb63b146f8a3cffcb5e78fb70d58b/.eslintrc.js#L40
@Gudahtt Gudahtt requested a review from a team as a code owner September 24, 2021 02:56
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this change. Does this make it possible to do something like this:

const { foo, bar, ...rest } = someObject;

where foo and bar are allowed to be unused? If so then it's not clear to me how this is easier to use or clearer than:

const { _foo, _bar, ...rest } = someObject;

I know you said we are already using this in controllers, but is there an example of this in use?

@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 24, 2021

This is the only use I know of: /~https://github.com/MetaMask/controllers/blob/main/src/network/NetworkController.ts#L291

The alternative you showed would not work because _foo and _bar aren't the properties that we want to exclude. I think this would work though:

const { foo: _foo, bar: _bar, ...rest } = someObject;

So... not terrible 🤔 A bit verbose maybe.

@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 24, 2021

I don't feel strongly either way on this one. The workaround of aliasing the unused vars works for me.

@rekmarks
Copy link
Member

The foo: _foo workaround seems annoying to me, I prefer we enable ignoreRestSiblings.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the NetworkController example again (now available here). For some reason, my brain wasn't connecting the dots when I looked at that initially, but now I understand. This change makes sense to me and I agree with Erik that the workaround seems annoying.

@Gudahtt Gudahtt merged commit 2847ac6 into main Apr 25, 2022
@Gudahtt Gudahtt deleted the add-ignore-rest-siblings-option-to-no-unused-vars-rule branch April 25, 2022 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants