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-vars firing incorrectly on args inside template-tag #2118

Open
davidtaylorhq opened this issue Mar 28, 2024 · 7 comments
Open

no-unused-vars firing incorrectly on args inside template-tag #2118

davidtaylorhq opened this issue Mar 28, 2024 · 7 comments

Comments

@davidtaylorhq
Copy link

davidtaylorhq commented Mar 28, 2024

Given this snippet:

const array = [];

<template>
  {{#each array as |item index|}}
    {{index}}
  {{/each}}
</template>

Eslint will fail with

error  'item' is defined but never used  no-unused-vars

In the same file, I can do someFunction((item, index) => console.log(index)); in regular javascript with no errors about 'item' being unused.

So it seems that the default 'args: after-used' behaviour is not being applied properly inside template tags.

davidtaylorhq added a commit to discourse/discourse-kanban-theme that referenced this issue Mar 28, 2024
@patricklx
Copy link
Contributor

Does _item also get reported as unused?

@davidtaylorhq
Copy link
Author

Underscores don't seem to make any difference out-the-box. Calling it _item, or _ doesn't make any difference

If I configure an eslint argsIgnorePattern, then underscored variables can be ignored:

/*eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]*/

const array = [];

<template>
  {{#each array as |_item index|}}
    {{index}}
  {{/each}}
</template>

^^ this passes ✅

But this argsIgnorePattern is not default eslint behaviour, so I imagine most projects rely on the default 'args: after-used'' behaviour.

@patricklx
Copy link
Contributor

Oh, right.
Does it make a difference of its a gts or gjs file?

@davidtaylorhq
Copy link
Author

Same issue in both gjs and gts 😓

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Mar 28, 2024

Isn't this correct behavior tho?
(Am i missing something? 😅)

@davidtaylorhq
Copy link
Author

davidtaylorhq commented Mar 28, 2024

This fails ❌

<template>
  {{#each array as |item index|}}
    {{index}}
  {{/each}}
</template>

This passes ✅

someFunction((item, index) => console.log(index));

Conceptually, they are the same, so the eslint result should be the same for both examples.

Eslint docs say

unused positional arguments that occur before the last used argument will not be checked, but all named arguments and all positional arguments after the last used argument will be checked.

@NullVoxPopuli
Copy link
Contributor

Ah! Thanks for that clarification! I didn't know they differentiate with prior positionals!

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

No branches or pull requests

3 participants