ember-cli / eslint-plugin-ember

An ESLint plugin that provides set of rules for Ember applications based on commonly known good practices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

davidtaylorhq opened this issue · comments

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.

Does _item also get reported as unused?

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.

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

Same issue in both gjs and gts 😓

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

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.

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