Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 895
Benjamin Martinez Avatar asked Sep 07 '19 10:09

Benjamin Martinez


People also ask

What is no unused vars?

This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of the following are true: It is called ( foo() ) or constructed ( new foo() ) It is read ( var bar = foo ) It is passed into a function as an argument ( doSomething(foo) )


1 Answers

Please upgrade the babel-eslint package to version 10.0.3.

This will most likely fix those false-positives where vars are used inside loops and wrongly reported as unused.

like image 62
Andreas Avatar answered Oct 03 '22 17:10

Andreas