Skip to content

eslint reporting no-unused-vars when variable is declared as @const and used in the key of an #each #8109

@OlsonDev

Description

@OlsonDev

Describe the bug

I'm not sure if this belongs here or on the eslint issues, but I suspect here is more accurate.

I have a generic Grid component that has the ability to have sub-rows within it. I have a piece of logic that looks like:

            {#each _rows as row, i (rowKey(row))}
              {@const _subRows = subRows(row)}
              {@const hasSubRows = row !== _subRows}
              {@const rowspan = hasSubRows ? getCount(_subRows) : null}
              {@const __rows = hasSubRows ? _subRows : [row]}
              {@const keyFunc = hasSubRows ? subRowKey : rowKey}
              {#each __rows as subRow, j (keyFunc(subRow))}
                <tr
                  ...attributes>
                    ...inner HTML content
                </tr>
              {/each}

and eslint is reporting:

  69:23  error  'keyFunc' is assigned a value but never used  no-unused-vars

This will unfortunately prevent our build pipeline from accepting this build. I've tried adding <!-- eslint-disable-next-line no-unused-vars --> before, but that doesn't seem to fix it.

By the way, the code does compile and run perfectly.

Thanks!

Reproduction

Here's a fairly minimal reproduction: REPL -- if the REPL supports eslint, I couldn't figure out how to enable it.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 7.67 GB / 31.73 GB
  Binaries:
    Node: 18.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.46)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    svelte: ^3.53.0 => 3.52.0
    webpack: ^5.75.0 => 5.74.0


### Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions