sveltejs / eslint-config

An ESLint config for Svelte
14 stars 11 forks source link

Disallow unused variables #9

Closed ehrencrona closed 3 years ago

ehrencrona commented 3 years ago

Disallow unused variables.

Describe the reason for the rule Unused variables can indicate bugs and dead code.

They should be allowed in function declarations where they can help clarify what parameters are expected. This can be done through

'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }]

There is ~only a single~ no instance in the code where I would say the error is inappropriate ~(in an array destructuring along the lines of const [_, myVar] = array)~ (as antony pointed out below, there are better ways of writing this)

Examples Please include an example of a block of code:

  1. with your suggested rule
  2. without your suggested rule
Screen Shot 2020-10-01 at 11 18 31 AM

Poll

antony commented 3 years ago

Just fyi, in your array example, you don't need to bypass this rule:

const [ , myVar ] = array

is how I do it.

antony commented 3 years ago

Those who voted for allow - since it's a pretty close tie - why did you vote for allow? what use are the unused variables?

dummdidumm commented 3 years ago

I vote for this rule with the given exception. I sometimes find it better to know what the unused variable is in a destructuring.

antony commented 3 years ago

@ehrencrona lets do this thing. Do you have a PR?

ehrencrona commented 3 years ago

I created one. The svelte projects has one warning after this rule is applied; I'll create a PR for that. The sapper project does not have any warnings. I can't find any other projects that use these settings.

benmccann commented 3 years ago

Those are the only two projects to worry about