簡體   English   中英

為什么我在 for...of 循環中收到“no-unused-vars”警告,我該如何解決?

[英]Why am I getting a 'no-unused-vars' warning in a for...of loop and how do I fix it?

我正在開發使用 Create React App 創建的 React 應用程序。 在每個 for...of 循環中,我都會收到這個奇怪的“no-unused-vars”警告,該警告指向我在 for 語句中實例化的變量。

ESLint 告訴我我的變量沒有被使用,但它實際上被使用了。

有沒有其他人收到類似的警告? 這是 ESLint 錯誤還是我在這里做錯了什么?
這不是什么大問題,但很煩人。
謝謝你的幫助。

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

控制台輸出

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

請參閱issue 12117 ,它與特定版本的 ESLint 相關。 您可以將 ESLint 版本恢復到 v6.1.0 以解決此問題。

請將babel-eslint包升級到10.0.3版本。

這很可能會修復那些在循環內使用 var 並錯誤地報告為未使用的誤報。

升級到eslint 6.8.0 和babel-eslint 10.1.0。

這是babel-eslint一個已知問題,與使用的eslint-scope版本有關。 看起來它是從eslint 6.1.0 開始的。

只需將您的軟件包升級到(至少):

"babel-eslint": 10.1.0,
"eslint": 6.8.0

您可以在此處查看 Github 問題:

我能夠通過使用它來修復它。

let track = null;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM