JoshuaKGoldberg / create-typescript-app

Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 💝
MIT License
621 stars 63 forks source link

🚀 Feature: make no-unused-variables more permissive #1515

Open sys13 opened 1 month ago

sys13 commented 1 month ago

Bug Report Checklist

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

JoshuaKGoldberg commented 1 month ago

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) => ... and function(_, 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?