首页 > 解决方案 > Why am I getting a 'no-unused-vars' warning in a for...of loop and how do I fix it?

问题描述

I'm working on a React app created with Create React App. In every for...of loop, I get this weird 'no-unused-vars' warning pointing to the variable I have instantiated in the for statement.

ESLint tells me my variable is not used, but it is actually used.

Does anybody else get a similar warning? Is it an ESLint bug or am I doing something wrong here?
This is not a big issue, but it is annoying.
Thanks for your help.

   for (let track of tracks) {
        let chords = RavelFormatter.splitEntries(track.pitches)
        for (let chord of chords) {
            var n = chord.split(':')
            total += n.length
        }
    }

Console output

  Line 13:  'track' is defined but never used       no-unused-vars
  Line 15:  'chord' is defined but never used       no-unused-vars

标签: javascriptreactjsecmascript-6eslint

解决方案


请将babel-eslint软件包升级到 version 10.0.3

这很可能会修复那些在循环内部使用 var 并错误地报告为未使用的误报。


推荐阅读