eslint-plugin-ember
eslint-plugin-ember copied to clipboard
no-unused-vars firing incorrectly on args inside template-tag
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 :x:
<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!