๐ Feature: make no-unused-variables more permissive
sys13 opened this issue ยท 2 comments
Bug Report Checklist
- I have pulled the latest
main
branch of the repository. - I have searched for related issues and found none that matched my issue.
Overview
I would suggest the following changes:
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrors: 'all',
ignoreRestSiblings: true,
varsIgnorePattern: '^_',
},
],
This can help in the common React case of const [_, setMyVar] = React.useState()
where you want to do array restructuring but don't want to keep the first argument. The other cases apply to (myVar, ...rest) => ...
and function(_, stuff)
which is useful when composing functions.
Additional Info
No response
Heya thanks for the suggestion @sys13!
const [_, setMyVar] = React.useState()
Is there a reason you don't want to do const [, setMyVar] = React.useState()
?
Also: I'm under the impression it's a bit of an antipattern / discouraged to set up state like this. Most React practices I've seen have encouraged keeping to simple state primitives and not relying on API details like "there's a rerender if I update this never-used state". Is there a reproduction case you can post for why you'd really want this?
The other cases apply to
(myVar, ...rest) => ...
andfunction(_, stuff)
which is useful when composing functions.
Similar question here. My general impression has been that having to declare unused parameters is a symptom of confusing code styles. I worry that this is not a particularly common need - so might not make sense as the default in a general-purpose create-*-app
?
Following up: no comments and I still very much like having all lint failures be the same. Thanks for posting!